def test_config_drive_network_metadata_dns_services(self):
        """
        Verify Services of vendor networking metadata on config drive

        Validate that there is at least one network information service in the
        vendor metadata. Attempt to ping every service IP address in the network
        information service(s). Validate that none of the ping attempts failed.

        The following assertions occur:
            - The number of network information services on the server is
              greater than or equal to 1
            - The list of failed ping attempts is empty.
        """
        self.assertGreaterEqual(len(self.vendor_meta.network_info.services), 1,
                                msg='Expected config drive to have at least 1'
                                ' network dns service configured')
        service_ips = [service.address for service in
                       self.vendor_meta.network_info.services]
        failed_pings = []
        for service_ip in service_ips:
            try:
                PingClient.ping_until_reachable(
                    service_ip, timeout=60, interval_time=5)
            except:
                failed_pings.append(service_ip)
        self.assertFalse(failed_pings, msg="Unable to reach the following "
                         "IP addresses: {0}".format(failed_pings))
Exemplo n.º 2
0
    def setUpClass(cls):
        """
        Perform actions that setup the necessary resources for testing.

        The following resources are created during the setup:
            - Create a server in active state.
        """
        super(StopServerTests, cls).setUpClass()
        cls.connection_timeout = cls.servers_config.connection_timeout
        cls.retry_interval = cls.servers_config.connection_retry_interval
        key_resp = cls.keypairs_client.create_keypair(rand_name("key"))
        assert key_resp.status_code is 200, ("Create keypair failed with response "
                                             "code {0}".format(key_resp.status_code))
        cls.key = key_resp.entity
        cls.resources.add(cls.key.name,
                          cls.keypairs_client.delete_keypair)
        cls.server = cls.server_behaviors.create_active_server(
            key_name=cls.key.name).entity
        cls.resources.add(cls.server.id, cls.servers_client.delete_server)

        cls.ping_ip = cls.server.addresses.get_by_name(
            cls.servers_config.network_for_ssh).ipv4
        PingClient.ping_until_reachable(
            cls.ping_ip, timeout=cls.connection_timeout,
            interval_time=cls.retry_interval)
Exemplo n.º 3
0
    def __init__(self,
                 ip_address,
                 username='******',
                 password=None,
                 key=None,
                 connection_timeout=600,
                 retry_interval=10):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        # Verify the IP address has a valid format
        try:
            IP(ip_address)
        except ValueError:
            raise InvalidAddressFormat(ip_address)

        # Verify the server can be pinged before attempting to connect
        PingClient.ping_until_reachable(ip_address,
                                        timeout=connection_timeout,
                                        interval_time=retry_interval)

        self.ip_address = ip_address
        self.username = username
        self.password = password

        self.client = WinRMClient(username=username,
                                  password=password,
                                  host=ip_address)
        connected = self.client.connect_with_retries()
        if not connected:
            raise WinRMConnectionException(ip_address=ip_address)
Exemplo n.º 4
0
    def __init__(self, ip_address, username='******',
                 password=None, key=None, connection_timeout=600,
                 retry_interval=10):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        # Verify the IP address has a valid format
        try:
            IP(ip_address)
        except ValueError:
            raise InvalidAddressFormat(ip_address)

        # Verify the server can be pinged before attempting to connect
        PingClient.ping_until_reachable(ip_address,
                                        timeout=connection_timeout,
                                        interval_time=retry_interval)

        self.ip_address = ip_address
        self.username = username
        self.password = password

        self.client = WinRMClient(
            username=username, password=password, host=ip_address)
        connected = self.client.connect_with_retries()
        if not connected:
            raise WinRMConnectionException(ip_address=ip_address)
Exemplo n.º 5
0
    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_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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    def setUpClass(cls):
        """
        Perform actions that setup the necessary resources for testing.

        The following resources are created during the setup:
            - Create a server in active state.
        """
        super(StopServerTests, cls).setUpClass()
        cls.connection_timeout = cls.servers_config.connection_timeout
        cls.retry_interval = cls.servers_config.connection_retry_interval
        key_resp = cls.keypairs_client.create_keypair(rand_name("key"))
        assert key_resp.status_code is 200, ("Create keypair failed with response "
                                             "code {0}".format(key_resp.status_code))
        cls.key = key_resp.entity
        cls.resources.add(cls.key.name,
                          cls.keypairs_client.delete_keypair)
        cls.server = cls.server_behaviors.create_active_server(
            key_name=cls.key.name).entity
        cls.resources.add(cls.server.id, cls.servers_client.delete_server)

        cls.ping_ip = cls.server.addresses.get_by_name(
            cls.servers_config.network_for_ssh).ipv4
        PingClient.ping_until_reachable(
            cls.ping_ip, timeout=cls.connection_timeout,
            interval_time=cls.retry_interval)
Exemplo n.º 12
0
    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))
Exemplo n.º 13
0
    def test_config_drive_network_metadata_dns_services(self):
        """
        Verify Services of vendor networking metadata on config drive

        Validate that there is at least one network information service in the
        vendor metadata. Attempt to ping every service IP address in the network
        information service(s). Validate that none of the ping attempts failed.

        The following assertions occur:
            - The number of network information services on the server is
              greater than or equal to 1
            - The list of failed ping attempts is empty.
        """
        self.assertGreaterEqual(len(self.vendor_meta.network_info.services),
                                1,
                                msg='Expected config drive to have at least 1'
                                ' network dns service configured')
        service_ips = [
            service.address
            for service in self.vendor_meta.network_info.services
        ]
        failed_pings = []
        for service_ip in service_ips:
            try:
                PingClient.ping_until_reachable(service_ip,
                                                timeout=60,
                                                interval_time=5)
            except:
                failed_pings.append(service_ip)
        self.assertFalse(failed_pings,
                         msg="Unable to reach the following "
                         "IP addresses: {0}".format(failed_pings))
Exemplo n.º 14
0
    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))
Exemplo n.º 15
0
    def __init__(self,
                 ip_address=None,
                 username='******',
                 password=None,
                 key=None,
                 connection_timeout=600,
                 retry_interval=10):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        self.ip_address = ip_address
        self.username = username
        self.password = password
        self.connection_timeout = connection_timeout

        # Verify the IP address has a valid format
        try:
            IP(ip_address)
        except ValueError:
            raise InvalidAddressFormat(ip_address)

        # Verify the server can be pinged before attempting to connect
        PingClient.ping_until_reachable(ip_address,
                                        timeout=connection_timeout,
                                        interval_time=retry_interval)

        if key is not None:
            auth_strategy = SSHAuthStrategy.KEY_STRING
        else:
            auth_strategy = SSHAuthStrategy.PASSWORD

        allow_agent = True
        if not key:
            allow_agent = False

        self.ssh_client = SSHClient(username=self.username,
                                    password=self.password,
                                    host=self.ip_address,
                                    tcp_timeout=20,
                                    auth_strategy=auth_strategy,
                                    look_for_keys=False,
                                    key=key,
                                    allow_agent=allow_agent)
        self.ssh_client.connect_with_timeout(cooldown=20,
                                             timeout=connection_timeout)
        if not self.ssh_client.is_connected():
            message = ('SSH timeout after {timeout} seconds: '
                       'Could not connect to {ip_address}.')
            raise SshConnectionException(
                message.format(timeout=connection_timeout,
                               ip_address=ip_address))
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)
Exemplo n.º 17
0
    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))
Exemplo n.º 18
0
    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))
Exemplo n.º 19
0
    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 _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)
Exemplo n.º 21
0
 def _is_instance_reachable(ip_address, retry_interval, timeout):
     """Verify the server can be pinged."""
     start = int(time.time())
     reachable = False
     while not reachable:
         reachable = PingClient.ping(ip_address)
         if reachable:
             return True
         time.sleep(retry_interval)
         if int(time.time()) - start >= timeout:
             return False
Exemplo n.º 22
0
    def __init__(self, ip_address=None, username='******', password=None,
                 key=None, connection_timeout=600, retry_interval=10):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        self.ip_address = ip_address
        self.username = username
        self.password = password
        self.connection_timeout = connection_timeout

        # Verify the IP address has a valid format
        try:
            IP(ip_address)
        except ValueError:
            raise InvalidAddressFormat(ip_address)

        # Verify the server can be pinged before attempting to connect
        PingClient.ping_until_reachable(ip_address,
                                        timeout=connection_timeout,
                                        interval_time=retry_interval)

        if key is not None:
            auth_strategy = SSHAuthStrategy.KEY_STRING
        else:
            auth_strategy = SSHAuthStrategy.PASSWORD

        allow_agent = True
        if not key:
            allow_agent = False

        self.ssh_client = SSHClient(
            username=self.username, password=self.password,
            host=self.ip_address, tcp_timeout=20, auth_strategy=auth_strategy,
            look_for_keys=False, key=key, allow_agent=allow_agent)
        self.ssh_client.connect_with_timeout(
            cooldown=20, timeout=connection_timeout)
        if not self.ssh_client.is_connected():
            message = ('SSH timeout after {timeout} seconds: '
                       'Could not connect to {ip_address}.')
            raise SshConnectionException(message.format(
                timeout=connection_timeout, ip_address=ip_address))
Exemplo n.º 23
0
    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))
Exemplo n.º 24
0
    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))
Exemplo n.º 25
0
    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),
        )
Exemplo n.º 26
0
    def verify_server_reachable(cls, ip=None):
        """
        @summary: Verify server connectivity with a basic ping check.
        @param ip: IP address to ping.
                   Defaults to SSH IPv4 address if no IP is provided
        @type ip: string
        """

        if not ip:
            ip = cls.server.addresses.get_by_name(
                cls.servers_config.network_for_ssh).ipv4
        if not PingClient.ping(ip):
            raise ServerUnreachable(
                "Server {id} was not pingable at {ip}".format(id=cls.server.id,
                                                              ip=ip))
Exemplo n.º 27
0
    def verify_server_reachable(cls, ip=None):
        """
        @summary: Verify server connectivity with a basic ping check.
        @param ip: IP address to ping.
                   Defaults to SSH IPv4 address if no IP is provided
        @type ip: string
        """

        if not ip:
            ip = cls.server.addresses.get_by_name(
                cls.servers_config.network_for_ssh).ipv4
        if not PingClient.ping(ip):
            raise ServerUnreachable(
                "Server {id} was not pingable at {ip}".format(
                    id=cls.server.id, ip=ip))
Exemplo n.º 28
0
    def __init__(self,
                 ip_address=None,
                 username='******',
                 password=None,
                 key=None,
                 connection_timeout=600,
                 retry_interval=10):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        if ip_address is None:
            raise ServerUnreachable("None")
        self.ip_address = ip_address
        self.username = username
        self.password = password

        # Verify the server can be pinged before attempting to connect
        start = int(time.time())
        reachable = False
        while not reachable:
            reachable = PingClient.ping(ip_address)
            if reachable:
                break
            time.sleep(retry_interval)
            if int(time.time()) - start >= connection_timeout:
                raise ServerUnreachable(ip_address)

        if key is not None:
            auth_strategy = SSHAuthStrategy.KEY_STRING
        else:
            auth_strategy = SSHAuthStrategy.PASSWORD

        self.ssh_client = SSHBehaviors(username=self.username,
                                       password=self.password,
                                       host=self.ip_address,
                                       tcp_timeout=20,
                                       auth_strategy=auth_strategy,
                                       look_for_keys=False,
                                       key=key)
        self.ssh_client.connect_with_timeout(cooldown=20,
                                             timeout=connection_timeout)
        if not self.ssh_client.is_connected():
            message = ('SSH timeout after {timeout} seconds: '
                       'Could not connect to {ip_address}.')
            raise SshConnectionException(
                message.format(timeout=connection_timeout,
                               ip_address=ip_address))
Exemplo n.º 29
0
    def __init__(self, ip_address=None, username='******', password=None,
                 key=None, connection_timeout=600, retry_interval=10):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        if ip_address is None:
            raise ServerUnreachable("None")
        self.ip_address = ip_address
        self.username = username
        self.password = password
        self.connection_timeout = connection_timeout

        # Verify the server can be pinged before attempting to connect
        start = int(time.time())
        reachable = False
        while not reachable:
            reachable = PingClient.ping(ip_address)
            if reachable:
                break
            time.sleep(retry_interval)
            if int(time.time()) - start >= connection_timeout:
                raise ServerUnreachable(
                    'Could not reach the server at {ip_address}'.format(
                        ip_address=ip_address))

        if key is not None:
            auth_strategy = SSHAuthStrategy.KEY_STRING
        else:
            auth_strategy = SSHAuthStrategy.PASSWORD

        self.ssh_client = SSHClient(
            username=self.username, password=self.password,
            host=self.ip_address, tcp_timeout=20, auth_strategy=auth_strategy,
            look_for_keys=False, key=key)
        self.ssh_client.connect_with_timeout(
            cooldown=20, timeout=connection_timeout)
        if not self.ssh_client.is_connected():
            message = ('SSH timeout after {timeout} seconds: '
                       'Could not connect to {ip_address}.')
            raise SshConnectionException(message.format(
                timeout=connection_timeout, ip_address=ip_address))