Browse Source

Merge "Fix incorrect usage of CertManager in k8s_api"

tags/1.0.0.0b1^0
Jenkins 3 years ago
parent
commit
d59d4c2465
2 changed files with 11 additions and 9 deletions
  1. 6
    6
      magnum/conductor/k8s_api.py
  2. 5
    3
      magnum/tests/unit/conductor/test_k8s_api.py

+ 6
- 6
magnum/conductor/k8s_api.py View File

@@ -67,12 +67,12 @@ class K8sAPI(apiv_api.ApivApi):
67 67
         :param bay: Bay object
68 68
         """
69 69
         magnum_cert_obj = cert_manager.get_backend().CertManager.get_cert(
70
-            bay.magnum_cert_ref)
70
+            bay.magnum_cert_ref, resource_ref=bay.uuid)
71 71
         self.cert_file = self._create_temp_file_with_content(
72
-            magnum_cert_obj.certificate)
72
+            magnum_cert_obj.get_certificate())
73 73
         private_key = serialization.load_pem_private_key(
74
-            magnum_cert_obj.private_key,
75
-            password=magnum_cert_obj.private_key_passphrase,
74
+            magnum_cert_obj.get_private_key(),
75
+            password=magnum_cert_obj.get_private_key_passphrase(),
76 76
             backend=default_backend(),
77 77
         )
78 78
         private_key = private_key.private_bytes(
@@ -82,9 +82,9 @@ class K8sAPI(apiv_api.ApivApi):
82 82
         self.key_file = self._create_temp_file_with_content(
83 83
             private_key)
84 84
         ca_cert_obj = cert_manager.get_backend().CertManager.get_cert(
85
-            bay.ca_cert_ref)
85
+            bay.ca_cert_ref, resource_ref=bay.uuid)
86 86
         self.ca_file = self._create_temp_file_with_content(
87
-            ca_cert_obj.certificate)
87
+            ca_cert_obj.get_certificate())
88 88
 
89 89
     def __del__(self):
90 90
         if self.ca_file:

+ 5
- 3
magnum/tests/unit/conductor/test_k8s_api.py View File

@@ -45,10 +45,12 @@ class TestK8sAPI(base.TestCase):
45 45
     def _mock_named_file_creation(self, content):
46 46
         return TestK8sAPI.file_dict[content]
47 47
 
48
-    def _mock_cert_mgr_get_cert(self, cert_ref):
48
+    def _mock_cert_mgr_get_cert(self, cert_ref, **kwargs):
49 49
         cert_obj = mock.MagicMock()
50
-        cert_obj.certificate = TestK8sAPI.content_dict[cert_ref]['certificate']
51
-        cert_obj.private_key = TestK8sAPI.content_dict[cert_ref]['private_key']
50
+        cert_obj.get_certificate.return_value = (
51
+            TestK8sAPI.content_dict[cert_ref]['certificate'])
52
+        cert_obj.get_private_key.return_value = (
53
+            TestK8sAPI.content_dict[cert_ref]['private_key'])
52 54
         return cert_obj
53 55
 
54 56
     @patch('magnum.conductor.k8s_api.serialization.load_pem_private_key')

Loading…
Cancel
Save