Move create_subnet into base class

This consolidate the logic to create/cleanup neutron subnet.

Change-Id: I731b78eb05dfa06a1c459872cc3941a43dd80327
This commit is contained in:
Hongbin Lu 2018-10-31 03:49:07 +00:00
parent 4e732fe5e9
commit 3d8b64b79b
2 changed files with 17 additions and 7 deletions

View File

@ -51,7 +51,6 @@ class TestContainer(base.BaseZunTest):
cls.images_client = cls.os_primary.images_client
cls.ports_client = cls.os_primary.ports_client
cls.sgs_client = cls.os_primary.sgs_client
cls.subnets_client = cls.os_primary.subnets_client
cls.vol_client = cls.os_primary.vol_client
@classmethod
@ -258,9 +257,8 @@ class TestContainer(base.BaseZunTest):
"""
test_net = self.create_network(name='test_net')
self.assertEqual(test_net['name'], 'test_net')
test_subnet = self.subnets_client.create_subnet(
name='test_subnet', network_id=test_net['id'], ip_version=4,
cidr='10.1.0.0/24')['subnet']
test_subnet = self.create_subnet(
test_net, name='test_subnet', cidr='10.1.0.0/24')
self.assertEqual(test_subnet['name'], 'test_subnet')
self.assertEqual(test_subnet['cidr'], '10.1.0.0/24')
_, model = self._run_container(nets=[{'network': test_net['id']}])
@ -284,9 +282,9 @@ class TestContainer(base.BaseZunTest):
client=self.os_admin.neutron_client,
name='test_net', shared=True)
self.assertEqual(test_net['name'], 'test_net')
test_subnet = self.os_admin.subnets_client.create_subnet(
name='test_subnet', network_id=test_net['id'], ip_version=4,
cidr='10.1.0.0/24')['subnet']
test_subnet = self.create_subnet(
test_net, client=self.os_admin.subnets_client,
name='test_subnet', cidr='10.1.0.0/24')
self.assertEqual(test_subnet['name'], 'test_subnet')
self.assertEqual(test_subnet['cidr'], '10.1.0.0/24')
_, model = self._run_container(nets=[{'network': test_net['id']}])

View File

@ -44,6 +44,7 @@ class BaseZunTest(api_version_utils.BaseMicroversionTest,
def setup_clients(cls):
super(BaseZunTest, cls).setup_clients()
cls.networks_client = cls.os_primary.neutron_client
cls.subnets_client = cls.os_primary.subnets_client
@classmethod
def setup_credentials(cls):
@ -79,3 +80,14 @@ class BaseZunTest(api_version_utils.BaseMicroversionTest,
network = client.create_network(**kwargs)['network']
self.addCleanup(client.delete_network, network['id'])
return network
def create_subnet(self, network, client=None, **values):
kwargs = {'name': data_utils.rand_name('test-subnet'),
'network_id': network['id'],
'ip_version': 4}
if values:
kwargs.update(values)
client = client or self.subnets_client
subnet = client.create_subnet(**kwargs)['subnet']
self.addCleanup(client.delete_subnet, subnet['id'])
return subnet