Set vip_namespace when migrating vips from 6.x

Change-Id: I7d76f7984a1870c070126b0ccde160f320576cf3
This commit is contained in:
Dmitry Nikishov 2016-12-07 11:45:57 +04:00
parent 89839b88c3
commit 36f3d95a47
2 changed files with 28 additions and 12 deletions

View File

@ -252,33 +252,36 @@ class TestClusterTransformers(nailgun_test_base.BaseUnitTest):
class TestVipTransformers(nailgun_test_base.BaseUnitTest):
def setUp(self):
ip = '0.0.0.0'
vip_dict = {'ip_addr': '0.0.0.0'}
self.data = {
1: {
'haproxy': ip,
'vrouter': ip,
'test': ip,
'haproxy': dict(vip_dict),
'vrouter': dict(vip_dict),
'test': dict(vip_dict),
},
2: {
'haproxy': ip,
'vrouter': ip,
'test': ip,
'haproxy': dict(vip_dict),
'vrouter': dict(vip_dict),
'test': dict(vip_dict),
}
}
self.mapping = {1: 'management', 2: 'public'}
def test_vip_transform(self):
ip = '0.0.0.0'
new_haproxy_vip_dict = {'ip_addr': '0.0.0.0',
'vip_namespace': 'haproxy'}
new_vrouter_vip_dict = {'ip_addr': '0.0.0.0',
'vip_namespace': 'vrouter'}
data = vip.transform_vips((self.data, self.mapping))
self.assertEqual(
data, ({
1: {
'management': ip,
'vrouter': ip,
'management': new_haproxy_vip_dict,
'vrouter': new_vrouter_vip_dict,
},
2: {
'public': ip,
'vrouter_pub': ip,
'public': new_haproxy_vip_dict,
'vrouter_pub': new_vrouter_vip_dict,
}}, {1: 'management', 2: 'public'})
)

View File

@ -41,6 +41,12 @@ def transform_vips(data):
"vrouter": "vrouter_pub",
},
}
vip_ns_rules = {
"vrouter": "vrouter",
"vrouter_pub": "vrouter",
"public": "haproxy",
"management": "haproxy",
}
renamed_vips = collections.defaultdict(dict)
vips, id_name_mapping = data
for ng_id, vips_obj in vips.items():
@ -50,6 +56,13 @@ def transform_vips(data):
continue
new_vip_name = ng_vip_rules[vip_name]
# When migrating from 6.x, vip_namespace key is not set for
# public/management vips
if not vip_addr.get('vip_namespace', None) and \
new_vip_name in vip_ns_rules:
vip_ns = vip_ns_rules[new_vip_name]
vip_addr['vip_namespace'] = vip_ns
renamed_vips[ng_id][new_vip_name] = vip_addr
return renamed_vips, id_name_mapping