def ping(): time.sleep(30) ssh_timeout = self.timeout > 30 and self.timeout or 30 if not (self.host or viaHost): self.fail('Wrong tests configurations, one from the next ' 'parameters are empty controller_node_name or ' 'controller_node_ip ') try: host = viaHost or self.host[0] ssh = SSHClient(host, self.usr, self.pwd, key_filename=self.key, timeout=ssh_timeout) LOG.debug('Get ssh to auxiliary host') ssh.exec_command_on_vm(command='ping -c1 -w1 8.8.8.8', user='******', password='******', vm=ip_address) LOG.debug('Get ssh to instance') return True except SSHExecCommandFailed as exc: output_msg = "Ping command failed." LOG.debug(exc) self.fail(output_msg) except Exception as exc: LOG.debug(exc) self.fail("Connection failed.")
def test_001_check_default_master_node_credential_usage(self): """Check usage of default credentials on master node Target component: Configuration Scenario: 1. Check user can not ssh on master node with default credentials. Duration: 20 s. Available since release: 2014.2-6.1 """ ssh_client = SSHClient('localhost', self.config.master.master_node_ssh_user, self.config.master.master_node_ssh_password, timeout=self.config.master.ssh_timeout) cmd = "date" output = [] try: output = ssh_client.exec_command(cmd) LOG.debug(output) except exceptions.SSHExecCommandFailed: self.verify_response_true( len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed') except exceptions.TimeoutException: self.verify_response_true( len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed') except exc.SSHException: self.verify_response_true( len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed') self.verify_response_true( len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed')
def test_os_databases(self): """Check amount of tables in databases is the same on each node Target Service: HA mysql Scenario: 1. Request list of tables for os databases on each node. 2. Check that amount of tables for each database is the same Duration: 100 s. """ dbs = ['nova', 'glance', 'keystone'] cmd = "mysql -e 'SHOW TABLES FROM %(database)s'" for database in dbs: LOG.info('Current database name is %s' % database) temp_set = set() for node in self.config.compute.online_controllers: LOG.info('Current controller node is %s' % node) cmd1 = cmd % {'database': database} LOG.info('Try to execute command %s' % cmd1) tables = SSHClient( node, self.controller_user, key_filename=self.controller_key, timeout=self.config.compute.ssh_timeout) output = self.verify(40, tables.exec_command, 1, 'Can list tables', 'get amount of tables for each database', cmd1) tables = set(output.splitlines()) if len(temp_set) == 0: temp_set = tables self.verify_response_true( len(tables.symmetric_difference(temp_set)) == 0, "Step 2 failed: Tables in %s database are " "different" % database) del temp_set
def test_001_check_default_master_node_credential_usage(self): """Check usage of default credentials on master node Target component: Configuration Scenario: 1. Check user can not ssh on master node with default credentials. Duration: 20 s. Available since release: 2014.2-6.1 """ ssh_client = SSHClient('localhost', self.usr, self.pwd, timeout=self.timeout) cmd = "date" output = [] try: output = ssh_client.exec_command(cmd) LOG.debug(output) except exceptions.SSHExecCommandFailed: self.verify_response_true(len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed') except exceptions.TimeoutException: self.verify_response_true(len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed') except exc.SSHException: self.verify_response_true(len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed') self.verify_response_true(len(output) == 0, 'Step 1 failed: Default credentials for ' 'ssh on master node were not changed')
def test_os_databases(self): """Check amount of tables in databases is the same on each node Target Service: HA mysql Scenario: 1. Request list of tables for os databases on each node. 2. Check that amount of tables for each database is the same Duration: 100 s. """ dbs = ['nova', 'glance', 'keystone'] cmd = "mysql -e 'SHOW TABLES FROM %(database)s'" for database in dbs: LOG.info('Current database name is %s' % database) temp_set = set() for node in self.config.compute.online_controllers: LOG.info('Current controller node is %s' % node) cmd1 = cmd % {'database': database} LOG.info('Try to execute command %s' % cmd1) tables = SSHClient(node, self.controller_user, key_filename=self.controller_key, timeout=self.config.compute.ssh_timeout) output = self.verify(40, tables.exec_command, 1, 'Can list tables', 'get amount of tables for each database', cmd1) tables = set(output.splitlines()) if len(temp_set) == 0: temp_set = tables self.verify_response_true( len(tables.symmetric_difference(temp_set)) == 0, "Step 2 failed: Tables in %s database are " "different" % database) del temp_set
def _run_ssh_cmd(self, host, cmd): """Open SSH session with host and execute command.""" try: sshclient = SSHClient(host, self.usr, self.pwd, key_filename=self.key, timeout=self.timeout) return sshclient.exec_longrun_command(cmd) except Exception: LOG.debug(traceback.format_exc()) self.fail("%s command failed." % cmd)
def _run_ssh_cmd(self, host, cmd): """Open SSH session with host and and execute command.""" try: sshclient = SSHClient(host, self.usr, self.pwd, key_filename=self.key, timeout=self.timeout) return sshclient.exec_longrun_command(cmd) except Exception: LOG.debug(traceback.format_exc()) self.fail("%s command failed." % cmd)
def run_ssh_cmd_with_exit_code(self, host, cmd): """Open SSH session with host and execute command. Fail if exit code != 0 """ try: sshclient = SSHClient(host, self.usr, self.pwd, key_filename=self.key, timeout=self.timeout) return sshclient.exec_command(cmd) except Exception: LOG.debug(traceback.format_exc()) self.fail("{0} command failed.".format(cmd))
def _run_ssh_cmd(self, cmd): """Open SSH session with Controller and and execute command.""" if not self.host: self.fail('Wrong test configuration: ' '"online_controllers" parameter is empty.') try: sshclient = SSHClient(self.host[0], self.usr, self.pwd, key_filename=self.key, timeout=self.timeout) return sshclient.exec_longrun_command(cmd) except Exception: LOG.debug(traceback.format_exc()) self.fail("%s command failed." % cmd)
def test_os_databases(self): """Check if amount of tables in databases is the same on each node Target Service: HA mysql Scenario: 1. Detect there are online database nodes. 2. Request list of tables for os databases on each node. 3. Check if amount of tables in databases is the same on each node Duration: 10 s. """ LOG.info("'Test OS Databases' started") dbs = ['nova', 'glance', 'keystone'] cmd = "mysql -h localhost -e 'SHOW TABLES FROM %(database)s'" databases = self.verify(20, self.get_database_nodes, 1, "Can not get database hostnames. Check that" " at least one controller is operable", "get database nodes", self.controller_ip, self.node_user, key=self.node_key) self.verify_response_body_not_equal(0, len(databases), self.no_db_msg, 1) if len(databases) == 1: self.skipTest(self.one_db_msg) for database in dbs: LOG.info('Current database name is %s' % database) temp_set = set() for node in databases: LOG.info('Current database node is %s' % node) cmd1 = cmd % {'database': database} LOG.info('Try to execute command %s' % cmd1) tables = SSHClient(node, self.node_user, key_filename=self.node_key, timeout=self.config.compute.ssh_timeout) output = self.verify(40, tables.exec_command, 2, 'Can list tables', 'get amount of tables for each database', cmd1) tables = set(output.splitlines()) if len(temp_set) == 0: temp_set = tables self.verify_response_true( len(tables.symmetric_difference(temp_set)) == 0, "Step 3 failed: Tables in %s database are " "different" % database) del temp_set
def test_os_databases(self): """Check if amount of tables in databases is the same on each node Target Service: HA mysql Scenario: 1. Detect there are online database nodes. 2. Request list of tables for os databases on each node. 3. Check if amount of tables in databases is the same on each node Duration: 10 s. """ LOG.info("'Test OS Databases' started") dbs = ["nova", "glance", "keystone"] cmd = "mysql -h localhost -e 'SHOW TABLES FROM %(database)s'" databases = self.verify( 20, self.get_database_nodes, 1, "Can not get database hostnames. Check that" " at least one controller is operable", "get database nodes", self.controller_ip, self.node_user, key=self.node_key, ) if len(databases) == 1: self.skipTest("There is only one database online. " "Nothing to check") for database in dbs: LOG.info("Current database name is %s" % database) temp_set = set() for node in databases: LOG.info("Current database node is %s" % node) cmd1 = cmd % {"database": database} LOG.info("Try to execute command %s" % cmd1) tables = SSHClient( node, self.node_user, key_filename=self.node_key, timeout=self.config.compute.ssh_timeout ) output = self.verify( 40, tables.exec_command, 2, "Can list tables", "get amount of tables for each database", cmd1 ) tables = set(output.splitlines()) if len(temp_set) == 0: temp_set = tables self.verify_response_true( len(tables.symmetric_difference(temp_set)) == 0, "Step 3 failed: Tables in %s database are " "different" % database, ) del temp_set
def get_database_nodes(cls, controller_ip, username, key): # retrieve data from controller ssh_client = SSHClient(controller_ip, username, key_filename=key, timeout=100) hiera_cmd = 'ruby -e \'require "hiera"; ' 'puts Hiera.new().lookup("database_nodes", {}, {}).keys\'' database_nodes = ssh_client.exec_command(hiera_cmd) database_nodes = database_nodes.splitlines() # get online nodes databases = [] for node in cls.config.compute.nodes: hostname = node["hostname"] if hostname in database_nodes and node["online"]: databases.append(hostname) return databases
def _run_ssh_cmd(self, cmd): """ Open SSH session with Controller and and execute command. """ if not self.host: self.fail('Wrong test configuration: ' '"online_controllers" parameter is empty.') try: sshclient = SSHClient(self.host[0], self.usr, self.pwd, key_filename=self.key, timeout=self.timeout) return sshclient.exec_longrun_command(cmd) except Exception: LOG.debug(traceback.format_exc()) self.fail("%s command failed." % cmd)
def get_database_nodes(cls, controller_ip, username, key): # retrieve data from controller ssh_client = SSHClient(controller_ip, username, key_filename=key, timeout=100) hiera_cmd = 'ruby -e \'require "hiera"; ' \ 'puts Hiera.new().lookup("database_nodes", {}, {}).keys\'' database_nodes = ssh_client.exec_command(hiera_cmd) database_nodes = database_nodes.splitlines() # get online nodes databases = [] for node in cls.config.compute.nodes: hostname = node['hostname'] if hostname in database_nodes and node['online']: databases.append(hostname) return databases
def get_database_nodes(cls, controller_ip, username, key): if version.StrictVersion(cls.release_version)\ < version.StrictVersion('7.0'): return cls.config.compute.online_controllers # retrieve data from controller ssh_client = SSHClient(controller_ip, username, key_filename=key, timeout=100) hiera_cmd = ('ruby -e \'require "hiera";' 'db = Hiera.new().lookup("database_nodes", {}, {}).keys;' 'if db != [] then puts db else puts "None" end\'') database_nodes = ssh_client.exec_command(hiera_cmd) # get online nodes database_nodes = database_nodes.splitlines() databases = [] for node in cls.config.compute.nodes: hostname = node['hostname'] if hostname in database_nodes and node['online']: databases.append(hostname) return databases