Changing create_server to be "non class method"
The change is done in order to remove VM in the test level
and not class level.
As it makes sense to have several tests in the same class and
having in mind that the resources could be limited, it makes
sense to remove unneeded resources in the end of every test.
The create_and_associate_floatingip function was changed to become
instance method as well and the creation of servers in floatingIP
scenario test was taken out from resource_setup.
Change-Id: Ibd8abc2b44b2e85de3e4cd2928799768ad1c0af5
diff --git a/neutron/tests/tempest/scenario/base.py b/neutron/tests/tempest/scenario/base.py
index 967a45e..1e20c74 100644
--- a/neutron/tests/tempest/scenario/base.py
+++ b/neutron/tests/tempest/scenario/base.py
@@ -36,24 +36,17 @@
def resource_setup(cls):
super(BaseTempestTestCase, cls).resource_setup()
- cls.servers = []
cls.keypairs = []
@classmethod
def resource_cleanup(cls):
- for server in cls.servers:
- cls.manager.servers_client.delete_server(server)
- waiters.wait_for_server_termination(cls.manager.servers_client,
- server)
-
for keypair in cls.keypairs:
cls.manager.keypairs_client.delete_keypair(
keypair_name=keypair['name'])
super(BaseTempestTestCase, cls).resource_cleanup()
- @classmethod
- def create_server(cls, flavor_ref, image_ref, key_name, networks,
+ def create_server(self, flavor_ref, image_ref, key_name, networks,
name=None, security_groups=None):
"""Create a server using tempest lib
All the parameters are the ones used in Compute API
@@ -78,14 +71,20 @@
if not security_groups:
security_groups = [{'name': 'default'}]
- server = cls.manager.servers_client.create_server(
+ server = self.manager.servers_client.create_server(
name=name,
flavorRef=flavor_ref,
imageRef=image_ref,
key_name=key_name,
networks=networks,
security_groups=security_groups)
- cls.servers.append(server['server']['id'])
+
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ waiters.wait_for_server_termination,
+ self.manager.servers_client, server['server']['id'])
+ self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+ self.manager.servers_client.delete_server,
+ server['server']['id'])
return server
@classmethod
@@ -155,50 +154,48 @@
cls.routers.append(router)
return router
- @classmethod
- def create_and_associate_floatingip(cls, port_id):
- fip = cls.manager.network_client.create_floatingip(
+ def create_and_associate_floatingip(self, port_id):
+ fip = self.manager.network_client.create_floatingip(
CONF.network.public_network_id,
port_id=port_id)['floatingip']
- cls.floating_ips.append(fip)
+ self.floating_ips.append(fip)
return fip
- @classmethod
- def setup_network_and_server(cls, router=None, **kwargs):
+ def setup_network_and_server(self, router=None, **kwargs):
"""Create network resources and a server.
Creating a network, subnet, router, keypair, security group
and a server.
"""
- cls.network = cls.create_network()
- LOG.debug("Created network %s", cls.network['name'])
- cls.subnet = cls.create_subnet(cls.network)
- LOG.debug("Created subnet %s", cls.subnet['id'])
+ self.network = self.create_network()
+ LOG.debug("Created network %s", self.network['name'])
+ self.subnet = self.create_subnet(self.network)
+ LOG.debug("Created subnet %s", self.subnet['id'])
- secgroup = cls.manager.network_client.create_security_group(
+ secgroup = self.manager.network_client.create_security_group(
name=data_utils.rand_name('secgroup-'))
LOG.debug("Created security group %s",
secgroup['security_group']['name'])
- cls.security_groups.append(secgroup['security_group'])
+ self.security_groups.append(secgroup['security_group'])
if not router:
- router = cls.create_router_by_client(**kwargs)
- cls.create_router_interface(router['id'], cls.subnet['id'])
- cls.keypair = cls.create_keypair()
- cls.create_loginable_secgroup_rule(
+ router = self.create_router_by_client(**kwargs)
+ self.create_router_interface(router['id'], self.subnet['id'])
+ self.keypair = self.create_keypair()
+ self.create_loginable_secgroup_rule(
secgroup_id=secgroup['security_group']['id'])
- cls.server = cls.create_server(
+ self.server = self.create_server(
flavor_ref=CONF.compute.flavor_ref,
image_ref=CONF.compute.image_ref,
- key_name=cls.keypair['name'],
- networks=[{'uuid': cls.network['id']}],
+ key_name=self.keypair['name'],
+ networks=[{'uuid': self.network['id']}],
security_groups=[{'name': secgroup['security_group']['name']}])
- waiters.wait_for_server_status(cls.manager.servers_client,
- cls.server['server']['id'],
+ waiters.wait_for_server_status(self.manager.servers_client,
+ self.server['server']['id'],
constants.SERVER_STATUS_ACTIVE)
- port = cls.client.list_ports(network_id=cls.network['id'],
- device_id=cls.server[
+ port = self.client.list_ports(network_id=self.network['id'],
+ device_id=self.server[
'server']['id'])['ports'][0]
- cls.fip = cls.create_and_associate_floatingip(port['id'])
+ self.fip = self.create_and_associate_floatingip(port['id'])
def check_connectivity(self, host, ssh_user, ssh_key, servers=None):
ssh_client = ssh.Client(host, ssh_user, pkey=ssh_key)
diff --git a/neutron/tests/tempest/scenario/test_floatingip.py b/neutron/tests/tempest/scenario/test_floatingip.py
index d4ad72a..1ccb6ac 100644
--- a/neutron/tests/tempest/scenario/test_floatingip.py
+++ b/neutron/tests/tempest/scenario/test_floatingip.py
@@ -51,15 +51,10 @@
cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id'])
cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id'])
- cls._src_server = cls._create_server()
if cls.same_network:
cls._dest_network = cls.network
else:
cls._dest_network = cls._create_dest_network()
- cls._dest_server_with_fip = cls._create_server(
- network=cls._dest_network)
- cls._dest_server_without_fip = cls._create_server(
- create_floating_ip=False, network=cls._dest_network)
@classmethod
def _create_dest_network(cls):
@@ -69,28 +64,27 @@
cls.create_router_interface(cls.router['id'], subnet['id'])
return network
- @classmethod
- def _create_server(cls, create_floating_ip=True, network=None):
+ def _create_server(self, create_floating_ip=True, network=None):
if network is None:
- network = cls.network
- port = cls.create_port(network, security_groups=[cls.secgroup['id']])
+ network = self.network
+ port = self.create_port(network, security_groups=[self.secgroup['id']])
if create_floating_ip:
- fip = cls.create_and_associate_floatingip(port['id'])
+ fip = self.create_and_associate_floatingip(port['id'])
else:
fip = None
- server = cls.create_server(
+ server = self.create_server(
flavor_ref=CONF.compute.flavor_ref,
image_ref=CONF.compute.image_ref,
- key_name=cls.keypair['name'],
+ key_name=self.keypair['name'],
networks=[{'port': port['id']}])['server']
- waiters.wait_for_server_status(cls.manager.servers_client,
+ waiters.wait_for_server_status(self.manager.servers_client,
server['id'],
constants.SERVER_STATUS_ACTIVE)
return {'port': port, 'fip': fip, 'server': server}
def _test_east_west(self):
# Source VM
- server1 = self._src_server
+ server1 = self._create_server()
server1_ip = server1['fip']['floating_ip_address']
ssh_client = ssh.Client(server1_ip,
CONF.validation.image_ssh_user,
@@ -98,9 +92,10 @@
# Destination VM
if self.dest_has_fip:
- dest_server = self._dest_server_with_fip
+ dest_server = self._create_server(network=self._dest_network)
else:
- dest_server = self._dest_server_without_fip
+ dest_server = self._create_server(create_floating_ip=False,
+ network=self._dest_network)
# Check connectivity
self.check_remote_connectivity(ssh_client,