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)
Beispiel #2
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)
    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))
    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)
    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))
Beispiel #6
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)
    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))
Beispiel #8
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))
Beispiel #9
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 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))
Beispiel #11
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))
Beispiel #12
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))
Beispiel #13
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))
Beispiel #14
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))
    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)