Fix issue with network creation and reapproval

* Once the interface is created, it shouldn't happen again
  in the event of a rerun. Storing a flag now to avoid check
  and skip if done already.

Change-Id: I71808b4e79889b6d3bd397d4fec459e7f9f07909
This commit is contained in:
adrian-turjak 2017-05-24 16:05:21 +12:00
parent ca21dabdf8
commit 7ea3d2bd35
3 changed files with 26 additions and 15 deletions

View File

@ -149,17 +149,22 @@ class NewDefaultNetworkAction(BaseAction, ProjectMixin):
self.add_note("Router already created for project %s" %
self.project_id)
try:
interface_body = {
"subnet_id": self.get_cache('subnet_id')
}
neutron.add_interface_router(self.get_cache('router_id'),
body=interface_body)
except Exception as e:
if not self.get_cache('port_id'):
try:
interface_body = {
"subnet_id": self.get_cache('subnet_id')
}
interface = neutron.add_interface_router(
self.get_cache('router_id'), body=interface_body)
except Exception as e:
self.add_note(
"Error: '%s' while attaching interface" % e)
raise
self.set_cache('port_id', interface['port_id'])
self.add_note("Interface added to router for subnet")
else:
self.add_note(
"Error: '%s' while attaching interface" % e)
raise
self.add_note("Interface added to router for subnet")
"Interface added to router for project %s" % self.project_id)
def _pre_approve(self):
# Note: Do we need to get this from cache? it is a required setting

View File

@ -94,11 +94,13 @@ class FakeNeutronClient(object):
def add_interface_router(self, router_id, body):
global neutron_cache
# find project_id
router = neutron_cache['RegionOne']['test_project_id'][
'routers'][router_id]
router['router']['interface'] = body
return router
port_id = "port_id_%s" % neutron_cache['RegionOne']['i']
neutron_cache['RegionOne']['i'] += 1
interface = {
'port_id': port_id,
'id': router_id,
'subnet_id': body['subnet_id']}
return interface
def update_quota(self, project_id, body):
global neutron_cache

View File

@ -81,6 +81,7 @@ class ProjectSetupActionTests(TestCase):
self.assertEquals(
action.action.cache,
{'network_id': 'net_id_0',
'port_id': 'port_id_3',
'router_id': 'router_id_2',
'subnet_id': 'subnet_id_1'}
)
@ -197,6 +198,7 @@ class ProjectSetupActionTests(TestCase):
self.assertEquals(
action.action.cache,
{'network_id': 'net_id_0',
'port_id': 'port_id_3',
'router_id': 'router_id_2',
'subnet_id': 'subnet_id_1'}
)
@ -256,6 +258,7 @@ class ProjectSetupActionTests(TestCase):
self.assertEquals(
action.action.cache,
{'network_id': 'net_id_0',
'port_id': 'port_id_3',
'router_id': 'router_id_2',
'subnet_id': 'subnet_id_1'}
)
@ -404,6 +407,7 @@ class ProjectSetupActionTests(TestCase):
self.assertEquals(
action.action.cache,
{'network_id': 'net_id_0',
'port_id': 'port_id_3',
'router_id': 'router_id_2',
'subnet_id': 'subnet_id_1'}
)