From 2e0b45265e2e0c47f29b7ce2d0e5a031d4fc72f4 Mon Sep 17 00:00:00 2001 From: Anna Khmelnitsky Date: Wed, 6 Feb 2019 13:55:27 -0800 Subject: [PATCH] Remove certificate decoding if not needed Python3 errors out otherwise Change-Id: I4826fb493fc808595c15fe7a45f5f03afaef872b --- vmware_nsxlib/v3/trust_management.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vmware_nsxlib/v3/trust_management.py b/vmware_nsxlib/v3/trust_management.py index be6b75dc..172e9439 100644 --- a/vmware_nsxlib/v3/trust_management.py +++ b/vmware_nsxlib/v3/trust_management.py @@ -12,6 +12,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +import six + from vmware_nsxlib.v3 import exceptions as nsxlib_exc from vmware_nsxlib.v3 import utils @@ -82,11 +85,13 @@ class NsxLibTrustManagement(utils.NsxLibApiBase): self.client.delete(resource) def find_cert_and_identity(self, name, cert_pem): - nsx_style_pem = cert_pem certs = self.get_certs() + if not isinstance(cert_pem, six.text_type): + cert_pem = cert_pem.decode('ascii') + cert_ids = [cert['id'] for cert in certs - if cert['pem_encoded'] == nsx_style_pem.decode('ascii')] + if cert['pem_encoded'] == cert_pem] if not cert_ids: raise nsxlib_exc.ResourceNotFound( manager=self.client.nsx_api_managers,