Skip to content

Commit

Permalink
Merge pull request #256 from richardstrnad/master
Browse files Browse the repository at this point in the history
Fix method set_scope of OutsideNetwork
  • Loading branch information
michsmit99 committed Nov 11, 2016
2 parents 55f7ae2 + c8662c2 commit 547e6ea
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions acitoolkit/acitoolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,8 @@ def _generate_attributes(self):
if self.get_addr() is None:
raise ValueError('OutsideNetwork ip is not set')
attributes['ip'] = self.get_addr()
if self._scope:
attributes['scope'] = self._scope
return attributes

def set_scope(self, scope):
Expand Down
83 changes: 83 additions & 0 deletions tests/acitoolkit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,89 @@ def test_create(self):
os.remove(expected_file)


class TestOutsideNetwork(unittest.TestCase):
"""
Test OutsideNetwork class
"""
def test_get_json(self):
"""
Test JSON creation for a OutsideNetwork
"""
tenant = Tenant('cisco')
out_net = OutsideNetwork('OutsideNetwork', tenant)
out_net.set_addr('0.0.0.0/0')
out_net_json = out_net.get_json()
self.assertTrue('l3extSubnet' in out_net_json)

def test_get_json_without_ip(self):
"""
Test JSON creation for a OutsideNetwork without an IP
This should raise an error
"""
tenant = Tenant('cisco')
out_net = OutsideNetwork('OutsideNetwork', tenant)
with self.assertRaises(ValueError):
out_net.get_json()

def test_get_parent_class(self):
"""
Test _get_parent_class method
"""
self.assertEqual(OutsideNetwork._get_parent_class(), OutsideEPG)

def test_get_name_dn_delimiters(self):
"""
Test _get_name_dn_delimiters method
"""
self.assertEqual(OutsideNetwork._get_name_dn_delimiters(),
['/extsubnet-[', '/'])

def test_set_scope(self):
"""
Test the set_scope method
"""
tenant = Tenant('cisco')
out_net = OutsideNetwork('OutsideNetwork', tenant)
out_net.set_addr('0.0.0.0/0')
valid_scopes = ['import-rtctrl', 'export-rtctrl', 'import-security',
'shared-security', 'shared-rtctrl']
for scope in valid_scopes:
out_net.set_scope(scope)
bad_scope = 'bad-scope'
self.assertRaises(ValueError, out_net.set_scope, bad_scope)

def test_get_json_detail(self):
"""
Make sure that the json is correct
"""
ip_add = '0.0.0.0/0'
out_net_name = 'OutsideNetwork'
tenant = Tenant('cisco')
out_net = OutsideNetwork(out_net_name, tenant)
out_net.set_addr(ip_add)
out_net_json = out_net.get_json()
self.assertEqual(ip_add,
out_net_json['l3extSubnet']['attributes']['ip'])
self.assertEqual(out_net_name,
out_net_json['l3extSubnet']['attributes']['name'])

def test_get_json_detail_set_scope(self):
"""
Make sure that the json is correct when a scope is set
"""
ip_add = '0.0.0.0/0'
out_net_name = 'OutsideNetwork'
tenant = Tenant('cisco')
out_net = OutsideNetwork(out_net_name, tenant)
out_net.set_addr(ip_add)
valid_scopes = ['import-rtctrl', 'export-rtctrl', 'import-security',
'shared-security', 'shared-rtctrl']
for scope in valid_scopes:
out_net_json = out_net.get_json()
self.assertEqual(scope,
out_net_json['l3extSubnet']['attributes']['scope'])


class TestContext(unittest.TestCase):
"""
Test Context class
Expand Down

0 comments on commit 547e6ea

Please sign in to comment.