From 255f1fa5c0fb2ce5ef58126741e5acda4c66b44d Mon Sep 17 00:00:00 2001 From: Duanshaohua Date: Thu, 3 Apr 2025 14:56:52 +0800 Subject: [PATCH 1/3] dss adaptation upgrade dss adaptation upgrade dss adaptation upgrade dss adaptation upgrade dss adaptation upgrade dss adaptation upgrade dss adaptation upgrade dss adaptation upgrade --- pkg/deploy/action/cantian_common/env_lun.sh | 18 +-- pkg/deploy/action/dss/common/exec_cmd.py | 49 ++++++++ pkg/deploy/action/dss/common/file_utils.py | 118 ++++++++++++++++++++ 3 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 pkg/deploy/action/dss/common/exec_cmd.py create mode 100644 pkg/deploy/action/dss/common/file_utils.py diff --git a/pkg/deploy/action/cantian_common/env_lun.sh b/pkg/deploy/action/cantian_common/env_lun.sh index a580a453..881f678a 100644 --- a/pkg/deploy/action/cantian_common/env_lun.sh +++ b/pkg/deploy/action/cantian_common/env_lun.sh @@ -9,16 +9,16 @@ cantian_user="cantian" cantian_group="cantian" cantian_common_group="cantiangroup" -PRE_INSTALL_ORDER=("cantian" "cms" "dbstor" "dss") -INSTALL_ORDER=("dbstor" "cms" "dss" "cantian" "ct_om" "cantian_exporter" "mysql" "logicrep") +PRE_INSTALL_ORDER=("cantian" "cms" "dss") +INSTALL_ORDER=( "cms" "dss" "cantian" "ct_om" "cantian_exporter" "mysql" "logicrep") START_ORDER=("cms" "dss" "cantian" "ct_om" "cantian_exporter" "logicrep") STOP_ORDER=("logicrep" "cms" "dss" "cantian" "ct_om" "cantian_exporter") -UNINSTALL_ORDER=("ct_om" "cantian" "dss" "cms" "dbstor" "logicrep") -BACKUP_ORDER=("cantian" "dss" "cms" "ct_om" "dbstor" ) +UNINSTALL_ORDER=("ct_om" "cantian" "dss" "cms" "logicrep") +BACKUP_ORDER=("cantian" "dss" "cms" "ct_om") CHECK_STATUS=("cantian" "cms" "dss" "ct_om" "cantian_exporter") -PRE_UPGRADE_ORDER=("ct_om" "cantian_exporter" "dbstor" "cms" "dss" "cantian" "mysql" "logicrep") -UPGRADE_ORDER=("ct_om" "cantian_exporter" "dbstor" "cms" "dss" "cantian" "mysql" "logicrep") -POST_UPGRADE_ORDER=("ct_om" "cantian_exporter" "dbstor" "cms" "dss" "cantian" "mysql") -ROLLBACK_ORDER=("dbstor" "cms" "cantian" "mysql" "ct_om" "cantian_exporter" "logicrep") -INIT_CONTAINER_ORDER=("dbstor" "cms" "cantian" "logicrep") +PRE_UPGRADE_ORDER=("ct_om" "cantian_exporter""cms" "cantian" "mysql" "logicrep") +UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql" "logicrep") +POST_UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "dss" "cantian" "mysql") +ROLLBACK_ORDER=("cms" "cantian" "mysql" "ct_om" "cantian_exporter" "logicrep") +INIT_CONTAINER_ORDER=("cms" "cantian" "logicrep") DIR_LIST=(/opt/cantian/cms /opt/cantian/cantian /opt/cantian/dbstor /opt/cantian/mysql ${CURRENT_FILE_PATH}/inspection/inspection_scripts/kernal ${CURRENT_FILE_PATH}/inspection/inspection_scripts/cms ${CURRENT_FILE_PATH}/inspection/inspection_scripts/ct_om) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/exec_cmd.py b/pkg/deploy/action/dss/common/exec_cmd.py new file mode 100644 index 00000000..c5763d1c --- /dev/null +++ b/pkg/deploy/action/dss/common/exec_cmd.py @@ -0,0 +1,49 @@ +import os +import signal +import subprocess + +TIME_OUT = 60 +FAIL = 1 + + +def close_child_process(proc): + try: + os.killpg(proc.pid, signal.SIGKILL) + except ProcessLookupError as err: + _ = err + return 'success' + except Exception as err: + return str(err) + + return 'success' + + +def exec_popen(cmd): + """ + subprocess.Popen in python3. + param cmd: commands need to execute + return: status code, standard output, error output + """ + bash_cmd = ["bash"] + pobj = subprocess.Popen(bash_cmd, shell=False, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid) + pobj.stdin.write(cmd.encode()) + pobj.stdin.write(os.linesep.encode()) + try: + stdout, stderr = pobj.communicate(timeout=TIME_OUT) + except Exception as err: + return pobj.returncode, "", str(err) + finally: + return_code = pobj.returncode + kill_fork_process_res = close_child_process(pobj) + + if kill_fork_process_res != "success": + return FAIL, "", "kill fork process failed, err_details: {}".format(kill_fork_process_res) + + stdout, stderr = stdout.decode(), stderr.decode() + if stdout[-1:] == os.linesep: + stdout = stdout[:-1] + if stderr[-1:] == os.linesep: + stderr = stderr[:-1] + + return return_code, stdout, stderr \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/file_utils.py b/pkg/deploy/action/dss/common/file_utils.py new file mode 100644 index 00000000..c13339e6 --- /dev/null +++ b/pkg/deploy/action/dss/common/file_utils.py @@ -0,0 +1,118 @@ +import os +import re +from exec_cmd import exec_popen + + +def pad_file_to_512(input_file, output_file=None): + """ + Pads a file to 512-byte alignment with zero bytes. + + Args: + input_file (str): Source file path. + output_file (str, optional): Destination file path . If None, overwrites the input file. + + Returns: + int: Final file size in bytes. + + Raises: + FileNotFoundError: If the input file does not exist. + IOError: If read/write fails. + """ + try: + if not os.path.isfile(input_file): + raise FileNotFoundError(f"Input file '{input_file}' not found.") + + with open(input_file, 'rb') as f: + data = f.read() + + original_size = len(data) + pad_size = (512 - original_size % 512) % 512 + if pad_size: + data += b'\x00' * pad_size + + if output_file is None: + output_file = input_file + + with open(output_file, 'wb') as f: + f.write(data) + + total_size = len(data) + return total_size + + except Exception as e: + raise IOError(f"Failed to pad file '{input_file}': {e}") + + +def parse_numeric(val: str) -> int: + try: + return int(float(val)) + except ValueError: + raise ValueError(f"Cannot convert '{val}' to integer.") + + +def get_written_size(vg_file_path: str) -> int: + cmd = f'dsscmd ls -p {vg_file_path} -w 0' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd ls` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + raise ValueError("Unexpected `dsscmd ls` output: too few lines.") + + headers = lines[0].split() + values = lines[1].split() + + if 'written_size' not in headers: + raise ValueError("'written_size' column not found.") + + index = headers.index('written_size') + return parse_numeric(values[index]) + + +def parse_hex_dump(raw_output: str) -> str: + hex_bytes = [] + + for line in raw_output.strip().splitlines(): + # Extract exactly 16 hex bytes using regex: 2-digit hex tokens + matches = re.findall(r'\b[0-9a-fA-F]{2}\b', line) + if matches: + hex_bytes.extend(matches) + + try: + byte_data = bytes.fromhex(''.join(hex_bytes)) + return byte_data.replace(b'\x00', b'').decode('utf-8', errors='replace').strip() + except Exception as e: + raise ValueError(f"Failed to decode hex dump: {e}") + + +def read_dss_content(vg_file_path: str, size: int) -> str: + cmd = f'dsscmd examine -p {vg_file_path} -o 0 -f x -s {size}' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd examine` failed: {stderr}") + + return parse_hex_dump(stdout) + + +def read_dss_file(vg_file_path: str) -> str: + written_size = get_written_size(vg_file_path) + if written_size == 0: + return "[Empty] No actual data written to this DSS file." + return read_dss_content(vg_file_path, written_size) + + +# Example usage: +if __name__ == "__main__": + # Example usage for padding file to 512-byte alignment + try: + pad_file_to_512("./example.txt") + except Exception as e: + print(f"Operation failed: {e}") + + # Example usage for reading DSS file content + path = '+vg1/testfile.txt' + content = read_dss_file(path) + print(content) -- Gitee From da894f4405e731f9ae2529bd7008a5b30fb2d2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E9=87=91=E6=9F=8F?= <1130065076@qq.com> Date: Tue, 8 Apr 2025 09:02:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?dss=E7=9A=84=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/deploy/action/appctl.sh | 5 + pkg/deploy/action/cantian/appctl.sh | 10 +- pkg/deploy/action/cantian/cantian_install.py | 13 +- pkg/deploy/action/cms/appctl.sh | 10 +- .../action/docker/dbstor_tool_opt_common.sh | 20 +++- .../action/dss/common/dss_upgrade_commit.py | 82 +++++++++++++ .../action/dss/common/dss_upgrade_detele.py | 101 ++++++++++++++++ .../common/dss_upgrade_local_status_file.py | 93 +++++++++++++++ .../action/dss/common/dss_upgrade_lock.py | 110 +++++++++++++++++ .../common/dss_upgrade_remote_status_file.py | 112 ++++++++++++++++++ .../action/dss/common/dss_upgrade_unlock.py | 81 +++++++++++++ .../action/dss/common/dss_upgrade_yaml.py | 62 ++++++++++ pkg/deploy/action/dss/common/file_utils.py | 12 +- .../action/dss/common/get_config_info.py | 36 ++++++ pkg/deploy/action/dss/dssctl.py | 6 +- pkg/deploy/action/pre_upgrade.sh | 4 +- pkg/deploy/action/upgrade.sh | 26 +++- pkg/deploy/action/upgrade_commit.sh | 14 ++- 18 files changed, 771 insertions(+), 26 deletions(-) create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_commit.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_detele.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_lock.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_unlock.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_yaml.py create mode 100644 pkg/deploy/action/dss/common/get_config_info.py diff --git a/pkg/deploy/action/appctl.sh b/pkg/deploy/action/appctl.sh index cab027eb..caec6c87 100644 --- a/pkg/deploy/action/appctl.sh +++ b/pkg/deploy/action/appctl.sh @@ -174,6 +174,7 @@ function upgrade_lock() { exit 1 fi upgrade_lock_by_dbstor + touch "${upgrade_path}"/"${upgrade_flag}" && chmod 600 "${upgrade_path}"/"${upgrade_flag}" update_remote_status_file_path_by_dbstor "${upgrade_path}"/"${upgrade_flag}" } @@ -422,6 +423,10 @@ case "$ACTION" in if [[ "$(find ${SUCCESS_FLAG_PATH} -type f -name pre_upgrade_"${INSTALL_TYPE}".success)" ]]; then UPGRADE_IP_PORT=$3 lock_file=${UPGRADE_NAME} + deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy") + if [[ "${deploy_mode}" == "dss" ]]; then + sh /opt/cantian/action/dss/appctl.sh start + fi create_upgrade_flag upgrade_lock do_deploy ${UPGRADE_NAME} ${INSTALL_TYPE} ${UPGRADE_IP_PORT} diff --git a/pkg/deploy/action/cantian/appctl.sh b/pkg/deploy/action/cantian/appctl.sh index 0f0d4657..27d4744c 100644 --- a/pkg/deploy/action/cantian/appctl.sh +++ b/pkg/deploy/action/cantian/appctl.sh @@ -390,6 +390,12 @@ function safety_upgrade_backup() cp -arf ${cantian_local}/* ${backup_dir}/cantian/cantian_local record_cantian_info ${backup_dir} + if [[ ${deploy_mode} == "dss" ]]; then + rm -rf /mnt/dbdata/local/cantian/tmp/data/data + rm -rf ${backup_dir}/cantian/cantian_local/tmp/data + mkdir -p /mnt/dbdata/local/cantian/tmp/data/data + mkdir -p ${backup_dir}/cantian/cantian_local/tmp/data + fi echo "check that all files are backed up to ensure that no data is lost for safety upgrade and rollback" check_backup_files ${backup_dir}/cantian/cantian_home_files_list.txt ${backup_dir}/cantian/cantian_home ${cantian_home} @@ -403,7 +409,7 @@ function safety_upgrade_backup() function copy_cantian_dbstor_cfg() { - if [[ x"${deploy_mode}" == x"file" ]]; then + if [[ x"${deploy_mode}" == x"file" ]] || [[ ${deploy_mode} == "dss" ]]; then return 0 fi echo "update the cantian local config files for dbstor in ${cantian_local}" @@ -466,6 +472,7 @@ function update_cantian_server() echo "link_type is rdma_1823" fi cp -arf ${cantian_home}/server/add-ons/kmc_shared/lib* ${cantian_home}/server/add-ons/ + rm -rf ${cantian_home}/server/bin/cms return 0 } @@ -542,6 +549,7 @@ function safety_rollback() fi rm -rf ${cantian_local}/* cp -arf ${backup_dir}/cantian/cantian_local/* ${cantian_local} + rm -rf ${cantian_home}/server/bin/cms echo "check that all files are rolled back to ensure that no data is lost for safety rollback" check_rollback_files ${backup_dir}/cantian/cantian_home_files_list.txt ${backup_dir}/cantian/cantian_home ${cantian_home} diff --git a/pkg/deploy/action/cantian/cantian_install.py b/pkg/deploy/action/cantian/cantian_install.py index b8f854e2..96db5af5 100644 --- a/pkg/deploy/action/cantian/cantian_install.py +++ b/pkg/deploy/action/cantian/cantian_install.py @@ -1155,12 +1155,13 @@ class Installer: chown data and gcc dirs :return: """ - cmd = "chown %s:%s -hR \"%s\";" % (self.user, self.group, self.data) - LOGGER.info("Change owner cmd: %s" % cmd) - ret_code, _, stderr = _exec_popen(cmd) - if ret_code: - raise Exception( - "chown to %s:%s return: %s%s%s" % (self.user, self.group, str(ret_code), os.linesep, stderr)) + if os.getuid() == 0: + cmd = "chown %s:%s -hR \"%s\";" % (self.user, self.group, self.data) + LOGGER.info("Change owner cmd: %s" % cmd) + ret_code, _, stderr = _exec_popen(cmd) + if ret_code: + raise Exception( + "chown to %s:%s return: %s%s%s" % (self.user, self.group, str(ret_code), os.linesep, stderr)) ########################################################################### # Is there a database installed by the user? If right, raise error diff --git a/pkg/deploy/action/cms/appctl.sh b/pkg/deploy/action/cms/appctl.sh index c7680264..defd913b 100644 --- a/pkg/deploy/action/cms/appctl.sh +++ b/pkg/deploy/action/cms/appctl.sh @@ -300,7 +300,7 @@ function pre_upgrade() return 1 fi - if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" ]]; then + if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" && x"${deploy_mode}" != x"dss" ]]; then echo "check gcc home: /mnt/dbdata/remote/share_${storage_share_fs}" if [ ! -d /mnt/dbdata/remote/share_${storage_share_fs}/gcc_home ];then echo "Error: gcc home does not exist!" @@ -345,7 +345,7 @@ function post_upgrade() fi ls -l ${cms_scripts} - if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" ]]; then + if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" && x"${deploy_mode}" != x"dss" ]]; then echo "check gcc home: /mnt/dbdata/remote/share_${storage_share_fs}" if [ ! -d /mnt/dbdata/remote/share_${storage_share_fs}/gcc_home ];then echo "Error: gcc home does not exist!" @@ -445,7 +445,7 @@ function update_cms_service() { ${cms_pkg_file}/cfg ${cms_pkg_file}/lib ${cms_pkg_file}/package.xml ${cantian_home}/server deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") - if [[ x"${deploy_mode}" == x"file" ]]; then + if [[ x"${deploy_mode}" == x"file" ]] || [[ ${deploy_mode} == "dss" ]]; then return 0 fi @@ -482,6 +482,10 @@ function chown_mod_cms_service() find ${cantian_home}/server/lib -type f | xargs chmod 500 find ${cantian_home}/server/cfg -type f | xargs chmod 400 + if [[ x"${deploy_mode}" == x"dss" ]]; then + sudo setcap CAP_SYS_RAWIO+ep "${cms_home}"/service/bin/cms + fi + chmod 400 ${cms_home}/service/package.xml chmod 400 ${cantian_home}/server/package.xml return 0 diff --git a/pkg/deploy/action/docker/dbstor_tool_opt_common.sh b/pkg/deploy/action/docker/dbstor_tool_opt_common.sh index dcc5bf3e..a5888628 100644 --- a/pkg/deploy/action/docker/dbstor_tool_opt_common.sh +++ b/pkg/deploy/action/docker/dbstor_tool_opt_common.sh @@ -150,6 +150,9 @@ function create_file_in_filesystem() { function update_local_status_file_path_by_dbstor() { if [[ "${deploy_mode}" != "dbstor" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_remote_status_file.py" + chown "${cantian_user}":"${cantian_group}" "${METADATA_FS_PATH}"/upgrade + chown "${cantian_user}":"${cantian_group}" "${METADATA_FS_PATH}"/upgrade/cluster_and_node_status return 0 fi chown "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH} @@ -202,12 +205,14 @@ function update_local_status_file_path_by_dbstor() { } function update_remote_status_file_path_by_dbstor() { + cluster_or_node_status_file_path=$1 if [[ "${deploy_mode}" != "dbstor" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_remote_status_file.py" ${cluster_or_node_status_file_path} + chown -hR "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH}/upgrade return 0 fi get_dbs_version dbs_vs=$? - cluster_or_node_status_file_path=$1 chown -hR "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH}/upgrade if [[ -d ${cluster_or_node_status_file_path} ]];then relative_path=$(realpath --relative-to="${METADATA_FS_PATH}"/upgrade "${dir_path}") @@ -239,10 +244,12 @@ function update_remote_status_file_path_by_dbstor() { } function delete_fs_upgrade_file_or_path_by_dbstor() { + local file_name=$1 if [[ "${deploy_mode}" != "dbstor" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_delete.py" ${file_name} return 0 fi - local file_name=$1 + logAndEchoInfo "Start to delete ${file_name} in file path ${file_path}" declare -a upgrade_dirs # shellcheck disable=SC2207 @@ -262,6 +269,8 @@ function delete_fs_upgrade_file_or_path_by_dbstor() { function update_version_yml_by_dbstor() { if [[ "${deploy_mode}" != "dbstor" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_yaml.py" ${PKG_PATH}/${VERSION_FILE} + chown "${cantian_user}":"${cantian_group}" "${PKG_PATH}/${VERSION_FILE}" return 0 fi chown "${cantian_user}":"${cantian_group}" "${PKG_PATH}/${VERSION_FILE}" @@ -276,10 +285,11 @@ function update_version_yml_by_dbstor() { } function upgrade_lock_by_dbstor() { + node_lock_file=${lock_file_prefix}${node_id} if [[ "${deploy_mode}" != "dbstor" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_lock.py" ${node_lock_file} return 0 fi - node_lock_file=${lock_file_prefix}${node_id} get_dbs_version dbs_vs=$? upgrade_nodes=$(query_filesystem ${dbs_vs} ${storage_share_fs} "/upgrade" | grep -E "${lock_file_prefix}" | wc -l) @@ -305,12 +315,14 @@ function upgrade_lock_by_dbstor() { } function upgrade_unlock_by_dbstor() { + node_lock_file=${lock_file_prefix}${node_id} if [[ "${deploy_mode}" != "dbstor" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_unlock.py" ${node_lock_file} return 0 fi get_dbs_version dbs_vs=$? - node_lock_file=${lock_file_prefix}${node_id} + lock_file=$(query_filesystem ${dbs_vs} ${storage_share_fs} "upgrade" | grep "${node_lock_file}" | wc -l) if [[ ${lock_file} -eq 0 ]];then diff --git a/pkg/deploy/action/dss/common/dss_upgrade_commit.py b/pkg/deploy/action/dss/common/dss_upgrade_commit.py new file mode 100644 index 00000000..4db5f4b4 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_commit.py @@ -0,0 +1,82 @@ +import os +import sys +from exec_cmd import exec_popen +from get_config_info import get_value +from file_utils import pad_file_to_512 +from file_utils import read_dss_file + +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from om_log import LOGGER as LOG + +class DssUpgradeCommit(object): + def __init__(self): + self.node_id = None + self.node_remote_status_file_name = None + self.node_remote_status_file_path = None + self.cantian_user = None + self.node_status_num = 0 + + def file_exits(self, vg_path): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd ls -p +vg1/upgrade/cluster_and_node_status"' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd ls commit` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + LOG.error(f"cluster_and_node_status file is not complete") + return False + + for line in lines: + if "status.txt" in line and "cluster" not in line: + self.node_status_num += 1 + return True + + def check_nodes(self): + if not self.file_exits(): + return False + self.cms_status_nums = get_value("cms_ip") + self.node_ip_num = len(self.cms_status_nums.split(";")) + if self.node_ip_num != self.node_status_num: + LOG.error(f"txt num is {self.node_status_num}, ip num is {self.node_ip_num}") + return False + return True + + def check_status_file(self): + self.context = [] + for i in range(self.node_ip_num): + node_status_file = "".join([" +vg1/upgrade/cluster_and_node_status/node", str(i), "status.txt"]) + self.context.append(read_dss_file(node_status_file)) + for rollup_result in self.context: + if rollup_result != "rollup_success": + LOG.error(f"rollup result is error {rollup_result}") + return False + return True + + def upgrade_commit(self): + self.cantian_user = get_value("deploy_user") + if not self.check_nodes() or self.check_status_file(): + return False + return True + +def main(): + err_msg = "Failed to check when upgrade_commit" + + dss_commit = DssUpgradeCommit() + try: + if dss_commit.upgrade_commit(): + sys.exit(0) + else: + sys.exit(1) + except AttributeError as _err: + raise Exception(err_msg) from _err + + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_detele.py b/pkg/deploy/action/dss/common/dss_upgrade_detele.py new file mode 100644 index 00000000..23f57237 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_detele.py @@ -0,0 +1,101 @@ +import os +import sys +from exec_cmd import exec_popen +from get_config_info import get_value +from file_utils import pad_file_to_512 +from file_utils import read_dss_file + +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) + +class DssDetele(object): + def __init__(self): + self.node_id = None + self.node_lock_file_name = None + self.node_lock_file_path = None + self.cantian_user = None + self.vg_lock_file_path = None + + def delete_file(self, input_file = None): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd rm -p +vg1/{input_file}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rm delete` failed: {stderr}") + + def delete_dir(self, input_file = None): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd rmdir -p +vg1/{input_file}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rmdir delete` failed: {stderr}") + + def node_num(self): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd ls -p "+vg1/upgrade""' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd ls delete` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + return + + node_num = len(lines) -1 + + return node_num + + def delete_dir_file(self, input_file = None): + node_number = self.node_num() + if input_file == "cluster_and_node_status": + for num in range(node_number): + file_name = "".join(["node", num, "_status.txt"]) + path_file_name = "/".join(["cluster_and_node_status", file_name]) + self.delete_file(path_file_name) + else: + for num in range(node_number): + _, version = input_file.split('.', 1) + file_name = "".join(["node", num, ".", version]) + self.delete_file(file_name) + + + def upgrade_detele_by_dss(self, input_file = None): + + upgrade_type = get_value("deploy_mode") + + if upgrade_type != "dss": + return + + if "updatesys" in input: + self.delete_file("updatesys.failed") + self.delete_file("updatesys.success") + elif input == "cluster_and_node_status": + self.delete_dir("cluster_and_node_status") + elif "cluster_and_node_status" in input: + self.delete_dir_file("cluster_and_node_status") + elif "upgrade_node" in input: + self.delete_dir_file("upgrade_node") + else: + self.delete_file(input) + + return + + +def main(): + err_msg = "Failed to delete dss when upgrade" + + dss_delete = DssDetele() + if len(sys.argv) < 1: + raise Exception(err_msg) + input_file = sys.argv[1] + try: + dss_delete.upgrade_detele_by_dss(input_file) + except AttributeError as _err: + raise Exception(err_msg) from _err + + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py b/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py new file mode 100644 index 00000000..4358eea4 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py @@ -0,0 +1,93 @@ +import os +import sys +from exec_cmd import exec_popen +from get_config_info import get_value +from file_utils import pad_file_to_512 +from file_utils import read_dss_file + +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) + +class DssRemoteStatusfile(object): + def __init__(self): + self.node_id = None + self.node_remote_status_file_name = None + self.node_remote_status_file_path = None + self.cantian_user = None + + + def mkdir_dir(self, dir): + cmd = f'mkdir -p /mnt/dbdata/remote/metadata_/{dir}' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`mkdir local` failed: {stderr}") + + def detele_file(self, path, dir): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd rmdir -p {path}/{dir}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rmdir local` failed: {stderr}") + + def file_exits(self, path, dir): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd ls -p {path}"' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd ls local` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + return + + for line in lines: + if dir in line: + self.detele_file(path, dir) + break + + def mkdir_local_status_file_to_path(self, path, dir): + + self.file_exits(path, dir) + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd mkdir -p {path} -n {dir}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd mkdir local` failed: {stderr}") + + def upgrade_local_status_file_by_dss(self): + + upgrade_type = get_value("deploy_mode") + + if upgrade_type != "dss": + return + + self.cantian_user = get_value("deploy_user") + self.node_id = get_value("node_id") + + self.mkdir_dir("upgrade") + self.mkdir_dir("upgrade/cluster_and_node_status") + + self.mkdir_local_status_file_to_path("+vg1", "upgrade") + self.mkdir_local_status_file_to_path("+vg1/upgrade", "cluster_and_node_status") + + + + return + + +def main(): + err_msg = "Failed to input file when upgrade" + + dss_local_status = DssRemoteStatusfile() + try: + dss_local_status.upgrade_local_status_file_by_dss() + except AttributeError as _err: + raise Exception(err_msg) from _err + + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_lock.py b/pkg/deploy/action/dss/common/dss_upgrade_lock.py new file mode 100644 index 00000000..971f96f4 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_lock.py @@ -0,0 +1,110 @@ +import os +import sys +from exec_cmd import exec_popen +from get_config_info import get_value +from file_utils import pad_file_to_512 +from file_utils import read_dss_file + +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) + +class DssLock(object): + def __init__(self): + self.node_id = None + self.node_lock_file_name = None + self.node_lock_file_path = None + self.cantian_user = None + self.vg_lock_file_path = None + self.lock_res = None + + def create_upgrade_file(self): + cmd =f'touch {self.node_lock_file_path}' + + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"touch lock file failed: {stderr}") + + + def create_vg_upgrade_path(self): + + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd mkdir -p +vg1 -d upgrade"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd mkdir lock` failed: {stderr}") + + def cp_node_lock_file_to_path(self): + + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd cp -s {self.node_lock_file_path} -d {self.vg_lock_file_path}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd cp lock` failed: {stderr}") + + + def is_locked_new(self): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd ls -p "+vg1/upgrade""' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + self.lock_res = "upgrade no exists" + return + + lines = stdout.strip().splitlines() + if len(lines) < 2: + self.lock_res = "upgrade is empty" + return + + for line in lines: + if self.node_lock_file_name in line: + raise RuntimeError(f"local lock is using") + if "upgrade_lock_" in line[5]: + raise RuntimeError(f"other lock is using, {line[5]}") + self.lock_res = "upgrade not lock" + + def upgrade_lock_by_dss(self, input_file = None): + + upgrade_type = get_value("deploy_mode") + + if upgrade_type != "dss": + return + + self.cantian_user = get_value("deploy_user") + self.node_id = get_value("node_id") + self.node_lock_file_name = os.path.basename(input_file) + self.node_lock_file_path = "/".join(["/mnt/dbdata/remote/metadata_/upgrade", self.node_lock_file_name]) + self.vg_lock_file_path = "/".join(["+vg1/upgrade", self.node_lock_file_name]) + + self.is_locked_new() + + if self.lock_res == "upgrade no exists": + self.create_vg_upgrade_path() + + if not os.path.exists(self.node_lock_file_path): + self.create_upgrade_file() + self.cp_node_lock_file_to_path() + pad_file_to_512(self.node_lock_file_path) + print("ugrade lock", self.node_id, "success") + + return + + +def main(): + err_msg = "Failed to lock dss when upgrade" + + dss_lock = DssLock() + if len(sys.argv) < 1: + raise Exception("upgrade lock no input") + input_file = sys.argv[1] + try: + dss_lock.upgrade_lock_by_dss(input_file) + except Exception as _err: + raise Exception(err_msg) from _err + + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py b/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py new file mode 100644 index 00000000..6b8079cd --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py @@ -0,0 +1,112 @@ +import os +import sys +from exec_cmd import exec_popen +from get_config_info import get_value +from file_utils import pad_file_to_512 +from file_utils import read_dss_file +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from om_log import LOGGER as LOG + + + +class DssRemoteStatusfile(object): + def __init__(self): + self.node_id = None + self.node_remote_status_file_name = None + self.node_remote_status_file_path = None + self.cantian_user = None + self.cluster_path = None + + def detele_file(self, vg_path): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd rm -p {vg_path}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd rm remote` failed: {stderr}") + + def file_exits(self, vg_path): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd ls -p {vg_path}"' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + return + + if "+vg1/upgrade/cluster_and_node_status" in vg_path: + self.cluster_path = "cluster_and_node_status path exists" + + lines = stdout.strip().splitlines() + + for line in lines: + if self.node_remote_status_file_name in line: + self.detele_file(self.vg_remote_file_path) + print(vg_path, "exists") + break + + + def cp_remote_status_file_to_path(self): + + self.file_exits(self.vg_remote_file_path) + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd cp -s {self.node_remote_status_file_path} -d {self.vg_remote_file_path}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd cp remote` failed: {stderr}") + + def mkdir_vg_path(self): + self.file_exits("+vg1/upgrade/cluster_and_node_status") + if self.cluster_path: + return + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd mkdir -p +vg1/upgrade -d cluster_and_node_status"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd mkdir remote` failed: {stderr}") + + def upgrade_remote_status_file_by_dss(self, remote_status_file): + + upgrade_type = get_value("deploy_mode") + + if upgrade_type != "dss": + return + + self.cantian_user = get_value("deploy_user") + self.node_id = get_value("node_id") + + if "cluster_and_node_status" in remote_status_file: + self.node_remote_status_file_name = os.path.basename(remote_status_file) + self.node_remote_status_file_path = remote_status_file + self.vg_remote_file_path = "/".join(["+vg1/upgrade/cluster_and_node_status", self.node_remote_status_file_name]) + self.mkdir_vg_path() + pad_file_to_512(self.node_remote_status_file_path) + self.cp_remote_status_file_to_path() + else: + self.node_remote_status_file_name = os.path.basename(remote_status_file) + self.node_remote_status_file_path = remote_status_file + self.vg_remote_file_path = "/".join(["+vg1/upgrade", self.node_remote_status_file_name]) + + pad_file_to_512(self.node_remote_status_file_path) + self.cp_remote_status_file_to_path() + + return + + +def main(): + err_msg = "Failed to input file when upgrade" + + dss_remote_status = DssRemoteStatusfile() + if len(sys.argv) < 1: + raise Exception(err_msg) + input_file = sys.argv[1] + try: + dss_remote_status.upgrade_remote_status_file_by_dss(input_file) + except AttributeError as _err: + raise Exception(err_msg) from _err + + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_unlock.py b/pkg/deploy/action/dss/common/dss_upgrade_unlock.py new file mode 100644 index 00000000..b3a6ed0f --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_unlock.py @@ -0,0 +1,81 @@ +import os +import sys +from exec_cmd import exec_popen +from get_config_info import get_value +from file_utils import pad_file_to_512 +from file_utils import read_dss_file + +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) + +class DssUnLock(object): + def __init__(self): + self.node_id = None + self.node_lock_file_name = None + self.node_lock_file_path = None + self.cantian_user = None + self.vg_lock_file_path = None + + def is_locked(self): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd ls -p "+vg1/upgrade""' + code, stdout, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd ls unlock` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + return False + + for line in lines: + if self.node_lock_file_name in line: + return + return False + + + def unlock_node(self): + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd rm -p {self.node_lock_file_name}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rm unlock` failed: {stderr}") + + + def upgrade_unlock_by_dss(self, input_file = None): + + upgrade_type = get_value("deploy_mode") + + if upgrade_type != "dss": + return + + self.cantian_user = get_value("deploy_user") + self.node_id = get_value("node_id") + self.node_detele_file_name = os.path.basename(input_file) + self.vg_detele_file_path = "/".join(["+vg1/upgrade", self.node_detele_file_name]) + + if self.is_locked(): + return + + self.unlock_node() + + return + + +def main(): + err_msg = "Failed to unlock dss when upgrade" + + dss_unlock = DssUnLock() + if len(sys.argv) < 1: + raise Exception(err_msg) + input_file = sys.argv[1] + try: + dss_unlock.upgrade_unlock_by_dss(input_file) + except AttributeError as _err: + raise Exception(err_msg) from _err + + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_yaml.py b/pkg/deploy/action/dss/common/dss_upgrade_yaml.py new file mode 100644 index 00000000..3907d0e1 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_yaml.py @@ -0,0 +1,62 @@ +import os +import sys +from exec_cmd import exec_popen +from get_config_info import get_value +from file_utils import pad_file_to_512 +from file_utils import read_dss_file + +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) + +class DssYaml(object): + def __init__(self): + self.node_id = None + self.node_yaml_file_name = None + self.node_yaml_file_path = None + self.cantian_user = None + self.vg_yaml_file_path = None + + def cp_yaml_file_to_path(self): + + cmd = f'su -s /bin/bash - {self.cantian_user} -c "dsscmd cp -s {self.node_yaml_file_path} -d {self.vg_yaml_file_path}"' + code, _, stderr = exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd cp yaml` failed: {stderr}") + + def upgrade_yaml_by_dss(self, input_file = None): + + upgrade_type = get_value("deploy_mode") + + if upgrade_type != "dss": + return + + self.cantian_user = get_value("deploy_user") + self.node_id = get_value("node_id") + self.node_yaml_file_name = os.path.basename(input_file) + self.node_yaml_file_path = input_file + self.vg_yaml_file_path = "/".join(["+vg1", self.node_yaml_file_name]) + + self.cp_yaml_file_to_path() + + return + + +def main(): + err_msg = "Failed to cp yaml when upgrade" + + dss_yaml = DssYaml() + if len(sys.argv) < 1: + raise Exception(err_msg) + input_file = sys.argv[1] + try: + dss_yaml.upgrade_yaml_by_dss(input_file) + except AttributeError as _err: + raise Exception(err_msg) from _err + + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/file_utils.py b/pkg/deploy/action/dss/common/file_utils.py index c13339e6..065a2c41 100644 --- a/pkg/deploy/action/dss/common/file_utils.py +++ b/pkg/deploy/action/dss/common/file_utils.py @@ -1,6 +1,9 @@ import os import re from exec_cmd import exec_popen +from get_config_info import get_value + +cantian_user = get_value("deploy_user") def pad_file_to_512(input_file, output_file=None): @@ -51,9 +54,14 @@ def parse_numeric(val: str) -> int: def get_written_size(vg_file_path: str) -> int: - cmd = f'dsscmd ls -p {vg_file_path} -w 0' + cmd = f'su -s /bin/bash - {cantian_user} -c "dsscmd ls -p {vg_file_path} -w 0"' code, stdout, stderr = exec_popen(cmd) + no_file_result = " ".join(["The path", vg_file_path, "is not exsit."]) + + if stdout == no_file_result: + return 0 + if code != 0: raise RuntimeError(f"`dsscmd ls` failed: {stderr}") @@ -88,7 +96,7 @@ def parse_hex_dump(raw_output: str) -> str: def read_dss_content(vg_file_path: str, size: int) -> str: - cmd = f'dsscmd examine -p {vg_file_path} -o 0 -f x -s {size}' + cmd = f'su -s /bin/bash - {cantian_user} -c "dsscmd examine -p {vg_file_path} -o 0 -f x -s {size}"' code, stdout, stderr = exec_popen(cmd) if code != 0: diff --git a/pkg/deploy/action/dss/common/get_config_info.py b/pkg/deploy/action/dss/common/get_config_info.py new file mode 100644 index 00000000..1f002223 --- /dev/null +++ b/pkg/deploy/action/dss/common/get_config_info.py @@ -0,0 +1,36 @@ +# -*- coding: UTF-8 -*- +import sys +import os +import json +from pathlib import Path + +CUR_PATH = os.path.dirname(os.path.realpath(__file__)) +INSTALL_FILE = str(Path(os.path.join(CUR_PATH, "../../../config/deploy_param.json"))) + + +def get_value(param): + with open(INSTALL_FILE, encoding="utf-8") as f: + _tmp = f.read() + info = json.loads(_tmp) + # deploy_user 格式为:用户:用户组 + if param == 'deploy_user': + return info.get('deploy_user').split(':')[0] + + if param == 'deploy_group': + return info.get('deploy_user').split(':')[1] + + if param == "cluster_scale": + return len(info.get("cms_ip").split(";")) + + if param == "deploy_mode": + if info.get('deploy_mode', ""): + return info.get('deploy_mode') + return "dbstor" if info.get('deploy_policy', "") in ["ModeB", "ModeC"] else "file" + + return info.get(param, "") + + +if __name__ == "__main__": + _param = sys.argv[1] + res = get_value(_param) + print(res) diff --git a/pkg/deploy/action/dss/dssctl.py b/pkg/deploy/action/dss/dssctl.py index e414507a..e2e685f3 100644 --- a/pkg/deploy/action/dss/dssctl.py +++ b/pkg/deploy/action/dss/dssctl.py @@ -436,13 +436,17 @@ class DssCtl(object): else: LOG.info("dssserver is offline.") return False + + def upgrade_backup(self, *args) -> None: + LOG.info("Start to upgrade_backup dss.") + LOG.info("Success to upgrade_backup dss.") def main(): parse = argparse.ArgumentParser() parse.add_argument("--action", type=str, choices=["install", "uninstall", "start", "stop", "pre_install", - "upgrade", "rollback", "pre_upgrade"]) + "upgrade", "rollback", "pre_upgrade", "check_status", "upgrade_backup"]) parse.add_argument("--mode", required=False, dest="mode", default="") arg = parse.parse_args() act = arg.action diff --git a/pkg/deploy/action/pre_upgrade.sh b/pkg/deploy/action/pre_upgrade.sh index 0233fc21..6526e2f7 100644 --- a/pkg/deploy/action/pre_upgrade.sh +++ b/pkg/deploy/action/pre_upgrade.sh @@ -321,7 +321,7 @@ function offline_upgrade() { check_cms_stat check_mem_avail check_upgrade_version - check_dbstor_client_compatibility + #check_dbstor_client_compatibility call_each_pre_upgrade gen_upgrade_plan } @@ -332,7 +332,7 @@ function rollup_upgrade() { local_node_health_check cantian_database_health_status_check component_version_dependency_check - check_dbstor_client_compatibility + #check_dbstor_client_compatibility call_each_pre_upgrade gen_upgrade_plan } diff --git a/pkg/deploy/action/upgrade.sh b/pkg/deploy/action/upgrade.sh index a4507cc2..ddf06881 100644 --- a/pkg/deploy/action/upgrade.sh +++ b/pkg/deploy/action/upgrade.sh @@ -79,7 +79,7 @@ function input_params_check() { fi # 离线升级需要检查阵列侧ip - if [ "${UPGRADE_MODE}" == "offline" ]; then + if [ ["${UPGRADE_MODE}" == "offline" ]]; then if [ -z "${DORADO_IP}" ]; then logAndEchoError "storage array ip must be provided" exit 1 @@ -293,7 +293,13 @@ function do_backup() { for upgrade_module in "${UPGRADE_ORDER[@]}"; do logAndEchoInfo "begin to backup ${upgrade_module}" - sh "${CURRENT_PATH}/${upgrade_module}/appctl.sh" upgrade_backup ${dircetory_path} + if [ "${upgrade_module}" == "dbstor" ]; then + if [ "${deploy_mode}" == "dss" ]; then + sh "${CURRENT_PATH}/dss/appctl.sh" upgrade_backup ${dircetory_path} + fi + else + sh "${CURRENT_PATH}/${upgrade_module}/appctl.sh" upgrade_backup ${dircetory_path} + fi if [ $? -ne 0 ]; then logAndEchoError "${upgrade_module} upgrade_backup failed" logAndEchoError "For details, see the /opt/cantian/log/${upgrade_module}. [Line:${LINENO}, File:${SCRIPT_NAME}]" @@ -403,7 +409,7 @@ function install_rpm() rpm -ivh --replacepkgs ${RPM_PATH} --nodeps --force tar -zxf ${RPM_UNPACK_PATH_FILE}/Cantian-RUN-CENTOS-64bit.tar.gz -C ${RPM_PACK_ORG_PATH} - if [ x"${deploy_mode}" != x"file" ];then + if [ x"${deploy_mode}" != x"file" ] && [ x"${deploy_mode}" != x"dss" ];then echo "start replace rpm package" install_dbstor if [ $? -ne 0 ];then @@ -873,6 +879,9 @@ function do_rollup_upgrade() { stop_cantian stop_cms + if [[ "${deploy_mode}" == "dss" ]]; then + sh /opt/cantian/action/dss/appctl.sh start + fi # 生成调用ct_backup成功的标记文件,避免重入调用时失败 touch "${storage_metadata_fs_path}/call_ctback_tool.success" && chmod 600 "${storage_metadata_fs_path}/call_ctback_tool.success" @@ -942,7 +951,11 @@ function post_upgrade_nodes_status() { # step1: 统计节点拉起情况 start_array=() readarray -t start_array <<< "$(echo "${cms_res}" | awk '{print $3}' | tail -n +$"2")" - if [ ${#start_array[@]} != "${node_count}" ]; then + cms_node_num=${#start_array[@]} + if [[ ${deploy_mode} == "dss" ]] && [ ${#start_array[@]} -ne 1 ]; then + cms_node_num=$((${#start_array[@]}/2)) + fi + if [ "${cms_node_num}" != "${node_count}" ]; then logAndEchoError "only ${#start_array[@]} nodes were detected, totals:${node_count}" && exit 1 fi @@ -982,7 +995,7 @@ function get_back_version() { function offline_upgrade() { cantian_status_check do_backup - if [[ ${node_id} == '0' ]] && [[ ${deploy_mode} != "file" ]]; then + if [[ ${node_id} == '0' ]] && [[ ${deploy_mode} != "file" ]] && [[ ${deploy_mode} != "dss" ]]; then creat_snapshot fi get_back_version @@ -1069,6 +1082,9 @@ function main() { # 升级成功后更新版本信息 show_cantian_version cp -fp ${CURRENT_PATH}/../versions.yml /opt/cantian + if [[ ${node_id} != '0' ]]; then + rm -rf /mnt/dbdata/remote/metadata_${storage_metadata_fs}/upgrade/upgrade_node* + fi logAndEchoInfo ">>>>> ${UPGRADE_MODE} upgrade performed successfully <<<<<" return 0 } diff --git a/pkg/deploy/action/upgrade_commit.sh b/pkg/deploy/action/upgrade_commit.sh index 17f7e27a..5a6ee6f8 100644 --- a/pkg/deploy/action/upgrade_commit.sh +++ b/pkg/deploy/action/upgrade_commit.sh @@ -70,6 +70,16 @@ function init_cluster_status_flag() { function node_status_check() { logAndEchoInfo "begin to check cluster upgrade status" + if [[ x"${deploy_mode}" != x"dss" ]];then + python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_commit.py" + result_python=$? + if [ $result_python -eq 0 ];then + return 3 + else + exit 1 + fi + fi + # 统计当前节点数目 node_count=$(expr "$(echo "${cms_ip}" | grep -o ";" | wc -l)" + 1) @@ -231,7 +241,7 @@ function clear_upgrade_residual_data() { delete_fs_upgrade_file_or_path_by_dbstor call_ctback_tool.success delete_fs_upgrade_file_or_path_by_dbstor cluster_and_node_status delete_fs_upgrade_file_or_path_by_dbstor updatesys.* - delete_fs_upgrade_file_or_path_by_dbstor upgrade_node.*."${target_version}" + delete_fs_upgrade_file_or_path_by_dbstor upgrade_node*."${target_version}" logAndEchoInfo "clear residual data success" } @@ -263,7 +273,7 @@ function offline_upgrade_commit() { fi raise_version_num deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") - if [[ x"${deploy_mode}" != x"file" ]];then + if [[ x"${deploy_mode}" != x"file" ]] && [[ x"${deploy_mode}" != x"dss" ]];then read -p "Please input dorado_ip:" dorado_ip echo "dorado_ip is: ${dorado_ip}" ping -c 1 "${dorado_ip}" > /dev/null 2>&1 -- Gitee From 0e1d108444b808bbb28af70548be32c318af9c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E9=87=91=E6=9F=8F?= <1130065076@qq.com> Date: Tue, 8 Apr 2025 09:02:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?dss=E7=9A=84=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/deploy/action/appctl.sh | 8 ++ pkg/deploy/action/cantian/appctl.sh | 14 ++- pkg/deploy/action/cantian_common/env_lun.sh | 16 ++-- pkg/deploy/action/cms/appctl.sh | 10 +- .../action/docker/dbstor_tool_opt_common.sh | 63 +++++++++++-- pkg/deploy/action/dss/appctl.sh | 2 +- .../action/dss/common/dss_upgrade_commit.py | 81 +++++++++++++++++ .../action/dss/common/dss_upgrade_detele.py | 91 +++++++++++++++++++ .../common/dss_upgrade_local_status_file.py | 53 +++++++++++ .../action/dss/common/dss_upgrade_lock.py | 86 ++++++++++++++++++ .../common/dss_upgrade_remote_status_file.py | 90 ++++++++++++++++++ .../action/dss/common/dss_upgrade_unlock.py | 63 +++++++++++++ .../action/dss/common/dss_upgrade_yaml.py | 69 ++++++++++++++ pkg/deploy/action/dss/dssctl.py | 8 +- pkg/deploy/action/pre_upgrade.sh | 14 ++- pkg/deploy/action/rollback.sh | 3 + pkg/deploy/action/upgrade.sh | 29 ++++-- pkg/deploy/action/upgrade_commit.sh | 13 ++- 18 files changed, 675 insertions(+), 38 deletions(-) create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_commit.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_detele.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_lock.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_unlock.py create mode 100644 pkg/deploy/action/dss/common/dss_upgrade_yaml.py diff --git a/pkg/deploy/action/appctl.sh b/pkg/deploy/action/appctl.sh index cab027eb..1ed3bd0a 100644 --- a/pkg/deploy/action/appctl.sh +++ b/pkg/deploy/action/appctl.sh @@ -174,6 +174,7 @@ function upgrade_lock() { exit 1 fi upgrade_lock_by_dbstor + touch "${upgrade_path}"/"${upgrade_flag}" && chmod 600 "${upgrade_path}"/"${upgrade_flag}" update_remote_status_file_path_by_dbstor "${upgrade_path}"/"${upgrade_flag}" } @@ -409,6 +410,7 @@ case "$ACTION" in CONFIG_PATH=$3 lock_file=${PRE_UPGRADE} FAIL_FLAG=/opt/cantian/pre_upgrade_${INSTALL_TYPE}.fail + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* clear_history_flag do_deploy ${PRE_UPGRADE} ${INSTALL_TYPE} ${CONFIG_PATH} if [ $? -ne 0 ]; then @@ -422,6 +424,11 @@ case "$ACTION" in if [[ "$(find ${SUCCESS_FLAG_PATH} -type f -name pre_upgrade_"${INSTALL_TYPE}".success)" ]]; then UPGRADE_IP_PORT=$3 lock_file=${UPGRADE_NAME} + deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy") + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* + if [[ "${deploy_mode}" == "dss" ]]; then + sh /opt/cantian/action/dss/appctl.sh start + fi create_upgrade_flag upgrade_lock do_deploy ${UPGRADE_NAME} ${INSTALL_TYPE} ${UPGRADE_IP_PORT} @@ -439,6 +446,7 @@ case "$ACTION" in ;; upgrade_commit) upgrade_init_flag + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* upgrade_lock lock_file=${UPGRADE_COMMIT_NAME} do_deploy ${UPGRADE_COMMIT_NAME} ${INSTALL_TYPE} diff --git a/pkg/deploy/action/cantian/appctl.sh b/pkg/deploy/action/cantian/appctl.sh index 0f0d4657..44950c24 100644 --- a/pkg/deploy/action/cantian/appctl.sh +++ b/pkg/deploy/action/cantian/appctl.sh @@ -390,6 +390,13 @@ function safety_upgrade_backup() cp -arf ${cantian_local}/* ${backup_dir}/cantian/cantian_local record_cantian_info ${backup_dir} + deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") + if [[ ${deploy_mode} == "dss" ]]; then + rm -rf /mnt/dbdata/local/cantian/tmp/data/data + mkdir -p /mnt/dbdata/local/cantian/tmp/data/data + chmod 750 /mnt/dbdata/local/cantian/tmp/data/data + chown ${cantian_user} /mnt/dbdata/local/cantian/tmp/data/data + fi echo "check that all files are backed up to ensure that no data is lost for safety upgrade and rollback" check_backup_files ${backup_dir}/cantian/cantian_home_files_list.txt ${backup_dir}/cantian/cantian_home ${cantian_home} @@ -403,7 +410,7 @@ function safety_upgrade_backup() function copy_cantian_dbstor_cfg() { - if [[ x"${deploy_mode}" == x"file" ]]; then + if [[ x"${deploy_mode}" == x"file" ]] || [[ ${deploy_mode} == "dss" ]]; then return 0 fi echo "update the cantian local config files for dbstor in ${cantian_local}" @@ -449,8 +456,8 @@ function update_cantian_server() rm -rf ${cantian_home}/server/* cp -arf ${cantian_pkg_file}/add-ons ${cantian_pkg_file}/admin ${cantian_pkg_file}/bin \ ${cantian_pkg_file}/cfg ${cantian_pkg_file}/lib ${cantian_pkg_file}/package.xml ${cantian_home}/server - - if [[ x"${deploy_mode}" == x"file" ]]; then + rm -rf ${cantian_home}/server/bin/cms + if [[ x"${deploy_mode}" == x"file" ]] || [[ x"${deploy_mode}" == x"dss" ]];then return 0 fi @@ -542,6 +549,7 @@ function safety_rollback() fi rm -rf ${cantian_local}/* cp -arf ${backup_dir}/cantian/cantian_local/* ${cantian_local} + rm -rf ${cantian_home}/server/bin/cms echo "check that all files are rolled back to ensure that no data is lost for safety rollback" check_rollback_files ${backup_dir}/cantian/cantian_home_files_list.txt ${backup_dir}/cantian/cantian_home ${cantian_home} diff --git a/pkg/deploy/action/cantian_common/env_lun.sh b/pkg/deploy/action/cantian_common/env_lun.sh index 881f678a..1994b8bf 100644 --- a/pkg/deploy/action/cantian_common/env_lun.sh +++ b/pkg/deploy/action/cantian_common/env_lun.sh @@ -10,15 +10,15 @@ cantian_group="cantian" cantian_common_group="cantiangroup" PRE_INSTALL_ORDER=("cantian" "cms" "dss") -INSTALL_ORDER=( "cms" "dss" "cantian" "ct_om" "cantian_exporter" "mysql" "logicrep") -START_ORDER=("cms" "dss" "cantian" "ct_om" "cantian_exporter" "logicrep") -STOP_ORDER=("logicrep" "cms" "dss" "cantian" "ct_om" "cantian_exporter") -UNINSTALL_ORDER=("ct_om" "cantian" "dss" "cms" "logicrep") +INSTALL_ORDER=( "cms" "dss" "cantian" "ct_om" "cantian_exporter" "mysql") +START_ORDER=("cms" "dss" "cantian" "ct_om" "cantian_exporter") +STOP_ORDER=("cms" "dss" "cantian" "ct_om" "cantian_exporter") +UNINSTALL_ORDER=("ct_om" "cantian" "dss" "cms") BACKUP_ORDER=("cantian" "dss" "cms" "ct_om") CHECK_STATUS=("cantian" "cms" "dss" "ct_om" "cantian_exporter") -PRE_UPGRADE_ORDER=("ct_om" "cantian_exporter""cms" "cantian" "mysql" "logicrep") -UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql" "logicrep") -POST_UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "dss" "cantian" "mysql") -ROLLBACK_ORDER=("cms" "cantian" "mysql" "ct_om" "cantian_exporter" "logicrep") +PRE_UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql") +UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql") +POST_UPGRADE_ORDER=("ct_om" "cantian_exporter" "cms" "cantian" "mysql") +ROLLBACK_ORDER=("cms" "cantian" "mysql" "ct_om" "cantian_exporter") INIT_CONTAINER_ORDER=("cms" "cantian" "logicrep") DIR_LIST=(/opt/cantian/cms /opt/cantian/cantian /opt/cantian/dbstor /opt/cantian/mysql ${CURRENT_FILE_PATH}/inspection/inspection_scripts/kernal ${CURRENT_FILE_PATH}/inspection/inspection_scripts/cms ${CURRENT_FILE_PATH}/inspection/inspection_scripts/ct_om) \ No newline at end of file diff --git a/pkg/deploy/action/cms/appctl.sh b/pkg/deploy/action/cms/appctl.sh index c7680264..986f56e8 100644 --- a/pkg/deploy/action/cms/appctl.sh +++ b/pkg/deploy/action/cms/appctl.sh @@ -300,7 +300,7 @@ function pre_upgrade() return 1 fi - if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" ]]; then + if [[ x"${deploy_mode}" == x"file" ]]; then echo "check gcc home: /mnt/dbdata/remote/share_${storage_share_fs}" if [ ! -d /mnt/dbdata/remote/share_${storage_share_fs}/gcc_home ];then echo "Error: gcc home does not exist!" @@ -345,7 +345,7 @@ function post_upgrade() fi ls -l ${cms_scripts} - if [[ x"${deploy_mode}" != x"dbstor" && x"${deploy_mode}" != x"combined" ]]; then + if [[ x"${deploy_mode}" == x"file" ]]; then echo "check gcc home: /mnt/dbdata/remote/share_${storage_share_fs}" if [ ! -d /mnt/dbdata/remote/share_${storage_share_fs}/gcc_home ];then echo "Error: gcc home does not exist!" @@ -445,7 +445,7 @@ function update_cms_service() { ${cms_pkg_file}/cfg ${cms_pkg_file}/lib ${cms_pkg_file}/package.xml ${cantian_home}/server deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") - if [[ x"${deploy_mode}" == x"file" ]]; then + if [[ x"${deploy_mode}" == x"file" ]] || [[ ${deploy_mode} == "dss" ]]; then return 0 fi @@ -482,6 +482,10 @@ function chown_mod_cms_service() find ${cantian_home}/server/lib -type f | xargs chmod 500 find ${cantian_home}/server/cfg -type f | xargs chmod 400 + if [[ x"${deploy_mode}" == x"dss" ]]; then + sudo setcap CAP_SYS_RAWIO+ep "${cms_home}"/service/bin/cms + fi + chmod 400 ${cms_home}/service/package.xml chmod 400 ${cantian_home}/server/package.xml return 0 diff --git a/pkg/deploy/action/docker/dbstor_tool_opt_common.sh b/pkg/deploy/action/docker/dbstor_tool_opt_common.sh index dcc5bf3e..3e82c25a 100644 --- a/pkg/deploy/action/docker/dbstor_tool_opt_common.sh +++ b/pkg/deploy/action/docker/dbstor_tool_opt_common.sh @@ -149,7 +149,16 @@ function create_file_in_filesystem() { } function update_local_status_file_path_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + if [[ "${deploy_mode}" == "dss" ]];then + mkdir -p "${METADATA_FS_PATH}"/upgrade/cluster_and_node_status + chown "${cantian_user}":"${cantian_group}" "${METADATA_FS_PATH}"/upgrade + chown "${cantian_user}":"${cantian_group}" "${METADATA_FS_PATH}"/upgrade/cluster_and_node_status + su -s /bin/bash - "${cantian_user}" -c "python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_local_status_file.py"" + result_local=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to local failed." + exit 0 + fi return 0 fi chown "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH} @@ -202,12 +211,19 @@ function update_local_status_file_path_by_dbstor() { } function update_remote_status_file_path_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + cluster_or_node_status_file_path=$1 + if [[ "${deploy_mode}" == "dss" ]];then + chown -hR "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH}/upgrade + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_remote_status_file.py ${cluster_or_node_status_file_path}" + result_remote=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to remote failed." + exit 0 + fi return 0 fi get_dbs_version dbs_vs=$? - cluster_or_node_status_file_path=$1 chown -hR "${cantian_user}":"${cantian_group}" ${METADATA_FS_PATH}/upgrade if [[ -d ${cluster_or_node_status_file_path} ]];then relative_path=$(realpath --relative-to="${METADATA_FS_PATH}"/upgrade "${dir_path}") @@ -239,10 +255,16 @@ function update_remote_status_file_path_by_dbstor() { } function delete_fs_upgrade_file_or_path_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + local file_name=$1 + if [[ "${deploy_mode}" == "dss" ]];then + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_delete.py ${file_name}" + result_yml=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to delete failed." + exit 1 + fi return 0 fi - local file_name=$1 logAndEchoInfo "Start to delete ${file_name} in file path ${file_path}" declare -a upgrade_dirs # shellcheck disable=SC2207 @@ -261,7 +283,14 @@ function delete_fs_upgrade_file_or_path_by_dbstor() { } function update_version_yml_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + if [[ "${deploy_mode}" == "dss" ]];then + chown "${cantian_user}":"${cantian_group}" "${PKG_PATH}/${VERSION_FILE}" + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_yaml.py ${PKG_PATH}/${VERSION_FILE}" + result_yml=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to yml failed." + exit 1 + fi return 0 fi chown "${cantian_user}":"${cantian_group}" "${PKG_PATH}/${VERSION_FILE}" @@ -276,10 +305,17 @@ function update_version_yml_by_dbstor() { } function upgrade_lock_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + node_lock_file=${lock_file_prefix}${node_id} + if [[ "${deploy_mode}" == "dss" ]];then + touch /mnt/dbdata/remote/metadata_/upgrade/${node_lock_file} + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_lock.py ${node_lock_file}" + result_lock=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to lock failed." + exit 1 + fi return 0 fi - node_lock_file=${lock_file_prefix}${node_id} get_dbs_version dbs_vs=$? upgrade_nodes=$(query_filesystem ${dbs_vs} ${storage_share_fs} "/upgrade" | grep -E "${lock_file_prefix}" | wc -l) @@ -305,12 +341,19 @@ function upgrade_lock_by_dbstor() { } function upgrade_unlock_by_dbstor() { - if [[ "${deploy_mode}" != "dbstor" ]];then + node_lock_file=${lock_file_prefix}${node_id} + if [[ "${deploy_mode}" == "dss" ]];then + su -s /bin/bash - "${cantian_user}" -c "python3 -B "${CURRENT_PATH}/dss/common/dss_upgrade_unlock.py" ${node_lock_file}" + result_unlock=$? + if [[ $? -ne 0 ]];then + logAndEchoError "file to rempte failed." + exit 1 + fi return 0 fi get_dbs_version dbs_vs=$? - node_lock_file=${lock_file_prefix}${node_id} + lock_file=$(query_filesystem ${dbs_vs} ${storage_share_fs} "upgrade" | grep "${node_lock_file}" | wc -l) if [[ ${lock_file} -eq 0 ]];then diff --git a/pkg/deploy/action/dss/appctl.sh b/pkg/deploy/action/dss/appctl.sh index 98c5e062..ca6b7560 100644 --- a/pkg/deploy/action/dss/appctl.sh +++ b/pkg/deploy/action/dss/appctl.sh @@ -63,7 +63,7 @@ function do_deploy() function permission_opt() { chmod 500 "${DSS_SOURCE}"/bin/* chown -hR "${cantian_user}":"${cantian_group}" "${DSS_SOURCE}" - chown "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* + chown -hR "${cantian_user}":"${cantian_group}" "${CURRENT_PATH}"/* chown root:root "${CURRENT_PATH}"/appctl.sh mkdir -p /opt/cantian/log/dss touch /opt/cantian/log/dss/dss_deploy.log diff --git a/pkg/deploy/action/dss/common/dss_upgrade_commit.py b/pkg/deploy/action/dss/common/dss_upgrade_commit.py new file mode 100644 index 00000000..26f1fa2a --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_commit.py @@ -0,0 +1,81 @@ +import os +import sys +from file_utils import read_dss_file +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssUpgradeCommit(object): + def __init__(self): + self.node_status_num = 0 + self.node_ip_num = 0 + + def file_exits(self): + ''' + 检查cluster_and_node_status下是否有文件存在 + ''' + cmd = "dsscmd ls -p +vg1/upgrade/cluster_and_node_status" + code, stdout, stderr = _exec_popen(cmd) + + if code != 0: + raise Exception(f"dsscmd ls commit failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + LOG.error(f"cluster_and_node_status file is not complete") + sys.exit(1) + + for line in lines: + if "status.txt" in line and "cluster" not in line: + self.node_status_num += 1 + + def check_nodes(self, cms_status="127.0.0.0"): + ''' + 检查节点状态文件和cms的ip数量是否相同 + ''' + self.node_ip_num = len(cms_status.split(";")) + if self.node_ip_num != self.node_status_num: + LOG.error(f"txt num is {self.node_status_num}, ip num is {self.node_ip_num}") + if self.node_ip_num < self.node_status_num: + LOG.error(f"the txt in cluster_and_node_status is not enough") + sys.exit(1) + sys.exit(1) + + def check_status_file(self): + ''' + 检查节点状态文件内容 + ''' + context = [] + for i in range(self.node_ip_num): + node_status_file = os.path.join("+vg1/upgrade/cluster_and_node_status", f"node{i}_status.txt") + context.append(read_dss_file(node_status_file)) + for rollup_result in context: + if rollup_result != "rollup_success": + LOG.error(f"rollup result is error {rollup_result}") + sys.exit(1) + + def upgrade_commit(self, input_status=None): + self.file_exits() + self.check_nodes(input_status) + self.check_status_file() + + +def main(): + dss_commit = DssUpgradeCommit() + if len(sys.argv) < 1: + raise Exception("remote not input") + input_status = sys.argv[1] + try: + dss_commit.upgrade_commit(input_status) + except Exception as e: + LOG.error(f"cluster file check error") + sys.exit(1) + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_detele.py b/pkg/deploy/action/dss/common/dss_upgrade_detele.py new file mode 100644 index 00000000..3516b18d --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_detele.py @@ -0,0 +1,91 @@ +import os +import sys +from get_config_info import get_value +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssDetele(object): + def __init__(self): + self.node_id = None + self.node_lock_file_name = None + self.node_lock_file_path = None + self.cantian_user = None + self.vg_lock_file_path = None + + def file_exits(self, input_file=None): + cmd = f'dsscmd ls -p +vg1/upgrade' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + return True + + lines = stdout.strip().splitlines() + + for line in lines: + if input_file in line: + return True + return False + + def delete_file(self, input_file=None): + cmd = f'dsscmd rm -p +vg1/{input_file}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rm delete` failed: {stderr}") + + def delete_special_file(self, file_name, vg_path_name): + cmd = f'dsscmd ls -p {vg_path_name}' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + return + + lines = stdout.strip().splitlines() + + for line in lines: + if file_name in line[5]: + self.delete_file(line[5]) + + def delete_dir(self, input_file=None): + cmd = f'dsscmd rmdir -p +vg1/upgrade/{input_file} -r' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rmdir delete` failed: {stderr}") + + def upgrade_detele_by_dss(self, input_file=None): + if "updatesys" in input_file: + self.delete_special_file("updatesys", "+vg1/upgrade") + elif input_file == "cluster_and_node_status": + self.delete_dir("cluster_and_node_status") + elif "cluster_and_node_status/node" in input_file: + self.delete_special_file("node", "+vg1/upgrade/cluster_and_node_status") + elif "upgrade_node" in input_file: + self.delete_special_file("upgrade_node", "+vg1/upgrade") + else: + if not self.file_exits(input_file): + return + self.delete_file(input_file) + + +def main(): + dss_delete = DssDetele() + if len(sys.argv) < 1: + raise Exception("Failed to delete dss when upgrade input") + input_file = sys.argv[1] + try: + dss_delete.upgrade_detele_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to delete dss file when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py b/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py new file mode 100644 index 00000000..4f7cdf0a --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_local_status_file.py @@ -0,0 +1,53 @@ +import os +import sys +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssLocalStatusfile(object): + def dir_exists(self, exists_path, exists_dir): + cmd = f"dsscmd ls -p {exists_path}" + code, stdout, stderr = _exec_popen(cmd) + + if code != 0: + raise Exception(f"dsscmd ls local failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + return False + + for line in lines: + if exists_dir in line: + return True + + def mkdir_local_status_file_to_path(self, mkdir_path, mkdir_dir): + if self.dir_exists(mkdir_path, mkdir_dir): + return + cmd = f"dsscmd mkdir -p {mkdir_path} -d {mkdir_dir}" + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise Exception(f"dsscmd mkdir local failed: {stderr}") + + def upgrade_local_status_file_by_dss(self): + self.mkdir_local_status_file_to_path("+vg1", "upgrade") + self.mkdir_local_status_file_to_path("+vg1/upgrade", "cluster_and_node_status") + + +def main(): + dss_local_status = DssLocalStatusfile() + try: + dss_local_status.upgrade_local_status_file_by_dss() + except Exception as e: + LOG.error(f"Failed with local file when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_lock.py b/pkg/deploy/action/dss/common/dss_upgrade_lock.py new file mode 100644 index 00000000..fc3a1161 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_lock.py @@ -0,0 +1,86 @@ +import os +import sys +from file_utils import pad_file_to_512 +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssLock(object): + def __init__(self): + self.node_lock_file_name = None + self.node_lock_file_path = None + self.vg_lock_file_path = None + self.lock_res = None + + def create_vg_upgrade_path(self): + + cmd = f'dsscmd mkdir -p +vg1 -d upgrade' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"dsscmd mkdir lock failed: {stderr}") + + def cp_node_lock_file_to_path(self): + + cmd = f'dsscmd cp -s {self.node_lock_file_path} -d {self.vg_lock_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"dsscmd cp lock failed: {stderr}") + + def is_locked_new(self): + cmd = f'dsscmd ls -p +vg1/upgrade' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + self.lock_res = "upgrade no exists" + return + + lines = stdout.strip().splitlines() + if len(lines) < 2: + self.lock_res = "upgrade is empty" + return + + for line in lines: + if self.node_lock_file_name in line: + self.lock_res = "node lock is existing" + return + if "upgrade_lock_" in line[5]: + raise RuntimeError(f"other lock is using, {line[5]}") + self.lock_res = "upgrade not lock" + + def upgrade_lock_by_dss(self, input_file=None): + self.node_lock_file_name = os.path.basename(input_file) + self.node_lock_file_path = os.path.join("/mnt/dbdata/remote/metadata_/upgrade", self.node_lock_file_name) + self.vg_lock_file_path = os.path.join("+vg1/upgrade", self.node_lock_file_name) + + self.is_locked_new() + if self.lock_res == "upgrade no exists": + self.create_vg_upgrade_path() + elif self.lock_res == "node lock is existing": + return + pad_file_to_512(self.node_lock_file_path) + self.cp_node_lock_file_to_path() + LOG.info(f"{self.node_lock_file_name} success") + + +def main(): + dss_lock = DssLock() + if len(sys.argv) < 1: + raise Exception("upgrade lock no input") + input_file = sys.argv[1] + try: + dss_lock.upgrade_lock_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to lock dss when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py b/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py new file mode 100644 index 00000000..5821e488 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_remote_status_file.py @@ -0,0 +1,90 @@ +import os +import sys +from get_config_info import get_value +from file_utils import pad_file_to_512 +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssRemoteStatusfile(object): + def __init__(self): + self.node_remote_status_file_name = None + self.node_remote_status_file_path = None + self.vg_remote_file_path = None + + def file_exits(self, vg_path): + cmd = f'dsscmd ls -p {vg_path}' + code, _, _ = _exec_popen(cmd) + + if code == 0: + return True + return False + + def detele_file(self, vg_path): + cmd = f'dsscmd rm -p {vg_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd rm remote` failed: {stderr}") + sys.exit(1) + + def cp_remote_status_file_to_path(self): + + if self.file_exits(self.vg_remote_file_path): + self.detele_file(self.vg_remote_file_path) + cmd = f'dsscmd cp -s {self.node_remote_status_file_path} -d {self.vg_remote_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd cp remote` failed: {stderr}") + sys.exit(1) + + def mkdir_vg_path(self): + if self.file_exits("+vg1/upgrade/cluster_and_node_status"): + return + cmd = f'dsscmd mkdir -p +vg1/upgrade -d cluster_and_node_status' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd mkdir remote` failed: {stderr}") + sys.exit(1) + + def upgrade_remote_status_file_by_dss(self, remote_status_file): + if "cluster_and_node_status" in remote_status_file: + self.node_remote_status_file_name = os.path.basename(remote_status_file) + self.node_remote_status_file_path = remote_status_file + self.vg_remote_file_path = os.path.join("+vg1/upgrade/cluster_and_node_status", + self.node_remote_status_file_name) + self.mkdir_vg_path() + pad_file_to_512(self.node_remote_status_file_path) + self.cp_remote_status_file_to_path() + else: + self.node_remote_status_file_name = os.path.basename(remote_status_file) + self.node_remote_status_file_path = remote_status_file + self.vg_remote_file_path = os.path.join("+vg1/upgrade", self.node_remote_status_file_name) + + pad_file_to_512(self.node_remote_status_file_path) + self.cp_remote_status_file_to_path() + return + + +def main(): + dss_remote_status = DssRemoteStatusfile() + if len(sys.argv) < 1: + raise Exception("remote not input") + input_file = sys.argv[1] + try: + dss_remote_status.upgrade_remote_status_file_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to input file when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_unlock.py b/pkg/deploy/action/dss/common/dss_upgrade_unlock.py new file mode 100644 index 00000000..34fb0c48 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_unlock.py @@ -0,0 +1,63 @@ +import os +import sys +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssUnLock(object): + def __init__(self): + self.node_lock_file_name = None + self.vg_lock_file_path = None + + def is_locked(self): + cmd = f'dsscmd ls -p +vg1/upgrade' + code, stdout, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd ls unlock` failed: {stderr}") + + lines = stdout.strip().splitlines() + if len(lines) < 2: + LOG.error(f"no file with lock") + sys.exit(1) + + for line in lines: + if self.node_lock_file_name in line: + return True + return False + + def unlock_node(self): + cmd = f'dsscmd rm -p {self.vg_lock_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd rm unlock` failed: {stderr}") + + def upgrade_unlock_by_dss(self, input_file=None): + self.node_lock_file_name = os.path.basename(input_file) + self.vg_lock_file_path = os.path.join("+vg1/upgrade", self.node_lock_file_name) + if self.is_locked(): + self.unlock_node() + return + + +def main(): + dss_unlock = DssUnLock() + if len(sys.argv) < 1: + raise Exception("Failed to unlock dss when upgrade input") + input_file = sys.argv[1] + try: + dss_unlock.upgrade_unlock_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to unlock dss when upgrade") + sys.exit(1) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/common/dss_upgrade_yaml.py b/pkg/deploy/action/dss/common/dss_upgrade_yaml.py new file mode 100644 index 00000000..d9c23034 --- /dev/null +++ b/pkg/deploy/action/dss/common/dss_upgrade_yaml.py @@ -0,0 +1,69 @@ +import os +import sys +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(CURRENT_PATH, "..", "..")) +from update_config import _exec_popen +sys.path.append(os.path.join(CURRENT_PATH, "..")) +from dssctl import LOG + + +class DssYaml(object): + def __init__(self): + self.node_yaml_file_name = None + self.node_yaml_file_path = None + self.vg_yaml_file_path = None + + def detele_file(self, vg_path): + cmd = f'dsscmd rm -p {vg_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + LOG.error(f"`dsscmd rm yaml` failed: {stderr}") + sys.exit(1) + + def file_exits(self): + cmd = f'dsscmd ls -p +vg1' + code, stdout, _ = _exec_popen(cmd) + + if code != 0: + return + + lines = stdout.strip().splitlines() + + for line in lines: + if self.node_yaml_file_name in line: + self.detele_file(self.vg_yaml_file_path) + break + + def cp_yaml_file_to_path(self): + + cmd = f'dsscmd cp -s {self.node_yaml_file_path} -d {self.vg_yaml_file_path}' + code, _, stderr = _exec_popen(cmd) + + if code != 0: + raise RuntimeError(f"`dsscmd cp yaml` failed: {stderr}") + + def upgrade_yaml_by_dss(self, input_file=None): + self.node_yaml_file_name = os.path.basename(input_file) + self.node_yaml_file_path = input_file + self.vg_yaml_file_path = os.path.join("+vg1", self.node_yaml_file_name) + self.cp_yaml_file_to_path() + return + + +def main(): + dss_yaml = DssYaml() + if len(sys.argv) < 1: + raise Exception("Failed to cp yaml when upgrade input") + input_file = sys.argv[1] + try: + dss_yaml.upgrade_yaml_by_dss(input_file) + except Exception as e: + LOG.error(f"Failed to cp yaml when upgrade") + sys.exit(1) + +if __name__ == "__main__": + try: + main() + except Exception as err: + exit(str(err)) \ No newline at end of file diff --git a/pkg/deploy/action/dss/dssctl.py b/pkg/deploy/action/dss/dssctl.py index e414507a..fe8e6d04 100644 --- a/pkg/deploy/action/dss/dssctl.py +++ b/pkg/deploy/action/dss/dssctl.py @@ -198,7 +198,7 @@ class DssCtl(object): LOG.info("start to init lun.") init_cmd = "dd if=/dev/zero of=%s bs=1M count=1 conv=notrunc" for key, value in VG_CONFIG.items(): - return_code, stdout, stderr = exec_popen(init_cmd % value, timeout=TIMEOUT) + return_code, stdout, stderr = exec_popen(init_cmd % value, timeout=120) if return_code: output = stdout + stderr err_msg = "Init lun cmd[%s] exec failed, details: %s" % (init_cmd % value, str(output)) @@ -436,13 +436,17 @@ class DssCtl(object): else: LOG.info("dssserver is offline.") return False + + def upgrade_backup(self, *args) -> None: + LOG.info("Start to upgrade_backup dss.") + LOG.info("Success to upgrade_backup dss.") def main(): parse = argparse.ArgumentParser() parse.add_argument("--action", type=str, choices=["install", "uninstall", "start", "stop", "pre_install", - "upgrade", "rollback", "pre_upgrade"]) + "upgrade", "rollback", "pre_upgrade", "check_status", "upgrade_backup"]) parse.add_argument("--mode", required=False, dest="mode", default="") arg = parse.parse_args() act = arg.action diff --git a/pkg/deploy/action/pre_upgrade.sh b/pkg/deploy/action/pre_upgrade.sh index 0233fc21..bab96de3 100644 --- a/pkg/deploy/action/pre_upgrade.sh +++ b/pkg/deploy/action/pre_upgrade.sh @@ -14,6 +14,11 @@ UPGRADE_MODE_LIS=("offline" "rollup") UPDATESYS_FLAG=/opt/cantian/updatesys.true upgrade_module_correct=false +deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") + +if [[ x"${deploy_mode}" == x"dss" ]]; then + cp -arf ${CURRENT_PATH}/cantian_common/env_lun.sh ${CURRENT_PATH}/env.sh +fi source ${CURRENT_PATH}/log4sh.sh source ${CURRENT_PATH}/env.sh @@ -264,7 +269,6 @@ function gen_upgrade_plan() { } function check_dbstor_client_compatibility() { - deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") if [[ x"${deploy_mode}" == x"file" || "${source_version}" == "2.0.0"* ]]; then return 0 fi @@ -321,7 +325,9 @@ function offline_upgrade() { check_cms_stat check_mem_avail check_upgrade_version - check_dbstor_client_compatibility + if [[ x"${deploy_mode}" == x"dbstor" ]]; then + check_dbstor_client_compatibility + fi call_each_pre_upgrade gen_upgrade_plan } @@ -332,7 +338,9 @@ function rollup_upgrade() { local_node_health_check cantian_database_health_status_check component_version_dependency_check - check_dbstor_client_compatibility + if [[ x"${deploy_mode}" == x"dbstor" ]]; then + check_dbstor_client_compatibility + fi call_each_pre_upgrade gen_upgrade_plan } diff --git a/pkg/deploy/action/rollback.sh b/pkg/deploy/action/rollback.sh index a7a69b7d..276ecc01 100644 --- a/pkg/deploy/action/rollback.sh +++ b/pkg/deploy/action/rollback.sh @@ -835,6 +835,9 @@ function main() { get_current_node modify_env source ${CURRENT_PATH}/docker/dbstor_tool_opt_common.sh + if [[ x"${deploy_mode}" == x"dss" ]]; then + cp -arf ${CURRENT_PATH}/cantian_common/env_lun.sh ${CURRENT_PATH}/env.sh + fi source ${CURRENT_PATH}/env.sh user=${cantian_user} diff --git a/pkg/deploy/action/upgrade.sh b/pkg/deploy/action/upgrade.sh index a4507cc2..03a5a7e2 100644 --- a/pkg/deploy/action/upgrade.sh +++ b/pkg/deploy/action/upgrade.sh @@ -50,12 +50,16 @@ if [[ x"${deploy_mode}" == x"file" ]];then fi fi +if [[ x"${deploy_mode}" == x"dss" ]]; then + cp -arf ${CURRENT_PATH}/cantian_common/env_lun.sh ${CURRENT_PATH}/env.sh +fi + source ${CURRENT_PATH}/docker/dbstor_tool_opt_common.sh source ${CURRENT_PATH}/env.sh function rpm_check(){ local count=2 - if [ x"${deploy_mode}" != x"file" ];then + if [ x"${deploy_mode}" != x"file" ] && [ x"${deploy_mode}" != x"dss" ];then count=3 fi rpm_pkg_count=$(ls "${CURRENT_PATH}"/../repo | wc -l) @@ -79,7 +83,7 @@ function input_params_check() { fi # 离线升级需要检查阵列侧ip - if [ "${UPGRADE_MODE}" == "offline" ]; then + if [[ "${UPGRADE_MODE}" == "offline" ]]; then if [ -z "${DORADO_IP}" ]; then logAndEchoError "storage array ip must be provided" exit 1 @@ -403,7 +407,7 @@ function install_rpm() rpm -ivh --replacepkgs ${RPM_PATH} --nodeps --force tar -zxf ${RPM_UNPACK_PATH_FILE}/Cantian-RUN-CENTOS-64bit.tar.gz -C ${RPM_PACK_ORG_PATH} - if [ x"${deploy_mode}" != x"file" ];then + if [ x"${deploy_mode}" != x"file" ] && [ x"${deploy_mode}" != x"dss" ];then echo "start replace rpm package" install_dbstor if [ $? -ne 0 ];then @@ -873,6 +877,9 @@ function do_rollup_upgrade() { stop_cantian stop_cms + if [[ "${deploy_mode}" == "dss" ]]; then + sh /opt/cantian/action/dss/appctl.sh start + fi # 生成调用ct_backup成功的标记文件,避免重入调用时失败 touch "${storage_metadata_fs_path}/call_ctback_tool.success" && chmod 600 "${storage_metadata_fs_path}/call_ctback_tool.success" @@ -937,11 +944,16 @@ function post_upgrade_nodes_status() { cms_ip=$(python3 ${CURRENT_PATH}/get_config_info.py "cms_ip") node_count=$(expr "$(echo "${cms_ip}" | grep -o ";" | wc -l)" + 1) - cms_res=$(su -s /bin/bash - "${cantian_user}" -c "cms stat") - # step1: 统计节点拉起情况 start_array=() - readarray -t start_array <<< "$(echo "${cms_res}" | awk '{print $3}' | tail -n +$"2")" + if [[ "${deploy_mode}" == "dss" ]]; then + cms_res=$(su -s /bin/bash - "${cantian_user}" -c "cms stat | grep dss") + readarray -t start_array <<< "$(echo "${cms_res}" | awk '{print $3}')" + else + cms_res=$(su -s /bin/bash - "${cantian_user}" -c "cms stat") + readarray -t start_array <<< "$(echo "${cms_res}" | awk '{print $3}' | tail -n +$"2")" + fi + if [ ${#start_array[@]} != "${node_count}" ]; then logAndEchoError "only ${#start_array[@]} nodes were detected, totals:${node_count}" && exit 1 fi @@ -982,7 +994,7 @@ function get_back_version() { function offline_upgrade() { cantian_status_check do_backup - if [[ ${node_id} == '0' ]] && [[ ${deploy_mode} != "file" ]]; then + if [[ ${node_id} == '0' ]] && [[ ${deploy_mode} != "file" ]] && [[ ${deploy_mode} != "dss" ]]; then creat_snapshot fi get_back_version @@ -1069,6 +1081,9 @@ function main() { # 升级成功后更新版本信息 show_cantian_version cp -fp ${CURRENT_PATH}/../versions.yml /opt/cantian + if [[ ${node_id} != '0' ]]; then + rm -rf /mnt/dbdata/remote/metadata_${storage_metadata_fs}/upgrade/upgrade_node* + fi logAndEchoInfo ">>>>> ${UPGRADE_MODE} upgrade performed successfully <<<<<" return 0 } diff --git a/pkg/deploy/action/upgrade_commit.sh b/pkg/deploy/action/upgrade_commit.sh index 17f7e27a..24fb9ddc 100644 --- a/pkg/deploy/action/upgrade_commit.sh +++ b/pkg/deploy/action/upgrade_commit.sh @@ -69,6 +69,17 @@ function init_cluster_status_flag() { function node_status_check() { logAndEchoInfo "begin to check cluster upgrade status" + deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") + if [[ x"${deploy_mode}" == x"dss" ]];then + cms_status_nums=$(python3 ${CURRENT_PATH}/get_config_info.py "cms_ip") + su -s /bin/bash - "${cantian_user}" -c "python3 -B ${CURRENT_PATH}/dss/common/dss_upgrade_commit.py ${cms_status_nums}" + result_python=$? + if [ $result_python -eq 0 ];then + return 3 + else + exit 1 + fi + fi # 统计当前节点数目 node_count=$(expr "$(echo "${cms_ip}" | grep -o ";" | wc -l)" + 1) @@ -263,7 +274,7 @@ function offline_upgrade_commit() { fi raise_version_num deploy_mode=$(python3 ${CURRENT_PATH}/get_config_info.py "deploy_mode") - if [[ x"${deploy_mode}" != x"file" ]];then + if [[ x"${deploy_mode}" != x"file" ]] && [[ x"${deploy_mode}" != x"dss" ]];then read -p "Please input dorado_ip:" dorado_ip echo "dorado_ip is: ${dorado_ip}" ping -c 1 "${dorado_ip}" > /dev/null 2>&1 -- Gitee