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.add_note("Router already created for project %s" %
self.project_id) self.project_id)
if not self.get_cache('port_id'):
try: try:
interface_body = { interface_body = {
"subnet_id": self.get_cache('subnet_id') "subnet_id": self.get_cache('subnet_id')
} }
neutron.add_interface_router(self.get_cache('router_id'), interface = neutron.add_interface_router(
body=interface_body) self.get_cache('router_id'), body=interface_body)
except Exception as e: except Exception as e:
self.add_note( self.add_note(
"Error: '%s' while attaching interface" % e) "Error: '%s' while attaching interface" % e)
raise raise
self.set_cache('port_id', interface['port_id'])
self.add_note("Interface added to router for subnet") self.add_note("Interface added to router for subnet")
else:
self.add_note(
"Interface added to router for project %s" % self.project_id)
def _pre_approve(self): def _pre_approve(self):
# Note: Do we need to get this from cache? it is a required setting # 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): def add_interface_router(self, router_id, body):
global neutron_cache global neutron_cache
# find project_id port_id = "port_id_%s" % neutron_cache['RegionOne']['i']
router = neutron_cache['RegionOne']['test_project_id'][ neutron_cache['RegionOne']['i'] += 1
'routers'][router_id] interface = {
router['router']['interface'] = body 'port_id': port_id,
return router 'id': router_id,
'subnet_id': body['subnet_id']}
return interface
def update_quota(self, project_id, body): def update_quota(self, project_id, body):
global neutron_cache global neutron_cache

View File

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