Use own server instance for a TestServerActions
In order to stabilize test passing and avoid errors appear sporadically
tests are going to use their own server instance created for it purposes
instead of using one which had been create before.
Related-PROD: PRODX-4874
Change-Id: I113e64e192af4e154ccdfd4371d6d094c6bbd75d
(cherry picked from commit 488a1037c3c61e6011cba19af83027c96fbf18bd)
(cherry picked from commit b171bccb1a287114d0aee30e9f997b621e8bc06d)
(cherry picked from commit 13fdc5291926345933ddbd7d898b0001dcf3485f)
diff --git a/tempest/api/compute/servers/test_server_actions.py b/tempest/api/compute/servers/test_server_actions.py
index 870c6f5..99469e7 100644
--- a/tempest/api/compute/servers/test_server_actions.py
+++ b/tempest/api/compute/servers/test_server_actions.py
@@ -38,46 +38,17 @@
"""Test server actions"""
def setUp(self):
- # NOTE(afazekas): Normally we use the same server with all test cases,
- # but if it has an issue, we build a new one
super(ServerActionsTestJSON, self).setUp()
- # Check if the server is in a clean state after test
- try:
- validation_resources = self.get_class_validation_resources(
- self.os_primary)
- # _test_rebuild_server test compares ip address attached to the
- # server before and after the rebuild, in order to avoid
- # a situation when a newly created server doesn't have a floating
- # ip attached at the beginning of the test_rebuild_server let's
- # make sure right here the floating ip is attached
- waiters.wait_for_server_floating_ip(
- self.client,
- self.client.show_server(self.server_id)['server'],
- validation_resources['floating_ip'])
- waiters.wait_for_server_status(self.client,
- self.server_id, 'ACTIVE')
- except lib_exc.NotFound:
- # The server was deleted by previous test, create a new one
- # Use class level validation resources to avoid them being
- # deleted once a test is over
- validation_resources = self.get_class_validation_resources(
- self.os_primary)
- server = self.create_test_server(
- validatable=True,
- validation_resources=validation_resources,
- wait_until='ACTIVE')
- self.__class__.server_id = server['id']
- except Exception:
- # Rebuild server if something happened to it during a test
- self.__class__.server_id = self.recreate_server(
- self.server_id, validatable=True)
-
- def tearDown(self):
- super(ServerActionsTestJSON, self).tearDown()
- # NOTE(zhufl): Because server_check_teardown will raise Exception
- # which will prevent other cleanup steps from being executed, so
- # server_check_teardown should be called after super's tearDown.
- self.server_check_teardown()
+ # Instead of reusing an instance which had been created before a new
+ # instance is created in favour of increasing stability of tests.
+ self.validation_resources = self.get_test_validation_resources(
+ self.os_primary)
+ server = self.create_test_server(
+ validatable=True,
+ validation_resources=self.validation_resources,
+ wait_until='ACTIVE')
+ self.server_id = server['id']
+ self.addCleanup(self.delete_server, self.server_id)
@classmethod
def setup_credentials(cls):
@@ -89,11 +60,6 @@
super(ServerActionsTestJSON, cls).setup_clients()
cls.client = cls.servers_client
- @classmethod
- def resource_setup(cls):
- super(ServerActionsTestJSON, cls).resource_setup()
- cls.server_id = cls.recreate_server(None, validatable=True)
-
@decorators.idempotent_id('6158df09-4b82-4ab3-af6d-29cf36af858d')
@testtools.skipUnless(CONF.compute_feature_enabled.change_password,
'Change password not available.')
@@ -103,15 +69,7 @@
The server's password should be set to the provided password and
the user can authenticate with the new password.
"""
- # Since this test messes with the password and makes the
- # server unreachable, it should create its own server
- validation_resources = self.get_test_validation_resources(
- self.os_primary)
- newserver = self.create_test_server(
- validatable=True,
- validation_resources=validation_resources,
- wait_until='ACTIVE')
- self.addCleanup(self.delete_server, newserver['id'])
+ newserver = self.client.show_server(self.server_id)['server']
# The server's password should be set to the provided password
new_password = 'Newpass1234'
self.client.change_password(newserver['id'], adminPass=new_password)
@@ -121,7 +79,7 @@
# Verify that the user can authenticate with the new password
server = self.client.show_server(newserver['id'])['server']
linux_client = remote_client.RemoteClient(
- self.get_server_ip(server, validation_resources),
+ self.get_server_ip(server, self.validation_resources),
self.ssh_user,
new_password,
server=server,
@@ -130,15 +88,13 @@
def _test_reboot_server(self, reboot_type):
if CONF.validation.run_validation:
- validation_resources = self.get_class_validation_resources(
- self.os_primary)
# Get the time the server was last rebooted,
server = self.client.show_server(self.server_id)['server']
linux_client = remote_client.RemoteClient(
- self.get_server_ip(server, validation_resources),
+ self.get_server_ip(server, self.validation_resources),
self.ssh_user,
- self.password,
- validation_resources['keypair']['private_key'],
+ getattr(self, "password", None),
+ self.validation_resources['keypair']['private_key'],
server=server,
servers_client=self.client)
boot_time = linux_client.get_boot_time()
@@ -152,10 +108,10 @@
if CONF.validation.run_validation:
# Log in and verify the boot time has changed
linux_client = remote_client.RemoteClient(
- self.get_server_ip(server, validation_resources),
+ self.get_server_ip(server, self.validation_resources),
self.ssh_user,
- self.password,
- validation_resources['keypair']['private_key'],
+ getattr(self, "password", None),
+ self.validation_resources['keypair']['private_key'],
server=server,
servers_client=self.client)
new_boot_time = linux_client.get_boot_time()
@@ -174,7 +130,7 @@
@decorators.idempotent_id('1d1c9104-1b0a-11e7-a3d4-fa163e65f5ce')
def test_remove_server_all_security_groups(self):
"""Test removing all security groups from server"""
- server = self.create_test_server(wait_until='ACTIVE')
+ server = self.client.show_server(self.server_id)['server']
# Remove all Security group
self.client.remove_security_group(
@@ -194,6 +150,22 @@
self.assertEqual(image_ref, rebuilt_server['image']['id'], msg)
def _test_rebuild_server(self):
+
+ def floating_ip_ready():
+ addresses = self.client.show_server(
+ self.server_id)['server']['addresses']
+ self.assertTrue(
+ self.validation_resources["floating_ip"]["ip"] in
+ [addr["addr"] for net in addresses.values() for addr in net]
+ )
+
+ # NOTE(pas-ha) we now always create 'validating' server
+ # create_server only waits for ACTIVE state, but floating ip
+ # may be assigned a bit later.
+ # as we compare network addresses before and after rebuild,
+ # need to ensure we remember the floating one too.
+ self.wait_for(floating_ip_ready)
+
# Get the IPs the server has before rebuilding it
original_addresses = (self.client.show_server(self.server_id)['server']
['addresses'])
@@ -208,11 +180,6 @@
metadata=meta,
adminPass=password)['server']
- # If the server was rebuilt on a different image, restore it to the
- # original image once the test ends
- if self.image_ref_alt != self.image_ref:
- self.addCleanup(self._rebuild_server_and_check, self.image_ref)
-
# Verify the properties in the initial response are correct
self.assertEqual(self.server_id, rebuilt_server['id'])
rebuilt_image_id = rebuilt_server['image']['id']
@@ -229,8 +196,6 @@
self.assertEqual(original_addresses, server['addresses'])
if CONF.validation.run_validation:
- validation_resources = self.get_class_validation_resources(
- self.os_primary)
# Authentication is attempted in the following order of priority:
# 1.The key passed in, if one was passed in.
# 2.Any key we can find through an SSH agent (if allowed).
@@ -238,10 +203,10 @@
# ~/.ssh/ (if allowed).
# 4.Plain username/password auth, if a password was given.
linux_client = remote_client.RemoteClient(
- self.get_server_ip(rebuilt_server, validation_resources),
+ self.get_server_ip(rebuilt_server, self.validation_resources),
self.ssh_alt_user,
password,
- validation_resources['keypair']['private_key'],
+ self.validation_resources['keypair']['private_key'],
server=rebuilt_server,
servers_client=self.client)
linux_client.validate_authentication()
@@ -317,13 +282,11 @@
self.assertEqual(self.server_id,
vol_after_rebuild['attachments'][0]['server_id'])
if CONF.validation.run_validation:
- validation_resources = self.get_class_validation_resources(
- self.os_primary)
linux_client = remote_client.RemoteClient(
- self.get_server_ip(server, validation_resources),
+ self.get_server_ip(server, self.validation_resources),
self.ssh_alt_user,
password=None,
- pkey=validation_resources['keypair']['private_key'],
+ pkey=self.validation_resources['keypair']['private_key'],
server=server,
servers_client=self.client)
linux_client.validate_authentication()
@@ -380,7 +343,7 @@
kwargs.update({'validatable': True,
'validation_resources': validation_resources})
server = self.create_test_server(**kwargs)
-
+ self.addCleanup(self.delete_server, server['id'])
# NOTE(mgoddard): Get detailed server to ensure addresses are present
# in fixed IP case.
server = self.servers_client.show_server(server['id'])['server']
@@ -394,10 +357,10 @@
self.client.get_console_output(server['id'])
if CONF.validation.run_validation:
linux_client = remote_client.RemoteClient(
- self.get_server_ip(server, validation_resources),
+ self.get_server_ip(server, self.validation_resources),
self.ssh_user,
password=None,
- pkey=validation_resources['keypair']['private_key'],
+ pkey=self.validation_resources['keypair']['private_key'],
server=server,
servers_client=self.client)
linux_client.validate_authentication()
@@ -629,7 +592,7 @@
The console output lines length should be bigger than the one
of test_get_console_output.
"""
- server = self.create_test_server(wait_until='ACTIVE')
+ server = self.client.show_server(self.server_id)['server']
def _check_full_length_console_log():
output = self.client.get_console_output(server['id'])['output']
@@ -653,14 +616,8 @@
in SHUTOFF status.
"""
- # NOTE: SHUTOFF is irregular status. To avoid test instability,
- # one server is created only for this test without using
- # the server that was created in setUpClass.
- server = self.create_test_server(wait_until='ACTIVE')
- temp_server_id = server['id']
-
- self.client.stop_server(temp_server_id)
- waiters.wait_for_server_status(self.client, temp_server_id, 'SHUTOFF')
+ self.client.stop_server(self.server_id)
+ waiters.wait_for_server_status(self.client, self.server_id, 'SHUTOFF')
self.wait_for(self._get_output)
@decorators.idempotent_id('bd61a9fd-062f-4670-972b-2d6c3e3b9e73')
@@ -730,11 +687,10 @@
'Pause is not available.')
def test_shelve_paused_server(self):
"""Test shelving a paused server"""
- server = self.create_test_server(wait_until='ACTIVE')
- self.client.pause_server(server['id'])
- waiters.wait_for_server_status(self.client, server['id'], 'PAUSED')
+ self.client.pause_server(self.server_id)
+ waiters.wait_for_server_status(self.client, self.server_id, 'PAUSED')
# Check if Shelve operation is successful on paused server.
- compute.shelve_server(self.client, server['id'],
+ compute.shelve_server(self.client, self.server_id,
force_shelve_offload=True)
@decorators.idempotent_id('af8eafd4-38a7-4a4b-bdbc-75145a580560')