Browse Source

Fixes in CreateUpgradeReleaseHandler

* add deployment_tasks in clone release
* fix typo
* copy net_roles_metadata on src releases

Change-Id: Ia3b29f3f6d36442d5980e9fdff951bfcc3ad814f
Closes-bug: 1617247
Sergey Abramov 2 years ago
parent
commit
8147718cf7
2 changed files with 26 additions and 7 deletions
  1. 10
    7
      cluster_upgrade/handlers.py
  2. 16
    0
      cluster_upgrade/tests/test_handlers.py

+ 10
- 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
@@ -152,13 +153,14 @@ class CreateUpgradeReleaseHandler(base.BaseHandler):
152 153
 
153 154
         Overwrite base default_mapping by orig default_maping values.
154 155
         """
156
+        base_nets = copy.deepcopy(base_nets)
157
+        orig_nets = copy.deepcopy(orig_nets)
155 158
         orig_network_dict = {n['id']: n for n in orig_nets}
156 159
         for base_net in base_nets:
157 160
             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
161
+            if orig_net is not None:
162
+                base_net['default_mapping'] = orig_net['default_mapping']
163
+        return base_nets
162 164
 
163 165
     @base.serialize
164 166
     def POST(self, cluster_id, release_id):
@@ -174,14 +176,15 @@ class CreateUpgradeReleaseHandler(base.BaseHandler):
174 176
         base_release = self.get_object_or_404(objects.Release, release_id)
175 177
         orig_cluster = self.get_object_or_404(objects.Cluster, cluster_id)
176 178
         orig_release = orig_cluster.release
177
-
178 179
         network_metadata = self.merge_network_roles(
179 180
             base_release.network_roles_metadata,
180 181
             orig_release.network_roles_metadata)
181
-        data = objects.Release.to_dict(base_release)
182
+        data = dict(base_release)
182 183
         data['network_roles_metadata'] = network_metadata
183 184
         data['name'] = '{0} Upgrade ({1})'.format(
184 185
             base_release.name, orig_release.id)
186
+        deployment_tasks = objects.Release.get_deployment_tasks(base_release)
187
+        data['deployment_tasks'] = deployment_tasks
185 188
         del data['id']
186 189
         new_release = objects.Release.create(data)
187
-        return new_release.to_dict()
190
+        return objects.Release.to_dict(new_release)

+ 16
- 0
cluster_upgrade/tests/test_handlers.py View File

@@ -247,3 +247,19 @@ class TestCopyVipsHandler(base.BaseIntegrationTest):
247 247
 
248 248
         self.assertEqual(resp.status_code, 200)
249 249
         self.assertTrue(copy_vips_mc.called)
250
+
251
+
252
+class TestCreateUpgradeReleaseHandler(base.BaseIntegrationTest):
253
+
254
+    def test_clone_release(self):
255
+        new_cluster = self.env.create_cluster(api=False)
256
+        release = self.env.create_release(
257
+            operating_system=consts.RELEASE_OS.ubuntu, version="new_version")
258
+        uri = reverse(
259
+            'CreateUpgradeReleaseHandler',
260
+            kwargs={'cluster_id': new_cluster.id, 'release_id': release.id})
261
+        resp = self.app.post(uri, headers=self.default_headers)
262
+        self.assertEqual(resp.status_code, 200)
263
+        self.assertEqual(
264
+            '{0} Upgrade ({1})'.format(release.name, new_cluster.release.id),
265
+            resp.json_body['name'])

Loading…
Cancel
Save