Merge "Apply neutron port constraint"

This commit is contained in:
Jenkins 2015-02-27 07:25:14 +00:00 committed by Gerrit Code Review
commit 1b49a9d4a1
8 changed files with 44 additions and 9 deletions

View File

@ -71,7 +71,10 @@ class FloatingIP(neutron.NeutronResource):
properties.Schema.STRING,
_('ID of an existing port with at least one IP address to '
'associate with this floating IP.'),
update_allowed=True
update_allowed=True,
constraints=[
constraints.CustomConstraint('neutron.port')
]
),
FIXED_IP_ADDRESS: properties.Schema(
properties.Schema.STRING,
@ -223,7 +226,10 @@ class FloatingIPAssociation(neutron.NeutronResource):
_('ID of an existing port with at least one IP address to '
'associate with this floating IP.'),
required=True,
update_allowed=True
update_allowed=True,
constraints=[
constraints.CustomConstraint('neutron.port')
]
),
FIXED_IP_ADDRESS: properties.Schema(
properties.Schema.STRING,

View File

@ -285,15 +285,22 @@ class RouterInterface(neutron.NeutronResource):
),
PORT_ID: properties.Schema(
properties.Schema.STRING,
_('The port id, either subnet or port_id should be specified.'),
support_status=support.SupportStatus(
support.DEPRECATED,
_('Deprecated in Kilo. '
'Use property %s.') % PORT)
'Use property %s.') % PORT),
constraints=[
constraints.CustomConstraint('neutron.port')
]
),
PORT: properties.Schema(
properties.Schema.STRING,
_('The port, either subnet or port should be specified.'),
support_status=support.SupportStatus(version='2015.1')
support_status=support.SupportStatus(version='2015.1'),
constraints=[
constraints.CustomConstraint('neutron.port')
]
)
}

View File

@ -139,7 +139,10 @@ class OSDBInstance(resource.Resource):
_('Name or UUID of Neutron port to attach this '
'NIC to. '
'Either %(port)s or %(net)s must be specified.') % {
'port': PORT, 'net': NET}
'port': PORT, 'net': NET},
constraints=[
constraints.CustomConstraint('neutron.port')
],
),
V4_FIXED_IP: properties.Schema(
properties.Schema.STRING,

View File

@ -240,7 +240,10 @@ class Server(stack_user.StackUser):
NETWORK_PORT: properties.Schema(
properties.Schema.STRING,
_('ID of an existing port to associate with this '
'server.')
'server.'),
constraints=[
constraints.CustomConstraint('neutron.port')
]
),
},
),

View File

@ -197,3 +197,8 @@ class HeatTestCase(testscenarios.WithScenarios,
self.m.StubOutWithMock(neutron.NetworkConstraint, 'validate')
neutron.NetworkConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
def stub_PortConstraint_validate(self):
self.m.StubOutWithMock(neutron.PortConstraint, 'validate')
neutron.PortConstraint.validate(
mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)

View File

@ -1874,6 +1874,7 @@ class NeutronRouterTest(common.HeatTestCase):
'ae478782-53c0-4434-ab16-49900c88016c',
{'port_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'}
).AndRaise(qe.NeutronClientException(status_code=404))
self.stub_PortConstraint_validate()
self.m.ReplayAll()
t = template_format.parse(neutron_template)
@ -2496,6 +2497,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
neutronclient.Client.delete_floatingip(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
).AndRaise(qe.NeutronClientException(status_code=404))
self.stub_PortConstraint_validate()
self.m.ReplayAll()
@ -2641,6 +2643,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
neutronclient.Client.show_port(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
).AndRaise(qe.PortNotFoundClient(status_code=404))
self.stub_PortConstraint_validate()
self.m.ReplayAll()

View File

@ -150,9 +150,11 @@ class OSDBInstanceTest(common.HeatTestCase):
self.fc.instances.get(fake_dbinstance.id).AndReturn(fake_dbinstance)
def _stubout_validate(self, instance, neutron=None,
mock_net_constraint=False):
mock_net_constraint=False,
with_port=True):
if mock_net_constraint:
self.stub_NetworkConstraint_validate()
trove.TroveClientPlugin._create().AndReturn(self.fc)
self.m.StubOutWithMock(self.fc, 'datastore_versions')
self.m.StubOutWithMock(self.fc.datastore_versions, 'list')
@ -162,6 +164,8 @@ class OSDBInstanceTest(common.HeatTestCase):
if neutron is not None:
self.m.StubOutWithMock(instance, 'is_using_neutron')
instance.is_using_neutron().AndReturn(bool(neutron))
if with_port:
self.stub_PortConstraint_validate()
self.m.ReplayAll()
def test_osdatabase_create(self):
@ -570,7 +574,7 @@ class OSDBInstanceTest(common.HeatTestCase):
"fixed_ip": "1.2.3.4"
}]
instance = self._setup_test_clouddbinstance('dbinstance_test', t)
self._stubout_validate(instance, neutron=True)
self._stubout_validate(instance, neutron=True, with_port=False)
ex = self.assertRaises(
exception.StackValidationFailed, instance.validate)
@ -614,6 +618,7 @@ class OSDBInstanceTest(common.HeatTestCase):
'v4-fixed-ip': '1.2.3.4'}]
).AndReturn(fake_dbinstance)
self._stubout_check_create_complete(fake_dbinstance)
self.stub_PortConstraint_validate()
self.m.ReplayAll()
scheduler.TaskRunner(instance.create)()

View File

@ -1060,6 +1060,7 @@ class ServersTest(common.HeatTestCase):
nova.NovaClientPlugin._create().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
self.stub_PortConstraint_validate()
self.m.ReplayAll()
error = self.assertRaises(exception.ResourcePropertyConflict,
@ -2463,6 +2464,7 @@ class ServersTest(common.HeatTestCase):
self.m.StubOutWithMock(return_server, 'interface_attach')
return_server.interface_attach(new_networks[0]['port'],
None, None).AndReturn(None)
self.stub_PortConstraint_validate()
self.m.ReplayAll()
scheduler.TaskRunner(server.update, update_template)()
@ -2535,7 +2537,7 @@ class ServersTest(common.HeatTestCase):
return_server.interface_attach(
new_networks[0]['port'], None, None).AndReturn(None)
self.stub_NetworkConstraint_validate()
self.stub_PortConstraint_validate()
self.m.ReplayAll()
scheduler.TaskRunner(server.update, update_template)()
@ -2598,6 +2600,7 @@ class ServersTest(common.HeatTestCase):
return_server.interface_attach(
new_networks[1]['port'], None, None).AndReturn(None)
self.stub_NetworkConstraint_validate()
self.stub_PortConstraint_validate()
self.m.ReplayAll()
scheduler.TaskRunner(server.update, update_template)()