Merge "Add nova.network custom constraint"

This commit is contained in:
Jenkins 2015-07-01 09:15:13 +00:00 committed by Gerrit Code Review
commit b8e7674c0c
3 changed files with 43 additions and 0 deletions

View File

@ -638,3 +638,12 @@ class FlavorConstraint(constraints.BaseCustomConstraint):
def validate_with_client(self, client, flavor):
client.client_plugin('nova').get_flavor_id(flavor)
class NetworkConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.NovaNetworkNotFound,
exception.PhysicalResourceNameAmbiguity)
def validate_with_client(self, client, network):
client.client_plugin('nova').get_nova_network_id(network)

View File

@ -448,6 +448,39 @@ class FlavorConstraintTest(common.HeatTestCase):
client.flavors.list.call_args_list)
class NetworkConstraintTest(common.HeatTestCase):
def test_validate(self):
client = fakes_nova.FakeClient()
self.stub_keystoneclient()
self.patchobject(nova.NovaClientPlugin, '_create', return_value=client)
client.networks = mock.Mock()
network = collections.namedtuple("Network", ['id', 'label'])
network.id = '7f47ff06-0353-4013-b814-123b70b1b27d'
network.label = 'foo'
client.networks.get.return_value = network
constraint = nova.NetworkConstraint()
ctx = utils.dummy_context()
self.assertTrue(constraint.validate(network.id, ctx))
client.networks.get.side_effect = nova_exceptions.NotFound('')
client.networks.find.return_value = network
self.assertTrue(constraint.validate(network.id, ctx))
client.networks.find.side_effect = nova_exceptions.NotFound('')
self.assertFalse(constraint.validate(network.id, ctx))
client.networks.find.side_effect = nova_exceptions.NoUniqueMatch()
self.assertFalse(constraint.validate(network.id, ctx))
network.id = 'nonuuid'
client.networks.find.return_value = network
client.networks.find.side_effect = None
self.assertTrue(constraint.validate(network.id, ctx))
class KeypairConstraintTest(common.HeatTestCase):
def test_validation(self):

View File

@ -65,6 +65,7 @@ heat.clients =
heat.constraints =
nova.flavor = heat.engine.clients.os.nova:FlavorConstraint
nova.network = heat.engine.clients.os.nova:NetworkConstraint
neutron.network = heat.engine.clients.os.neutron:NetworkConstraint
neutron.port = heat.engine.clients.os.neutron:PortConstraint
neutron.router = heat.engine.clients.os.neutron:RouterConstraint