Browse Source

Merge branch master into stable/mitaka

Change-Id: Ie7b982cac3fa19a431f0368c933cd6dd0877e256
Ilya Kharin 2 years ago
parent
commit
e4d4a0b4b4
2 changed files with 51 additions and 24 deletions
  1. 15
    7
      cluster_upgrade/handlers.py
  2. 36
    17
      cluster_upgrade/tests/test_handlers.py

+ 15
- 7
cluster_upgrade/handlers.py View File

@@ -14,6 +14,7 @@
14 14
 #    License for the specific language governing permissions and limitations
15 15
 #    under the License.
16 16
 
17
+import copy
17 18
 import six
18 19
 
19 20
 from nailgun.api.v1.handlers import base
@@ -112,6 +113,7 @@ class CopyVIPsHandler(base.BaseHandler):
112 113
 
113 114
     @base.handle_errors
114 115
     @base.validate
116
+    @base.serialize
115 117
     def POST(self, cluster_id):
116 118
         """Copy VIPs from original cluster to new one
117 119
 
@@ -119,6 +121,7 @@ class CopyVIPsHandler(base.BaseHandler):
119 121
         clusters that is created on cluster clone operation
120 122
 
121 123
         :param cluster_id: id of cluster that VIPs must be copied to
124
+        :returns: Collection of JSON-serialised VIPs.
122 125
 
123 126
         :http: * 200 (OK)
124 127
                * 400 (validation failed)
@@ -143,6 +146,9 @@ class CopyVIPsHandler(base.BaseHandler):
143 146
 
144 147
         upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter,
145 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)
146 152
 
147 153
 
148 154
 class CreateUpgradeReleaseHandler(base.BaseHandler):
@@ -152,13 +158,14 @@ class CreateUpgradeReleaseHandler(base.BaseHandler):
152 158
 
153 159
         Overwrite base default_mapping by orig default_maping values.
154 160
         """
161
+        base_nets = copy.deepcopy(base_nets)
162
+        orig_nets = copy.deepcopy(orig_nets)
155 163
         orig_network_dict = {n['id']: n for n in orig_nets}
156 164
         for base_net in base_nets:
157 165
             orig_net = orig_network_dict.get(base_net['id'])
158
-            if orig_net is None:
159
-                orig_net = base_net
160
-            base_net['default_mapping'] = orig_net['default_mapping']
161
-        return base_net
166
+            if orig_net is not None:
167
+                base_net['default_mapping'] = orig_net['default_mapping']
168
+        return base_nets
162 169
 
163 170
     @base.serialize
164 171
     def POST(self, cluster_id, release_id):
@@ -174,14 +181,15 @@ class CreateUpgradeReleaseHandler(base.BaseHandler):
174 181
         base_release = self.get_object_or_404(objects.Release, release_id)
175 182
         orig_cluster = self.get_object_or_404(objects.Cluster, cluster_id)
176 183
         orig_release = orig_cluster.release
177
-
178 184
         network_metadata = self.merge_network_roles(
179 185
             base_release.network_roles_metadata,
180 186
             orig_release.network_roles_metadata)
181
-        data = objects.Release.to_dict(base_release)
187
+        data = dict(base_release)
182 188
         data['network_roles_metadata'] = network_metadata
183 189
         data['name'] = '{0} Upgrade ({1})'.format(
184 190
             base_release.name, orig_release.id)
191
+        deployment_tasks = objects.Release.get_deployment_tasks(base_release)
192
+        data['deployment_tasks'] = deployment_tasks
185 193
         del data['id']
186 194
         new_release = objects.Release.create(data)
187
-        return new_release.to_dict()
195
+        return objects.Release.to_dict(new_release)

+ 36
- 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,26 +225,44 @@ 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, [])
239
+
240
+        resp = self.app.post(
241
+            reverse(
242
+                'CopyVIPsHandler',
243
+                kwargs={'cluster_id': new_cluster.id}
244
+            ),
245
+            headers=self.default_headers,
246
+        )
234 247
 
235
-        relations.UpgradeRelationObject.create_relation(
236
-            orig_cluster.id, new_cluster.id)
248
+        orig_vips_addrs = set(orig_vips.values())
249
+        new_vips_addrs = {vip["ip_addr"] for vip in resp.json_body}
250
+
251
+        self.assertEqual(resp.status_code, 200)
252
+        self.assertEqual(orig_vips_addrs, new_vips_addrs)
237 253
 
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
-            )
247 254
 
255
+class TestCreateUpgradeReleaseHandler(base.BaseIntegrationTest):
256
+
257
+    def test_clone_release(self):
258
+        new_cluster = self.env.create_cluster(api=False)
259
+        release = self.env.create_release(
260
+            operating_system=consts.RELEASE_OS.ubuntu, version="new_version")
261
+        uri = reverse(
262
+            'CreateUpgradeReleaseHandler',
263
+            kwargs={'cluster_id': new_cluster.id, 'release_id': release.id})
264
+        resp = self.app.post(uri, headers=self.default_headers)
248 265
         self.assertEqual(resp.status_code, 200)
249
-        self.assertTrue(copy_vips_mc.called)
266
+        self.assertEqual(
267
+            '{0} Upgrade ({1})'.format(release.name, new_cluster.release.id),
268
+            resp.json_body['name'])

Loading…
Cancel
Save