summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Kharin <akscram@gmail.com>2016-08-29 23:39:58 +0300
committerIlya Kharin <akscram@gmail.com>2016-08-29 23:41:29 +0300
commite4d4a0b4b47202ffba3d0d1703dfc536f3a26fda (patch)
treef1db9ac408d8200ccda07157108803ec7b689c54
parent40dd411fe461441e943de806f5de632eeb64dc4a (diff)
parent5ead3bf1b7957c3e3d9e42be6a31e82ea4e17cfc (diff)
Merge branch master into stable/mitaka
Notes
Notes (review): Code-Review+2: Sergey Abramov <sabramov@mirantis.com> Code-Review+2: Yuriy Taraday <yorik.sar@gmail.com> Workflow+1: Yuriy Taraday <yorik.sar@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 30 Aug 2016 09:03:45 +0000 Reviewed-on: https://review.openstack.org/362431 Project: openstack/fuel-nailgun-extension-cluster-upgrade Branch: refs/heads/stable/mitaka
-rw-r--r--cluster_upgrade/handlers.py22
-rw-r--r--cluster_upgrade/tests/test_handlers.py53
2 files changed, 51 insertions, 24 deletions
diff --git a/cluster_upgrade/handlers.py b/cluster_upgrade/handlers.py
index d4b7f71..4e7f96d 100644
--- a/cluster_upgrade/handlers.py
+++ b/cluster_upgrade/handlers.py
@@ -14,6 +14,7 @@
14# License for the specific language governing permissions and limitations 14# License for the specific language governing permissions and limitations
15# under the License. 15# under the License.
16 16
17import copy
17import six 18import six
18 19
19from nailgun.api.v1.handlers import base 20from nailgun.api.v1.handlers import base
@@ -112,6 +113,7 @@ class CopyVIPsHandler(base.BaseHandler):
112 113
113 @base.handle_errors 114 @base.handle_errors
114 @base.validate 115 @base.validate
116 @base.serialize
115 def POST(self, cluster_id): 117 def POST(self, cluster_id):
116 """Copy VIPs from original cluster to new one 118 """Copy VIPs from original cluster to new one
117 119
@@ -119,6 +121,7 @@ class CopyVIPsHandler(base.BaseHandler):
119 clusters that is created on cluster clone operation 121 clusters that is created on cluster clone operation
120 122
121 :param cluster_id: id of cluster that VIPs must be copied to 123 :param cluster_id: id of cluster that VIPs must be copied to
124 :returns: Collection of JSON-serialised VIPs.
122 125
123 :http: * 200 (OK) 126 :http: * 200 (OK)
124 * 400 (validation failed) 127 * 400 (validation failed)
@@ -143,6 +146,9 @@ class CopyVIPsHandler(base.BaseHandler):
143 146
144 upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter, 147 upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter,
145 seed_cluster_adapter) 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
148class CreateUpgradeReleaseHandler(base.BaseHandler): 154class CreateUpgradeReleaseHandler(base.BaseHandler):
@@ -152,13 +158,14 @@ class CreateUpgradeReleaseHandler(base.BaseHandler):
152 158
153 Overwrite base default_mapping by orig default_maping values. 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 orig_network_dict = {n['id']: n for n in orig_nets} 163 orig_network_dict = {n['id']: n for n in orig_nets}
156 for base_net in base_nets: 164 for base_net in base_nets:
157 orig_net = orig_network_dict.get(base_net['id']) 165 orig_net = orig_network_dict.get(base_net['id'])
158 if orig_net is None: 166 if orig_net is not None:
159 orig_net = base_net 167 base_net['default_mapping'] = orig_net['default_mapping']
160 base_net['default_mapping'] = orig_net['default_mapping'] 168 return base_nets
161 return base_net
162 169
163 @base.serialize 170 @base.serialize
164 def POST(self, cluster_id, release_id): 171 def POST(self, cluster_id, release_id):
@@ -174,14 +181,15 @@ class CreateUpgradeReleaseHandler(base.BaseHandler):
174 base_release = self.get_object_or_404(objects.Release, release_id) 181 base_release = self.get_object_or_404(objects.Release, release_id)
175 orig_cluster = self.get_object_or_404(objects.Cluster, cluster_id) 182 orig_cluster = self.get_object_or_404(objects.Cluster, cluster_id)
176 orig_release = orig_cluster.release 183 orig_release = orig_cluster.release
177
178 network_metadata = self.merge_network_roles( 184 network_metadata = self.merge_network_roles(
179 base_release.network_roles_metadata, 185 base_release.network_roles_metadata,
180 orig_release.network_roles_metadata) 186 orig_release.network_roles_metadata)
181 data = objects.Release.to_dict(base_release) 187 data = dict(base_release)
182 data['network_roles_metadata'] = network_metadata 188 data['network_roles_metadata'] = network_metadata
183 data['name'] = '{0} Upgrade ({1})'.format( 189 data['name'] = '{0} Upgrade ({1})'.format(
184 base_release.name, orig_release.id) 190 base_release.name, orig_release.id)
191 deployment_tasks = objects.Release.get_deployment_tasks(base_release)
192 data['deployment_tasks'] = deployment_tasks
185 del data['id'] 193 del data['id']
186 new_release = objects.Release.create(data) 194 new_release = objects.Release.create(data)
187 return new_release.to_dict() 195 return objects.Release.to_dict(new_release)
diff --git a/cluster_upgrade/tests/test_handlers.py b/cluster_upgrade/tests/test_handlers.py
index ad7239a..6e4382d 100644
--- a/cluster_upgrade/tests/test_handlers.py
+++ b/cluster_upgrade/tests/test_handlers.py
@@ -23,6 +23,7 @@ from nailgun.test import base
23from nailgun.utils import reverse 23from nailgun.utils import reverse
24 24
25from . import base as tests_base 25from . import base as tests_base
26from ..objects import adapters
26 27
27 28
28class TestClusterUpgradeCloneHandler(tests_base.BaseCloneClusterTest): 29class TestClusterUpgradeCloneHandler(tests_base.BaseCloneClusterTest):
@@ -224,26 +225,44 @@ class TestNodeReassignHandler(base.BaseIntegrationTest):
224 self.assertEqual(400, resp.status_code) 225 self.assertEqual(400, resp.status_code)
225 226
226 227
227class TestCopyVipsHandler(base.BaseIntegrationTest): 228class 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): 234 src_net_manager = self.src_cluster.get_network_manager()
230 from ..objects import relations 235 orig_vips = src_net_manager.assign_vips_for_net_groups()
231 236
232 orig_cluster = self.env.create_cluster(api=False) 237 new_cluster = self.helper.clone_cluster(self.src_cluster, self.data)
233 new_cluster = self.env.create_cluster(api=False) 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( 248 orig_vips_addrs = set(orig_vips.values())
236 orig_cluster.id, new_cluster.id) 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
255class 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 self.assertEqual(resp.status_code, 200) 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'])