Adding vpn + dhcp unit tests

Change-Id: I4941b2f1ebcfbf855700fb417527ba9c1f18e23b
changes/84/555284/1
Adit Sarfaty 5 years ago
parent 3483579700
commit 9e2e758911

@ -17,7 +17,6 @@ from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase
from vmware_nsxlib.v3 import native_dhcp
# TODO(asarfaty): Add more test cases here
class TestNativeDhcp(nsxlib_testcase.NsxLibTestCase):
"""Tests for vmware_nsxlib.v3.native_dhcp.NsxLibNativeDhcp."""
@ -31,15 +30,18 @@ class TestNativeDhcp(nsxlib_testcase.NsxLibTestCase):
self.default_dns_domain = 'b.com'
self.default_dns_nameserver = '2.2.2.2'
def _get_server_config(self, with_net_dns=True, with_default_dns=True):
net = {'name': 'dummy',
'id': 'dummy'}
def _get_server_config(self, with_net_dns=True, with_default_dns=True,
tags=None, gateway_ip='2.2.2.2', cidr='5.5.0.0/24',
port_ip='5.5.0.1', net_name='dummy',
net_id='dummy_uuid'):
net = {'name': net_name, 'id': net_id}
subnet = {'dns_nameservers': None,
'gateway_ip': '2.2.2.2',
'cidr': '5.5.0.0/24',
'gateway_ip': gateway_ip,
'cidr': cidr,
'host_routes': []}
port = {'fixed_ips': [{'ip_address': '5.5.0.1'}]}
tags = []
port = {'fixed_ips': [{'ip_address': port_ip}]}
if not tags:
tags = []
if with_net_dns:
net['dns_domain'] = {'dns_domain': self.net_dns_domain}
subnet['dns_nameservers'] = [self.subnet_dns_nameserver]
@ -87,6 +89,33 @@ class TestNativeDhcp(nsxlib_testcase.NsxLibTestCase):
self.assertEqual(nsxlib_testcase.DNS_NAMESERVERS,
result['dns_nameservers'])
def test_build_server_config_with_tags(self):
tags = [{'scope': 'a', 'value': 'a'}]
result = self._get_server_config(tags=tags)
self.assertEqual(tags, result['tags'])
def test_build_server_config_with_gateway(self):
gw_ip = '10.10.10.10'
result = self._get_server_config(gateway_ip=gw_ip)
self.assertEqual(gw_ip, result['gateway_ip'])
def test_build_server_config_with_server_ip(self):
result = self._get_server_config(cidr='7.7.7.0/24', port_ip='7.7.7.14')
self.assertEqual('7.7.7.14/24', result['server_ip'])
def test_build_server_config_with_name(self):
net_name = 'net1'
net_id = 'uuid1uuid2'
result = self._get_server_config(net_name=net_name, net_id=net_id)
self.assertEqual('%s_%s...%s' % (net_name, net_id[:5], net_id[-5:]),
result['name'])
def test_build_server_config_no_name(self):
net_id = 'uuid1uuid2'
result = self._get_server_config(net_name=None, net_id=net_id)
self.assertEqual('dhcpserver_%s...%s' % (net_id[:5], net_id[-5:]),
result['name'])
def test_build_static_routes(self):
gateway_ip = '2.2.2.2'
cidr = '5.5.0.0/24'

@ -285,8 +285,7 @@ class TestSession(test_resources.BaseTestResource):
}, sort_keys=True),
headers=self.default_headers())
# TODO(asarfaty): add tests for update & rules
def test_session_update(self):
def test_session_update_with_rules(self):
fake_sess = test_constants.FAKE_VPN_SESS.copy()
mocked_resource = self.get_mocked_resource(response=fake_sess)
uuid = test_constants.FAKE_VPN_SESS_ID
@ -308,6 +307,24 @@ class TestSession(test_resources.BaseTestResource):
data=jsonutils.dumps(fake_sess, sort_keys=True),
headers=self.default_headers())
def test_session_update_no_rules(self):
fake_sess = test_constants.FAKE_VPN_SESS.copy()
mocked_resource = self.get_mocked_resource(response=fake_sess)
uuid = test_constants.FAKE_VPN_SESS_ID
new_name = 'session'
new_desc = 'desc'
mocked_resource.update(uuid, name=new_name, description=new_desc,
enabled=False)
fake_sess['description'] = new_desc
fake_sess['display_name'] = new_name
fake_sess['enabled'] = False
test_client.assert_json_call(
'put', mocked_resource,
'https://1.2.3.4/api/v1/%s/%s' % (mocked_resource.uri_segment,
uuid),
data=jsonutils.dumps(fake_sess, sort_keys=True),
headers=self.default_headers())
class TestService(test_resources.BaseTestResource):

Loading…
Cancel
Save