Merge "Move network constraint to neutron plugin"
This commit is contained in:
commit
a550ac0307
@ -11,9 +11,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutronclient.common import exceptions
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
from neutronclient.v2_0 import client as nc
|
||||
|
||||
from heat.engine.clients import client_plugin
|
||||
from heat.engine import constraints
|
||||
|
||||
|
||||
class NeutronClientPlugin(client_plugin.ClientPlugin):
|
||||
@ -35,3 +38,13 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
||||
}
|
||||
|
||||
return nc.Client(**args)
|
||||
|
||||
|
||||
class NetworkConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
expected_exceptions = (exceptions.NeutronClientException,)
|
||||
|
||||
def validate_with_client(self, client, value):
|
||||
neutron_client = client.client('neutron')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
neutron_client, 'network', value)
|
||||
|
@ -12,12 +12,10 @@
|
||||
# under the License.
|
||||
|
||||
from heat.engine import attributes
|
||||
from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
from heat.engine.resources.neutron import neutron
|
||||
|
||||
import neutronclient.common.exceptions as neutron_exp
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
|
||||
|
||||
class Net(neutron.NeutronResource):
|
||||
@ -182,16 +180,6 @@ class Net(neutron.NeutronResource):
|
||||
raise ex
|
||||
|
||||
|
||||
class NetworkConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
expected_exceptions = (neutron_exp.NeutronClientException,)
|
||||
|
||||
def validate_with_client(self, client, value):
|
||||
neutron_client = client.client('neutron')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
neutron_client, 'network', value)
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {
|
||||
'OS::Neutron::Net': Net,
|
||||
|
@ -2451,16 +2451,17 @@ class NetworkConstraintTest(HeatTestCase):
|
||||
nc = self.m.CreateMockAnything()
|
||||
self.m.StubOutWithMock(neutron.NeutronClientPlugin, '_create')
|
||||
neutron.NeutronClientPlugin._create().AndReturn(nc)
|
||||
self.m.StubOutWithMock(net.neutronV20, 'find_resourceid_by_name_or_id')
|
||||
net.neutronV20.find_resourceid_by_name_or_id(
|
||||
self.m.StubOutWithMock(neutron.neutronV20,
|
||||
'find_resourceid_by_name_or_id')
|
||||
neutron.neutronV20.find_resourceid_by_name_or_id(
|
||||
nc, 'network', 'foo'
|
||||
).AndReturn('foo')
|
||||
net.neutronV20.find_resourceid_by_name_or_id(
|
||||
neutron.neutronV20.find_resourceid_by_name_or_id(
|
||||
nc, 'network', 'bar'
|
||||
).AndRaise(qe.NeutronClientException(status_code=404))
|
||||
self.m.ReplayAll()
|
||||
|
||||
constraint = net.NetworkConstraint()
|
||||
constraint = neutron.NetworkConstraint()
|
||||
ctx = utils.dummy_context()
|
||||
self.assertTrue(constraint.validate("foo", ctx))
|
||||
self.assertFalse(constraint.validate("bar", ctx))
|
||||
|
@ -50,7 +50,7 @@ heat.clients =
|
||||
|
||||
heat.constraints =
|
||||
nova.flavor = heat.engine.resources.server:FlavorConstraint
|
||||
neutron.network = heat.engine.resources.neutron.net:NetworkConstraint
|
||||
neutron.network = heat.engine.clients.os.neutron:NetworkConstraint
|
||||
glance.image = heat.engine.resources.image:ImageConstraint
|
||||
iso_8601 = heat.engine.resources.iso_8601:ISO8601Constraint
|
||||
nova.keypair = heat.engine.resources.nova_keypair:KeypairConstraint
|
||||
|
Loading…
x
Reference in New Issue
Block a user