Exemplo n.º 1
0
    def __init__(self, ip_address=None, server_id=None, username=None,
                 password=None, config=None, os_distro=None, key=None):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        ssh_timeout = config.connection_timeout
        if ip_address is None:
            raise ServerUnreachable("None")
        self.ip_address = ip_address
        self.username = username
        if self.username is None:
            self.username = '******'
        self.password = password
        self.server_id = server_id

        start = int(time.time())
        reachable = False
        while not reachable:
            reachable = PingClient.ping(ip_address,
                                        config.ip_address_version_for_ssh)
            time.sleep(config.connection_retry_interval)
            if int(time.time()) - start >= config.connection_timeout:
                raise ServerUnreachable(ip_address)

        self.ssh_client = SSHBaseClient(self.ip_address,
                                        self.username,
                                        self.password,
                                        timeout=ssh_timeout,
                                        key=key)
        if not self.ssh_client.test_connection_auth():
            self.client_log.error("Ssh connection failed for: IP:{0} \
                    Username:{1} Password: {2}".format(self.ip_address,
                                                       self.username,
                                                       self.password))
            raise SshConnectionException("ssh connection failed")
Exemplo n.º 2
0
 def can_ping_public_ip(self, public_addresses, ip_address_version_for_ssh):
     """
     @summary: Checks if you can ping a public ip
     @param addresses: List of public addresses
     @type addresses: Address List
     @return: True if you can ping, False otherwise
     @rtype: bool
     """
     for public_address in public_addresses:
         if public_address.version == 4 and not PingClient.ping(public_address.addr, ip_address_version_for_ssh):
             return False
     return True
Exemplo n.º 3
0
 def can_remote_ping_private_ip(self, private_addresses):
     """
     @summary: Checks if you can ping a private ip from this server.
     @param private_addresses: List of private addresses
     @type private_addresses: Address List
     @return: True if you can ping, False otherwise
     @rtype: bool
     """
     for private_address in private_addresses:
         if private_address.version == 4 and not PingClient.ping_using_remote_machine(self.ssh_client, private_address.addr):
             return False
     return True
Exemplo n.º 4
0
 def can_ping_public_ip(self, public_addresses, ip_address_version_for_ssh):
     """
     @summary: Checks if you can ping a public ip
     @param addresses: List of public addresses
     @type addresses: Address List
     @return: True if you can ping, False otherwise
     @rtype: bool
     """
     for public_address in public_addresses:
         if public_address.version == 4 and not PingClient.ping(
                 public_address.addr, ip_address_version_for_ssh):
             return False
     return True
Exemplo n.º 5
0
 def can_remote_ping_private_ip(self, private_addresses):
     """
     @summary: Checks if you can ping a private ip from this server.
     @param private_addresses: List of private addresses
     @type private_addresses: Address List
     @return: True if you can ping, False otherwise
     @rtype: bool
     """
     for private_address in private_addresses:
         if private_address.version == 4 and not PingClient.ping_using_remote_machine(
                 self.ssh_client, private_address.addr):
             return False
     return True
    def __init__(self,
                 ip_address=None,
                 server_id=None,
                 username=None,
                 password=None,
                 config=None,
                 os_distro=None,
                 key=None):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        ssh_timeout = config.connection_timeout
        if ip_address is None:
            raise ServerUnreachable("None")
        self.ip_address = ip_address
        self.username = username
        if self.username is None:
            self.username = '******'
        self.password = password
        self.server_id = server_id

        start = int(time.time())
        reachable = False
        while not reachable:
            reachable = PingClient.ping(ip_address,
                                        config.ip_address_version_for_ssh)
            time.sleep(config.connection_retry_interval)
            if int(time.time()) - start >= config.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=ssh_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=ssh_timeout, ip_address=ip_address))
Exemplo n.º 7
0
    def __init__(self,
                 ip_address=None,
                 server_id=None,
                 username=None,
                 password=None,
                 config=None,
                 os_distro=None,
                 key=None):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        ssh_timeout = config.connection_timeout
        if ip_address is None:
            raise ServerUnreachable("None")
        self.ip_address = ip_address
        self.username = username
        if self.username is None:
            self.username = '******'
        self.password = password
        self.server_id = server_id

        start = int(time.time())
        reachable = False
        while not reachable:
            reachable = PingClient.ping(ip_address,
                                        config.ip_address_version_for_ssh)
            time.sleep(config.connection_retry_interval)
            if int(time.time()) - start >= config.connection_timeout:
                raise ServerUnreachable(ip_address)

        self.ssh_client = SSHBaseClient(self.ip_address,
                                        self.username,
                                        self.password,
                                        timeout=ssh_timeout,
                                        key=key)
        if not self.ssh_client.test_connection_auth():
            self.client_log.error("Ssh connection failed for: IP:{0} \
                    Username:{1} Password: {2}".format(self.ip_address,
                                                       self.username,
                                                       self.password))
            raise SshConnectionException("ssh connection failed")
    def test_public_ping(self):
        """Testing ping on servers with public network"""
        msg_err = 'Public ping to IP address {0} - FAILED'
        msg_ok = 'Public ping to IP address {0} - OK'

        pub_ipv4_addr = []
        pub_ipv4_addr.extend(self.server_persona1.pnet_fix_ipv4)
        pub_ipv4_addr.extend(self.server_persona2.pnet_fix_ipv4)
        all_pub_ips_ping_result = []
        failure_flag = False
        for ip_addr in pub_ipv4_addr:
            ip_addr_reachable = PingClient.ping(ip_addr, 4)
            if ip_addr_reachable:
                all_pub_ips_ping_result.append(msg_ok.format(ip_addr))
            else:
                all_pub_ips_ping_result.append(msg_err.format(ip_addr))
                failure_flag = True
        msg = 'Got connectivity failures. Ping Results: {0}'

        # Fail the test if any ping failure is found
        self.assertFalse(failure_flag, msg.format(all_pub_ips_ping_result))
Exemplo n.º 9
0
    def __init__(self, ip_address=None, server_id=None, username=None,
                 password=None, config=None, os_distro=None, key=None):
        self.client_log = cclogging.getLogger(
            cclogging.get_object_namespace(self.__class__))

        ssh_timeout = config.connection_timeout
        if ip_address is None:
            raise ServerUnreachable("None")
        self.ip_address = ip_address
        self.username = username
        if self.username is None:
            self.username = '******'
        self.password = password
        self.server_id = server_id

        start = int(time.time())
        reachable = False
        while not reachable:
            reachable = PingClient.ping(ip_address,
                                        config.ip_address_version_for_ssh)
            time.sleep(config.connection_retry_interval)
            if int(time.time()) - start >= config.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=ssh_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=ssh_timeout, ip_address=ip_address))