def check_file_present(connection, config_file_path): """ return True if file is present else return False""" try: stdout, stderr, exit_code = utilities.execute_bash( connection, CommandFactory.check_file(config_file_path)) if stdout == "Found": logger.debug("file path exist {}".format(config_file_path)) return True except Exception as e: logger.debug("File path not exist {}".format(config_file_path)) return False
def check_config(self): filename = os.path.join(self.get_config_directory(), "config.dat") cmd = CommandFactory.check_file(filename) logger.debug("check file cmd: {}".format(cmd)) command_output, std_err, exit_code = utilities.execute_bash( self.connection, command_name=cmd, callback_func=self.ignore_err) if exit_code == 0 and "Found" in command_output: return True else: return False
def delete_config(self): # TODO: # error handling logger.debug("start delete_config") filename = "{}/../var/lib/couchbase/config/config.dat".format( helper_lib.get_base_directory_of_given_path( self.repository.cb_shell_path)) cmd = CommandFactory.check_file(filename, self.need_sudo, self.uid) logger.debug("check file cmd: {}".format(cmd)) command_output, std_err, exit_code = utilities.execute_bash( self.connection, command_name=cmd, callback_func=self.ignore_err) if exit_code == 0 and "Found" in command_output: cmd = CommandFactory.os_mv(filename, "{}.bak".format(filename), self.need_sudo, self.uid) logger.debug("rename config cmd: {}".format(cmd)) command_output, std_err, exit_code = utilities.execute_bash( self.connection, command_name=cmd) logger.debug( "rename config.dat to bak - exit_code: {} stdout: {} std_err: {}" .format(exit_code, command_output, std_err)) filename = "{}/../etc/couchdb/local.ini".format( helper_lib.get_base_directory_of_given_path( self.repository.cb_shell_path)) command_output, std_err, exit_code = self.run_os_command( os_command='sed', filename=filename, regex='s/view_index_dir.*//') logger.debug( "clean local.ini index - exit_code: {} stdout: {} std_err: {}". format(exit_code, command_output, std_err)) command_output, std_err, exit_code = self.run_os_command( os_command='sed', filename=filename, regex='s/database_dir.*//') logger.debug( "clean local.ini data - exit_code: {} stdout: {} std_err: {}". format(exit_code, command_output, std_err)) command_output, std_err, exit_code = self.run_os_command( os_command='change_permission', path=filename) logger.debug( "fix local.ini permission - exit_code: {} stdout: {} std_err: {}". format(exit_code, command_output, std_err))