def test_suspend_delete_server(self): """ Verify that a server can be suspended and then deleted by the user. Will suspend the server and waits for the server state to be suspended followed by pinging the ip until it's unreachable. Deletes the server as the user and the server was deleted successfully. The following assertions occur: - 202 status code response from the stop server call. - 204 status code response from the start server call. - Verify the server was deleted successfully. """ self.ping_ip = self.server.addresses.get_by_name( self.servers_config.network_for_ssh).ipv4 response = self.admin_servers_client.suspend_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SUSPENDED) PingClient.ping_until_unreachable(self.ping_ip, timeout=60, interval_time=5) delete_response = self.servers_client.delete_server(self.server.id) self.assertEqual(delete_response.status_code, 204, msg="Delete server {0} failed with response code " "{1}".format(self.server.id, delete_response.status_code)) self.server_behaviors.wait_for_server_to_be_deleted(self.server.id)
def test_pause_reboot_server(self): """ Verify that a server reboot during pause does not restore it. First step is getting the IP address for communication based on the configuration. We pause the instance making sure that there is no connectivity. After that we check what happens when we reboot the instance and expecting a "Forbidden" exception and finally making sure the connectivity is still down. This test will be successful if: - Ensures a 202 response is returned from the pause call. - Pings the server expecting an unreachable destination. - Pings the server again expecting an unreachable destination after the failed reboot. """ self.ping_ip = self.get_ip_address_for_live_communication(self.server) response = self.admin_servers_client.pause_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.PAUSED) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) with self.assertRaises(Forbidden): self.servers_client.reboot(self.server.id, NovaServerRebootTypes.HARD) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5)
def test_suspend_delete_server(self): """ Verify that a server can be suspended and then deleted by the user. Will suspend the server and waits for the server state to be suspended followed by pinging the ip until it's unreachable. Deletes the server as the user and the server was deleted successfully. The following assertions occur: - 202 status code response from the stop server call. - 204 status code response from the start server call. - Verify the server was deleted successfully. """ self.ping_ip = self.server.addresses.get_by_name( self.servers_config.network_for_ssh).ipv4 response = self.admin_servers_client.suspend_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SUSPENDED) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) delete_response = self.servers_client.delete_server(self.server.id) self.assertEqual(delete_response.status_code, 204, msg="Delete server {0} failed with response code " "{1}".format(self.server.id, delete_response.status_code)) self.server_behaviors.wait_for_server_to_be_deleted(self.server.id)
def test_reboot_hard_suspended_server(self): """ Verify that a server reboot after suspend does not restore it. Will suspend the server and waits for the server state to be suspended followed by pinging the ip until it's unreachable. Tries to reboot the server and expects a "Forbidden" exception to be raised. Then will ping until it's unreachable again. The following assertions occur: - 202 status code response from the stop server call. - 202 status code response from the start server call. - Get remote instance client returns true (successful connection). """ self.ping_ip = self.server.addresses.get_by_name( self.servers_config.network_for_ssh).ipv4 response = self.admin_servers_client.suspend_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SUSPENDED) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) with self.assertRaises(Forbidden): self.servers_client.reboot(self.server.id, NovaServerRebootTypes.HARD) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5)
def test_stop_start_server(self): """Verify that a server can be stopped and then started""" response = self.admin_servers_client.stop_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SHUTOFF) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) response = self.admin_servers_client.start_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable( self.ping_ip, timeout=60, interval_time=5) self.assertTrue(self.server_behaviors.get_remote_instance_client( self.server, self.servers_config), "Unable to connect to active server {0} after stopping " "and starting".format(self.server.id))
def test_suspend_reboot_hard_server(self): """ Verify that a server reboot after suspend does not restore it. Will suspend the server and waits for the server state to be "PAUSED" followed by pinging the ip until its unreachable. Tries to reboot the server and expects a "ActionInProgress" exception to be raised. Then will ping until its unreachable again. The following assertions occur: - 202 status code response from the stop server call. - Expect a "ActionInProgress" exception is raised when rebooting. """ ping_ip = self.get_accessible_ip_address(self.server) response = self.admin_servers_client.suspend_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.PAUSED) PingClient.ping_until_unreachable( ping_ip, timeout=60, interval_time=5) with self.assertRaises(ActionInProgress): self.servers_client.reboot(self.server.id, NovaServerRebootTypes.HARD) PingClient.ping_until_unreachable( ping_ip, timeout=60, interval_time=5)
def test_reboot_hard_suspended_server(self): """ Verify that a server reboot after suspend does not restore it. Will suspend the server and waits for the server state to be suspended followed by pinging the ip until it's unreachable. Tries to reboot the server and expects a "Forbidden" exception to be raised. Then will ping until it's unreachable again. The following assertions occur: - 202 status code response from the stop server call. - 202 status code response from the start server call. - Get remote instance client returns true (successful connection). """ self.ping_ip = self.server.addresses.get_by_name( self.servers_config.network_for_ssh).ipv4 response = self.admin_servers_client.suspend_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SUSPENDED) PingClient.ping_until_unreachable(self.ping_ip, timeout=60, interval_time=5) with self.assertRaises(Forbidden): self.servers_client.reboot(self.server.id, NovaServerRebootTypes.HARD) PingClient.ping_until_unreachable(self.ping_ip, timeout=60, interval_time=5)
def test_pause_unpause_server(self): """Verify that a server can be paused and then unpaused successfully""" response = self.admin_servers_client.pause_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.PAUSED) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) response = self.admin_servers_client.unpause_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable( self.ping_ip, timeout=60, interval_time=5) self.assertTrue(self.server_behaviors.get_remote_instance_client( self.server, self.servers_config), "Unable to connect to active server {0} after unpausing".format( self.server.id))
def test_pause_unpause_server(self): """ Verify that a server can be paused and then unpaused successfully. First step is getting the IP address for communication based on the configuration, after that we pause the instance making sure that there is no connectivity. After that we check what happens when we unpause the instance and making sure the connectivity is restored. The following assertions occur: - Ensures a 202 response is returned from the pause call. - Ensures a 202 response is returned from the unpause call. - Pings the server expecting a reachable destination. - Get the remote instance of the server returns true. """ self.ping_ip = self.get_ip_address_for_live_communication(self.server) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) response = self.admin_servers_client.pause_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.PAUSED) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) response = self.admin_servers_client.unpause_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable( self.ping_ip, timeout=60, interval_time=5) self.assertTrue(self.server_behaviors.get_remote_instance_client( self.server, self.servers_config), "Unable to connect to active server {0} after unpausing".format( self.server.id))
def test_pause_unpause_server(self): """ Verify that a server can be paused and then unpaused successfully. First step is getting the IP address for communication based on the configuration, after that we pause the instance making sure that there is no connectivity. After that we check what happens when we unpause the instance and making sure the connectivity is restored. The following assertions occur: - A 202 response is returned from the pause call. - A 202 response is returned from the unpause call. - The remote instance client is able to connect to the instance after it is unpaused. """ self.ping_ip = self.get_accessible_ip_address(self.server) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) response = self.admin_servers_client.pause_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.PAUSED) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) response = self.admin_servers_client.unpause_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable( self.ping_ip, timeout=60, interval_time=5) self.assertTrue(self.server_behaviors.get_remote_instance_client( self.server, self.servers_config), "Unable to connect to active server {0} after unpausing".format( self.server.id))
def test_suspend_resume_server(self): """ Verify that a server can be suspended and then resumed. Will suspend the server and waits for the server state to be suspended followed by pinging the ip until it's unreachable. Resumes the server and waits for the server state to be active followed by pinging the server until it's reachable. Then retrieve the instance. The following assertions occur: - 202 status code response from the stop server call. - 202 status code response from the start server call. - Get remote instance client returns true (successful connection). """ self.ping_ip = self.server.addresses.get_by_name( self.servers_config.network_for_ssh).ipv4 response = self.admin_servers_client.suspend_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SUSPENDED) PingClient.ping_until_unreachable(self.ping_ip, timeout=60, interval_time=5) response = self.admin_servers_client.resume_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable(self.ping_ip, timeout=600, interval_time=5) self.assertTrue( self.server_behaviors.get_remote_instance_client( self.server, self.servers_config, key=self.key.private_key), "Unable to connect to active server {0} after suspending " "and resuming".format(self.server.id))
def test_stop_start_server(self): """ Verify that a server can be stopped and then started. Will stop the server and waits for the server state to be shutoff followed by pinging the ip until its unreachable. Start the server back up and wait for the server state to be active followed by pinging the server until its reachable. Then retrieve the instance. The following assertions occur: - 202 status code response from the stop server call. - 202 status code response from the start server call. - Get remote instance client returns true (successful connection). """ response = self.admin_servers_client.stop_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SHUTOFF) PingClient.ping_until_unreachable(self.ping_ip, timeout=60, interval_time=5) response = self.admin_servers_client.start_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable(self.ping_ip, timeout=60, interval_time=5) self.assertTrue( self.server_behaviors.get_remote_instance_client( self.server, self.servers_config), "Unable to connect to active server {0} after stopping " "and starting".format(self.server.id))
def test_suspend_resume_server(self): """ Verify that a server can be suspended and then resumed. Will suspend the server and waits for the server state to be suspended followed by pinging the ip until it's unreachable. Resumes the server and waits for the server state to be active followed by pinging the server until it's reachable. Then retrieve the instance. The following assertions occur: - 202 status code response from the stop server call. - 202 status code response from the start server call. - Get remote instance client returns true (successful connection). """ self.ping_ip = self.server.addresses.get_by_name( self.servers_config.network_for_ssh).ipv4 response = self.admin_servers_client.suspend_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.SUSPENDED) PingClient.ping_until_unreachable( self.ping_ip, timeout=60, interval_time=5) response = self.admin_servers_client.resume_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status( self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable( self.ping_ip, timeout=600, interval_time=5) self.assertTrue(self.server_behaviors.get_remote_instance_client( self.server, self.servers_config, key=self.key.private_key), "Unable to connect to active server {0} after suspending " "and resuming".format(self.server.id))
def test_stop_start_server(self): """ Verify that a server can be stopped and then started. Will stop the server and waits for the server state to be shutoff followed by pinging the ip until its unreachable. Start the server back up and wait for the server state to be active followed by pinging the server until its reachable. Then retrieve the instance. The following assertions occur: - 202 status code response from the stop server call. - 202 status code response from the start server call. - Get remote instance client returns true (successful connection). """ response = self.admin_servers_client.stop_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status(self.server.id, ServerStates.SHUTOFF) PingClient.ping_until_unreachable( self.ping_ip, timeout=self.connection_timeout, interval_time=self.retry_interval ) response = self.admin_servers_client.start_server(self.server.id) self.assertEqual(response.status_code, 202) self.admin_server_behaviors.wait_for_server_status(self.server.id, ServerStates.ACTIVE) PingClient.ping_until_reachable( self.ping_ip, timeout=self.connection_timeout, interval_time=self.retry_interval ) self.assertTrue( self.server_behaviors.get_remote_instance_client( self.server, self.servers_config, key=self.key.private_key ), "Unable to connect to active server {0} after stopping " "and starting".format(self.server.id), )
def _pinger(ip, delta, conn_flag, connection_timeout): """ Pinger function which is responsible for connectivity check starting before migrate starts and finishing 10 seconds after migrate finished If we do not get connectivity lost at all we put 0 for the delta otherwise we calculate the delta time without connectivity """ ping_resp = PingClient.ping_until_unreachable( ip, timeout=connection_timeout, interval_time=1) conn_flag.put("Connection lost") if ping_resp is None: t0 = time() ping_reach = PingClient.ping_until_reachable( ip, timeout=connection_timeout, interval_time=1) time_pass = time() - t0 delta.put(time_pass) else: delta.put(0)
def _pinger(ip, delta, conn_flag, connection_timeout): """ Pinger function which is responsible for connectivity check starting before migrate starts and finishing 10 seconds after migrate finished If we do not get connectivity lost at all we put 0 for the delta otherwise we calculate the delta time without connectivity """ ping_resp = PingClient.ping_until_unreachable(ip, timeout=connection_timeout, interval_time=1) conn_flag.put("Connection lost") if ping_resp is None: t0 = time() ping_reach = PingClient.ping_until_reachable( ip, timeout=connection_timeout, interval_time=1) time_pass = time() - t0 delta.put(time_pass) else: delta.put(0)