diff --git a/test_repo/compute/fixtures.py b/test_repo/compute/fixtures.py index 0f1d9a14..95ced4e7 100644 --- a/test_repo/compute/fixtures.py +++ b/test_repo/compute/fixtures.py @@ -63,9 +63,9 @@ class ComputeFixture(BaseTestFixture): cls.disk_path = cls.servers_config.instance_disk_path cls.endpoint_config = UserAuthConfig() - user_config = UserConfig() + cls.user_config = UserConfig() access_data = AuthProvider.get_access_data(cls.endpoint_config, - user_config) + cls.user_config) compute_service = access_data.get_service( cls.compute_endpoint.compute_endpoint_name) @@ -111,6 +111,29 @@ class ComputeFixture(BaseTestFixture): image_ref = image_response.headers['location'] return image_ref.rsplit('/')[-1] + def validate_instance_action(self, action, server_id, + user_id, project_id, request_id): + message = "Expected {0} to be {1}, was {2}." + + self.assertEqual(action.instance_uuid, server_id, + msg=message.format('instance id', + action.instance_uuid, + server_id)) + self.assertEqual(action.user_id, user_id, + msg=message.format('user id', + action.user_id, + user_id)) + self.assertEqual(action.project_id, project_id, + msg=message.format('project id', + action.project_id, + project_id)) + self.assertIsNotNone(action.start_time) + self.assertEquals(action.request_id, request_id, + msg=message.format('request id', + action.request_id, + request_id)) + self.assertIsNone(action.message) + class CreateServerFixture(ComputeFixture): """ diff --git a/test_repo/compute/functional/servers/actions/test_change_password.py b/test_repo/compute/functional/servers/actions/test_change_password.py index 04eaac57..9a2515fe 100644 --- a/test_repo/compute/functional/servers/actions/test_change_password.py +++ b/test_repo/compute/functional/servers/actions/test_change_password.py @@ -71,3 +71,26 @@ class ChangeServerPasswordTests(CreateServerFixture): remote_client.can_connect_to_public_ip(), "Could not connect to server (%s) using new admin password %s" % (public_address, self.new_password)) + + @tags(type='smoke', net='no') + @unittest.skip("lp1183712") + def test_password_changed_server_instance_actions(self): + """ + Verify the correct actions are logged during a password change. + """ + + actions = self.servers_client.get_instance_actions( + self.server.id).entity + + # Verify the change password action is listed + self.assertTrue(any(a.action == 'changePassword' for a in actions)) + filtered_actions = [a for a in actions + if a.action == 'changePassword'] + self.assertEquals(len(filtered_actions), 1) + + password_action = filtered_actions[0] + self.validate_instance_action( + password_action, self.server.id, self.user_config.user_id, + self.user_config.tenant_id, + self.resp.headers['x-compute-request-id']) + diff --git a/test_repo/compute/functional/servers/actions/test_rebuild_server.py b/test_repo/compute/functional/servers/actions/test_rebuild_server.py index a19f1361..740afa09 100644 --- a/test_repo/compute/functional/servers/actions/test_rebuild_server.py +++ b/test_repo/compute/functional/servers/actions/test_rebuild_server.py @@ -156,3 +156,22 @@ class RebuildServerTests(ComputeFixture): # Verify the values of the metadata items are correct self.assertEqual(rebuilt_server.metadata.key, 'value') + + @tags(type='smoke', net='no') + def test_rebuilt_server_instance_actions(self): + """Verify the correct actions are logged during a rebuild.""" + + actions = self.servers_client.get_instance_actions( + self.server.id).entity + + # Verify the rebuild action is listed + self.assertTrue(any(a.action == 'rebuild' for a in actions)) + filtered_actions = [a for a in actions if a.action == 'rebuild'] + self.assertEquals(len(filtered_actions), 1) + + rebuild_action = filtered_actions[0] + self.validate_instance_action( + rebuild_action, self.server.id, self.user_config.user_id, + self.user_config.tenant_id, + self.rebuilt_server_response.headers['x-compute-request-id']) + diff --git a/test_repo/compute/functional/servers/actions/test_resize_server_confirm.py b/test_repo/compute/functional/servers/actions/test_resize_server_confirm.py index d84fb599..61339102 100644 --- a/test_repo/compute/functional/servers/actions/test_resize_server_confirm.py +++ b/test_repo/compute/functional/servers/actions/test_resize_server_confirm.py @@ -14,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. """ +import unittest2 as unittest + from cafe.drivers.unittest.decorators import tags from cloudcafe.compute.common.types import NovaServerStatusTypes -from cloudcafe.compute.common.equality_tools import EqualityTools from test_repo.compute.fixtures import ComputeFixture @@ -30,11 +31,13 @@ class ResizeServerUpConfirmTests(ComputeFixture): cls.resources.add(server_to_resize.id, cls.servers_client.delete_server) # resize server and confirm - cls.servers_client.resize(server_to_resize.id, cls.flavor_ref_alt) - cls.server_behaviors.wait_for_server_status(server_to_resize.id, - NovaServerStatusTypes.VERIFY_RESIZE) + cls.resize_resp = cls.servers_client.resize( + server_to_resize.id, cls.flavor_ref_alt) + cls.server_behaviors.wait_for_server_status( + server_to_resize.id, NovaServerStatusTypes.VERIFY_RESIZE) - cls.servers_client.confirm_resize(server_to_resize.id) + cls.confirm_resize_resp = cls.servers_client.confirm_resize( + server_to_resize.id) cls.server_behaviors.wait_for_server_status(server_to_resize.id, NovaServerStatusTypes.ACTIVE) resized_server_response = cls.servers_client.get_server(server_to_resize.id) @@ -95,3 +98,33 @@ class ResizeServerUpConfirmTests(ComputeFixture): self.assertTrue(int(self.resized_flavor.ram) == server_ram_size or lower_limit <= server_ram_size, msg="Ram size after confirm-resize did not match. Expected ram size : %s, Actual ram size : %s" % (self.resized_flavor.ram, server_ram_size)) + + @tags(type='smoke', net='no') + @unittest.skip("lp1183712") + def test_resized_server_instance_actions(self): + """Verify the correct actions are logged during a confirmed resize.""" + + actions = self.servers_client.get_instance_actions( + self.server.id).entity + + # Verify the resize action is listed + self.assertTrue(any(a.action == 'resize' for a in actions)) + filtered_actions = [a for a in actions if a.action == 'resize'] + self.assertEquals(len(filtered_actions), 1) + + resize_action = filtered_actions[0] + self.validate_instance_action( + resize_action, self.server.id, self.user_config.user_id, + self.user_config.tenant_id, + self.resize_resp.headers['x-compute-request-id']) + + # Verify the confirm resize action is listed + self.assertTrue(any(a.action == 'confirmResize' for a in actions)) + filtered_actions = [a for a in actions if a.action == 'confirmResize'] + self.assertEquals(len(filtered_actions), 1) + + resize_action = filtered_actions[0] + self.validate_instance_action( + resize_action, self.server.id, self.user_config.user_id, + self.user_config.tenant_id, + self.confirm_resize_resp.headers['x-compute-request-id']) diff --git a/test_repo/compute/functional/servers/actions/test_resize_server_revert.py b/test_repo/compute/functional/servers/actions/test_resize_server_revert.py index f9904653..92414b5a 100644 --- a/test_repo/compute/functional/servers/actions/test_resize_server_revert.py +++ b/test_repo/compute/functional/servers/actions/test_resize_server_revert.py @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. """ +import unittest2 as unittest + from cafe.drivers.unittest.decorators import tags from cloudcafe.compute.common.types import NovaServerStatusTypes from test_repo.compute.fixtures import ComputeFixture @@ -29,11 +31,13 @@ class ResizeServerUpRevertTests(ComputeFixture): cls.resources.add(server_to_resize.id, cls.servers_client.delete_server) # resize server and confirm - cls.servers_client.resize(server_to_resize.id, cls.flavor_ref_alt) + cls.resize_resp = cls.servers_client.resize( + server_to_resize.id, cls.flavor_ref_alt) cls.server_behaviors.wait_for_server_status(server_to_resize.id, NovaServerStatusTypes.VERIFY_RESIZE) - cls.servers_client.revert_resize(server_to_resize.id) + cls.revert_resize_resp = cls.servers_client.revert_resize( + server_to_resize.id) cls.server_behaviors.wait_for_server_status(server_to_resize.id, NovaServerStatusTypes.ACTIVE) resized_server_response = cls.servers_client.get_server(server_to_resize.id) @@ -89,3 +93,33 @@ class ResizeServerUpRevertTests(ComputeFixture): self.assertTrue(int(self.flavor.ram) == server_ram_size or lower_limit <= server_ram_size, msg="Ram size after confirm-resize did not match. Expected ram size : %s, Actual ram size : %s" % (self.flavor.ram, server_ram_size)) + + @tags(type='smoke', net='no') + @unittest.skip("lp1183712") + def test_resize_reverted_server_instance_actions(self): + """Verify the correct actions are logged during a resize revert.""" + + actions = self.servers_client.get_instance_actions( + self.server.id).entity + + # Verify the resize action is listed + self.assertTrue(any(a.action == 'resize' for a in actions)) + filtered_actions = [a for a in actions if a.action == 'resize'] + self.assertEquals(len(filtered_actions), 1) + + resize_action = filtered_actions[0] + self.validate_instance_action( + resize_action, self.server.id, self.user_config.user_id, + self.user_config.tenant_id, + self.resize_resp.headers['x-compute-request-id']) + + # Verify the revert resize action is listed + self.assertTrue(any(a.action == 'revertResize' for a in actions)) + filtered_actions = [a for a in actions if a.action == 'revertResize'] + self.assertEquals(len(filtered_actions), 1) + + resize_action = filtered_actions[0] + self.validate_instance_action( + resize_action, self.server.id, self.user_config.user_id, + self.user_config.tenant_id, + self.revert_resize_resp.headers['x-compute-request-id']) diff --git a/test_repo/compute/functional/servers/test_create_server.py b/test_repo/compute/functional/servers/test_create_server.py index 7c6e7db3..8c3fa7d7 100644 --- a/test_repo/compute/functional/servers/test_create_server.py +++ b/test_repo/compute/functional/servers/test_create_server.py @@ -203,3 +203,21 @@ class CreateServerTest(ComputeFixture): # Verify the values of the metadata items are correct self.assertEqual(self.server.metadata.meta_key_1, 'meta_value_1') self.assertEqual(self.server.metadata.meta_key_2, 'meta_value_2') + + @tags(type='smoke', net='no') + def test_created_server_instance_actions(self): + """Verify the correct actions are logged while creating a server.""" + + actions = self.servers_client.get_instance_actions( + self.server.id).entity + + # Verify the create action is listed + self.assertTrue(any(a.action == 'create' for a in actions)) + filtered_actions = [a for a in actions if a.action == 'create'] + self.assertEquals(len(filtered_actions), 1) + + create_action = filtered_actions[0] + self.validate_instance_action( + create_action, self.server.id, self.user_config.user_id, + self.user_config.tenant_id, + self.create_resp.headers['x-compute-request-id'])