Fix stack-update for OS::Nova::Server resource
This fixes stack-update for `OS::Nova::Server` resource, when network name rather than network id is used. Change-Id: I484f7f8890485eca42eaa31e034f6d19b369c72a Closes-Bug: #1439071
This commit is contained in:
parent
a1f74de009
commit
d213a2414e
@ -929,20 +929,34 @@ class Server(stack_user.StackUser):
|
|||||||
old_networks.remove(net)
|
old_networks.remove(net)
|
||||||
return not_updated_networks
|
return not_updated_networks
|
||||||
|
|
||||||
|
def _get_network_id(self, net):
|
||||||
|
net_id = None
|
||||||
|
if net.get(self.NETWORK_ID):
|
||||||
|
if self.is_using_neutron():
|
||||||
|
net_id = self.client_plugin(
|
||||||
|
'neutron').resolve_network(
|
||||||
|
net,
|
||||||
|
self.NETWORK_ID, self.NETWORK_UUID)
|
||||||
|
else:
|
||||||
|
net_id = self.client_plugin(
|
||||||
|
'nova').get_nova_network_id(net.get(self.NETWORK_ID))
|
||||||
|
return net_id
|
||||||
|
|
||||||
def update_networks_matching_iface_port(self, nets, interfaces):
|
def update_networks_matching_iface_port(self, nets, interfaces):
|
||||||
|
|
||||||
def find_equal(port, net_id, ip, nets):
|
def find_equal(port, net_id, ip, nets):
|
||||||
for net in nets:
|
for net in nets:
|
||||||
|
|
||||||
if (net.get('port') == port or
|
if (net.get('port') == port or
|
||||||
(net.get('fixed_ip') == ip and
|
(net.get('fixed_ip') == ip and
|
||||||
(net.get('network') == net_id or
|
(self._get_network_id(net) == net_id or
|
||||||
net.get('uuid') == net_id))):
|
net.get('uuid') == net_id))):
|
||||||
return net
|
return net
|
||||||
|
|
||||||
def find_poor_net(net_id, nets):
|
def find_poor_net(net_id, nets):
|
||||||
for net in nets:
|
for net in nets:
|
||||||
if (not net.get('port') and not net.get('fixed_ip') and
|
if (not net.get('port') and not net.get('fixed_ip') and
|
||||||
(net.get('network') == net_id or
|
(self._get_network_id(net) == net_id or
|
||||||
net.get('uuid') == net_id)):
|
net.get('uuid') == net_id)):
|
||||||
return net
|
return net
|
||||||
|
|
||||||
@ -1035,21 +1049,23 @@ class Server(stack_user.StackUser):
|
|||||||
# according to nova interface-detach command detached port
|
# according to nova interface-detach command detached port
|
||||||
# will be deleted
|
# will be deleted
|
||||||
for net in old_networks:
|
for net in old_networks:
|
||||||
|
if net.get(self.NETWORK_PORT):
|
||||||
checker = scheduler.TaskRunner(server.interface_detach,
|
checker = scheduler.TaskRunner(server.interface_detach,
|
||||||
net.get('port'))
|
net.get(self.NETWORK_PORT))
|
||||||
checkers.append(checker)
|
checkers.append(checker)
|
||||||
|
|
||||||
# attach section similar for both variants that
|
# attach section similar for both variants that
|
||||||
# were mentioned above
|
# were mentioned above
|
||||||
|
|
||||||
for net in new_networks:
|
for net in new_networks:
|
||||||
if net.get('port'):
|
if net.get(self.NETWORK_PORT):
|
||||||
checker = scheduler.TaskRunner(server.interface_attach,
|
checker = scheduler.TaskRunner(server.interface_attach,
|
||||||
net['port'], None, None)
|
net.get(self.NETWORK_PORT),
|
||||||
|
None, None)
|
||||||
checkers.append(checker)
|
checkers.append(checker)
|
||||||
elif net.get('network'):
|
elif net.get(self.NETWORK_ID):
|
||||||
checker = scheduler.TaskRunner(server.interface_attach,
|
checker = scheduler.TaskRunner(server.interface_attach,
|
||||||
None, net['network'],
|
None, self._get_network_id(net),
|
||||||
net.get('fixed_ip'))
|
net.get('fixed_ip'))
|
||||||
checkers.append(checker)
|
checkers.append(checker)
|
||||||
|
|
||||||
|
@ -2480,6 +2480,56 @@ class ServersTest(common.HeatTestCase):
|
|||||||
|
|
||||||
return fake_interface(port, net, ip)
|
return fake_interface(port, net, ip)
|
||||||
|
|
||||||
|
def test_get_network_id_neutron(self):
|
||||||
|
return_server = self.fc.servers.list()[3]
|
||||||
|
server = self._create_test_server(return_server, 'networks_update')
|
||||||
|
|
||||||
|
self.patchobject(server, 'is_using_neutron', return_value=True)
|
||||||
|
|
||||||
|
net = {'port': '2a60cbaa-3d33-4af6-a9ce-83594ac546fc'}
|
||||||
|
net_id = server._get_network_id(net)
|
||||||
|
self.assertEqual(None, net_id)
|
||||||
|
|
||||||
|
net = {'network': 'f3ef5d2f-d7ba-4b27-af66-58ca0b81e032',
|
||||||
|
'fixed_ip': '1.2.3.4'}
|
||||||
|
self.patchobject(neutron.NeutronClientPlugin, 'resolve_network',
|
||||||
|
return_value='f3ef5d2f-d7ba-4b27-af66-58ca0b81e032')
|
||||||
|
net_id = server._get_network_id(net)
|
||||||
|
self.assertEqual('f3ef5d2f-d7ba-4b27-af66-58ca0b81e032', net_id)
|
||||||
|
|
||||||
|
net = {'network': 'private_net',
|
||||||
|
'fixed_ip': '1.2.3.4'}
|
||||||
|
self.patchobject(neutron.NeutronClientPlugin, 'resolve_network',
|
||||||
|
return_value='f3ef5d2f-d7ba-4b27-af66-58ca0b81e032')
|
||||||
|
net_id = server._get_network_id(net)
|
||||||
|
self.assertEqual('f3ef5d2f-d7ba-4b27-af66-58ca0b81e032', net_id)
|
||||||
|
|
||||||
|
def test_get_network_id_nova(self):
|
||||||
|
return_server = self.fc.servers.list()[3]
|
||||||
|
server = self._create_test_server(return_server, 'networks_update')
|
||||||
|
|
||||||
|
self.patchobject(server, 'is_using_neutron', return_value=False)
|
||||||
|
|
||||||
|
net = {'port': '2a60cbaa-3d33-4af6-a9ce-83594ac546fc'}
|
||||||
|
|
||||||
|
net_id = server._get_network_id(net)
|
||||||
|
self.assertEqual(None, net_id)
|
||||||
|
|
||||||
|
net = {'network': 'f3ef5d2f-d7ba-4b27-af66-58ca0b81e032',
|
||||||
|
'fixed_ip': '1.2.3.4'}
|
||||||
|
|
||||||
|
self.patchobject(nova.NovaClientPlugin, 'get_nova_network_id',
|
||||||
|
return_value='f3ef5d2f-d7ba-4b27-af66-58ca0b81e032')
|
||||||
|
net_id = server._get_network_id(net)
|
||||||
|
self.assertEqual('f3ef5d2f-d7ba-4b27-af66-58ca0b81e032', net_id)
|
||||||
|
|
||||||
|
net = {'network': 'private_net',
|
||||||
|
'fixed_ip': '1.2.3.4'}
|
||||||
|
self.patchobject(nova.NovaClientPlugin, 'get_nova_network_id',
|
||||||
|
return_value='f3ef5d2f-d7ba-4b27-af66-58ca0b81e032')
|
||||||
|
net_id = server._get_network_id(net)
|
||||||
|
self.assertEqual('f3ef5d2f-d7ba-4b27-af66-58ca0b81e032', net_id)
|
||||||
|
|
||||||
def test_get_network_matches_no_matching(self):
|
def test_get_network_matches_no_matching(self):
|
||||||
return_server = self.fc.servers.list()[3]
|
return_server = self.fc.servers.list()[3]
|
||||||
server = self._create_test_server(return_server, 'networks_update')
|
server = self._create_test_server(return_server, 'networks_update')
|
||||||
@ -2544,7 +2594,7 @@ class ServersTest(common.HeatTestCase):
|
|||||||
self.create_old_net(port='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
|
self.create_old_net(port='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
|
||||||
self.create_old_net(net='gggggggg-1111-1111-1111-gggggggggggg',
|
self.create_old_net(net='gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
ip='1.2.3.4'),
|
ip='1.2.3.4'),
|
||||||
self.create_old_net(net='f3ef5d2f-d7ba-4b27-af66-58ca0b81e032'),
|
self.create_old_net(net='gggggggg-1111-1111-1111-gggggggggggg'),
|
||||||
self.create_old_net(port='dddddddd-dddd-dddd-dddd-dddddddddddd'),
|
self.create_old_net(port='dddddddd-dddd-dddd-dddd-dddddddddddd'),
|
||||||
self.create_old_net(uuid='gggggggg-1111-1111-1111-gggggggggggg',
|
self.create_old_net(uuid='gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
ip='5.6.7.8'),
|
ip='5.6.7.8'),
|
||||||
@ -2556,7 +2606,7 @@ class ServersTest(common.HeatTestCase):
|
|||||||
self.create_fake_iface('cccccccc-cccc-cccc-cccc-cccccccccccc',
|
self.create_fake_iface('cccccccc-cccc-cccc-cccc-cccccccccccc',
|
||||||
nets[2]['network'], '10.0.0.11'),
|
nets[2]['network'], '10.0.0.11'),
|
||||||
self.create_fake_iface(nets[3]['port'],
|
self.create_fake_iface(nets[3]['port'],
|
||||||
'f3ef5d2f-d7ba-4b27-af66-58ca0b81e032',
|
'gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
'10.0.0.12'),
|
'10.0.0.12'),
|
||||||
self.create_fake_iface(nets[0]['port'],
|
self.create_fake_iface(nets[0]['port'],
|
||||||
'gggggggg-1111-1111-1111-gggggggggggg',
|
'gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
@ -2576,7 +2626,7 @@ class ServersTest(common.HeatTestCase):
|
|||||||
'fixed_ip': '1.2.3.4',
|
'fixed_ip': '1.2.3.4',
|
||||||
'uuid': None},
|
'uuid': None},
|
||||||
{'port': 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
{'port': 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
||||||
'network': 'f3ef5d2f-d7ba-4b27-af66-58ca0b81e032',
|
'network': 'gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
'fixed_ip': None,
|
'fixed_ip': None,
|
||||||
'uuid': None},
|
'uuid': None},
|
||||||
{'port': 'dddddddd-dddd-dddd-dddd-dddddddddddd',
|
{'port': 'dddddddd-dddd-dddd-dddd-dddddddddddd',
|
||||||
@ -2592,6 +2642,9 @@ class ServersTest(common.HeatTestCase):
|
|||||||
'fixed_ip': None,
|
'fixed_ip': None,
|
||||||
'uuid': '0da8adbf-a7e2-4c59-a511-96b03d2da0d7'}]
|
'uuid': '0da8adbf-a7e2-4c59-a511-96b03d2da0d7'}]
|
||||||
|
|
||||||
|
self.patchobject(neutron.NeutronClientPlugin, 'resolve_network',
|
||||||
|
return_value='gggggggg-1111-1111-1111-gggggggggggg')
|
||||||
|
|
||||||
server.update_networks_matching_iface_port(nets, interfaces)
|
server.update_networks_matching_iface_port(nets, interfaces)
|
||||||
self.assertEqual(expected, nets)
|
self.assertEqual(expected, nets)
|
||||||
|
|
||||||
@ -2658,6 +2711,8 @@ class ServersTest(common.HeatTestCase):
|
|||||||
return_server.interface_attach(None, new_networks[0]['network'],
|
return_server.interface_attach(None, new_networks[0]['network'],
|
||||||
new_networks[0]['fixed_ip']).AndReturn(
|
new_networks[0]['fixed_ip']).AndReturn(
|
||||||
None)
|
None)
|
||||||
|
self.patchobject(neutron.NeutronClientPlugin, 'resolve_network',
|
||||||
|
return_value='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||||
self.stub_NetworkConstraint_validate()
|
self.stub_NetworkConstraint_validate()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
@ -2754,6 +2809,8 @@ class ServersTest(common.HeatTestCase):
|
|||||||
return_server.interface_detach(
|
return_server.interface_detach(
|
||||||
poor_interfaces[3].port_id).InAnyOrder().AndReturn(None)
|
poor_interfaces[3].port_id).InAnyOrder().AndReturn(None)
|
||||||
|
|
||||||
|
self.patchobject(neutron.NeutronClientPlugin, 'resolve_network',
|
||||||
|
return_value='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||||
self.m.StubOutWithMock(return_server, 'interface_attach')
|
self.m.StubOutWithMock(return_server, 'interface_attach')
|
||||||
return_server.interface_attach(
|
return_server.interface_attach(
|
||||||
new_networks[1]['port'], None, None).AndReturn(None)
|
new_networks[1]['port'], None, None).AndReturn(None)
|
||||||
@ -2797,6 +2854,8 @@ class ServersTest(common.HeatTestCase):
|
|||||||
'31.32.33.34')
|
'31.32.33.34')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
self.patchobject(neutron.NeutronClientPlugin, 'resolve_network',
|
||||||
|
return_value='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||||
return_server.interface_list().AndReturn(poor_interfaces)
|
return_server.interface_list().AndReturn(poor_interfaces)
|
||||||
|
|
||||||
self.m.StubOutWithMock(return_server, 'interface_detach')
|
self.m.StubOutWithMock(return_server, 'interface_detach')
|
||||||
@ -2847,6 +2906,9 @@ class ServersTest(common.HeatTestCase):
|
|||||||
'31.32.33.34')
|
'31.32.33.34')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
self.patchobject(neutron.NeutronClientPlugin, 'resolve_network',
|
||||||
|
return_value='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||||
|
|
||||||
return_server.interface_list().AndReturn(poor_interfaces)
|
return_server.interface_list().AndReturn(poor_interfaces)
|
||||||
|
|
||||||
self.m.StubOutWithMock(return_server, 'interface_detach')
|
self.m.StubOutWithMock(return_server, 'interface_detach')
|
||||||
|
Loading…
Reference in New Issue
Block a user