Browse Source

Return VIPs on the clone operation

The test was also fixed and returned to the integrational manner.

Change-Id: Iea2301c95ec84e10cda8e1437f85f10c0c3e5437
Closes-Bug: #1617943
Ilya Kharin 2 years ago
parent
commit
5ead3bf1b7
2 changed files with 25 additions and 17 deletions
  1. 5
    0
      cluster_upgrade/handlers.py
  2. 20
    17
      cluster_upgrade/tests/test_handlers.py

+ 5
- 0
cluster_upgrade/handlers.py View File

@@ -113,6 +113,7 @@ class CopyVIPsHandler(base.BaseHandler):
113 113
 
114 114
     @base.handle_errors
115 115
     @base.validate
116
+    @base.serialize
116 117
     def POST(self, cluster_id):
117 118
         """Copy VIPs from original cluster to new one
118 119
 
@@ -120,6 +121,7 @@ class CopyVIPsHandler(base.BaseHandler):
120 121
         clusters that is created on cluster clone operation
121 122
 
122 123
         :param cluster_id: id of cluster that VIPs must be copied to
124
+        :returns: Collection of JSON-serialised VIPs.
123 125
 
124 126
         :http: * 200 (OK)
125 127
                * 400 (validation failed)
@@ -144,6 +146,9 @@ class CopyVIPsHandler(base.BaseHandler):
144 146
 
145 147
         upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter,
146 148
                                         seed_cluster_adapter)
149
+        cluster_vips = objects.IPAddrCollection.get_vips_by_cluster_id(
150
+            cluster.id)
151
+        return objects.IPAddrCollection.to_list(cluster_vips)
147 152
 
148 153
 
149 154
 class CreateUpgradeReleaseHandler(base.BaseHandler):

+ 20
- 17
cluster_upgrade/tests/test_handlers.py View File

@@ -23,6 +23,7 @@ from nailgun.test import base
23 23
 from nailgun.utils import reverse
24 24
 
25 25
 from . import base as tests_base
26
+from ..objects import adapters
26 27
 
27 28
 
28 29
 class TestClusterUpgradeCloneHandler(tests_base.BaseCloneClusterTest):
@@ -224,29 +225,31 @@ class TestNodeReassignHandler(base.BaseIntegrationTest):
224 225
         self.assertEqual(400, resp.status_code)
225 226
 
226 227
 
227
-class TestCopyVipsHandler(base.BaseIntegrationTest):
228
+class TestCopyVipsHandler(tests_base.BaseCloneClusterTest):
229
+    def test_copy_vips(self):
230
+        node_db = self.env.create_node(cluster_id=self.src_cluster.id,
231
+                                       roles=["controller"])
232
+        node = adapters.NailgunNodeAdapter(node_db)
228 233
 
229
-    def test_copy_vips_called(self):
230
-        from ..objects import relations
234
+        src_net_manager = self.src_cluster.get_network_manager()
235
+        orig_vips = src_net_manager.assign_vips_for_net_groups()
231 236
 
232
-        orig_cluster = self.env.create_cluster(api=False)
233
-        new_cluster = self.env.create_cluster(api=False)
237
+        new_cluster = self.helper.clone_cluster(self.src_cluster, self.data)
238
+        self.helper.assign_node_to_cluster(node, new_cluster, node.roles, [])
234 239
 
235
-        relations.UpgradeRelationObject.create_relation(
236
-            orig_cluster.id, new_cluster.id)
240
+        resp = self.app.post(
241
+            reverse(
242
+                'CopyVIPsHandler',
243
+                kwargs={'cluster_id': new_cluster.id}
244
+            ),
245
+            headers=self.default_headers,
246
+        )
237 247
 
238
-        with mock.patch('cluster_upgrade.handlers'
239
-                        '.upgrade.UpgradeHelper.copy_vips') as copy_vips_mc:
240
-            resp = self.app.post(
241
-                reverse(
242
-                    'CopyVIPsHandler',
243
-                    kwargs={'cluster_id': new_cluster.id}
244
-                ),
245
-                headers=self.default_headers,
246
-            )
248
+        orig_vips_addrs = set(orig_vips.values())
249
+        new_vips_addrs = {vip["ip_addr"] for vip in resp.json_body}
247 250
 
248 251
         self.assertEqual(resp.status_code, 200)
249
-        self.assertTrue(copy_vips_mc.called)
252
+        self.assertEqual(orig_vips_addrs, new_vips_addrs)
250 253
 
251 254
 
252 255
 class TestCreateUpgradeReleaseHandler(base.BaseIntegrationTest):

Loading…
Cancel
Save