From 6da39e6fea04d55677af209b507aae0326953b6c Mon Sep 17 00:00:00 2001 From: liuheng Date: Thu, 4 Jan 2024 15:49:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=80=E7=AB=99=E5=BC=8F=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=B5=84=E6=BA=90=E6=B1=A0=E5=8C=96=20back=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/base_utils/template/xml_status.py | 21 ++++------ script/base_utils/template/xml_template.py | 46 +++++++++++----------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/script/base_utils/template/xml_status.py b/script/base_utils/template/xml_status.py index 9d4bb75..5075b4d 100644 --- a/script/base_utils/template/xml_status.py +++ b/script/base_utils/template/xml_status.py @@ -202,11 +202,10 @@ class DatabaseInstallStatus(TemplateStatus): if not user_input: XmlConstant.OPENGAUSS_INSTALL_DIR = XmlConstant.DATABASE_INSTALL_DIR return DataPortStatus() - elif not check_database_dir(user_input): + if not check_database_dir(user_input): continue - else: - XmlConstant.OPENGAUSS_INSTALL_DIR = user_input - return DataPortStatus() + XmlConstant.OPENGAUSS_INSTALL_DIR = user_input + return DataPortStatus() class DataPortStatus(TemplateStatus): @@ -219,13 +218,11 @@ class DataPortStatus(TemplateStatus): if user_input.lower() in ('back', 'b'): return DatabaseInstallStatus() if not user_input: - XmlConstant.DATABASE_PORT = XmlConstant.DATABASE_PORT return PriStandbyStatus() if not check_port(user_input): continue - else: - XmlConstant.DATABASE_PORT = user_input - return PriStandbyStatus() + XmlConstant.DATABASE_PORT = user_input + return PriStandbyStatus() class PriStandbyStatus(TemplateStatus): @@ -314,12 +311,10 @@ class DdesDssVgNameStatus(TemplateStatus): sys.exit(0) user_input = input(XmlConstant.RESOURCE_DATA.get('intput_ss_dss_vg_name')).strip() if user_input.lower() in ('back', 'b'): - return DdesStatus() + return DdesDssHomeStatus() if not user_input: XmlConstant.DDES_INFO['ss_dss_vg_name'] = XmlConstant.DSS_VG_NAME_DIR return DdesDssVgInfoStatus() - if not check_database_dir(user_input): - continue XmlConstant.DDES_INFO['ss_dss_vg_name'] = user_input return DdesDssVgInfoStatus() @@ -332,7 +327,7 @@ class DdesDssVgInfoStatus(TemplateStatus): sys.exit(0) user_input = input(XmlConstant.RESOURCE_DATA.get('input_dss_vg_info')).strip() if user_input.lower() in ('back', 'b'): - return DdesDssHomeStatus() + return DdesDssVgNameStatus() if not user_input: XmlConstant.DDES_INFO['dss_vg_info'] = XmlConstant.DSS_VG_INFO_DIR return DdesVotingStatus() @@ -486,7 +481,7 @@ class PriStandbyIpStatus(TemplateStatus): return PriStandbyCountStatus() if not user_input: GaussLog.printMessage(XmlConstant.RESOURCE_DATA.get('ip_hostname_empty')) - return PriStandbyIpStatus() + continue if not get_ip_hostname(user_input): continue GaussLog.printMessage(XmlConstant.RESOURCE_DATA.get('finish')) diff --git a/script/base_utils/template/xml_template.py b/script/base_utils/template/xml_template.py index a17975c..165bab6 100644 --- a/script/base_utils/template/xml_template.py +++ b/script/base_utils/template/xml_template.py @@ -93,19 +93,6 @@ def with_chinese(): XmlConstant.select_option(XmlConstant.RESOURCE_DATA.get('chinese'), XmlConstant.RESOURCE_DATA.get('english')) check_common(check_input_chinese) - -def display_xml_info(): - if not os.path.exists(XmlConstant.TARGET_XML): - raise Exception("new xml file not found!") - GaussLog.printMessage("%s %s" % (XmlConstant.RESOURCE_DATA.get('target_xml_dir'), XmlConstant.TARGET_XML)) - GaussLog.printMessage(XmlConstant.RESOURCE_DATA.get('target_xml_content')) - # use cat - cmd = "cat %s" % XmlConstant.TARGET_XML - (status, output) = subprocess.getstatusoutput(cmd) - if status == 0: - GaussLog.printMessage(output) - - def confirm_xml(): for i in range(XmlConstant.TRIES): if i == 3: @@ -127,6 +114,7 @@ class GenerateTemplate: self.tree = ET.ElementTree() self.root = None self.xml_file_path = "" + self.target_xml = "" def load_xml(self): try: @@ -174,15 +162,15 @@ class GenerateTemplate: def update_database_install_dir(self): for child in self.root[0]: if child.get('name') == "gaussdbAppPath": - child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.DATABASE_INSTALL_DIR, 'app')) + child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.OPENGAUSS_INSTALL_DIR, 'app')) elif child.get('name') == "gaussdbLogPath": - child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.DATABASE_INSTALL_DIR, 'log')) + child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.OPENGAUSS_INSTALL_DIR, 'log')) elif child.get('name') == "tmpMppdbPath": - child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.DATABASE_INSTALL_DIR, 'tmp')) + child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.OPENGAUSS_INSTALL_DIR, 'tmp')) elif child.get('name') == "gaussdbToolPath": - child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.DATABASE_INSTALL_DIR, 'tool')) + child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.OPENGAUSS_INSTALL_DIR, 'tool')) elif child.get('name') == "corePath": - child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.DATABASE_INSTALL_DIR, 'corefile')) + child.attrib['value'] = os.path.normpath(os.path.join(XmlConstant.OPENGAUSS_INSTALL_DIR, 'corefile')) def update_cluster_label_common_info(self): self.update_cluster_label_nodename_info() @@ -195,7 +183,7 @@ class GenerateTemplate: child.attrib['value'] = XmlConstant.DATABASE_PORT def update_node_ip_hostname_info(self): - datanode1 = os.path.normpath(os.path.join(XmlConstant.DATABASE_INSTALL_DIR, "data/dn1")) + datanode1 = os.path.normpath(os.path.join(XmlConstant.OPENGAUSS_INSTALL_DIR, "data/dn1")) if not XmlConstant.IS_PRI_STANDBY: datanode1_value = datanode1 else: @@ -262,9 +250,21 @@ class GenerateTemplate: self.update_cm_info() def generate_new_xml_file(self): - if os.path.exists(XmlConstant.TARGET_XML): - os.remove(XmlConstant.TARGET_XML) - ET.ElementTree(self.root).write(XmlConstant.TARGET_XML) + self.target_xml = XmlConstant.TARGET_XML + if os.path.exists(self.target_xml): + os.remove(self.target_xml) + ET.ElementTree(self.root).write(self.target_xml) + + def display_xml_info(self): + if not os.path.exists(self.target_xml): + raise Exception("new xml file not found!") + GaussLog.printMessage("%s %s" % (XmlConstant.RESOURCE_DATA.get('target_xml_dir'), self.target_xml)) + GaussLog.printMessage(XmlConstant.RESOURCE_DATA.get('target_xml_content')) + # use cat + cmd = "cat %s" % self.target_xml + (status, output) = subprocess.getstatusoutput(cmd) + if status == 0: + GaussLog.printMessage(output) def run(self): # get locale @@ -290,6 +290,6 @@ class GenerateTemplate: # generate a new xml file self.generate_new_xml_file() # display xml info - display_xml_info() + self.display_xml_info() # confirm xml content confirm_xml()