Move network constraint to neutron plugin
This allows exception imports to be encapsulated inside the neutron plugin, and plugins are likely the most appropriate place for custom constraints to live. Change-Id: I5766edb305b7cfffdcd8943fb6edce7f3e9ff26d
This commit is contained in:
parent
09b31c1d0d
commit
ec35f074cc
@ -11,9 +11,12 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# 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 neutronclient.v2_0 import client as nc
|
||||||
|
|
||||||
from heat.engine.clients import client_plugin
|
from heat.engine.clients import client_plugin
|
||||||
|
from heat.engine import constraints
|
||||||
|
|
||||||
|
|
||||||
class NeutronClientPlugin(client_plugin.ClientPlugin):
|
class NeutronClientPlugin(client_plugin.ClientPlugin):
|
||||||
@ -35,3 +38,13 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nc.Client(**args)
|
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.
|
# under the License.
|
||||||
|
|
||||||
from heat.engine import attributes
|
from heat.engine import attributes
|
||||||
from heat.engine import constraints
|
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine.resources.neutron import neutron
|
from heat.engine.resources.neutron import neutron
|
||||||
|
|
||||||
import neutronclient.common.exceptions as neutron_exp
|
import neutronclient.common.exceptions as neutron_exp
|
||||||
from neutronclient.neutron import v2_0 as neutronV20
|
|
||||||
|
|
||||||
|
|
||||||
class Net(neutron.NeutronResource):
|
class Net(neutron.NeutronResource):
|
||||||
@ -182,16 +180,6 @@ class Net(neutron.NeutronResource):
|
|||||||
raise ex
|
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():
|
def resource_mapping():
|
||||||
return {
|
return {
|
||||||
'OS::Neutron::Net': Net,
|
'OS::Neutron::Net': Net,
|
||||||
|
@ -2397,16 +2397,17 @@ class NetworkConstraintTest(HeatTestCase):
|
|||||||
nc = self.m.CreateMockAnything()
|
nc = self.m.CreateMockAnything()
|
||||||
self.m.StubOutWithMock(neutron.NeutronClientPlugin, '_create')
|
self.m.StubOutWithMock(neutron.NeutronClientPlugin, '_create')
|
||||||
neutron.NeutronClientPlugin._create().AndReturn(nc)
|
neutron.NeutronClientPlugin._create().AndReturn(nc)
|
||||||
self.m.StubOutWithMock(net.neutronV20, 'find_resourceid_by_name_or_id')
|
self.m.StubOutWithMock(neutron.neutronV20,
|
||||||
net.neutronV20.find_resourceid_by_name_or_id(
|
'find_resourceid_by_name_or_id')
|
||||||
|
neutron.neutronV20.find_resourceid_by_name_or_id(
|
||||||
nc, 'network', 'foo'
|
nc, 'network', 'foo'
|
||||||
).AndReturn('foo')
|
).AndReturn('foo')
|
||||||
net.neutronV20.find_resourceid_by_name_or_id(
|
neutron.neutronV20.find_resourceid_by_name_or_id(
|
||||||
nc, 'network', 'bar'
|
nc, 'network', 'bar'
|
||||||
).AndRaise(qe.NeutronClientException(status_code=404))
|
).AndRaise(qe.NeutronClientException(status_code=404))
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
constraint = net.NetworkConstraint()
|
constraint = neutron.NetworkConstraint()
|
||||||
ctx = utils.dummy_context()
|
ctx = utils.dummy_context()
|
||||||
self.assertTrue(constraint.validate("foo", ctx))
|
self.assertTrue(constraint.validate("foo", ctx))
|
||||||
self.assertFalse(constraint.validate("bar", ctx))
|
self.assertFalse(constraint.validate("bar", ctx))
|
||||||
|
@ -50,7 +50,7 @@ heat.clients =
|
|||||||
|
|
||||||
heat.constraints =
|
heat.constraints =
|
||||||
nova.flavor = heat.engine.resources.server:FlavorConstraint
|
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
|
glance.image = heat.engine.resources.image:ImageConstraint
|
||||||
iso_8601 = heat.engine.resources.iso_8601:ISO8601Constraint
|
iso_8601 = heat.engine.resources.iso_8601:ISO8601Constraint
|
||||||
nova.keypair = heat.engine.resources.nova_keypair:KeypairConstraint
|
nova.keypair = heat.engine.resources.nova_keypair:KeypairConstraint
|
||||||
|
Loading…
Reference in New Issue
Block a user