Add new certificate api find_cert_with_pem
and fix policy certificate resource type Change-Id: I0b87ea9b6563ef6d046659ff12015db1eba42283
This commit is contained in:
parent
5b29902ae9
commit
980da1ddd4
|
@ -6086,6 +6086,22 @@ class TestPolicyCertificate(NsxPolicyLibTestCase):
|
|||
sleep=0.1, tenant=TEST_TENANT)
|
||||
self.assertEqual(info, actual_info)
|
||||
|
||||
def test_find_cert_with_pem(self):
|
||||
id1 = '1'
|
||||
id2 = '2'
|
||||
pem1 = '111'
|
||||
pem2 = '222'
|
||||
with mock.patch.object(self.policy_api, "list",
|
||||
return_value={'results': [
|
||||
{'id': id1, 'pem_encoded': pem1},
|
||||
{'id': id2, 'pem_encoded': pem2}]}) as api:
|
||||
cert_ids = self.resourceApi.find_cert_with_pem(
|
||||
pem1, tenant=TEST_TENANT)
|
||||
self.assertEqual(1, len(cert_ids))
|
||||
self.assertEqual(id1, cert_ids[0])
|
||||
expected_def = core_defs.CertificateDef(tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api, expected_def)
|
||||
|
||||
|
||||
class TestPolicyExcludeList(NsxPolicyLibTestCase):
|
||||
|
||||
|
|
|
@ -2384,7 +2384,7 @@ class CertificateDef(ResourceDef):
|
|||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return "TlsTrustData"
|
||||
return "TlsCertificate"
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(CertificateDef, self).get_obj_dict()
|
||||
|
|
|
@ -4487,6 +4487,14 @@ class NsxPolicyCertApi(NsxPolicyResourceBase):
|
|||
certificate_def = self.entry_def(tenant=tenant)
|
||||
return self._list(certificate_def)
|
||||
|
||||
def find_cert_with_pem(self, cert_pem,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
# Find certificate with cert_pem
|
||||
certs = self.list(tenant=tenant)
|
||||
cert_ids = [cert['id'] for cert in certs
|
||||
if cert['pem_encoded'] == cert_pem]
|
||||
return cert_ids
|
||||
|
||||
def update(self, certificate_id, name=IGNORE,
|
||||
pem_encoded=IGNORE, private_key=IGNORE,
|
||||
passphrase=IGNORE, key_algo=IGNORE, description=IGNORE,
|
||||
|
|
Loading…
Reference in New Issue