Refactor test cases after adding new params to create_floatingip.

Change-Id: I1feaed67e46edce85397907528e23c4a5f487c1f
This commit is contained in:
Federico Ressi 2018-07-06 09:46:39 +02:00
parent e96fe65007
commit 3dfa94cf4c
14 changed files with 35 additions and 85 deletions

View File

@ -162,14 +162,12 @@ class ExternalNetworksRBACTestJSON(base.BaseAdminNetworkTest):
target_tenant=self.admin_client.tenant_id)
self.create_subnet(net, client=self.admin_client, enable_dhcp=False)
with testtools.ExpectedException(lib_exc.NotFound):
self.client2.create_floatingip(
floating_network_id=net['id'])
self.create_floatingip(net['id'], client=self.client2)
self.admin_client.create_rbac_policy(
object_type='network', object_id=net['id'],
action='access_as_external',
target_tenant=self.client2.tenant_id)
self.client2.create_floatingip(
floating_network_id=net['id'])
self.create_floatingip(net['id'], client=self.client2)
@decorators.idempotent_id('476be1e0-f72e-47dc-9a14-4435926bbe82')
def test_policy_allows_tenant_to_attach_ext_gw(self):

View File

@ -32,7 +32,7 @@ class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest):
def resource_setup(cls):
super(FloatingIPAdminTestJSON, cls).resource_setup()
cls.ext_net_id = CONF.network.public_network_id
cls.floating_ip = cls.create_floatingip(cls.ext_net_id)
cls.floating_ip = cls.create_floatingip()
cls.alt_client = cls.os_alt.network_client
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
@ -44,10 +44,7 @@ class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest):
@decorators.attr(type='negative')
@decorators.idempotent_id('11116ee9-4e99-5b15-b8e1-aa7df92ca589')
def test_associate_floating_ip_with_port_from_another_project(self):
body = self.client.create_floatingip(
floating_network_id=self.ext_net_id)
floating_ip = body['floatingip']
self.addCleanup(self.client.delete_floatingip, floating_ip['id'])
floating_ip = self.create_floatingip()
project_id = self.create_project()['id']
port = self.admin_client.create_port(network_id=self.network['id'],
@ -65,20 +62,17 @@ class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest):
# other tests may end up stealing the IP before we can use it
# since it's on the external network so we need to retry if it's
# in use.
for i in range(100):
for _ in range(100):
fip = self.get_unused_ip(self.ext_net_id, ip_version=4)
try:
body = self.admin_client.create_floatingip(
floating_network_id=self.ext_net_id,
floating_ip_address=fip)
created_floating_ip = self.create_floatingip(
floating_ip_address=fip,
client=self.admin_client)
break
except lib_exc.Conflict:
pass
else:
self.fail("Could not get an unused IP after 100 attempts")
created_floating_ip = body['floatingip']
self.addCleanup(self.admin_client.delete_floatingip,
created_floating_ip['id'])
self.assertIsNotNone(created_floating_ip['id'])
self.assertIsNotNone(created_floating_ip['tenant_id'])
self.assertEqual(created_floating_ip['floating_ip_address'], fip)

View File

@ -167,11 +167,7 @@ class QuotasAdminNegativeTestJSON(test_quotas.QuotasTestBase):
new_quotas = {'floatingip': 1}
self._setup_quotas(tenant_id, **new_quotas)
ext_net_id = CONF.network.public_network_id
fip_args = {'tenant_id': tenant_id,
'floating_network_id': ext_net_id}
fip = self.admin_client.create_floatingip(**fip_args)['floatingip']
self.addCleanup(self.admin_client.delete_floatingip, fip['id'])
self.create_floatingip(client=self.admin_client, tenant_id=tenant_id)
self.assertRaises(lib_exc.Conflict,
self.admin_client.create_floatingip, **fip_args)
self.assertRaises(lib_exc.Conflict, self.create_floatingip,
client=self.admin_client, tenant_id=tenant_id)

View File

@ -15,7 +15,6 @@ from tempest.lib import decorators
from tempest.lib import exceptions as lib_exc
from neutron_tempest_plugin.api import base
from neutron_tempest_plugin import config
class TagTestJSON(base.BaseAdminNetworkTest):
@ -177,9 +176,7 @@ class TagFloatingIpTestJSON(TagTestJSON):
@classmethod
@utils.requires_ext(extension="router", service="network")
def _create_resource(cls):
cls.ext_net_id = config.CONF.network.public_network_id
floatingip = cls.create_floatingip(cls.ext_net_id)
return floatingip['id']
return cls.create_floatingip()['id']
@decorators.attr(type='smoke')
@decorators.idempotent_id('53f6c2bf-e272-4e9e-b9a9-b165eb7be807')
@ -418,9 +415,7 @@ class TagFilterFloatingIpTestJSON(TagFilterTestJSON):
@classmethod
@utils.requires_ext(extension="router", service="network")
def _create_resource(cls):
cls.ext_net_id = config.CONF.network.public_network_id
floatingip = cls.create_floatingip(cls.ext_net_id)
return floatingip['id']
return cls.create_floatingip()['id']
def _list_resource(self, filters):
res = self.client.list_floatingips(**filters)

View File

@ -48,11 +48,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest):
# originally the floating IP had no attributes other than its
# association, so an update with an empty body was a signal to
# clear the association. This test ensures we maintain that behavior.
body = self.client.create_floatingip(
floating_network_id=self.ext_net_id,
port_id=self.ports[0]['id'],
)['floatingip']
self.floating_ips.append(body)
body = self.create_floatingip(port=self.ports[0])
self.assertEqual(self.ports[0]['id'], body['port_id'])
body = self.client.update_floatingip(body['id'])['floatingip']
self.assertFalse(body['port_id'])
@ -61,12 +57,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest):
@utils.requires_ext(extension="standard-attr-description",
service="network")
def test_create_update_floatingip_description(self):
body = self.client.create_floatingip(
floating_network_id=self.ext_net_id,
port_id=self.ports[0]['id'],
description='d1'
)['floatingip']
self.floating_ips.append(body)
body = self.create_floatingip(port=self.ports[0], description='d1')
self.assertEqual('d1', body['description'])
body = self.client.show_floatingip(body['id'])['floatingip']
self.assertEqual('d1', body['description'])
@ -84,12 +75,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest):
service="network")
def test_floatingip_update_extra_attributes_port_id_not_changed(self):
port_id = self.ports[1]['id']
body = self.client.create_floatingip(
floating_network_id=self.ext_net_id,
port_id=port_id,
description='d1'
)['floatingip']
self.floating_ips.append(body)
body = self.create_floatingip(port_id=port_id, description='d1')
self.assertEqual('d1', body['description'])
body = self.client.show_floatingip(body['id'])['floatingip']
self.assertEqual(port_id, body['port_id'])
@ -112,12 +98,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest):
@utils.requires_ext(extension="fip-port-details", service="network")
def test_create_update_floatingip_port_details(self):
body = self.client.create_floatingip(
floating_network_id=self.ext_net_id,
port_id=self.ports[0]['id'],
description='d1'
)['floatingip']
self.floating_ips.append(body)
body = self.create_floatingip(port=self.ports[0], description='d1')
self._assert_port_details(self.ports[0], body)
body = self.client.show_floatingip(body['id'])['floatingip']
self._assert_port_details(self.ports[0], body)

View File

@ -53,14 +53,8 @@ class FloatingIPNegativeTestJSON(base.BaseNetworkTest):
self.addCleanup(self.client.update_router, self.router['id'],
external_gateway_info={})
port = self.create_port(net)
body1 = self.client.create_floatingip(
floating_network_id=self.ext_net_id)
floating_ip1 = body1['floatingip']
self.addCleanup(self.client.delete_floatingip, floating_ip1['id'])
body2 = self.client.create_floatingip(
floating_network_id=self.ext_net_id)
floating_ip2 = body2['floatingip']
self.addCleanup(self.client.delete_floatingip, floating_ip2['id'])
floating_ip1 = self.create_floatingip()
floating_ip2 = self.create_floatingip()
self.client.update_floatingip(floating_ip1['id'],
port_id=port['id'])
self.assertRaises(lib_exc.Conflict, self.client.update_floatingip,

View File

@ -325,12 +325,7 @@ class TestRevisions(base.BaseAdminNetworkTest, bsg.BaseSecGroupTest):
subnet['id'])
port = self.create_port(net)
self.addCleanup(self.client.delete_port, port['id'])
body = self.client.create_floatingip(
floating_network_id=ext_id,
port_id=port['id'],
description='d1'
)['floatingip']
self.floating_ips.append(body)
body = self.create_floatingip(port=port, description='d1')
self.assertIn('revision_number', body)
b2 = self.client.update_floatingip(body['id'], description='d2')
self.assertGreater(b2['floatingip']['revision_number'],

View File

@ -247,14 +247,14 @@ class TestTimeStampWithL3(base_routers.BaseRouterTest):
@decorators.idempotent_id('8ae55186-464f-4b87-1c9f-eb2765ee81ac')
def test_create_floatingip_with_timestamp(self):
fip = self.create_floatingip(self.ext_net_id)
fip = self.create_floatingip()
# Verifies body contains timestamp fields
self.assertIsNotNone(fip['created_at'])
self.assertIsNotNone(fip['updated_at'])
@decorators.idempotent_id('a3ac215a-61ac-13f9-9d3c-57c51f11afa1')
def test_update_floatingip_with_timestamp(self):
fip = self.create_floatingip(self.ext_net_id)
fip = self.create_floatingip()
origin_updated_at = fip['updated_at']
update_body = {'description': 'new'}
body = self.client.update_floatingip(fip['id'], **update_body)
@ -266,7 +266,7 @@ class TestTimeStampWithL3(base_routers.BaseRouterTest):
@decorators.idempotent_id('32a6a086-e1ef-413b-b13a-0cfe13ef051e')
def test_show_floatingip_attribute_with_timestamp(self):
fip = self.create_floatingip(self.ext_net_id)
fip = self.create_floatingip()
body = self.client.show_floatingip(fip['id'])
show_fip = body['floatingip']
# verify the timestamp from creation and showed is same

View File

@ -85,13 +85,12 @@ class FloatingIpTestCasesAdmin(base.BaseTempestTestCase):
network_id=self.network['id'],
device_id=server['server']['id']
)['ports'][0]
fips.append(self.create_and_associate_floatingip(
port['id'], client=self.os_admin.network_client))
fip = self.create_floatingip(port=port,
client=self.os_admin.network_client)
fips.append(fip)
server_ssh_clients.append(ssh.Client(
fips[i]['floating_ip_address'], CONF.validation.image_ssh_user,
pkey=self.keypair['private_key']))
self.addCleanup(self.os_admin.network_client.delete_floatingip,
fips[i]['id'])
return server_ssh_clients, fips
@decorators.idempotent_id('6bba729b-3fb6-494b-9e1e-82bbd89a1045')

View File

@ -76,11 +76,9 @@ class DNSIntegrationTests(base.BaseTempestTestCase, DNSMixin):
cls.keypair = cls.create_keypair()
def _create_floatingip_with_dns(self, dns_name):
fip = self.os_primary.network_client.create_floatingip(
CONF.network.public_network_id, dns_name=dns_name,
dns_domain=self.zone['name'])['floatingip']
self.floating_ips.append(fip)
return fip
return self.create_floatingip(client=self.os_primary.network_client,
dns_name=dns_name,
dns_domain=self.zone['name'])
def _create_server(self, name=None):
port = self.create_port(self.network)
@ -92,7 +90,7 @@ class DNSIntegrationTests(base.BaseTempestTestCase, DNSMixin):
waiters.wait_for_server_status(self.os_primary.servers_client,
server['id'],
constants.SERVER_STATUS_ACTIVE)
fip = self.create_and_associate_floatingip(port['id'])
fip = self.create_floatingip(port=port)
return {'port': port, 'fip': fip, 'server': server}
def _verify_dns_records(self, address, name):

View File

@ -87,7 +87,7 @@ class FloatingIpTestCasesMixin(object):
network = self.network
port = self.create_port(network, security_groups=[self.secgroup['id']])
if create_floating_ip:
fip = self.create_and_associate_floatingip(port['id'])
fip = self.create_floatingip(port=port)
else:
fip = None
server = self.create_server(

View File

@ -58,7 +58,7 @@ class NetworkMtuBaseTest(base.BaseTempestTestCase):
constants.SERVER_STATUS_ACTIVE)
port = self.client.list_ports(
network_id=net['id'], device_id=server['server']['id'])['ports'][0]
fip = self.create_and_associate_floatingip(port['id'])
fip = self.create_floatingip(port=port)
return server, fip
def _get_network_params(self):

View File

@ -67,7 +67,7 @@ class NetworkSecGroupTest(base.BaseTempestTestCase):
port = self.client.list_ports(
network_id=self.network['id'], device_id=server['server'][
'id'])['ports'][0]
fips.append(self.create_and_associate_floatingip(port['id']))
fips.append(self.create_floatingip(port=port))
server_ssh_clients.append(ssh.Client(
fips[i]['floating_ip_address'], CONF.validation.image_ssh_user,
pkey=self.keypair['private_key']))

View File

@ -65,7 +65,7 @@ class TrunkTest(base.BaseTempestTestCase):
'server': server}
def _create_server_with_fip(self, port_id, **server_kwargs):
fip = self.create_and_associate_floatingip(port_id)
fip = self.create_floatingip(port_id=port_id)
return (
self.create_server(
flavor_ref=CONF.compute.flavor_ref,