Merge "Do not match subnets if no networks defined"
This commit is contained in:
commit
89f82480c9
|
@ -677,13 +677,18 @@ class Server(stack_user.StackUser):
|
|||
# It is not known which subnet a server might be assigned
|
||||
# to so all subnets in a network should be created before
|
||||
# the servers in that network.
|
||||
nets = self.properties.get(self.NETWORKS)
|
||||
if not nets:
|
||||
return
|
||||
for res in self.stack.itervalues():
|
||||
if (res.has_interface('OS::Neutron::Subnet')):
|
||||
subnet_net = res.properties.get(subnet.Subnet.NETWORK_ID)
|
||||
for net in self.properties.get(self.NETWORKS):
|
||||
# we do not need to worry about NETWORK_ID values which are
|
||||
# names instead of UUIDs since these were not created
|
||||
# by this stack
|
||||
if res.has_interface('OS::Neutron::Subnet'):
|
||||
subnet_net = (res.properties.get(subnet.Subnet.NETWORK_ID)
|
||||
or res.properties.get(subnet.Subnet.NETWORK))
|
||||
for net in nets:
|
||||
# worry about network_id because that could be the match
|
||||
# assigned to the subnet as well and could have been
|
||||
# created by this stack. Regardless, the server should
|
||||
# still wait on the subnet.
|
||||
net_id = (net.get(self.NETWORK_ID) or
|
||||
net.get(self.NETWORK_UUID))
|
||||
if net_id and net_id == subnet_net:
|
||||
|
|
|
@ -67,6 +67,36 @@ wp_template = '''
|
|||
}
|
||||
'''
|
||||
|
||||
subnet_template = '''
|
||||
heat_template_version: 2013-05-23
|
||||
resources:
|
||||
server:
|
||||
type: OS::Nova::Server
|
||||
properties:
|
||||
image: F17-x86_64-gold
|
||||
flavor: m1.large
|
||||
networks:
|
||||
- { uuid: 12345 }
|
||||
subnet:
|
||||
type: OS::Neutron::Subnet
|
||||
properties:
|
||||
network: 12345
|
||||
'''
|
||||
|
||||
no_subnet_template = '''
|
||||
heat_template_version: 2013-05-23
|
||||
resources:
|
||||
server:
|
||||
type: OS::Nova::Server
|
||||
properties:
|
||||
image: F17-x86_64-gold
|
||||
flavor: m1.large
|
||||
subnet:
|
||||
type: OS::Neutron::Subnet
|
||||
properties:
|
||||
network: 12345
|
||||
'''
|
||||
|
||||
|
||||
class ServersTest(HeatTestCase):
|
||||
def setUp(self):
|
||||
|
@ -90,8 +120,8 @@ class ServersTest(HeatTestCase):
|
|||
yield max_personality_size
|
||||
yield max_server_meta
|
||||
|
||||
def _setup_test_stack(self, stack_name):
|
||||
t = template_format.parse(wp_template)
|
||||
def _setup_test_stack(self, stack_name, test_templ=wp_template):
|
||||
t = template_format.parse(test_templ)
|
||||
templ = template.Template(t)
|
||||
stack = parser.Stack(utils.dummy_context(), stack_name, templ,
|
||||
environment.Environment({'key_name': 'test'}),
|
||||
|
@ -188,6 +218,26 @@ class ServersTest(HeatTestCase):
|
|||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
||||
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
|
||||
|
||||
def test_subnet_dependency(self):
|
||||
template, stack = self._setup_test_stack('subnet-test',
|
||||
subnet_template)
|
||||
server_rsrc = stack['server']
|
||||
subnet_rsrc = stack['subnet']
|
||||
deps = []
|
||||
server_rsrc.add_dependencies(deps)
|
||||
self.assertEqual(4, len(deps))
|
||||
self.assertEqual(subnet_rsrc, deps[3])
|
||||
|
||||
def test_subnet_nodeps(self):
|
||||
template, stack = self._setup_test_stack('subnet-test',
|
||||
no_subnet_template)
|
||||
server_rsrc = stack['server']
|
||||
subnet_rsrc = stack['subnet']
|
||||
deps = []
|
||||
server_rsrc.add_dependencies(deps)
|
||||
self.assertEqual(2, len(deps))
|
||||
self.assertNotIn(subnet_rsrc, deps)
|
||||
|
||||
def test_server_create(self):
|
||||
return_server = self.fc.servers.list()[1]
|
||||
return_server.id = '5678'
|
||||
|
|
Loading…
Reference in New Issue