From db90ea27ba8331c5c8689b2e6e3d1d60cd9306c0 Mon Sep 17 00:00:00 2001 From: Dmitriy Uvarenkov Date: Wed, 3 Aug 2016 12:27:58 +0300 Subject: [PATCH] Network validation in Manila Added new validation checks. If client is using neutron, manila expects both neutron net and neutron subnet properties OR their absense. Nova network is only expected when neutron is not used. Change-Id: I7c259d7b2c9c4ed554bca89ef3d286c25716a33b --- .../openstack/manila/share_network.py | 10 ++++++++ .../openstack/manila/test_share_network.py | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/heat/engine/resources/openstack/manila/share_network.py b/heat/engine/resources/openstack/manila/share_network.py index 5d0e4bb72f..1c047ba988 100644 --- a/heat/engine/resources/openstack/manila/share_network.py +++ b/heat/engine/resources/openstack/manila/share_network.py @@ -128,6 +128,16 @@ class ManilaShareNetwork(resource.Resource): raise exception.ResourcePropertyConflict(self.NEUTRON_SUBNET, self.NOVA_NETWORK) + if self.is_using_neutron() and self.properties[self.NOVA_NETWORK]: + msg = _('With Neutron enabled you need to pass Neutron network ' + 'and Neutron subnet instead of Nova network') + raise exception.StackValidationFailed(message=msg) + + if (self.properties[self.NEUTRON_NETWORK] and not + self.properties[self.NEUTRON_SUBNET]): + raise exception.ResourcePropertyDependency( + prop1=self.NEUTRON_NETWORK, prop2=self.NEUTRON_SUBNET) + if (self.properties[self.NEUTRON_NETWORK] and self.properties[self.NEUTRON_SUBNET]): plg = self.client_plugin('neutron') diff --git a/heat/tests/openstack/manila/test_share_network.py b/heat/tests/openstack/manila/test_share_network.py index 8344304a9f..0b679a2685 100644 --- a/heat/tests/openstack/manila/test_share_network.py +++ b/heat/tests/openstack/manila/test_share_network.py @@ -251,6 +251,30 @@ class ManilaShareNetworkTest(common.HeatTestCase): self.assertRaisesRegexp(exception.ResourcePropertyConflict, msg, net.validate) + def test_nova_net_while_using_neutron(self): + t = template_format.parse(stack_template) + t['resources']['share_network']['properties']['nova_network'] = 'n' + del t['resources']['share_network']['properties']['neutron_network'] + del t['resources']['share_network']['properties']['neutron_subnet'] + stack = utils.parse_stack(t) + rsrc_defn = stack.t.resource_definitions(stack)['share_network'] + net = self._create_network('share_network', rsrc_defn, stack) + net.is_using_neutron = mock.Mock(return_value=True) + msg = ('With Neutron enabled you need to pass Neutron network ' + 'and Neutron subnet instead of Nova network') + self.assertRaisesRegexp(exception.StackValidationFailed, msg, + net.validate) + + def test_neutron_net_without_neutron_subnet(self): + t = template_format.parse(stack_template) + del t['resources']['share_network']['properties']['neutron_subnet'] + stack = utils.parse_stack(t) + rsrc_defn = stack.t.resource_definitions(stack)['share_network'] + net = self._create_network('share_network', rsrc_defn, stack) + msg = ('neutron_network cannot be specified without neutron_subnet.') + self.assertRaisesRegexp(exception.ResourcePropertyDependency, msg, + net.validate) + def test_nova_constraint_fail(self): validate = self.patchobject(nova.NetworkConstraint, 'validate') validate.return_value = False