Merge "Revert "Resolve name/id using translation rules""

This commit is contained in:
Jenkins 2016-02-11 18:22:10 +00:00 committed by Gerrit Code Review
commit 823a6bbd90
9 changed files with 153 additions and 302 deletions

View File

@ -137,14 +137,6 @@ 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'
)
]
@ -223,7 +215,8 @@ class FloatingIP(neutron.NeutronResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
props['floating_network_id'] = props.pop(self.FLOATING_NETWORK)
self.client_plugin().resolve_network(props, self.FLOATING_NETWORK,
'floating_network_id')
fip = self.client().create_floatingip({
'floatingip': props})['floatingip']
self.resource_id_set(fip['id'])
@ -314,7 +307,9 @@ 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

@ -341,22 +341,6 @@ 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'
)
]
@ -378,7 +362,7 @@ class Port(neutron.NeutronResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
props['network_id'] = props.pop(self.NETWORK)
self.client_plugin().resolve_network(props, self.NETWORK, 'network_id')
self._prepare_port_properties(props)
qos_policy = props.pop(self.QOS_POLICY, None)
if qos_policy:
@ -472,6 +456,19 @@ 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:
after_id = self.client_plugin().find_neutron_resource(
after_props, self.NETWORK, 'network')
before_id = self.client_plugin().find_neutron_resource(
before_props, self.NETWORK, '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

@ -164,17 +164,8 @@ 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')
]
if props.get(self.L3_AGENT_ID):
rules.extend([
return [
translation.TranslationRule(
props,
translation.TranslationRule.ADD,
@ -184,8 +175,8 @@ class Router(neutron.NeutronResource):
props,
translation.TranslationRule.DELETE,
[self.L3_AGENT_ID]
)])
return rules
)
]
def validate(self):
super(Router, self).validate()
@ -222,7 +213,8 @@ class Router(neutron.NeutronResource):
def _resolve_gateway(self, props):
gateway = props.get(self.EXTERNAL_GATEWAY)
if gateway:
gateway['network_id'] = gateway.pop(self.EXTERNAL_GATEWAY_NETWORK)
self.client_plugin().resolve_network(
gateway, self.EXTERNAL_GATEWAY_NETWORK, 'network_id')
if gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT] is None:
del gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT]
return props
@ -394,33 +386,7 @@ 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):
@ -440,12 +406,15 @@ class RouterInterface(neutron.NeutronResource):
self.PORT)
def handle_create(self):
router_id = dict(self.properties).get(self.ROUTER)
router_id = self.client_plugin().resolve_router(
dict(self.properties), self.ROUTER, 'router_id')
key = 'subnet_id'
value = dict(self.properties).get(self.SUBNET)
value = self.client_plugin().resolve_subnet(
dict(self.properties), self.SUBNET, key)
if not value:
key = 'port_id'
value = dict(self.properties).get(self.PORT)
value = self.client_plugin().resolve_port(
dict(self.properties), self.PORT, key)
self.client().add_interface_router(
router_id,
{key: value})
@ -519,16 +488,7 @@ 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):
@ -559,7 +519,8 @@ class RouterGateway(neutron.NeutronResource):
def handle_create(self):
router_id = self.properties[self.ROUTER_ID]
network_id = dict(self.properties).get(self.NETWORK)
network_id = self.client_plugin().resolve_network(
dict(self.properties), self.NETWORK, 'network_id')
self.client().add_gateway_router(
router_id,
{'network_id': network_id})

View File

@ -271,27 +271,10 @@ 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.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'
)
translation.TranslationRule(props,
translation.TranslationRule.REPLACE,
[self.NETWORK],
value_path=[self.NETWORK_ID])
]
@classmethod
@ -344,9 +327,12 @@ class Subnet(neutron.NeutronResource):
props = self.prepare_properties(
self.properties,
self.physical_resource_name())
props['network_id'] = props.pop(self.NETWORK)
self.client_plugin().resolve_network(props, self.NETWORK,
'network_id')
if self.SUBNETPOOL in props and props[self.SUBNETPOOL]:
props['subnetpool_id'] = props.pop('subnetpool')
props['subnetpool_id'] = self.client_plugin(
).find_resourceid_by_name_or_id(
'subnetpool', 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: abcd1234
network: xyz1234
fixed_ips:
- subnet: sub1234
ip_address: 10.0.0.10
@ -135,13 +135,6 @@ 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']
@ -153,7 +146,6 @@ 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)
@ -168,26 +160,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']
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)
def test_floating_ip_deprecated_router_gateway(self):
t = template_format.parse(neutron_floating_template_deprecated)
del t['resources']['router_interface']
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnet',
'sub1234',
'network',
'abcd1234',
cmd_resource=None,
).MultipleTimes().AndReturn('sub1234')
).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):
neutronclient.Client.create_floatingip({
'floatingip': {'floating_network_id': u'abcd1234'}
}).AndReturn({'floatingip': {
@ -211,6 +203,14 @@ 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,40 +247,13 @@ 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,
@ -302,6 +275,12 @@ 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',
@ -316,7 +295,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
}})
neutronclient.Client.create_port({'port': {
'network_id': u'abcd1234',
'network_id': u'xyz1234',
'fixed_ips': [
{'subnet_id': u'sub1234', 'ip_address': u'10.0.0.10'}
],
@ -479,23 +458,7 @@ 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)
@ -505,10 +468,8 @@ 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)
@ -531,24 +492,22 @@ 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,
).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()
).AndReturn('xyz1234')
neutronclient.Client.create_floatingip({
'floatingip': {'floating_network_id': u'abcd1234',
'floatingip': {'floating_network_id': u'xyz1234',
'floating_ip_address': '172.24.4.98'}
}).AndReturn({'floatingip': {
'status': 'ACTIVE',
@ -564,10 +523,6 @@ 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,12 +515,6 @@ 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'] = [
@ -541,6 +535,12 @@ 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

@ -175,23 +175,7 @@ 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']
@ -211,10 +195,8 @@ 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']
@ -227,10 +209,8 @@ 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']
@ -243,10 +223,8 @@ 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
@ -258,7 +236,6 @@ 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({
@ -488,18 +465,6 @@ 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'}
@ -557,14 +522,14 @@ class NeutronRouterTest(common.HeatTestCase):
'router',
'3e46229d-8fce-4733-819a-b5fe630550f8',
cmd_resource=None,
).MultipleTimes().AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')
).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,
).MultipleTimes().AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
neutronclient.Client.add_interface_router(
'3e46229d-8fce-4733-819a-b5fe630550f8',
{'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
@ -607,18 +572,20 @@ 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),
'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')
).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')
neutronclient.Client.add_interface_router(
'ae478782-53c0-4434-ab16-49900c88016c',
{'port_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'}
@ -642,7 +609,7 @@ class NeutronRouterTest(common.HeatTestCase):
rsrc = self.create_router_interface(
t, stack, 'router_interface', properties={
'router': 'ae478782-53c0-4434-ab16-49900c88016c',
'port': '9577cafd-8e98-4059-a2e6-8a771b4d318e'
port_key: '9577cafd-8e98-4059-a2e6-8a771b4d318e'
})
# Ensure that properties correctly translates
@ -657,25 +624,6 @@ 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'] = {
@ -718,7 +666,6 @@ 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(
@ -760,13 +707,7 @@ class NeutronRouterTest(common.HeatTestCase):
'network',
'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')
).MultipleTimes().AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
neutronclient.Client.create_router({
"router": {
@ -807,6 +748,7 @@ 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": {
@ -828,7 +770,9 @@ class NeutronRouterTest(common.HeatTestCase):
t = template_format.parse(neutron_external_gateway_template)
stack = utils.parse_stack(t)
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')
@ -844,12 +788,6 @@ 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": {
@ -905,24 +843,13 @@ 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),
'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,6 +128,12 @@ 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',
'None',
cmd_resource=None,
).AndReturn('None')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'router',
@ -182,6 +188,12 @@ 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',
'None',
cmd_resource=None,
).AndReturn('None')
stack = utils.parse_stack(t)
rsrc = self.create_subnet(t, stack, 'sub_net')
self.m.ReplayAll()
@ -212,6 +224,13 @@ 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',
'None',
cmd_resource=None,
).AndReturn('None')
stack = utils.parse_stack(t)
rsrc = self.create_subnet(t, stack, 'sub_net')
self.m.ReplayAll()
@ -258,7 +277,19 @@ class NeutronSubnetTest(common.HeatTestCase):
'subnetpool',
'None',
cmd_resource=None,
).MultipleTimes().AndReturn('None')
).AndReturn('None')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'None',
cmd_resource=None,
).AndReturn('None')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'subnetpool',
'None',
cmd_resource=None,
).AndReturn('None')
neutronclient.Client.create_subnet({
'subnet': {
'network_id': u'None',
@ -306,15 +337,22 @@ class NeutronSubnetTest(common.HeatTestCase):
self.m.VerifyAll()
def test_subnet_deprecated(self):
t = self._test_subnet(resolve_neutron=False)
stack = utils.parse_stack(t)
rsrc = self.create_subnet(t, stack, 'sub_net')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'None',
cmd_resource=None,
).AndReturn('None')
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'router',
'None',
cmd_resource=None,
).MultipleTimes().AndReturn('None')
t = self._test_subnet(resolve_neutron=False)
stack = utils.parse_stack(t)
rsrc = self.create_subnet(t, stack, 'sub_net')
).AndReturn('None')
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
@ -427,6 +465,12 @@ class NeutronSubnetTest(common.HeatTestCase):
return t
def test_subnet_disable_dhcp(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'None',
cmd_resource=None,
).AndReturn('None')
neutronclient.Client.create_subnet({
'subnet': {
'name': utils.PhysName('test_stack', 'test_subnet'),
@ -546,6 +590,12 @@ class NeutronSubnetTest(common.HeatTestCase):
}, p)
def test_ipv6_subnet(self):
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'None',
cmd_resource=None,
).AndReturn('None')
neutronclient.Client.create_subnet({
'subnet': {
'name': utils.PhysName('test_stack', 'test_subnet'),
@ -636,19 +686,6 @@ 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'
@ -659,7 +696,6 @@ 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

@ -305,9 +305,6 @@ class ServersTest(common.HeatTestCase):
self.stub_VolumeConstraint_validate()
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']
@ -318,9 +315,6 @@ 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']