Skip to content

Commit

Permalink
Fixed cassandra read methods of VN and RT in snat_agent
Browse files Browse the repository at this point in the history
Change-Id: Ie9493ee7aaed88372e65618d99d43f44c1a8e5c2
Closes-bug: #1491246
  • Loading branch information
anbu-enovance committed Sep 7, 2015
1 parent 897cfff commit 47697c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
17 changes: 4 additions & 13 deletions src/config/svc-monitor/svc_monitor/snat_agent.py
Expand Up @@ -86,10 +86,7 @@ def _get_net_uuids(self, vmi_uuids):
for uuid in vmi_uuids]

def _virtual_network_read(self, net_uuid):
(ok, result) = DBBaseSM()._cassandra.read('virtual-network', net_uuid)
if not ok:
return
return VirtualNetwork.from_dict(**result[0])
return DBBaseSM().read_vnc_obj(obj_type="virtual_network", uuid=net_uuid)

def _add_route_table(self, net_uuid, rt_obj):
net_obj = self._virtual_network_read(net_uuid)
Expand Down Expand Up @@ -134,17 +131,11 @@ def _get_route_table(self, router_obj, project_obj):
rt_name = 'rt_' + router_obj.uuid
rt_fq_name = project_obj.fq_name + [rt_name]
try:
rt_uuid = self._cassandra.fq_name_to_uuid('route-table',
rt_fq_name)
except NoIdError:
return

(ok, result) = DBBaseSM()._cassandra.read('route-table', rt_uuid)
if not ok:
return DBBaseSM().read_vnc_obj(
obj_type="route_table", fq_name=rt_fq_name)
except vnc_exc.NoIdError:
return

return RouteTable.from_dict(**result[0])

def _add_snat_instance(self, router_obj):
try:
vnc_rtr_obj = self._vnc_lib.logical_router_read(id=router_obj.uuid)
Expand Down
24 changes: 12 additions & 12 deletions src/config/svc-monitor/svc_monitor/tests/test_snat_agent.py
Expand Up @@ -158,7 +158,7 @@ def test_gateway_set(self):
# will return the private virtual network, and will return
# an error when trying to read the service snat VN
def db_read_side_effect(obj_type, uuids):
if obj_type != 'virtual-network':
if obj_type != 'virtual_network':
return (False, None)
if 'private1-uuid' in uuids:
return (True, [{'fq_name': ['default-domain',
Expand Down Expand Up @@ -204,7 +204,7 @@ def no_id_side_effect(type, fq_name):

# check that the correct private network is read
self.cassandra.read.assert_called_with(
'virtual-network', 'private1-uuid')
'virtual_network', ['private1-uuid'])

# check that the snat service network is created
left = ('default-domain:demo:snat-si-left_snat_' +
Expand Down Expand Up @@ -240,7 +240,7 @@ def _test_snat_delete(self, router_dict):

# now we have a route table
def no_id_side_effect(type, fq_name):
if type == 'route-table':
if type == 'route_table':
return 'fake-uuid'

raise NoIdError("xxx")
Expand All @@ -258,7 +258,7 @@ def no_id_side_effect(type, fq_name):
rt_dict['virtual_network_back_refs'] = [{'uuid': 'private1-uuid'}]

def db_read_side_effect(obj_type, uuids):
if obj_type == 'route-table':
if obj_type == 'route_table':
return (True, [rt_dict])
if 'private1-uuid' in uuids:
return (True, [{'fq_name': ['default-domain',
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_snat_delete_without_rt_net_back_refs(self):

# now we have a route table
def no_id_side_effect(type, fq_name):
if type == 'route-table':
if type == 'route_table':
return 'fake-uuid'

raise NoIdError("xxx")
Expand All @@ -320,7 +320,7 @@ def no_id_side_effect(type, fq_name):
rt_dict = self.obj_to_dict(rt_obj)

def db_read_side_effect(obj_type, uuids):
if obj_type == 'route-table':
if obj_type == 'route_table':
return (True, [rt_dict])
if 'private2-uuid' in uuids:
return (True, [{'fq_name': ['default-domain',
Expand Down Expand Up @@ -413,7 +413,7 @@ def test_add_interface(self):

# now we have a route table
def no_id_side_effect(type, fq_name):
if type == 'route-table':
if type == 'route_table':
return 'fake-uuid'

raise NoIdError("xxx")
Expand All @@ -427,7 +427,7 @@ def no_id_side_effect(type, fq_name):
rt_dict['virtual_network_back_refs'] = [{'uuid': 'private1-uuid'}]

def db_read_side_effect(obj_type, uuids):
if obj_type == 'route-table':
if obj_type == 'route_table':
return (True, [rt_dict])
if 'private2-uuid' in uuids:
return (True, [{'fq_name': ['default-domain',
Expand All @@ -445,8 +445,8 @@ def db_read_side_effect(obj_type, uuids):
self.snat_agent.update_snat_instance(router)

# check that the correct private network is read
self.cassandra.read.assert_called_with('virtual-network',
'private2-uuid')
self.cassandra.read.assert_called_with('virtual_network',
['private2-uuid'])

# check that the route table is applied to the network
rt_name = 'rt_' + ROUTER_1['uuid']
Expand Down Expand Up @@ -482,7 +482,7 @@ def test_del_interface(self):
rt_obj = self.vnc_lib.route_table_create.mock_calls[0][1][0]

def db_read_side_effect(obj_type, uuids):
if obj_type == 'route-table':
if obj_type == 'route_table':
return (True, [self.obj_to_dict(rt_obj)])
if 'private1-uuid' in uuids:
return (True, [{'fq_name': ['default-domain',
Expand All @@ -501,7 +501,7 @@ def db_read_side_effect(obj_type, uuids):

# check that the correct private network is read
self.cassandra.read.assert_called_with(
'virtual-network', 'private1-uuid')
'virtual_network', ['private1-uuid'])

# check that the route table is applied to the network
self.vnc_lib.virtual_network_update.assert_called_with(
Expand Down

0 comments on commit 47697c9

Please sign in to comment.