Merge "Resolve name/id using translation rules"

This commit is contained in:
Jenkins 2016-03-08 08:25:14 +00:00 committed by Gerrit Code Review
commit bbda7712dd
9 changed files with 324 additions and 157 deletions

View File

@ -146,6 +146,14 @@ class FloatingIP(neutron.NeutronResource):
translation.TranslationRule.REPLACE,
[self.FLOATING_NETWORK],
value_path=[self.FLOATING_NETWORK_ID]
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.FLOATING_NETWORK],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='network'
)
]
@ -224,8 +232,7 @@ class FloatingIP(neutron.NeutronResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
self.client_plugin().resolve_network(props, self.FLOATING_NETWORK,
'floating_network_id')
props['floating_network_id'] = props.pop(self.FLOATING_NETWORK)
fip = self.client().create_floatingip({
'floatingip': props})['floatingip']
self.resource_id_set(fip['id'])
@ -321,9 +328,7 @@ class FloatingIPAssociation(neutron.NeutronResource):
def handle_create(self):
props = self.prepare_properties(self.properties, self.name)
floatingip_id = props.pop(self.FLOATINGIP_ID)
self.client().update_floatingip(floatingip_id, {
'floatingip': props})
self.resource_id_set(self.id)

View File

@ -358,6 +358,22 @@ class Port(neutron.NeutronResource):
translation.TranslationRule.REPLACE,
[self.FIXED_IPS, self.FIXED_IP_SUBNET],
value_name=self.FIXED_IP_SUBNET_ID
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.NETWORK],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='network'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.FIXED_IPS, self.FIXED_IP_SUBNET],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='subnet'
)
]
@ -379,7 +395,7 @@ class Port(neutron.NeutronResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
self.client_plugin().resolve_network(props, self.NETWORK, 'network_id')
props['network_id'] = props.pop(self.NETWORK)
self._prepare_port_properties(props)
qos_policy = props.pop(self.QOS_POLICY, None)
if qos_policy:
@ -473,21 +489,6 @@ class Port(neutron.NeutronResource):
"""Mandatory replace based on props."""
return after_props.get(self.REPLACEMENT_POLICY) == 'REPLACE_ALWAYS'
def needs_replace_with_prop_diff(self, changed_properties_set,
after_props, before_props):
"""Needs replace based on prop_diff."""
# Switching between name and ID is OK, provided the value resolves
# to the same network. If the network changes, port is replaced.
if self.NETWORK in changed_properties_set:
before_id = self.client_plugin().find_resourceid_by_name_or_id(
'network',
before_props[self.NETWORK])
after_id = self.client_plugin().find_resourceid_by_name_or_id(
'network',
after_props[self.NETWORK])
changed_properties_set.remove(self.NETWORK)
return before_id != after_id
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
self.prepare_update_properties(prop_diff)

View File

@ -197,8 +197,25 @@ class Router(neutron.NeutronResource):
}
def translation_rules(self, props):
rules = [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.EXTERNAL_GATEWAY, self.EXTERNAL_GATEWAY_NETWORK],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='network'),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.EXTERNAL_GATEWAY, self.EXTERNAL_GATEWAY_FIXED_IPS,
self.SUBNET],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='subnet')
]
if props.get(self.L3_AGENT_ID):
return [
rules.extend([
translation.TranslationRule(
props,
translation.TranslationRule.ADD,
@ -208,8 +225,8 @@ class Router(neutron.NeutronResource):
props,
translation.TranslationRule.DELETE,
[self.L3_AGENT_ID]
)
]
)])
return rules
def validate(self):
super(Router, self).validate()
@ -246,8 +263,7 @@ class Router(neutron.NeutronResource):
def _resolve_gateway(self, props):
gateway = props.get(self.EXTERNAL_GATEWAY)
if gateway:
self.client_plugin().resolve_network(
gateway, self.EXTERNAL_GATEWAY_NETWORK, 'network_id')
gateway['network_id'] = gateway.pop(self.EXTERNAL_GATEWAY_NETWORK)
if gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT] is None:
del gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT]
if gateway[self.EXTERNAL_GATEWAY_FIXED_IPS] is None:
@ -270,9 +286,8 @@ class Router(neutron.NeutronResource):
for key, value in six.iteritems(fixed_ip):
if value is None:
fixed_ip.pop(key)
if fixed_ip.get(self.SUBNET):
self.client_plugin().resolve_subnet(
fixed_ip, self.SUBNET, 'subnet_id')
if self.SUBNET in fixed_ip:
fixed_ip['subnet_id'] = fixed_ip.pop(self.SUBNET)
def handle_create(self):
props = self.prepare_properties(
@ -437,7 +452,33 @@ class RouterInterface(neutron.NeutronResource):
translation.TranslationRule.REPLACE,
[self.SUBNET],
value_path=[self.SUBNET_ID]
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.PORT],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='port'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.ROUTER],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='router'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.SUBNET],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='subnet'
)
]
def validate(self):
@ -457,15 +498,12 @@ class RouterInterface(neutron.NeutronResource):
self.PORT)
def handle_create(self):
router_id = self.client_plugin().resolve_router(
dict(self.properties), self.ROUTER, 'router_id')
router_id = dict(self.properties).get(self.ROUTER)
key = 'subnet_id'
value = self.client_plugin().resolve_subnet(
dict(self.properties), self.SUBNET, key)
value = dict(self.properties).get(self.SUBNET)
if not value:
key = 'port_id'
value = self.client_plugin().resolve_port(
dict(self.properties), self.PORT, key)
value = dict(self.properties).get(self.PORT)
self.client().add_interface_router(
router_id,
{key: value})
@ -539,7 +577,16 @@ class RouterGateway(neutron.NeutronResource):
translation.TranslationRule.REPLACE,
[self.NETWORK],
value_path=[self.NETWORK_ID]
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.NETWORK],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='network'
)
]
def add_dependencies(self, deps):
@ -570,8 +617,7 @@ class RouterGateway(neutron.NeutronResource):
def handle_create(self):
router_id = self.properties[self.ROUTER_ID]
network_id = self.client_plugin().resolve_network(
dict(self.properties), self.NETWORK, 'network_id')
network_id = dict(self.properties).get(self.NETWORK)
self.client().add_gateway_router(
router_id,
{'network_id': network_id})

View File

@ -281,10 +281,27 @@ class Subnet(neutron.NeutronResource):
def translation_rules(self, props):
return [
translation.TranslationRule(props,
translation.TranslationRule.REPLACE,
[self.NETWORK],
value_path=[self.NETWORK_ID])
translation.TranslationRule(
props,
translation.TranslationRule.REPLACE,
[self.NETWORK],
value_path=[self.NETWORK_ID]),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.NETWORK],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='network'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.SUBNETPOOL],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='subnetpool'
)
]
@classmethod
@ -337,12 +354,9 @@ class Subnet(neutron.NeutronResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
self.client_plugin().resolve_network(props, self.NETWORK,
'network_id')
props['network_id'] = props.pop(self.NETWORK)
if self.SUBNETPOOL in props and props[self.SUBNETPOOL]:
props['subnetpool_id'] = self.client_plugin(
).find_resourceid_by_name_or_id(
'subnetpool', props.pop('subnetpool'))
props['subnetpool_id'] = props.pop('subnetpool')
self._null_gateway_ip(props)
subnet = self.client().create_subnet({'subnet': props})['subnet']
self.resource_id_set(subnet['id'])

View File

@ -38,7 +38,7 @@ resources:
port_floating:
type: OS::Neutron::Port
properties:
network: xyz1234
network: abcd1234
fixed_ips:
- subnet: sub1234
ip_address: 10.0.0.10
@ -135,6 +135,13 @@ class NeutronFloatingIPTest(common.HeatTestCase):
return_value=True)
def test_floating_ip_validate(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
self.m.ReplayAll()
t = template_format.parse(neutron_floating_no_assoc_template)
stack = utils.parse_stack(t)
fip = stack['floating_ip']
@ -146,6 +153,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
fip = stack['floating_ip']
self.assertRaises(exception.ResourcePropertyDependency,
fip.validate)
self.m.VerifyAll()
def test_floating_ip_router_interface(self):
t = template_format.parse(neutron_floating_template)
@ -160,26 +168,26 @@ class NeutronFloatingIPTest(common.HeatTestCase):
def test_floating_ip_deprecated_router_interface(self):
t = template_format.parse(neutron_floating_template_deprecated)
del t['resources']['gateway']
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
self._test_floating_ip(t, resolve_neutron=False)
self._test_floating_ip(t)
def test_floating_ip_deprecated_router_gateway(self):
t = template_format.parse(neutron_floating_template_deprecated)
del t['resources']['router_interface']
self._test_floating_ip(t, r_iface=False)
def _test_floating_ip(self, tmpl, r_iface=True):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
self._test_floating_ip(t, resolve_neutron=False, r_iface=False)
def _test_floating_ip(self, tmpl, resolve_neutron=True, r_iface=True):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).MultipleTimes().AndReturn('sub1234')
neutronclient.Client.create_floatingip({
'floatingip': {'floating_network_id': u'abcd1234'}
}).AndReturn({'floatingip': {
@ -203,14 +211,6 @@ class NeutronFloatingIPTest(common.HeatTestCase):
'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
qe.NeutronClientException(status_code=404))
self.stub_NetworkConstraint_validate()
if resolve_neutron:
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
stack = utils.parse_stack(tmpl)
# assert the implicit dependency between the floating_ip
@ -247,13 +247,40 @@ class NeutronFloatingIPTest(common.HeatTestCase):
self.m.VerifyAll()
def test_FnGetRefId(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).MultipleTimes().AndReturn('sub1234')
self.m.ReplayAll()
t = template_format.parse(neutron_floating_template)
stack = utils.parse_stack(t)
rsrc = stack['floating_ip']
rsrc.resource_id = 'xyz'
self.assertEqual('xyz', rsrc.FnGetRefId())
self.m.VerifyAll()
def test_FnGetRefId_convergence_cache_data(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).MultipleTimes().AndReturn('sub1234')
self.m.ReplayAll()
t = template_format.parse(neutron_floating_template)
template = tmpl.Template(t)
stack = parser.Stack(utils.dummy_context(), 'test', template,
@ -275,12 +302,6 @@ class NeutronFloatingIPTest(common.HeatTestCase):
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'xyz1234',
cmd_resource=None,
).MultipleTimes().AndReturn('xyz1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
@ -295,7 +316,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
}})
neutronclient.Client.create_port({'port': {
'network_id': u'xyz1234',
'network_id': u'abcd1234',
'fixed_ips': [
{'subnet_id': u'sub1234', 'ip_address': u'10.0.0.10'}
],
@ -458,7 +479,23 @@ class NeutronFloatingIPTest(common.HeatTestCase):
self.m.VerifyAll()
def _test_floating_dependancy(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('abcd1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'router',
'subnet_uuid',
cmd_resource=None,
).MultipleTimes().AndReturn('subnet_uuid')
self.m.ReplayAll()
def test_floatip_port_dependency_subnet(self):
self._test_floating_dependancy()
t = template_format.parse(neutron_floating_no_assoc_template)
stack = utils.parse_stack(t)
@ -468,8 +505,10 @@ class NeutronFloatingIPTest(common.HeatTestCase):
required_by = set(stack.dependencies.required_by(
stack['router_interface']))
self.assertIn(stack['floating_ip'], required_by)
self.m.VerifyAll()
def test_floatip_port_dependency_network(self):
self._test_floating_dependancy()
t = template_format.parse(neutron_floating_no_assoc_template)
del t['resources']['port_floating']['properties']['fixed_ips']
stack = utils.parse_stack(t)
@ -492,22 +531,24 @@ class NeutronFloatingIPTest(common.HeatTestCase):
stack['router_interface']))
self.assertIn(stack['floating_ip'], required_by)
p_show.assert_called_once_with('net_uuid')
self.m.VerifyAll()
def test_floatingip_create_specify_ip_address(self):
t = template_format.parse(neutron_floating_template)
props = t['resources']['floating_ip']['properties']
props['floating_ip_address'] = '172.24.4.98'
stack = utils.parse_stack(t)
self.stub_NetworkConstraint_validate()
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'abcd1234',
cmd_resource=None,
).AndReturn('xyz1234')
).MultipleTimes().AndReturn('abcd1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).MultipleTimes().AndReturn('sub1234')
self.stub_NetworkConstraint_validate()
neutronclient.Client.create_floatingip({
'floatingip': {'floating_network_id': u'xyz1234',
'floatingip': {'floating_network_id': u'abcd1234',
'floating_ip_address': '172.24.4.98'}
}).AndReturn({'floatingip': {
'status': 'ACTIVE',
@ -523,6 +564,10 @@ class NeutronFloatingIPTest(common.HeatTestCase):
}})
self.m.ReplayAll()
t = template_format.parse(neutron_floating_template)
props = t['resources']['floating_ip']['properties']
props['floating_ip_address'] = '172.24.4.98'
stack = utils.parse_stack(t)
fip = stack['floating_ip']
scheduler.TaskRunner(fip.create)()
self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)

View File

@ -515,6 +515,12 @@ class NeutronPortTest(common.HeatTestCase):
"ip_address": "10.0.0.2"
}
}})
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'net5678',
cmd_resource=None,
).MultipleTimes().AndReturn('net5678')
call_dict = copy.deepcopy(props)
call_dict['security_groups'] = [
@ -535,12 +541,6 @@ class NeutronPortTest(common.HeatTestCase):
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})
neutronclient.Client.show_port(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
).AndReturn({'port': {
"status": "ACTIVE",
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})
neutronclient.Client.update_port(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
{'port': {'fixed_ips': []}}

View File

@ -178,7 +178,23 @@ class NeutronRouterTest(common.HeatTestCase):
self.assertEqual([u'792ff887-6c85-4a56-b518-23f24fa65581'],
rsrc.properties['l3_agent_ids'])
def _test_validate(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'net1234',
cmd_resource=None,
).MultipleTimes().AndReturn('net1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).MultipleTimes().AndReturn('sub1234')
self.m.ReplayAll()
def test_router_validate_distribute_l3_agents(self):
self._test_validate()
t = template_format.parse(neutron_template)
props = t['resources']['router']['properties']
@ -198,8 +214,10 @@ class NeutronRouterTest(common.HeatTestCase):
rsrc.validate)
self.assertIn('distributed, l3_agent_id/l3_agent_ids',
six.text_type(exc))
self.m.VerifyAll()
def test_router_validate_l3_agents(self):
self._test_validate()
t = template_format.parse(neutron_template)
props = t['resources']['router']['properties']
@ -212,8 +230,10 @@ class NeutronRouterTest(common.HeatTestCase):
self.assertIn('Non HA routers can only have one L3 agent',
six.text_type(exc))
self.assertIsNone(rsrc.properties.get(rsrc.L3_AGENT_ID))
self.m.VerifyAll()
def test_router_validate_ha_distribute(self):
self._test_validate()
t = template_format.parse(neutron_template)
props = t['resources']['router']['properties']
@ -226,8 +246,10 @@ class NeutronRouterTest(common.HeatTestCase):
exc = self.assertRaises(exception.ResourcePropertyConflict,
rsrc.validate)
self.assertIn('distributed, ha', six.text_type(exc))
self.m.VerifyAll()
def test_router_validate_ha_l3_agents(self):
self._test_validate()
t = template_format.parse(neutron_template)
props = t['resources']['router']['properties']
# test non ha can not specify more than one l3 agent id
@ -239,6 +261,7 @@ class NeutronRouterTest(common.HeatTestCase):
rsrc.validate)
self.assertIn('Non HA routers can only have one L3 agent.',
six.text_type(exc))
self.m.VerifyAll()
def test_router(self):
neutronclient.Client.create_router({
@ -468,6 +491,18 @@ class NeutronRouterTest(common.HeatTestCase):
self._test_router_interface(resolve_router=False)
def _test_router_interface(self, resolve_router=True):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'router',
'3e46229d-8fce-4733-819a-b5fe630550f8',
cmd_resource=None,
).AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'91e47a57-7508-46fe-afc9-fc454e8580e1',
cmd_resource=None,
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
neutronclient.Client.add_interface_router(
'3e46229d-8fce-4733-819a-b5fe630550f8',
{'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
@ -525,14 +560,14 @@ class NeutronRouterTest(common.HeatTestCase):
'router',
'3e46229d-8fce-4733-819a-b5fe630550f8',
cmd_resource=None,
).AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')
).MultipleTimes().AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'91e47a57-7508-46fe-afc9-fc454e8580e1',
cmd_resource=None,
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
).MultipleTimes().AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
neutronclient.Client.add_interface_router(
'3e46229d-8fce-4733-819a-b5fe630550f8',
{'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
@ -575,20 +610,18 @@ class NeutronRouterTest(common.HeatTestCase):
self._test_router_interface_with_port(resolve_port=False)
def _test_router_interface_with_port(self, resolve_port=True):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'router',
'ae478782-53c0-4434-ab16-49900c88016c',
cmd_resource=None,
).AndReturn('ae478782-53c0-4434-ab16-49900c88016c')
port_key = 'port'
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'port',
'9577cafd-8e98-4059-a2e6-8a771b4d318e',
cmd_resource=None,
).AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
).MultipleTimes().AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'router',
'ae478782-53c0-4434-ab16-49900c88016c',
cmd_resource=None,
).MultipleTimes().AndReturn('ae478782-53c0-4434-ab16-49900c88016c')
neutronclient.Client.add_interface_router(
'ae478782-53c0-4434-ab16-49900c88016c',
{'port_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'}
@ -612,7 +645,7 @@ class NeutronRouterTest(common.HeatTestCase):
rsrc = self.create_router_interface(
t, stack, 'router_interface', properties={
'router': 'ae478782-53c0-4434-ab16-49900c88016c',
port_key: '9577cafd-8e98-4059-a2e6-8a771b4d318e'
'port': '9577cafd-8e98-4059-a2e6-8a771b4d318e'
})
# Ensure that properties correctly translates
@ -627,6 +660,25 @@ class NeutronRouterTest(common.HeatTestCase):
self.m.VerifyAll()
def test_router_interface_validate(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'port',
'9577cafd-8e98-4059-a2e6-8a771b4d318e',
cmd_resource=None,
).MultipleTimes().AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'router',
'ae478782-53c0-4434-ab16-49900c88016c',
cmd_resource=None,
).MultipleTimes().AndReturn('ae478782-53c0-4434-ab16-49900c88016c')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'9577cafd-8e98-4059-a2e6-8a771b4d318e',
cmd_resource=None,
).MultipleTimes().AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
self.m.ReplayAll()
t = template_format.parse(neutron_template)
json = t['resources']['router_interface']
json['properties'] = {
@ -669,6 +721,7 @@ class NeutronRouterTest(common.HeatTestCase):
self.assertEqual("At least one of the following properties "
"must be specified: subnet, port",
six.text_type(ex))
self.m.VerifyAll()
def test_gateway_router(self):
neutronV20.find_resourceid_by_name_or_id(
@ -710,14 +763,25 @@ class NeutronRouterTest(common.HeatTestCase):
'network',
'public',
cmd_resource=None,
).MultipleTimes().AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).AndReturn('sub1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).MultipleTimes().AndReturn('sub1234')
neutronclient.Client.create_router({
"router": {
"name": "Test Router",
@ -765,7 +829,6 @@ class NeutronRouterTest(common.HeatTestCase):
def test_create_router_gateway_as_property(self):
self._create_router_with_gateway()
neutronclient.Client.show_router(
'3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
"router": {
@ -790,12 +853,11 @@ class NeutronRouterTest(common.HeatTestCase):
self.m.ReplayAll()
t = template_format.parse(neutron_external_gateway_template)
stack = utils.parse_stack(t)
router = stack['router']
scheduler.TaskRunner(router.create)()
self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8',
router.FnGetRefId())
gateway_info = router.FnGetAtt('external_gateway_info')
rsrc = self.create_router(t, stack, 'router')
rsrc.validate()
ref_id = rsrc.FnGetRefId()
self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8', ref_id)
gateway_info = rsrc.FnGetAtt('external_gateway_info')
self.assertEqual('fc68ea2c-b60b-4b4f-bd82-94ec81110766',
gateway_info.get('network_id'))
self.assertTrue(gateway_info.get('enable_snat'))
@ -811,6 +873,12 @@ class NeutronRouterTest(common.HeatTestCase):
'public',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronclient.Client.create_router({
"router": {
@ -868,13 +936,30 @@ class NeutronRouterTest(common.HeatTestCase):
def test_update_router_gateway_as_property(self):
self._create_router_with_gateway()
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'other_public',
cmd_resource=None,
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
cmd_resource=None,
).AndReturn('sub1234')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'91e47a57-7508-46fe-afc9-fc454e8580e1',
cmd_resource=None,
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
neutronclient.Client.update_router(
'3e46229d-8fce-4733-819a-b5fe630550f8',

View File

@ -128,12 +128,6 @@ class NeutronSubnetTest(common.HeatTestCase):
{'start': '10.0.3.110', 'end': '10.0.3.200'}]}}
t = self._test_subnet(u_props=update_props)
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronclient.Client.update_subnet(
'91e47a57-7508-46fe-afc9-fc454e8580e1', update_props)
stack = utils.parse_stack(t)
@ -184,12 +178,6 @@ class NeutronSubnetTest(common.HeatTestCase):
del update_props_merged['subnet']['value_specs']
t = self._test_subnet(u_props=update_props_merged)
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
stack = utils.parse_stack(t)
self.patchobject(stack['net'], 'FnGetRefId',
return_value='fc68ea2c-b60b-4b4f-bd82-94ec81110766')
@ -222,13 +210,6 @@ class NeutronSubnetTest(common.HeatTestCase):
'name': utils.PhysName('test_stack', 'test_subnet'),
}}
t = self._test_subnet(u_props=update_props_name)
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
stack = utils.parse_stack(t)
self.patchobject(stack['net'], 'FnGetRefId',
return_value='fc68ea2c-b60b-4b4f-bd82-94ec81110766')
@ -277,19 +258,7 @@ class NeutronSubnetTest(common.HeatTestCase):
'subnetpool',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnetpool',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
).MultipleTimes().AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronclient.Client.create_subnet({
'subnet': {
'network_id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
@ -339,12 +308,6 @@ class NeutronSubnetTest(common.HeatTestCase):
self.m.VerifyAll()
def test_subnet_deprecated(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
t = self._test_subnet(resolve_neutron=False)
stack = utils.parse_stack(t)
self.patchobject(stack['net'], 'FnGetRefId',
@ -462,12 +425,6 @@ class NeutronSubnetTest(common.HeatTestCase):
return t
def test_subnet_disable_dhcp(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronclient.Client.create_subnet({
'subnet': {
'name': utils.PhysName('test_stack', 'test_subnet'),
@ -589,12 +546,6 @@ class NeutronSubnetTest(common.HeatTestCase):
}, p)
def test_ipv6_subnet(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
cmd_resource=None,
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronclient.Client.create_subnet({
'subnet': {
'name': utils.PhysName('test_stack', 'test_subnet'),
@ -693,6 +644,19 @@ class NeutronSubnetTest(common.HeatTestCase):
"supported for ipv4.", six.text_type(ex))
def test_validate_both_subnetpool_cidr(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnetpool',
'new_pool',
cmd_resource=None,
).AndReturn('new_pool')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnetpool',
'new_pool',
cmd_resource=None,
).AndReturn('new_pool')
self.m.ReplayAll()
t = template_format.parse(neutron_template)
props = t['resources']['sub_net']['properties']
props['subnetpool'] = 'new_pool'
@ -705,6 +669,7 @@ class NeutronSubnetTest(common.HeatTestCase):
msg = ("Cannot define the following properties at the same time: "
"subnetpool, cidr.")
self.assertEqual(msg, six.text_type(ex))
self.m.VerifyAll()
def test_validate_none_subnetpool_cidr(self):
t = template_format.parse(neutron_template)

View File

@ -318,6 +318,9 @@ class ServersTest(common.HeatTestCase):
self.mock_flavor)
def test_subnet_dependency(self):
self.resolve = self.patchobject(neutronV20,
'find_resourceid_by_name_or_id')
self.resolve.return_value = '12345'
template, stack = self._setup_test_stack('subnet-test',
subnet_template)
server_rsrc = stack['server']
@ -328,6 +331,9 @@ class ServersTest(common.HeatTestCase):
self.assertEqual(subnet_rsrc, deps[3])
def test_subnet_nodeps(self):
self.resolve = self.patchobject(neutronV20,
'find_resourceid_by_name_or_id')
self.resolve.return_value = '12345'
template, stack = self._setup_test_stack('subnet-test',
no_subnet_template)
server_rsrc = stack['server']