Do no net/subnet checks during validate
Currently validation fails if the network or the subnet are defined in the same template as the server because they don't exist during validate. _validate_belonging_subnet_to_net is called during _build_nics so this check still happens when the required resources actually exist. Also, test method validate_internal_port_subnet_not_this_network was not running because its name was not prefixed with test_. Fixing and updating this test revealed issues with the validation failed message. Closes-Bug: #1503060 Change-Id: I2e062abf5b9fb7446b979ba6acc2e2b531d957d6
This commit is contained in:
parent
7e911cec08
commit
4348b7abab
|
@ -20,7 +20,6 @@ from oslo_utils import netutils
|
|||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.common.i18n import _LI
|
||||
from heat.engine.cfn import functions as cfn_funcs
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -65,32 +64,20 @@ class ServerNetworkMixin(object):
|
|||
network=network[self.NETWORK_ID],
|
||||
server=self.name))
|
||||
|
||||
# If subnet and net are specified with some external resources, check
|
||||
# them. Otherwise, if their are resources of current stack, skip
|
||||
# validating in case of raising error and check it only during
|
||||
# resource creating.
|
||||
is_ref = False
|
||||
for item in [subnet, net_uuid, net_id]:
|
||||
if isinstance(item, (cfn_funcs.ResourceRef, cfn_funcs.GetAtt)):
|
||||
is_ref = True
|
||||
break
|
||||
if not is_ref:
|
||||
self._validate_belonging_subnet_to_net(network)
|
||||
|
||||
def _validate_belonging_subnet_to_net(self, network):
|
||||
if network.get(self.NETWORK_PORT) is None and self.is_using_neutron():
|
||||
net = self._get_network_id(network)
|
||||
# check if there are subnet and network both specified that
|
||||
# subnet belongs to specified network
|
||||
if (network.get(self.NETWORK_SUBNET) is not None
|
||||
and (net is not None)):
|
||||
subnet = network.get(self.NETWORK_SUBNET)
|
||||
if (subnet is not None and net is not None):
|
||||
subnet_net = self.client_plugin(
|
||||
'neutron').network_id_from_subnet_id(
|
||||
self._get_subnet_id(network))
|
||||
if subnet_net != net:
|
||||
msg = _('Specified subnet %(subnet)s does not belongs to'
|
||||
msg = _('Specified subnet %(subnet)s does not belongs to '
|
||||
'network %(network)s.') % {
|
||||
'subnet': subnet_net,
|
||||
'subnet': subnet,
|
||||
'network': net}
|
||||
raise exception.StackValidationFailed(message=msg)
|
||||
|
||||
|
|
|
@ -1378,11 +1378,6 @@ class ServersTest(common.HeatTestCase):
|
|||
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
|
||||
self.stub_NetworkConstraint_validate()
|
||||
|
||||
self.patchobject(neutronV20, 'find_resourceid_by_name_or_id',
|
||||
return_value='12345')
|
||||
self.patchobject(neutronclient.Client, 'show_network',
|
||||
return_value={'network': {'subnets': ['abcd1234']}})
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertIsNone(server.validate())
|
||||
|
@ -1404,11 +1399,6 @@ class ServersTest(common.HeatTestCase):
|
|||
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
|
||||
self.stub_NetworkConstraint_validate()
|
||||
|
||||
self.patchobject(neutronV20, 'find_resourceid_by_name_or_id',
|
||||
return_value='12345')
|
||||
self.patchobject(neutronclient.Client, 'show_network',
|
||||
return_value={'network': {'subnets': ['abcd1234']}})
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertIsNone(server.validate())
|
||||
|
@ -3869,7 +3859,7 @@ class ServerInternalPortTest(common.HeatTestCase):
|
|||
self.assertEqual([{'port-id': '12345', 'net-id': '4321'}], nics)
|
||||
self.assertEqual(0, create_internal_port.call_count)
|
||||
|
||||
def validate_internal_port_subnet_not_this_network(self):
|
||||
def test_validate_internal_port_subnet_not_this_network(self):
|
||||
tmpl = """
|
||||
heat_template_version: 2015-10-15
|
||||
resources:
|
||||
|
@ -3885,14 +3875,19 @@ class ServerInternalPortTest(common.HeatTestCase):
|
|||
t, stack, server = self._return_template_stack_and_rsrc_defn('test',
|
||||
tmpl)
|
||||
|
||||
networks = server.properties['networks']
|
||||
for network in networks:
|
||||
# validation passes at validate time
|
||||
server._validate_network(network)
|
||||
|
||||
self.patchobject(neutron.NeutronClientPlugin,
|
||||
'network_id_from_subnet_id',
|
||||
return_value='not_this_network')
|
||||
self.resolve.return_value = '4321'
|
||||
|
||||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
server.validate)
|
||||
self.assertEqual('Specified subnet 1234 does not belongs to'
|
||||
server._build_nics, networks)
|
||||
self.assertEqual('Specified subnet 1234 does not belongs to '
|
||||
'network 4321.', six.text_type(ex))
|
||||
|
||||
def test_build_nics_create_internal_port_all_props(self):
|
||||
|
|
Loading…
Reference in New Issue