Return VIPs on the clone operation

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

Change-Id: Iea2301c95ec84e10cda8e1437f85f10c0c3e5437
Closes-Bug: #1617943
This commit is contained in:
Ilya Kharin 2016-08-28 15:14:12 +03:00
parent 8147718cf7
commit 5ead3bf1b7
2 changed files with 25 additions and 17 deletions

View File

@ -113,6 +113,7 @@ class CopyVIPsHandler(base.BaseHandler):
@base.handle_errors
@base.validate
@base.serialize
def POST(self, cluster_id):
"""Copy VIPs from original cluster to new one
@ -120,6 +121,7 @@ class CopyVIPsHandler(base.BaseHandler):
clusters that is created on cluster clone operation
:param cluster_id: id of cluster that VIPs must be copied to
:returns: Collection of JSON-serialised VIPs.
:http: * 200 (OK)
* 400 (validation failed)
@ -144,6 +146,9 @@ class CopyVIPsHandler(base.BaseHandler):
upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter,
seed_cluster_adapter)
cluster_vips = objects.IPAddrCollection.get_vips_by_cluster_id(
cluster.id)
return objects.IPAddrCollection.to_list(cluster_vips)
class CreateUpgradeReleaseHandler(base.BaseHandler):

View File

@ -23,6 +23,7 @@ from nailgun.test import base
from nailgun.utils import reverse
from . import base as tests_base
from ..objects import adapters
class TestClusterUpgradeCloneHandler(tests_base.BaseCloneClusterTest):
@ -224,29 +225,31 @@ class TestNodeReassignHandler(base.BaseIntegrationTest):
self.assertEqual(400, resp.status_code)
class TestCopyVipsHandler(base.BaseIntegrationTest):
class TestCopyVipsHandler(tests_base.BaseCloneClusterTest):
def test_copy_vips(self):
node_db = self.env.create_node(cluster_id=self.src_cluster.id,
roles=["controller"])
node = adapters.NailgunNodeAdapter(node_db)
def test_copy_vips_called(self):
from ..objects import relations
src_net_manager = self.src_cluster.get_network_manager()
orig_vips = src_net_manager.assign_vips_for_net_groups()
orig_cluster = self.env.create_cluster(api=False)
new_cluster = self.env.create_cluster(api=False)
new_cluster = self.helper.clone_cluster(self.src_cluster, self.data)
self.helper.assign_node_to_cluster(node, new_cluster, node.roles, [])
relations.UpgradeRelationObject.create_relation(
orig_cluster.id, new_cluster.id)
resp = self.app.post(
reverse(
'CopyVIPsHandler',
kwargs={'cluster_id': new_cluster.id}
),
headers=self.default_headers,
)
with mock.patch('cluster_upgrade.handlers'
'.upgrade.UpgradeHelper.copy_vips') as copy_vips_mc:
resp = self.app.post(
reverse(
'CopyVIPsHandler',
kwargs={'cluster_id': new_cluster.id}
),
headers=self.default_headers,
)
orig_vips_addrs = set(orig_vips.values())
new_vips_addrs = {vip["ip_addr"] for vip in resp.json_body}
self.assertEqual(resp.status_code, 200)
self.assertTrue(copy_vips_mc.called)
self.assertEqual(orig_vips_addrs, new_vips_addrs)
class TestCreateUpgradeReleaseHandler(base.BaseIntegrationTest):