def remove_backup_repo(self): remote_client = RemoteMachineShellConnection(self.backup_node) output, error = remote_client.execute_command("ls " + self.backup_path) if not error: command = "rm -rf {0}".format(self.backup_path) output, error = remote_client.execute_command(command) remote_client.log_command_output(output, error)
def stop_measure_sched_delay(self): for server in self.servers: shell = RemoteMachineShellConnection(server) cmd = "killall -9 -r .*measure-sched-delays" output, error = shell.execute_command(cmd) shell.log_command_output(output, error) shell.disconnect() self.log.info("measure-sched-delays was stopped on {0}".format(server.ip))
def stop_measure_sched_delay(self): for server in self.servers: shell = RemoteMachineShellConnection(server) cmd = "killall -9 -r .*measure-sched-delays" output, error = shell.execute_command(cmd) shell.log_command_output(output, error) shell.disconnect() self.log.info("measure-sched-delays was stopped on {0}".format( server.ip))
def remove_backup(self): remote_client = RemoteMachineShellConnection(self.backup_node) cmd = "cbbackupmgr remove --archive {0} --repo backup_{1}".format( self.backup_path, self.rand) command = "{0}{1}".format(self.cli_command_location, cmd) output, error = remote_client.execute_command(command) remote_client.log_command_output(output, error) if error: raise Exception("Backup not removed successfully") self.is_backup_exists = False
def _restore_with_tool(self, mappings, namespaces, include, restore_args, use_https=False): if not self.is_backup_exists: return self.is_backup_exists, "Backup not found" remote_client = RemoteMachineShellConnection(self.backup_node) if use_https: command = "{0}cbbackupmgr restore --archive {1} --repo backup_{2} --cluster couchbases://{3}" \ " --username {4} --password {5} --force-updates {6} --no-ssl-verify".format( self.cli_command_location, self.backup_path, self.rand, self.restore_node.ip, self.restore_node.rest_username, self.restore_node.rest_password, self.disabled_services) else: command = "{0}cbbackupmgr restore --archive {1} --repo backup_{2} --cluster couchbase://{3}" \ " --username {4} --password {5} --force-updates {6}".format( self.cli_command_location, self.backup_path, self.rand, self.restore_node.ip, self.restore_node.rest_username, self.restore_node.rest_password, self.disabled_services) if not restore_args: mapping_args = "" if mappings: mapping_args += "--map-data " remappings = [] if self.backup_bucket != self.restore_bucket: bucket_mapping = "{0}={1}".format( self.backup_bucket, self.restore_bucket) remappings.append(bucket_mapping) for mapping in mappings: mapping_tokens = mapping.split(":") src = "{0}.{1}".format( self.backup_bucket, mapping_tokens[0]) tgt = "{0}.{1}".format( self.restore_bucket, mapping_tokens[1]) remappings.append("{0}={1}".format(src, tgt)) mapping_args += ",".join(remappings) elif self.backup_bucket != self.restore_bucket: mapping_args += "--map-data " mapping_args += "{0}={1}".format( self.backup_bucket, self.restore_bucket) config_args = "--include-data " if include else "--exclude-data " if namespaces: namespaces = ["{0}.{1}".format(self.backup_bucket, namespace) for namespace in namespaces] config_args += ",".join(namespaces) else: config_args += self.backup_bucket restore_args = "{0} {1}".format(mapping_args, config_args) command = "{0} {1}".format(command, restore_args) output, error = remote_client.execute_command(command) remote_client.log_command_output(output, error) if error or not [x for x in output if 'Restore completed successfully' in x]: self.log.error(output) return False, output return True, output
def drop_data_to_bucket_from_eventing(self,server): shell = RemoteMachineShellConnection(server) shell.info = shell.extract_remote_info() if shell.info.type.lower() == "windows": raise Exception("Should not run on windows") o, r = shell.execute_command("/sbin/iptables -A OUTPUT -p tcp --dport 11210 -j DROP") shell.log_command_output(o, r) # o, r = shell.execute_command("/sbin/iptables -A INPUT -p tcp --dport 11210 -j DROP") # shell.log_command_output(o, r) log.info("enabled firewall on {0}".format(server)) o, r = shell.execute_command("/sbin/iptables --list") shell.log_command_output(o, r) shell.disconnect()
class MemcachetestRunner(): def __init__(self, server, path="/tmp/", memcached_ip="localhost", memcached_port="11211", num_items=100000, extra_params=""): self.server = server self.shell = RemoteMachineShellConnection(self.server) self.path = path self.memcached_ip = memcached_ip self.memcached_port = memcached_port self.num_items = num_items self.extra_params = extra_params self.log = logger.Logger.get_logger() def start_memcachetest(self): #check that memcachetest already installed exists = self.shell.file_exists('/usr/local/bin/', 'memcachetest') if not exists: #try to get from git and install output, error = self.shell.execute_command_raw("cd {0}; git clone git://github.com/membase/memcachetest.git".format(self.path)) self.shell.log_command_output(output, error) output, error = self.shell.execute_command_raw("cd {0}/memcachetest; ./config/autorun.sh && ./configure && make install".format(self.path)) self.shell.log_command_output(output, error) else: self.log.info("memcachetest already set on {0}:/usr/local/bin/memcachetest".format(self.server.ip, self.path)) self.stop_memcachetest() return self.launch_memcachetest() def launch_memcachetest(self): command = "{0}/memcachetest/memcachetest -h {1}:{2} -i {3} {4}".format(self.path, self.memcached_ip, self.memcached_port, self.num_items, self.extra_params) output, error = self.shell.execute_command_raw(command) status = self.shell.log_command_output(output, error, track_words="downstream timeout") def stop_memcachetest(self): cmd = "killall memcachetest" output, error = self.shell.execute_command(cmd) self.shell.log_command_output(output, error) self.log.info("memcachetest was stopped on {0}".format(self.server.ip))
def start_measure_sched_delays(self): for server in self.servers: shell = RemoteMachineShellConnection(server) exists = shell.file_exists(self.path, 'measure-sched-delays') if not exists: shell.copy_file_local_to_remote( "resources/linux/measure-sched-delays.tar.gz", "{0}.tar.gz".format(self.path)) output, error = shell.execute_command_raw( "cd /tmp/; tar -xvzf measure-sched-delays.tar.gz") shell.log_command_output(output, error) output, error = shell.execute_command_raw( "cd {0}; ./configure; make".format(self.path)) shell.log_command_output(output, error) else: self.log.info( "measure-sched-delays already deployed on {0}:{1}".format( server.ip, self.path)) self.stop_measure_sched_delay() output, error = shell.execute_command_raw( "rm -rf {0}/sched-delay*".format(self.path)) shell.log_command_output(output, error) self.launch_measure_sched_delay(shell, file="sched-delay-{0}".format( server.ip)) shell.disconnect()
def start_measure_sched_delays(self): for server in self.servers: shell = RemoteMachineShellConnection(server) exists = shell.file_exists(self.path, 'measure-sched-delays') if not exists: shell.copy_file_local_to_remote("resources/linux/measure-sched-delays.tar.gz", "{0}.tar.gz".format(self.path)) output, error = shell.execute_command_raw("cd /tmp/; tar -xvzf measure-sched-delays.tar.gz") shell.log_command_output(output, error) output, error = shell.execute_command_raw("cd {0}; ./configure; make".format(self.path)) shell.log_command_output(output, error) else: self.log.info("measure-sched-delays already deployed on {0}:{1}".format(server.ip, self.path)) self.stop_measure_sched_delay() output, error = shell.execute_command_raw("rm -rf {0}/sched-delay*".format(self.path)) shell.log_command_output(output, error) self.launch_measure_sched_delay(shell, file="sched-delay-{0}".format(server.ip)) shell.disconnect()
def reset_firewall(self,server): shell = RemoteMachineShellConnection(server) shell.info = shell.extract_remote_info() o, r = shell.execute_command("/sbin/iptables --flush") shell.log_command_output(o, r) shell.disconnect()
def _backup_with_tool(self, namespaces, include, config_args, backup_args, use_https=False): remote_client = RemoteMachineShellConnection(self.backup_node) os_platform = remote_client.extract_remote_info().type.lower() if os_platform == 'linux': if remote_client.nonroot: self.cli_command_location = testconstants.LINUX_NONROOT_CB_BIN_PATH else: self.cli_command_location = testconstants.LINUX_COUCHBASE_BIN_PATH self.backup_path = testconstants.LINUX_BACKUP_PATH elif os_platform == 'windows': self.cmd_ext = ".exe" self.cli_command_location = \ testconstants.WIN_COUCHBASE_BIN_PATH_RAW self.backup_path = testconstants.WIN_BACKUP_C_PATH elif os_platform == 'mac': self.cli_command_location = testconstants.MAC_COUCHBASE_BIN_PATH self.backup_path = testconstants.LINUX_BACKUP_PATH else: raise Exception("OS not supported.") command = self.cli_command_location + "cbbackupmgr config --archive {0} --repo backup_{1} {2}".format( self.backup_path, self.rand, self.disabled_services) if not config_args: config_args = "--include-data " if include else " --exclude-data " if namespaces: namespaces = ["{0}.{1}".format(self.backup_bucket, namespace) for namespace in namespaces] config_args += ",".join(namespaces) else: if isinstance(self.backup_bucket, list): config_args += ",".join(self.backup_bucket) else: config_args += self.backup_bucket command += " {0}".format(config_args) output, error = remote_client.execute_command(command) remote_client.log_command_output(output, error) if error or not [ x for x in output if 'created successfully in archive' in x] and not [ x for x in output if "`backup_" + str(self.rand) + "` exists" in x]: self.is_backup_exists = False return self.is_backup_exists, output if use_https: cmd = f"cbbackupmgr backup --archive {self.backup_path} --repo backup_{self.rand} " \ f"--cluster couchbases://{self.backup_node.ip} --username {self.backup_node.rest_username} " \ f"--password {self.backup_node.rest_password} --no-ssl-verify" else: cmd = f"cbbackupmgr backup --archive {self.backup_path} --repo backup_{self.rand} " \ f"--cluster couchbase://{self.backup_node.ip} --username {self.backup_node.rest_username} " \ f"--password {self.backup_node.rest_password}" command = "{0}{1}".format(self.cli_command_location, cmd) if backup_args: command += " {0}".format(backup_args) self.log.info(f"Backing-up using command: {command}") output, error = remote_client.execute_command(command) remote_client.log_command_output(output, error) if error or not [x for x in output if 'Backup successfully completed' in x or 'Backup completed successfully' in x]: self.is_backup_exists = False return self.is_backup_exists, output self.is_backup_exists = True return self.is_backup_exists, output