instruction
stringclasses
14 values
output
stringlengths
105
12.9k
input
stringlengths
0
4.12k
give a code to
from shell_util.shell_conn import ShellConnection def delete_info_for_server(server, ipaddr=None): """ Delete the info associated with the given server or ipaddr :param server: server to delete the info for :param ipaddr: ipaddr to delete the info for :return: None """ ipaddr = ipaddr or server.ip if ipaddr in RemoteMachineShellConnection.__info_dict: del RemoteMachineShellConnection.__info_dict[ipaddr] RemoteMachineShellConnection.__info_dict.pop(ipaddr, None)
Delete the info associated with the given server or ipaddr
generate comment:
def execute_batch_command(self, command): """ Execute a batch of commands. This method copies the commands onto a batch file, changes the file type to executable and then executes them on the remote server :param command: commands to execute in a batch :return: output of the batch commands """ remote_command = "echo \"%s\" > /tmp/cmd.bat ; " \ "chmod u=rwx /tmp/cmd.bat; /tmp/cmd.bat" % command o, r = self.execute_command_raw(remote_command) if r and r!=['']: log.error("Command didn't run successfully. Error: {0}".format(r)) return o, r
def execute_batch_command(self, command): remote_command = "echo \"%s\" > /tmp/cmd.bat ; " \ "chmod u=rwx /tmp/cmd.bat; /tmp/cmd.bat" % command o, r = self.execute_command_raw(remote_command) if r and r!=['']: log.error("Command didn't run successfully. Error: {0}".format(r)) return o, r
generate python code for
def write_remote_file(self, remote_path, filename, lines): """ Writes content to a remote file specified by the path. :param remote_path: Remote path to write the file to. :param filename: Name of the file to write to. :param lines: Lines to write to the file. :return: None """ cmd = 'echo "%s" > %s/%s' % (''.join(lines), remote_path, filename) self.execute_command(cmd)
Writes content to a remote file specified by the path.
def __repr__(self): """ Returns a string representation of the TestInputServer object with ip, port and ssh_username :return: A string representation of the TestInputServer object """ #ip_str = "ip:{0}".format(self.ip) ip_str = "ip:{0} port:{1}".format(self.ip, self.port) ssh_username_str = "ssh_username:{0}".format(self.ssh_username) return "{0} {1}".format(ip_str, ssh_username_str)
Returns a string representation of the TestInputServer object with ip, port and ssh_username
generate comment:
def reset_env_variables(self): """ Reset environment previously set and restart couchbase server :return: None """ shell = self._ssh_client.invoke_shell() if getattr(self, "info", None) is None: self.info = self.extract_remote_info() init_file = "couchbase-server" file_path = "/opt/couchbase/bin/" backupfile = file_path + init_file + ".bak" sourceFile = file_path + init_file o, r = self.execute_command("mv " + backupfile + " " + sourceFile) self.log_command_output(o, r) # Restart Couchbase o, r = self.execute_command("service couchbase-server restart") self.log_command_output(o, r) shell.close()
def reset_env_variables(self): shell = self._ssh_client.invoke_shell() if getattr(self, "info", None) is None: self.info = self.extract_remote_info() init_file = "couchbase-server" file_path = "/opt/couchbase/bin/" backupfile = file_path + init_file + ".bak" sourceFile = file_path + init_file o, r = self.execute_command("mv " + backupfile + " " + sourceFile) self.log_command_output(o, r) # Restart Couchbase o, r = self.execute_command("service couchbase-server restart") self.log_command_output(o, r) shell.close()
generate python code for
def delete_network_rule(self): """ Delete all traffic control rules set for eth0 :return: None """ o, r = self.execute_command("tc qdisc del dev eth0 root") self.log_command_output(o, r)
Delete all traffic control rules set for eth0
generate python code for the following
def cleanup_all_configuration(self, data_path): """ Deletes the contents of the parent folder that holds the data and config directories. Override method for Windows :param data_path: The path key from the /nodes/self end-point which looks something like "/opt/couchbase/var/lib/couchbase/data" on Linux or "c:/Program Files/Couchbase/Server/var/lib/couchbase/data" on Windows. :return: None """ path = data_path.replace("/data", "") if "c:/Program Files" in path: path = path.replace("c:/Program Files", "/cygdrive/c/Program\ Files") o, r = self.execute_command(f"rm -rf {path}/*") self.log_command_output(o, r)
Deletes the contents of the parent folder that holds the data and config directories. Override method for Windows
generate comment for following function:
def get_server(ip, config): """ Get the server information from the config :param ip: ip to get information for :param config: config :return: TestInputServer object """ server = TestInputServer() server.ip = ip server.bkrs_client = False for section in config.sections(): if section == ip: options = config.options(section) for option in options: if option == 'username': server.ssh_username = config.get(section, option) if option == 'password': server.ssh_password = config.get(section, option) if option == 'cli': server.cli_path = config.get(section, option) if option == 'ssh_key': server.ssh_key = config.get(section, option) if option == 'port': server.port = config.get(section, option) if option == 'ip': server.ip = config.get(section, option) if option == 'internal_ip': server.internal_ip = config.get(section, option) if option == 'services': server.services = config.get(section, option) if option == 'n1ql_port': server.n1ql_port = config.get(section, option) if option == 'index_port': server.index_port = config.get(section, option) if option == 'fts_port': server.fts_port = config.get(section, option) if option == 'eventing_port': server.eventing_port = config.get(section, option) if option == 'collections': # collections_map = {collection: {bucket:'', scope:'', param:''}} collections = config.get(section, option).split(',') for collection in collections: server.collections_map[collection] = TestInputParser\ .get_collection_config(collection, config) break #get username #get password #get port #get cli_path #get key return server
def get_server(ip, config): server = TestInputServer() server.ip = ip server.bkrs_client = False for section in config.sections(): if section == ip: options = config.options(section) for option in options: if option == 'username': server.ssh_username = config.get(section, option) if option == 'password': server.ssh_password = config.get(section, option) if option == 'cli': server.cli_path = config.get(section, option) if option == 'ssh_key': server.ssh_key = config.get(section, option) if option == 'port': server.port = config.get(section, option) if option == 'ip': server.ip = config.get(section, option) if option == 'internal_ip': server.internal_ip = config.get(section, option) if option == 'services': server.services = config.get(section, option) if option == 'n1ql_port': server.n1ql_port = config.get(section, option) if option == 'index_port': server.index_port = config.get(section, option) if option == 'fts_port': server.fts_port = config.get(section, option) if option == 'eventing_port': server.eventing_port = config.get(section, option) if option == 'collections': # collections_map = {collection: {bucket:'', scope:'', param:''}} collections = config.get(section, option).split(',') for collection in collections: server.collections_map[collection] = TestInputParser\ .get_collection_config(collection, config) break #get username #get password #get port #get cli_path #get key return server
generate python code for
def disable_file_size_limit(self): """ Change the file size limit to unlimited for indexer process :return: None """ o, r = self.execute_command("prlimit --fsize=unlimited --pid $(pgrep indexer)") self.log_command_output(o, r)
Change the file size limit to unlimited for indexer process
generate doc string for following function:
def kill_goxdcr(self): """ Kill XDCR process on remote server :return: None """ o, r = self.execute_command("killall -9 goxdcr") self.log_command_output(o, r)
def kill_goxdcr(self): o, r = self.execute_command("killall -9 goxdcr") self.log_command_output(o, r)
give python code to
import os def copy_files_local_to_remote(self, src_path, des_path): """ Copy multi files from local to remote server :param src_path: source path of the files to be copied :param des_path: destination path of the files to be copied :return: None """ files = os.listdir(src_path) self.log.info("copy files from {0} to {1}".format(src_path, des_path)) # self.execute_batch_command("cp -r {0}/* {1}".format(src_path, des_path)) for file in files: if file.find("wget") != 1: a = "" full_src_path = os.path.join(src_path, file) full_des_path = os.path.join(des_path, file) self.copy_file_local_to_remote(full_src_path, full_des_path)
Copy multi files from local to remote server
generate python code for the following
import time from time import sleep def monitor_process_memory(self, process_name, duration_in_seconds=180, end=False): """ Monitor this process and return list of memories in 7 secs interval till the duration specified :param process_name: the name of the process to monitor :param duration_in_seconds: the duration to monitor the process till, in seconds :param end: False :return: list of virtual size (in kB) and resident set size for """ end_time = time.time() + float(duration_in_seconds) count = 0 vsz = [] rss = [] while time.time() < end_time and not end: # get the process list process = self.is_process_running(process_name) if process: vsz.append(process.vsz) rss.append(process.rss) else: log.info("{0}:process {1} is not running. Wait for 2 seconds" .format(self.remote_shell.ip, process_name)) count += 1 self.sleep(2) if count == 5: log.error("{0}:process {1} is not running at all." .format(self.remote_shell.ip, process_name)) exit(1) log.info("sleep for 7 seconds before poll new processes") self.sleep(7) return vsz, rss
Monitor this process and return list of memories in 7 secs interval till the duration specified
Code the following:
def get_process_statistics_parameter(self, parameter, process_name=None, process_pid=None): """ Get the process statistics for given parameter :param parameter: parameter to get statistics for :param process_name: name of process to get statistics for :param process_pid: pid of process to get statistics for :return: process statistics for parameter if present else None """ if not parameter: self.log.error("parameter cannot be None") parameters_list = self.get_process_statistics(process_name, process_pid) if not parameters_list: self.log.error("no statistics found") return None parameters_dic = dict(item.split(' = ') for item in parameters_list) if parameter in parameters_dic: return parameters_dic[parameter] else: self.log.error("parameter '{0}' is not found".format(parameter)) return None
Get the process statistics for given parameter
give a code to
def get_cbbackupmgr_config(config, section): """ Get CB backup manager configuration :param config: config :param section: section to get configuration from :return: dict of configuration options """ options = {} for option in config.options(section): options[option] = config.get(section, option) return options
Get CB backup manager configuration
generate code for the following
def get_memcache_pid(self): """ Get the pid of memcached process :return: pid of memcached process """ raise NotImplementedError
Get the pid of memcached process
generate python code for the following
def populate_debug_build_url(self): """ Populates the debug_info build url variable. :return: None """ self.node_install_info.debug_build_url = self.__construct_build_url( is_debuginfo_build=True) self.log.info("{} - Debug build url :: {}" .format(self.node_install_info.server.ip, self.node_install_info.debug_build_url))
Populates the debug_info build url variable.
give a code to
def __init__(self): """ Creates an instance of the TestInputServer class. This object holds the server information required for installation, cli and rest api calls. """ self.ip = '' self.internal_ip = '' self.hostname = '' self.ssh_username = '' self.ssh_password = '' self.ssh_key = '' self.rest_username = '' self.rest_password = '' self.services = '' self.port = '' self.cli_path = '' self.data_path = '' self.index_path = '' self.cbas_path = '' self.n1ql_port = '' self.index_port = '' self.fts_port = '' self.eventing_port = '' self.es_username = '' self.es_password = '' self.upgraded = False self.collections_map = {} self.cbbackupmgr = {} self.hosted_on_cloud = False self.dummy = False
Creates an instance of the TestInputServer class. This object holds the server information required for installation, cli and rest api calls.
give a code to
def is_couchbase_running(self): """ Checks if couchbase is currently running on the remote server :return: True if couchbase is running else False """ o = self.is_process_running('erl.exe') if o is not None: return True return False
Checks if couchbase is currently running on the remote server
generate python code for the following
def download_build(self, node_installer, build_url, non_root_installer=False): """ Download the Couchbase build on the remote server :param node_installer: node installer object :param build_url: build url to download the Couchbase build from. :param non_root_installer: Change the downloaded build to executable if True :return: None """ download_dir = self.get_download_dir(node_installer) f_name = build_url.split("/")[-1] # Remove old build (if exists) cmd = "rm -f {}/couchbase-server*".format(download_dir) node_installer.shell.execute_command(cmd) # Download the build cmd = node_installer.wget_cmd.format(download_dir, build_url) node_installer.shell.execute_command(cmd) if non_root_installer: node_installer.shell.execute_cmd("chmod a+x {}/{}" .format(download_dir, f_name)) node_installer.shell.disconnect()
Download the Couchbase build on the remote server
give a code to
def alt_addr_add_node(self, main_server=None, internal_IP=None, server_add=None, user="Administrator", passwd="password", services="kv", cmd_ext=""): """ Add node to couchbase cluster using alternative address :param main_server: couchbase cluster address :param internal_IP: internal or alternate address to the server to add :param server_add: server object of the server to add to cluster :param user: username to connect to cluster :param passwd: password to connect to cluster :param services: services that's part of the node to be added :param cmd_ext: curl extension to execute with :return: output of the curl command adding node to cluster. """ """ in alternate address, we need to use curl to add node """ if internal_IP is None: raise Exception("Need internal IP to add node.") if main_server is None: raise Exception("Need master IP to run") cmd = 'curl{0} -X POST -d "hostname={1}&user={2}&password={3}&services={4}" '\ .format(cmd_ext, internal_IP, server_add.rest_username, server_add.rest_password, services) cmd += '-u {0}:{1} https://{2}:18091/controller/addNode'\ .format(main_server.rest_username, main_server.rest_password, main_server.ip) output, error = self.execute_command(cmd) return output, error
Add node to couchbase cluster using alternative address
generate code for the above:
def validate_server_status(self, node_helpers): """ Checks if the servers are supported OS for Couchbase installation :param node_helpers: list of node helpers of type NodeInstallInfo :return: True if the servers are supported OS for Couchbase installation else False """ result = True known_os = set() for node_helper in node_helpers: if node_helper.os_type not in SUPPORTED_OS: self.log.critical( "{} - Unsupported os: {}" .format(node_helper.server.ip, node_helper.os_type)) result = False else: known_os.add(node_helper.os_type) if len(known_os) != 1: self.log.critical("Multiple OS versions found!") result = False return result
Checks if the servers are supported OS for Couchbase installation
give python code to
def cleanup_data_config(self, data_path): """ Cleans up the data config directory and its contents Override method for Windows :param data_path: path to data config directory :return: None """ if "c:/Program Files" in data_path: data_path = data_path.replace("c:/Program Files", "/cygdrive/c/Program\ Files") o, r = self.execute_command("rm -rf ""{0}""/*".format(data_path)) self.log_command_output(o, r) o, r = self.execute_command("rm -rf ""{0}""/*" \ .format( data_path.replace("data", "config"))) self.log_command_output(o, r)
Cleans up the data config directory and its contents Override method for Windows
generate python code for
def start_indexer(self): """ Start indexer process on remote server :return: None """ o, r = self.execute_command("taskkill /F /T /IM indexer*") self.log_command_output(o, r)
Start indexer process on remote server
generate comment:
def get_data_file_size(self, path=None): """ Get the size of the file in the specified path :param path: path of the file to get the size of :return: size of the file in the path """ output, error = self.execute_command('du -b {0}'.format(path)) if error: return 0 else: for line in output: size = line.strip().split('\t') if size[0].isdigit(): print((size[0])) return size[0] else: return 0
def get_data_file_size(self, path=None): output, error = self.execute_command('du -b {0}'.format(path)) if error: return 0 else: for line in output: size = line.strip().split('\t') if size[0].isdigit(): print((size[0])) return size[0] else: return 0
generate python code for the following
def get_mem_usage_by_process(self, process_name): """ Get the memory usage of a process :param process_name: name of the process to get the memory usage for :return: the memory usage of the process if available else None """ output, error = self.execute_command( 'ps -e -o %mem,cmd|grep {0}'.format(process_name), debug=False) if output: for line in output: if not 'grep' in line.strip().split(' '): return float(line.strip().split(' ')[0])
Get the memory usage of a process
generate comment for above
def execute_cbcollect_info(self, file, options=""): """ Execute cbcollect command on remote server :param file: file name to store the cbcollect as :param options: options for the cbcollect command :return: output of the cbcollect command """ cbcollect_command = "%scbcollect_info" % (LINUX_COUCHBASE_BIN_PATH) if self.nonroot: cbcollect_command = "%scbcollect_info" % (LINUX_NONROOT_CB_BIN_PATH) self.extract_remote_info() if self.info.type.lower() == 'windows': cbcollect_command = "%scbcollect_info.exe" % (WIN_COUCHBASE_BIN_PATH) if self.info.distribution_type.lower() == 'mac': cbcollect_command = "%scbcollect_info" % (MAC_COUCHBASE_BIN_PATH) command = "%s %s %s" % (cbcollect_command, file, options) output, error = self.execute_command(command, use_channel=True) return output, error
def execute_cbcollect_info(self, file, options=""): cbcollect_command = "%scbcollect_info" % (LINUX_COUCHBASE_BIN_PATH) if self.nonroot: cbcollect_command = "%scbcollect_info" % (LINUX_NONROOT_CB_BIN_PATH) self.extract_remote_info() if self.info.type.lower() == 'windows': cbcollect_command = "%scbcollect_info.exe" % (WIN_COUCHBASE_BIN_PATH) if self.info.distribution_type.lower() == 'mac': cbcollect_command = "%scbcollect_info" % (MAC_COUCHBASE_BIN_PATH) command = "%s %s %s" % (cbcollect_command, file, options) output, error = self.execute_command(command, use_channel=True) return output, error
generate doc string for following function:
def get_server_ips(config, section): """ Get server IPs from config :param config: config :param section: section to get server IPs from :return: list of IP addresses """ ips = [] options = config.options(section) for option in options: ips.append(config.get(section, option)) return ips
def get_server_ips(config, section): ips = [] options = config.options(section) for option in options: ips.append(config.get(section, option)) return ips
generate comment:
def reconnect_if_inactive(self): """ If the SSH channel is inactive, retry the connection """ tp = self._ssh_client.get_transport() if tp and not tp.active: self.log.warning("%s - SSH connection inactive" % self.ip) self.ssh_connect_with_retries(self.ip, self.username, self.password, self.ssh_key)
def reconnect_if_inactive(self): tp = self._ssh_client.get_transport() if tp and not tp.active: self.log.warning("%s - SSH connection inactive" % self.ip) self.ssh_connect_with_retries(self.ip, self.username, self.password, self.ssh_key)
generate doc string for following function:
def stop_couchbase(self, num_retries=5, poll_interval=10): """ Stop couchbase service on remote server :param num_retries: None :param poll_interval: None :return: None """ cb_process = '/Applications/Couchbase\ Server.app/Contents/MacOS/Couchbase\ Server' cmd = "ps aux | grep {0} | awk '{{print $2}}' | xargs kill -9 "\ .format(cb_process) o, r = self.execute_command(cmd) self.log_command_output(o, r) o, r = self.execute_command("killall -9 epmd") self.log_command_output(o, r)
def stop_couchbase(self, num_retries=5, poll_interval=10): cb_process = '/Applications/Couchbase\ Server.app/Contents/MacOS/Couchbase\ Server' cmd = "ps aux | grep {0} | awk '{{print $2}}' | xargs kill -9 "\ .format(cb_process) o, r = self.execute_command(cmd) self.log_command_output(o, r) o, r = self.execute_command("killall -9 epmd") self.log_command_output(o, r)
generate comment for following function:
def get_instances(cls): """ Returns a list of instances of the class :return: generator that yields instances of the class """ for ins in cls.__refs__: yield ins
def get_instances(cls): for ins in cls.__refs__: yield ins
generate python code for
def __init__(self, logger): """ Creates an instance of InstallHelper object :param logger: logger object """ self.log = logger
Creates an instance of InstallHelper object
generate code for the following
import os def find_file(self, remote_path, file): """ Check if file exists in remote path :param remote_path: remote path of the file to be checked :param file: filename to be checked :return: file path of the file if exists, None otherwise """ sftp = self._ssh_client.open_sftp() try: files = sftp.listdir(remote_path) for name in files: if name == file: found_it = os.path.join(remote_path, name) log.info("File {0} was found".format(found_it)) return found_it else: log.error('File(s) name in {0}'.format(remote_path)) for name in files: log.info(name) log.error('Can not find {0}'.format(file)) except IOError: pass sftp.close()
Check if file exists in remote path
give a code to
def get_port_recvq(self, port): """ Given a port, extracts address:port of services listening on that port (only ipv4) Override for Unix systems :param port: port to listen on :return: list of addresses and ports of services listening """ raise NotImplementedError
Given a port, extracts address:port of services listening on that port (only ipv4) Override for Unix systems
def start_server(self): """ Starts the Couchbase server on the remote server. The method runs the sever from non-default location if it's run as nonroot user. Else from default location. :return: None """ if self.is_couchbase_installed(): if self.nonroot: cmd = '%s%scouchbase-server \-- -noinput -detached '\ % (self.nr_home_path, LINUX_COUCHBASE_BIN_PATH) else: cmd = "systemctl start couchbase-server.service" o, r = self.execute_command(cmd) self.log_command_output(o, r)
Starts the Couchbase server on the remote server. The method runs the sever from non-default location if it's run as nonroot user. Else from default location.
generate comment:
def get_ram_info(self, win_info=None, mac=False): """ Get the RAM info of the remote server :param win_info: Windows info in case of windows :param mac: Get info for macOS if True :return: RAM info of the remote server if found else None """ if win_info: if 'Virtual Memory Max Size' not in win_info: win_info = self.create_windows_info() o = "Virtual Memory Max Size =" \ + win_info['Virtual Memory Max Size'] + '\n' \ + "Virtual Memory Available =" \ + win_info['Virtual Memory Available'] + '\n' \ + "Virtual Memory In Use =" + win_info['Virtual Memory In Use'] elif mac: o, r = self.execute_command_raw( '/sbin/sysctl -n hw.memsize', debug=False) else: o, r = self.execute_command_raw('cat /proc/meminfo', debug=False) if o: return o
def get_ram_info(self, win_info=None, mac=False): if win_info: if 'Virtual Memory Max Size' not in win_info: win_info = self.create_windows_info() o = "Virtual Memory Max Size =" \ + win_info['Virtual Memory Max Size'] + '\n' \ + "Virtual Memory Available =" \ + win_info['Virtual Memory Available'] + '\n' \ + "Virtual Memory In Use =" + win_info['Virtual Memory In Use'] elif mac: o, r = self.execute_command_raw( '/sbin/sysctl -n hw.memsize', debug=False) else: o, r = self.execute_command_raw('cat /proc/meminfo', debug=False) if o: return o
generate comment.
def download_build_locally(self, build_url): """ Downloads the Couchbase build locally :param build_url: Download url to download the build from :return: tuple containing the path to the download build file as well as the resulting HTTPMessage object. """ f_path = "{}/{}".format(".", build_url.split('/')[-1]) f, r = urllib.request.urlretrieve(build_url, f_path) return f, r
def download_build_locally(self, build_url): f_path = "{}/{}".format(".", build_url.split('/')[-1]) f, r = urllib.request.urlretrieve(build_url, f_path) return f, r
give python code to
def __str__(self): """ Returns a string representation of the TestInputServer object with ip, port and ssh_username :return: A string representation of the TestInputServer object """ #ip_str = "ip:{0}".format(self.ip) ip_str = "ip:{0} port:{1}".format(self.ip, self.port) ssh_username_str = "ssh_username:{0}".format(self.ssh_username) return "{0} {1}".format(ip_str, ssh_username_str)
Returns a string representation of the TestInputServer object with ip, port and ssh_username
generate python code for
def restart_couchbase(self): """ Restarts the Couchbase server on the remote server :return: None """ o, r = self.execute_command("service couchbase-server restart") self.log_command_output(o, r)
Restarts the Couchbase server on the remote server
generate python code for the above
def remove_folders(self, list): """ Remove folders from list provided :param list: paths of folders to be removed :return: None """ for folder in list: output, error = self.execute_command( "rm -rf {0}".format(folder), debug=False) self.log_command_output(output, error)
Remove folders from list provided
generate doc string for following function:
def start_indexer(self): """ Start indexer process on remote server :return: None """ o, r = self.execute_command("taskkill /F /T /IM indexer*") self.log_command_output(o, r)
def start_indexer(self): o, r = self.execute_command("taskkill /F /T /IM indexer*") self.log_command_output(o, r)
generate python code for
def remove_folders(self, list): """ Remove folders from list provided :param list: paths of folders to be removed :return: None """ for folder in list: output, error = self.execute_command( "rm -rf {0}".format(folder), debug=False) self.log_command_output(output, error)
Remove folders from list provided
generate comment for following function:
def fill_disk_space(self, location): """ Fill up the disk fully at the location specified. This method creates a junk file of the specified size in the location specified :param location: Location to fill the disk :param size: Size of disk space to fill up, in MB :return: Output and error message from filling up the disk. """ command = "dd if=/dev/zero of={0}/disk-quota.ext3 count={1}; df -Thl"\ .format(location, 1024000000) output, error = self.execute_command(command) return output, error
def fill_disk_space(self, location): command = "dd if=/dev/zero of={0}/disk-quota.ext3 count={1}; df -Thl"\ .format(location, 1024000000) output, error = self.execute_command(command) return output, error
generate python code for the following
def disable_file_size_limit(self): """ Change the file size limit to unlimited for indexer process :return: None """ o, r = self.execute_command("prlimit --fsize=unlimited --pid $(pgrep indexer)") self.log_command_output(o, r)
Change the file size limit to unlimited for indexer process
give a code to
def get_collection_config(collection, config): """ Get collection configuration :param collection: collection name to get configuration for :param config: config :return: dict of collection information """ collection_config = {} for section in config.sections(): if section == collection: options = config.options(section) for option in options: if option == 'bucket': collection_config['bucket'] = config.get(section, option) if option == 'scope': collection_config['scope'] = config.get(section, option) if option.lower() == 'maxttl': collection_config['maxTTL'] = config.get(section, option) return collection_config
Get collection configuration
generate python code for the above
def get_membase_build(config, section): """ Get the membase build information from the config :param config: config :param section: section to get information from :return: membase build information """ membase_build = TestInputBuild() for option in config.options(section): if option == 'version': pass if option == 'url': pass return membase_build
Get the membase build information from the config
generate comment for above
def kill_goxdcr(self): """ Kill XDCR process on remote server :return: None """ o, r = self.execute_command("killall -9 goxdcr") self.log_command_output(o, r)
def kill_goxdcr(self): o, r = self.execute_command("killall -9 goxdcr") self.log_command_output(o, r)
give a code to
def kill_cbft_process(self): """ Kill the full text search process on remote server :return: output and error of command killing FTS process """ o, r = self.execute_command("taskkill /F /T /IM cbft.exe*") self.log_command_output(o, r)
Kill the full text search process on remote server
generate python code for the following
import os def find_file(self, remote_path, file): """ Check if file exists in remote path :param remote_path: remote path of the file to be checked :param file: filename to be checked :return: file path of the file if exists, None otherwise """ sftp = self._ssh_client.open_sftp() try: files = sftp.listdir(remote_path) for name in files: if name == file: found_it = os.path.join(remote_path, name) log.info("File {0} was found".format(found_it)) return found_it else: log.error('File(s) name in {0}'.format(remote_path)) for name in files: log.info(name) log.error('Can not find {0}'.format(file)) except IOError: pass sftp.close()
Check if file exists in remote path
generate comment for following function:
def get_processes_binding_to_ip_family(self, ip_family="ipv4"): """ Get all the processes binding to a particular ip family :param ip_family: ip family to get processes binding of :return: list of processes binding to ip family """ output, error = self.execute_command( "lsof -i -P -n | grep LISTEN | grep couchbase| grep -i {0}" .format(ip_family), debug=True) self.log_command_output(output, error, debug=True) return output
def get_processes_binding_to_ip_family(self, ip_family="ipv4"): output, error = self.execute_command( "lsof -i -P -n | grep LISTEN | grep couchbase| grep -i {0}" .format(ip_family), debug=True) self.log_command_output(output, error, debug=True) return output
generate python code for the following
def configure_log_location(self, new_log_location): """ Configure the log location for Couchbase server on remote server :param new_log_location: path to new location to store logs :return: None """ mv_logs = testconstants.LINUX_LOG_PATH + '/' + new_log_location print((" MV LOGS %s" % mv_logs)) error_log_tag = "error_logger_mf_dir" # ADD NON_ROOT user config_details log.info("CHANGE LOG LOCATION TO %s".format(mv_logs)) output, error = self.execute_command("rm -rf %s" % mv_logs) self.log_command_output(output, error) output, error = self.execute_command("mkdir %s" % mv_logs) self.log_command_output(output, error) output, error = self.execute_command("chown -R couchbase %s" % mv_logs) self.log_command_output(output, error) output, error = self.execute_command("sed -i '/%s, /c \\{%s, \"%s\"\}.' %s" % (error_log_tag, error_log_tag, mv_logs, testconstants.LINUX_STATIC_CONFIG)) self.log_command_output(output, error)
Configure the log location for Couchbase server on remote server
def cpu_stress(self, stop_time): """ Applies CPU stress for a specified duration on the 20 CPU cores. Override method for Windows :param stop_time: duration to apply the CPU stress for. :return: None """ raise NotImplementedError
def cpu_stress(self, stop_time): raise NotImplementedError
generate code for the above:
def file_ends_with(self, remotepath, pattern): """ Check if file ending with this pattern is present in remote machine :param remotepath: path of the file to check :param pattern: pattern to test against :return: True if file ending with this pattern is present in remote machine else False """ sftp = self._ssh_client.open_sftp() files_matched = [] try: file_names = sftp.listdir(remotepath) for name in file_names: if name.endswith(pattern): files_matched.append("{0}/{1}".format(remotepath, name)) except IOError: # ignore this error pass sftp.close() if len(files_matched) > 0: log.info("found these files : {0}".format(files_matched)) return files_matched
Check if file ending with this pattern is present in remote machine
generate python code for the above
def get_cbversion(self): """ Get the installed version of Couchbase Server installed on the remote server. This gets the versions from both default path or non-default paths. Returns in format fv = a.b.c-xxxx, sv = a.b.c, bn = xxxx :return: full version, main version and the build version of the Couchbase Server installed """ output = "" fv = sv = bn = tmp = "" err_msg = "{} - Couchbase Server not found".format(self.ip) if self.nonroot: if self.file_exists('/home/%s/cb/%s' % (self.username, self.cb_path), self.version_file): output = self.read_remote_file('/home/%s/cb/%s' % (self.username, self.cb_path), self.version_file) else: log.info(err_msg) else: if self.file_exists(self.cb_path, self.version_file): output = self.read_remote_file(self.cb_path, self.version_file) else: log.info(err_msg) if output: for x in output: x = x.strip() if x and x[:5] in CB_RELEASE_BUILDS.keys() and "-" in x: fv = x tmp = x.split("-") sv = tmp[0] bn = tmp[1] break return fv, sv, bn
Get the installed version of Couchbase Server installed on the remote server. This gets the versions from both default path or non-default paths. Returns in format fv = a.b.c-xxxx, sv = a.b.c, bn = xxxx
give python code to
def enable_packet_loss(self): """ Changes network to lose 25% of packets using traffic control This is used to simulate a network environment where approximately 25% of packets are lost. :return: None """ o, r = self.execute_command("tc qdisc add dev eth0 root netem loss 25%") self.log_command_output(o, r)
Changes network to lose 25% of packets using traffic control This is used to simulate a network environment where approximately 25% of packets are lost.
def delete_files(self, file_location, debug=False): """ Delete the files in the specified location :param file_location: path to files to delete :param debug: print debug information if True :return: None """ command = "%s%s" % ("rm -rf ", file_location) output, error = self.execute_command(command, debug=debug) if debug: self.log_command_output(output, error)
Delete the files in the specified location
generate python code for the following
def start_memcached(self): """ Start memcached process on remote server :return: None """ o, r = self.execute_command("taskkill /F /T /IM memcached") self.log_command_output(o, r, debug=False)
Start memcached process on remote server
generate code for the following
def uninstall(self): """ Uninstalls Couchbase server on Windows machine :return: True on success """ self.shell.stop_couchbase() cmd = self.cmds["uninstall"] self.shell.execute_command(cmd) return True
Uninstalls Couchbase server on Windows machine
generate doc string for following function:
def get_processes_binding_to_ip_family(self, ip_family="ipv4"): """ Get all the processes binding to a particular ip family :param ip_family: ip family to get processes binding of :return: list of processes binding to ip family """ output, error = self.execute_command( "lsof -i -P -n | grep LISTEN | grep couchbase| grep -i {0}" .format(ip_family), debug=True) self.log_command_output(output, error, debug=True) return output
def get_processes_binding_to_ip_family(self, ip_family="ipv4"): output, error = self.execute_command( "lsof -i -P -n | grep LISTEN | grep couchbase| grep -i {0}" .format(ip_family), debug=True) self.log_command_output(output, error, debug=True) return output
give python code to
def get_bkrs_client_config(config, section, global_properties, ui_settings): """ Get back up restore client configuration :param config: config :param section: section to get configuration from :param global_properties: dict of global properties :param ui_settings: TestInputMembaseSetting object with membase settings :return: TestInputServer with backup restore client information """ server = TestInputServer() options = config.options(section) for option in options: if option == 'ip': server.ip = config.get(section, option) if option == 'password': server.ssh_password = config.get(section, option) if option == 'port': server.port = config.get(section, option) if 'username' not in options: server.ssh_username = global_properties['username'] if 'password' not in options: server.ssh_password = global_properties['password'] if 'port' not in option: server.port = global_properties['port'] if ui_settings is None: try: ui_settings = TestInputParser.get_membase_settings(config, "membase") except Exception: raise Exception("Ini file needs 'membase' section") server.rest_username = ui_settings.rest_username server.rest_password = ui_settings.rest_password server.bkrs_client = True return server
Get back up restore client configuration
generate code for the above:
def file_exists(self, remotepath, filename, pause_time=30): """ Check if file exists in remote machine :param remotepath: path of the file to check :param filename: filename of the file to check :param pause_time: time between each command execution in seconds :return: True if file exists in remote machine else False """ sftp = self._ssh_client.open_sftp() try: if "Program" in remotepath: if "Program\\" in remotepath: remotepath = remotepath.replace("Program\\", "Program") output, _ = self.execute_command("cat '{0}{1}'".format(remotepath, filename)) if output and output[0]: return True else: return False filenames = sftp.listdir_attr(remotepath) for name in filenames: if filename in name.filename and int(name.st_size) > 0: sftp.close() return True elif filename in name.filename and int(name.st_size) == 0: if name.filename == NR_INSTALL_LOCATION_FILE: continue log.info("File {0} will be deleted".format(filename)) if not remotepath.endswith("/"): remotepath += "/" self.execute_command("rm -rf {0}*{1}*".format(remotepath, filename)) self.sleep(pause_time, "** Network or sever may be busy. **"\ "\nWait {0} seconds before executing next instrucion"\ .format(pause_time)) sftp.close() return False except IOError: return False
Check if file exists in remote machine
Code the following:
def get_port_recvq(self, port): """ Given a port, extracts address:port of services listening on that port (only ipv4) :param port: port to listen on :return: list of addresses and ports of services listening """ command = "ss -4anpe | grep :%s | grep 'LISTEN' | awk -F ' ' '{print $5}'" % port o, r = self.execute_command(command) self.log_command_output(o, r) return o
Given a port, extracts address:port of services listening on that port (only ipv4)
generate comment:
def get_ip_address(self): """ Get ip address of a remote server Override method for Windows :return: ip address of remote server """ raise NotImplementedError
def get_ip_address(self): raise NotImplementedError
generate code for the above:
def kill_eventing_process(self, name): """ Kill eventing process on remote server :param name: name of eventing process :return: None """ o, r = self.execute_command(command="killall -9 {0}".format(name)) self.log_command_output(o, r)
Kill eventing process on remote server
give python code to
from subprocess import Popen def remove_directory_recursive(self, remote_path): """ Recursively remove directory in remote machine. :param remote_path: directory path to remove :return: True if successful else False """ if self.remote: sftp = self._ssh_client.open_sftp() try: log.info("removing {0} directory...".format(remote_path)) self.rmtree(sftp, remote_path) except IOError: return False finally: sftp.close() else: try: p = Popen("rm -rf {0}".format(remote_path), shell=True, stdout=PIPE, stderr=PIPE) p.communicate() except IOError: return False return True
Recursively remove directory in remote machine.
def stop_memcached(self): """ Stop memcached process on remote server :return: None """ o, r = self.execute_command("kill -SIGSTOP $(pgrep memcached)") self.log_command_output(o, r, debug=False)
def stop_memcached(self): o, r = self.execute_command("kill -SIGSTOP $(pgrep memcached)") self.log_command_output(o, r, debug=False)
give a code to
from shell_util.remote_connection import RemoteMachineShellConnection def __init__(self, test_server): """ Creates an instance of Linux installer class :param test_server: server object of type TestInputServer """ super(Linux, self).__init__() self.shell = RemoteMachineShellConnection(test_server)
Creates an instance of Linux installer class
generate code for the above:
def get_ip_address(self): """ Get ip address of a remote server Override method for Windows :return: ip address of remote server """ raise NotImplementedError
Get ip address of a remote server Override method for Windows
generate comment for following function:
def uninstall(self): """ Uninstalls Couchbase server on Linux machine :return: True on success """ self.shell.stop_couchbase() cmd = self.cmds if self.shell.nonroot: cmd = self.non_root_cmds cmd = cmd[self.shell.info.deliverable_type]["uninstall"] self.shell.execute_command(cmd) return True
def uninstall(self): self.shell.stop_couchbase() cmd = self.cmds if self.shell.nonroot: cmd = self.non_root_cmds cmd = cmd[self.shell.info.deliverable_type]["uninstall"] self.shell.execute_command(cmd) return True
def pause_beam(self): """ Pauses the beam.smp process on remote server :return: None """ o, r = self.execute_command("killall -SIGSTOP beam.smp") self.log_command_output(o, r)
def pause_beam(self): o, r = self.execute_command("killall -SIGSTOP beam.smp") self.log_command_output(o, r)
generate python code for the following
def get_port_recvq(self, port): """ Given a port, extracts address:port of services listening on that port (only ipv4) Override for Unix systems :param port: port to listen on :return: list of addresses and ports of services listening """ raise NotImplementedError
Given a port, extracts address:port of services listening on that port (only ipv4) Override for Unix systems
generate doc string for following function:
def start_memcached(self): """ Start memcached process on remote server :return: None """ o, r = self.execute_command("kill -SIGCONT $(pgrep memcached)") self.log_command_output(o, r, debug=False)
def start_memcached(self): o, r = self.execute_command("kill -SIGCONT $(pgrep memcached)") self.log_command_output(o, r, debug=False)
give a code to
def get_data_file_size(self, path=None): """ Get the size of the file in the specified path :param path: path of the file to get the size of :return: size of the file in the path """ output, error = self.execute_command('du -b {0}'.format(path)) if error: return 0 else: for line in output: size = line.strip().split('\t') if size[0].isdigit(): print((size[0])) return size[0] else: return 0
Get the size of the file in the specified path
generate code for the above:
def get_download_dir(node_installer): """ Gets the download directory for the given node. Returns non-root download directory in case of nonroot installation. Else returns the default download directory. :param node_installer: node installer object :return: download directory for given node """ if node_installer.shell.nonroot: return node_installer.nonroot_download_dir return node_installer.download_dir
Gets the download directory for the given node. Returns non-root download directory in case of nonroot installation. Else returns the default download directory.
give a code to
def install(self, build_url): """ Installs Couchbase server on Linux machine :param build_url: build url to get the Couchbase package from :return: True on successful installation else False """ cmd = self.cmds if self.shell.nonroot: cmd = self.non_root_cmds cmd = cmd[self.shell.info.deliverable_type]["install"] f_name = build_url.split("/")[-1] cmd = cmd.replace("buildpath", "{}/{}" .format(self.download_dir, f_name)) self.shell.execute_command(cmd) output, err = self.shell.execute_command(cmd) if output[0] == '1': return True self.shell.log.critical("Output: {}, Error: {}".format(output, err)) return False
Installs Couchbase server on Linux machine
generate python code for the above
def remove_folders(self, list): """ Remove folders from list provided :param list: paths of folders to be removed :return: None """ for folder in list: output, error = self.execute_command( "rm -rf {0}".format(folder), debug=False) self.log_command_output(output, error)
Remove folders from list provided
generate python code for the above
def _check_output(self, word_check, output): """ Check if certain word is present in the output :param word_check: string or list of strings to check :param output: the output to check against :return: True if word is present in the output else False """ found = False if len(output) >= 1: if isinstance(word_check, list): for ele in word_check: for x in output: if ele.lower() in str(x.lower()): log.info("Found '{0} in output".format(ele)) found = True break elif isinstance(word_check, str): for x in output: if word_check.lower() in str(x.lower()): log.info("Found '{0}' in output".format(word_check)) found = True break else: self.log.error("invalid {0}".format(word_check)) return found
Check if certain word is present in the output
generate python code for
import os def get_server_options(servers, membase_settings, global_properties): """ Set the various server properties from membase and global properties :param servers: list of servers to set the values of :param membase_settings: TestInputMembaseSetting object with membase settings :param global_properties: dict of global properties :return: list of servers with values set """ for server in servers: if server.ssh_username == '' and 'username' in global_properties: server.ssh_username = global_properties['username'] if server.ssh_password == '' and 'password' in global_properties: server.ssh_password = global_properties['password'] if server.ssh_key == '' and 'ssh_key' in global_properties: server.ssh_key = os.path.expanduser(global_properties['ssh_key']) if not server.port and 'port' in global_properties: server.port = global_properties['port'] if server.cli_path == '' and 'cli' in global_properties: server.cli_path = global_properties['cli'] if server.rest_username == '' and membase_settings.rest_username != '': server.rest_username = membase_settings.rest_username if server.rest_password == '' and membase_settings.rest_password != '': server.rest_password = membase_settings.rest_password if server.data_path == '' and 'data_path' in global_properties: server.data_path = global_properties['data_path'] if server.index_path == '' and 'index_path' in global_properties: server.index_path = global_properties['index_path'] if server.cbas_path == '' and 'cbas_path' in global_properties: server.cbas_path = global_properties['cbas_path'] if server.services == '' and 'services' in global_properties: server.services = global_properties['services'] if server.n1ql_port == '' and 'n1ql_port' in global_properties: server.n1ql_port = global_properties['n1ql_port'] if server.index_port == '' and 'index_port' in global_properties: server.index_port = global_properties['index_port'] if server.eventing_port == '' and 'eventing_port' in global_properties: server.eventing_port = global_properties['eventing_port'] if server.es_username == '' and 'es_username' in global_properties: server.es_username = global_properties['es_username'] if server.es_password == '' and 'es_password' in global_properties: server.es_password = global_properties['es_password'] return servers
Set the various server properties from membase and global properties
give a code to
def is_couchbase_running(self): """ Checks if couchbase is currently running on the remote server :return: True if couchbase is running else False """ o = self.is_process_running('erl.exe') if o is not None: return True return False
Checks if couchbase is currently running on the remote server
generate python code for the above
from typing import re def _recover_disk_full_failure(self, location): """ Recover the disk full failures on remote server :param location: location of the disk to recover :return: output and error message from recovering disk """ delete_file = "{0}/disk-quota.ext3".format(location) output, error = self.execute_command("rm -f {0}".format(delete_file)) return output, error
Recover the disk full failures on remote server
generate comment:
def start_membase(self): """ Start membase process on remote server :return: None """ o, r = self.execute_command("net start membaseserver") self.log_command_output(o, r)
def start_membase(self): o, r = self.execute_command("net start membaseserver") self.log_command_output(o, r)
Code the following:
def unpause_memcached(self, os="linux"): """ Unpauses the memcached process on remote server :param os: os type of remote server :return: None """ log.info("*** unpause memcached process ***") if self.nonroot: o, r = self.execute_command("killall -SIGCONT memcached.bin") else: o, r = self.execute_command("killall -SIGCONT memcached") self.log_command_output(o, r)
Unpauses the memcached process on remote server
def check_build_url_status(self): """ Checks the build url status. Checks if the url is reachable and valid. :return: None """ self.check_url_status(self.node_install_info.build_url)
def check_build_url_status(self): self.check_url_status(self.node_install_info.build_url)
def unmount_partition(self, location): """ Unmount the partition at the specified location. :param location: Location of the partition which has to be unmounted :return: Output and error message from the umount command """ command = "umount -l {0}; df -Th".format(location) output, error = self.execute_command(command) return output, error
def unmount_partition(self, location): command = "umount -l {0}; df -Th".format(location) output, error = self.execute_command(command) return output, error
give a code to
def kill_cbft_process(self): """ Kill the full text search process on remote server :return: output and error of command killing FTS process """ o, r = self.execute_command("killall -9 cbft") self.log_command_output(o, r) if r and r[0] and "command not found" in r[0]: o, r = self.execute_command("pkill cbft") self.log_command_output(o, r) return o, r
Kill the full text search process on remote server
generate python code for the above
def get_cbversion(self): """ Get the installed version of Couchbase Server installed on the remote server. This gets the versions from both default path or non-default paths. Returns in format fv = a.b.c-xxxx, sv = a.b.c, bn = xxxx :return: full version, main version and the build version of the Couchbase Server installed """ output = "" fv = sv = bn = tmp = "" err_msg = "{} - Couchbase Server not found".format(self.ip) if self.nonroot: if self.file_exists('/home/%s/cb/%s' % (self.username, self.cb_path), self.version_file): output = self.read_remote_file('/home/%s/cb/%s' % (self.username, self.cb_path), self.version_file) else: log.info(err_msg) else: if self.file_exists(self.cb_path, self.version_file): output = self.read_remote_file(self.cb_path, self.version_file) else: log.info(err_msg) if output: for x in output: x = x.strip() if x and x[:5] in CB_RELEASE_BUILDS.keys() and "-" in x: fv = x tmp = x.split("-") sv = tmp[0] bn = tmp[1] break return fv, sv, bn
Get the installed version of Couchbase Server installed on the remote server. This gets the versions from both default path or non-default paths. Returns in format fv = a.b.c-xxxx, sv = a.b.c, bn = xxxx
Code the following:
def kill_cbft_process(self): """ Kill the full text search process on remote server :return: output and error of command killing FTS process """ o, r = self.execute_command("killall -9 cbft") self.log_command_output(o, r) if r and r[0] and "command not found" in r[0]: o, r = self.execute_command("pkill cbft") self.log_command_output(o, r) return o, r
Kill the full text search process on remote server
generate python code for the following
def __init__(self, logger, node_install_info, steps): """ Creates an instance of the NodeInstaller object. This object is used to install Couchbase server builds on remote servers. :param logger: logger object for logging :param node_install_info: node install info of type NodeInstallInfo :param steps: list of steps to run in the installation process """ super(NodeInstaller, self).__init__() self.log = logger self.steps = steps self.node_install_info = node_install_info self.result = False
Creates an instance of the NodeInstaller object. This object is used to install Couchbase server builds on remote servers.
give a code to
def stop_indexer(self): """ Stop indexer process on remote server :return: None """ o, r = self.execute_command("taskkill /F /T /IM indexer*") self.log_command_output(o, r, debug=False)
Stop indexer process on remote server
generate python code for the above
def get_membase_build(config, section): """ Get the membase build information from the config :param config: config :param section: section to get information from :return: membase build information """ membase_build = TestInputBuild() for option in config.options(section): if option == 'version': pass if option == 'url': pass return membase_build
Get the membase build information from the config
def get_server_options(servers, membase_settings, global_properties): """ Set the various server properties from membase and global properties :param servers: list of servers to set the values of :param membase_settings: TestInputMembaseSetting object with membase settings :param global_properties: dict of global properties :return: list of servers with values set """ for server in servers: if server.ssh_username == '' and 'username' in global_properties: server.ssh_username = global_properties['username'] if server.ssh_password == '' and 'password' in global_properties: server.ssh_password = global_properties['password'] if server.ssh_key == '' and 'ssh_key' in global_properties: server.ssh_key = os.path.expanduser(global_properties['ssh_key']) if not server.port and 'port' in global_properties: server.port = global_properties['port'] if server.cli_path == '' and 'cli' in global_properties: server.cli_path = global_properties['cli'] if server.rest_username == '' and membase_settings.rest_username != '': server.rest_username = membase_settings.rest_username if server.rest_password == '' and membase_settings.rest_password != '': server.rest_password = membase_settings.rest_password if server.data_path == '' and 'data_path' in global_properties: server.data_path = global_properties['data_path'] if server.index_path == '' and 'index_path' in global_properties: server.index_path = global_properties['index_path'] if server.cbas_path == '' and 'cbas_path' in global_properties: server.cbas_path = global_properties['cbas_path'] if server.services == '' and 'services' in global_properties: server.services = global_properties['services'] if server.n1ql_port == '' and 'n1ql_port' in global_properties: server.n1ql_port = global_properties['n1ql_port'] if server.index_port == '' and 'index_port' in global_properties: server.index_port = global_properties['index_port'] if server.eventing_port == '' and 'eventing_port' in global_properties: server.eventing_port = global_properties['eventing_port'] if server.es_username == '' and 'es_username' in global_properties: server.es_username = global_properties['es_username'] if server.es_password == '' and 'es_password' in global_properties: server.es_password = global_properties['es_password'] return servers
def get_server_options(servers, membase_settings, global_properties): for server in servers: if server.ssh_username == '' and 'username' in global_properties: server.ssh_username = global_properties['username'] if server.ssh_password == '' and 'password' in global_properties: server.ssh_password = global_properties['password'] if server.ssh_key == '' and 'ssh_key' in global_properties: server.ssh_key = os.path.expanduser(global_properties['ssh_key']) if not server.port and 'port' in global_properties: server.port = global_properties['port'] if server.cli_path == '' and 'cli' in global_properties: server.cli_path = global_properties['cli'] if server.rest_username == '' and membase_settings.rest_username != '': server.rest_username = membase_settings.rest_username if server.rest_password == '' and membase_settings.rest_password != '': server.rest_password = membase_settings.rest_password if server.data_path == '' and 'data_path' in global_properties: server.data_path = global_properties['data_path'] if server.index_path == '' and 'index_path' in global_properties: server.index_path = global_properties['index_path'] if server.cbas_path == '' and 'cbas_path' in global_properties: server.cbas_path = global_properties['cbas_path'] if server.services == '' and 'services' in global_properties: server.services = global_properties['services'] if server.n1ql_port == '' and 'n1ql_port' in global_properties: server.n1ql_port = global_properties['n1ql_port'] if server.index_port == '' and 'index_port' in global_properties: server.index_port = global_properties['index_port'] if server.eventing_port == '' and 'eventing_port' in global_properties: server.eventing_port = global_properties['eventing_port'] if server.es_username == '' and 'es_username' in global_properties: server.es_username = global_properties['es_username'] if server.es_password == '' and 'es_password' in global_properties: server.es_password = global_properties['es_password'] return servers
generate comment:
def __init__(self, test_server, info=None): """ Creates a new shell connection for Unix based platforms :param test_server: test server to create the shell connection for :param info: None """ super(Unix, self).__init__(test_server) self.nonroot = False self.info = info
def __init__(self, test_server, info=None): super(Unix, self).__init__(test_server) self.nonroot = False self.info = info
generate code for the above:
def start_server(self): """ Starts the Couchbase server on the remote server. The method runs the sever from non-default location if it's run as nonroot user. Else from default location. :return: None """ o, r = self.execute_command("net start couchbaseserver") self.log_command_output(o, r)
Starts the Couchbase server on the remote server. The method runs the sever from non-default location if it's run as nonroot user. Else from default location.
generate comment for above
def disable_disk_readonly(self, disk_location): """ Disables read-only mode for the specified disk location. :param disk_location: disk location to disable read-only mode. :return: None """ o, r = self.execute_command("chmod -R 777 {}".format(disk_location)) self.log_command_output(o, r)
def disable_disk_readonly(self, disk_location): o, r = self.execute_command("chmod -R 777 {}".format(disk_location)) self.log_command_output(o, r)
generate python code for the above
def is_enterprise(self): """ Check if the couchbase installed is enterprise edition or not :return: True if couchbase installed is enterprise edition else False """ enterprise = False runtime_file_path = "" if self.nonroot: if self.file_exists("%s/opt/couchbase/etc/" % self.nr_home_path, "runtime.ini"): runtime_file_path = "%s/opt/couchbase/etc/" % self.nr_home_path else: log.info("couchbase server at {0} may not installed yet in nonroot server" .format(self.ip)) elif self.file_exists("/opt/couchbase/etc/", "runtime.ini"): runtime_file_path = "/opt/couchbase/etc/" else: log.info("{} - Couchbase server not found".format(self.ip)) output = self.read_remote_file(runtime_file_path, "runtime.ini") for x in output: x = x.strip() if x and "license = enterprise" in x: enterprise = True return enterprise
Check if the couchbase installed is enterprise edition or not
generate code for the following
def disable_firewall(self): """ Clear firewall rules on the remote server :return: None """ output, error = self.execute_command('netsh advfirewall set publicprofile state off') self.log_command_output(output, error) output, error = self.execute_command('netsh advfirewall set privateprofile state off') self.log_command_output(output, error) # for details see RemoteUtilHelper.enable_firewall for windows output, error = self.execute_command('netsh advfirewall firewall delete rule name="block erl.exe in"') self.log_command_output(output, error) output, error = self.execute_command('netsh advfirewall firewall delete rule name="block erl.exe out"') self.log_command_output(output, error)
Clear firewall rules on the remote server
give python code to
import os def copy_files_local_to_remote(self, src_path, des_path): """ Copy multi files from local to remote server :param src_path: source path of the files to be copied :param des_path: destination path of the files to be copied :return: None """ files = os.listdir(src_path) self.log.info("copy files from {0} to {1}".format(src_path, des_path)) # self.execute_batch_command("cp -r {0}/* {1}".format(src_path, des_path)) for file in files: if file.find("wget") != 1: a = "" full_src_path = os.path.join(src_path, file) full_des_path = os.path.join(des_path, file) self.copy_file_local_to_remote(full_src_path, full_des_path)
Copy multi files from local to remote server
give python code to
def cleanup_all_configuration(self, data_path): """ Deletes the contents of the parent folder that holds the data and config directories. :param data_path: The path key from the /nodes/self end-point which looks something like "/opt/couchbase/var/lib/couchbase/data" on Linux or "c:/Program Files/Couchbase/Server/var/lib/couchbase/data" on Windows. :return: None """ # The path returned on both Linux and Windows by the /nodes/self end-point uses forward slashes. path = data_path.replace("/data", "") o, r = self.execute_command("rm -rf %s/*" % path) self.log_command_output(o, r)
Deletes the contents of the parent folder that holds the data and config directories.
give a code to
def handle_command_line_u_or_v(option, argument): """ Parse command line arguments for -u or -v :param option: option to parse :param argument: argument to check :return: parsed arguments as TestInputBuild """ input_build = TestInputBuild() if option == "-u": # let's check whether this url exists or not # let's extract version from this url pass if option == "-v": allbuilds = BuildQuery().get_all_builds() for build in allbuilds: if build.product_version == argument: input_build.url = build.url input_build.version = argument break return input_build
Parse command line arguments for -u or -v
give a code to
def kill_cbft_process(self): """ Kill the full text search process on remote server :return: output and error of command killing FTS process """ o, r = self.execute_command("killall -9 cbft") self.log_command_output(o, r) if r and r[0] and "command not found" in r[0]: o, r = self.execute_command("pkill cbft") self.log_command_output(o, r) return o, r
Kill the full text search process on remote server
generate comment.
def disable_file_limit_desc(self): """ Change the file limit for all processes to 1606494 :return: """ o, r = self.execute_command("sysctl -w fs.file-max=1606494;sysctl -p") self.log_command_output(o, r)
def disable_file_limit_desc(self): o, r = self.execute_command("sysctl -w fs.file-max=1606494;sysctl -p") self.log_command_output(o, r)