コード例 #1
0
ファイル: install_oracle.py プロジェクト: yangleiqing0/ZDBM
 def install_oracle():
     # GetLicense().linux_command(
     #     'cd /opt/zdbm/shell && echo "oracle" > oracle_pwd && sh mdb_env_setting.sh < oracle_pwd')
     # print('设置中间环境关于ORACLE变量配置结束')
     # is_scp_ok = False
     # eventlet.monkey_patch()  # 必须加这条代码
     # while not is_scp_ok:
     #     print('将ORACLE打包文件scp到目标服务器开始')
     #     stdout = errs = True
     #     with eventlet.Timeout(1000, False):  # 设置超时时间为2秒
     #         GetLicense().linux_command(
     #             "ps -ef | grep app11204.tar.gz | grep -v grep | awk '{ print $2}' | xargs kill -9",
     #             ip=ZDBM_PACKAGE_IP, port=ZDBM_PACKAGE_PORT, password=ZDBM_PACKAGE_PWD)
     #         stdout, errs = GetLicense().get_result("sshpass -p %s scp -P %s -o StrictHostKeychecking=no "
     #                                                "/soft/%s root@%s:/u01" % (
     #                                                ROOT_PASSWORD, SSH_PORT, OR11204_PACKAGE, IP),
     #                                                ip=ZDBM_PACKAGE_IP, port=ZDBM_PACKAGE_PORT,
     #                                                password=ZDBM_PACKAGE_PWD)
     #     if not stdout:
     #         is_scp_ok = True
     #     else:
     #         print('将ORACLE打包文件scp到目标服务器超时')
     # print('将ORACLE打包文件scp到目标服务器结束')
     # GetLicense().linux_command(
     #     'cd /u01 && rm -rf app && tar -xf %s && chown -R oracle:oinstall app && cp /u01/app/oratab '
     #     '/u01/app/oraInst.loc /etc && chown -R oracle:oinstall /etc/oraInst.loc' % OR11204_PACKAGE)
     # print('解压%s结束' % OR11204_PACKAGE)
     GetLicense().linux_command(
         'export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_11.2.0.4 &&'
         'export PATH=$ORACLE_HOME/bin:$PATH:/usr/sbin && export PATH='
         '/u01/app/oracle/product/11.2.0.4/dbhome_11.2.0.4/bin:/usr/local/bin:/usr/bin &&'
         'lsnrctl start',
         username=ORACLE_USER,
         password=ORACLE_PWD)
     print('设置ORACLE变量启动监听结束')
コード例 #2
0
ファイル: Vdb_test.py プロジェクト: yangleiqing0/ZDBM
    def test_v2p(self):
        # 通过vdb全量恢复源库
        # 先创建路径
        com = "cd {path}&&ls | grep {name} | xargs rm -rf && ps -ef | grep pmon_{name} | grep -v grep | awk {c} | xargs kill -9".format(path=MDB1_V2P_PATH, name=self.params['dbName'], c='{print $2}').replace("{", "'{").replace("}", "}'")
        GetLicense().linux_command(com, ip=self.params['MDB_IP'], password=self.params['PWD'])
        GetLicense().linux_command("killall sbt-server", ip=self.params['MDB_IP'], password=self.params['PWD'])
        time.sleep(30)
        # 通过test_recovery_preset_by_vdb方法获得提交的参数
        parameters = self.test_recovery_preset_by_vdb()
        if json.loads(parameters['actualresult'])['data']['canParameters'] is None:
            parameters = json.loads(parameters['actualresult'])['data']['adviseParameters'] + \
                         json.loads(parameters['actualresult'])['data']['cannotParameters']
        else:
            parameters = json.loads(parameters['actualresult'])['data']['adviseParameters'] + \
                         json.loads(parameters['actualresult'])['data']['cannotParameters'] + \
                         json.loads(parameters['actualresult'])['data']['canParameters']
        print('parameters:', parameters)
        data = '{"vdbID":%s,"targetSoftwareID":%s,"targetDir":"%s","parameters":%s}' % \
               (NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_id'], NEED_PARAMETER[self.params['envName']+'_softwares_id'],MDB1_V2P_PATH,str(parameters).replace('\'', '\"'))
        print('data:', data)
        content = RequestMethod().to_requests(self.request_method, 'recovery/full/by/vdb', data=data)
        job_status_sql = 'select job_status from zdbm_jobs where vdb_name="%s" and job_type="RECOVERY_V2P" and deleted_at is null order by id desc' % \
                         NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name']
        time.sleep(2)
        times = 5 * 60  # 5分钟
        while 1:
            job_status = ConnMysql().select_mysql(job_status_sql)[0]
            print("V2P恢复状态: ", job_status, '时间过去:', 300 - times, '秒')
            times -= 2
            if job_status == 'FAILURE':
                content = 'V2P恢复失败'
                break
            if times == 0:
                content = "5分钟内V2P未恢复成功"
                break
            elif job_status == 'SUCCESS':
                break
            else:
                time.sleep(2)
                continue
        GetLicense().linux_command("killall sbt-server", ip=self.params['MDB_IP'], password=self.params['PWD'])
        GetLicense().linux_command("lsof | grep datafile | awk '{ print $2}' | xargs kill -9", ip=self.params['MDB_IP'], password=self.params['PWD'])

        return {
            'actualresult': content
        }
コード例 #3
0
    def get_jenkins(self):
        # 先清除192.168.12.50服务器上的镜像和容器
        GetLicense().linux_command(
            'docker stop myjenkins && docker rm myjenkins && docker rmi myjenkins:v3 && rm -rf myjenkins.tar'
        )

        GetLicense().linux_command(
            'sshpass -p %s scp -o StrictHostKeychecking=no '
            '/soft/%s root@%s:/opt && echo "scp OK"' %
            (ROOT_PASSWORD, MY_JENKINS_NAME, IP),
            ip=ZDBM_PACKAGE_IP,
            port=ZDBM_PACKAGE_PORT,
            password=ZDBM_PACKAGE_PWD)
        GetLicense().linux_command(
            'cd /opt && docker load -i %s && '
            'docker run -d -it -p 8082:8080 -p 50000:50000 -u root  --name myjenkins '
            'myjenkins:v3 /start.sh && '
            'echo "start OK"' % MY_JENKINS_NAME)
コード例 #4
0
    def env_lsnrctl(self):
        # 环境的监听启动状态
        Ce().login()
        lsnrctl_status_com = '%s && lsnrctl %s' % (
            ORACLE_HOME_COMMAND, self.params['lsnrctl_status'])
        GetLicense().linux_command(com=lsnrctl_status_com,
                                   ip=self.params['ip'],
                                   username=ORACLE_USER,
                                   password=ORACLE_PWD)

        content = EnvTest(params=self.params).test_env_test()['actualresult']
        return {'actualresult': content}
コード例 #5
0
 def source_force(self):
     # 开启关闭强制归档状态
     forcelog_oracle = 'echo "alter database %s force logging;\n exit" > /home/oracle/forcelogtest.sql &&' \
                    'source /home/oracle/.bash_profile && export ORACLE_SID=%s' \
                    '&&sqlplus / as sysdba @/home/oracle/forcelogtest.sql ' % (
                    self.params['forcelogmode'], self.params['dbName'])
     GetLicense().linux_command(com=forcelog_oracle,
                                ip=self.params['ORACLE_IP'],
                                username=ORACLE_USER,
                                password=ORACLE_PWD)
     content = self.test_source()
     return {'actualresult': content}
コード例 #6
0
ファイル: initialize.py プロジェクト: yangleiqing0/ZDBM
    def reset_mysql():
        # 将docker-compose文件的mysql的端口设置为3306映射容器内的3306,然后重新加载通过docker-compose文件更新mysql
        GetLicense().linux_command(
            'cd /opt/zdbm/config && sed -i "51c     ports:"   docker-compose.yaml &&  sed -i "51s/^/    &/" docker-compose.yaml &&'
            'sed -i "52c        - 3306:3306"   docker-compose.yaml &&  sed -i "52s/^/    &/" docker-compose.yaml &&'
            '/usr/local/bin/docker-compose -f /opt/zdbm/config/docker-compose.yaml up -d && docker restart zdbm'
        )
        print('将zdbm的mysql端口暴露')

        sql = 'insert into zdbm_users values(999,"2019-05-17 09:15:37","2019-05-17 09:15:37",NULL,"yanglei",' \
              '"$2a$10$j0c7si1lQucFAUXIGysyWel4GB0RpEy3maVz2bW.7u5zuhy5JfaaS",NULL,"*****@*****.**",NULL,1,0) '
        ConnMysql().operate_mysql(sql)
        print('预设置用户yanglei')
コード例 #7
0
    def source_archive(self):
        # 源库开启关闭归档
        shutdwn_oracle = 'echo "shutdown immediate\n exit" > /home/oracle/shutdowntest.sql &&source /home/oracle/.bash_' \
                         'profile && export ORACLE_SID=%s' \
                      '&&sqlplus / as sysdba @/home/oracle/shutdowntest.sql ' % self.params['dbName']
        GetLicense().linux_command(com=shutdwn_oracle,
                                   ip=self.params['ORACLE_IP'],
                                   username=ORACLE_USER,
                                   password=ORACLE_PWD)

        startup_oracle = 'echo "startup mount\n exit" > /home/oracle/startuptest.sql &&' \
                         'source /home/oracle/.bash_profile && export ORACLE_SID=%s' \
                         '&&sqlplus / as sysdba @/home/oracle/startuptest.sql ' % self.params['dbName']
        GetLicense().linux_command(com=startup_oracle,
                                   ip=self.params['ORACLE_IP'],
                                   username=ORACLE_USER,
                                   password=ORACLE_PWD)

        alter_oracle = 'echo "alter database %s;\n exit" > /home/oracle/alteroracletest.sql &&' \
                         'source /home/oracle/.bash_profile && export ORACLE_SID=%s' \
                         '&&sqlplus / as sysdba @/home/oracle/alteroracletest.sql ' % (self.params['archivemode'],self.params['dbName'])
        GetLicense().linux_command(com=alter_oracle,
                                   ip=self.params['ORACLE_IP'],
                                   username=ORACLE_USER,
                                   password=ORACLE_PWD)
        open_oracle = 'echo "alter database open;\n exit" > /home/oracle/opentest.sql &&' \
                       'source /home/oracle/.bash_profile && export ORACLE_SID=%s' \
                       '&&sqlplus / as sysdba @/home/oracle/opentest.sql ' % self.params['dbName']
        GetLicense().linux_command(com=open_oracle,
                                   ip=self.params['ORACLE_IP'],
                                   username=ORACLE_USER,
                                   password=ORACLE_PWD)
        node, all_online = Ce(IP).listen_nodes_online()
        content = self.test_source()
        if all_online is False:
            content = " {} 节点 一直不在线".format(node)
        return {'actualresult': content}
コード例 #8
0
 def test_increment_check(self):
     db_name = self.params["dbName"]
     select_source_id_sql = "select id from zdbm_orcl_source_dbs where deleted_at is null and db_name='{}'".format(
         db_name)
     source_id = ConnMysql().select_mysql_new(select_source_id_sql)
     sql = "alter system archive log current"
     GetLicense().linux_oracle(sql, db_name, self.params["ip"])
     print(source_id, db_name)
     time.sleep(5)
     update_sql = "update zdbm_orcl_source_db_archives a  INNER JOIN (" \
                  "select id from zdbm_orcl_source_db_archives where source_id={} " \
                  "order by next_scn desc limit 1) b on a.id = b.id set a.name='',a.arch_status='BACKUP_ERROR'," \
                  "a.backup_status='SOURCE_LOSE'".format(source_id)
     ConnMysql().operate_mysql(update_sql)
     time.sleep(5)
     content = RequestMethod().to_requests(
         self.request_method, "source/increment/check/{}".format(source_id))
     print(content)
     NEED_PARAMETER["increment_source_id"] = source_id
     return {'actualresult': content}
コード例 #9
0
 def test_license_update_license(self):
     # 更新授权码
     lice = self.params['license']
     if lice == '获取':
         key = LicenseTest({'request_method': 'get'}).test_license_key_zdbm_license_key()['actualresult']
         key = key.split('\n')
         lice = str(GetLicense(key).write_key())[2:-1]
     print("lice:", lice)
     data = '{"license":"%s"}' % lice
     del_sql = 'update zdbm_license_infos set license=" " where id=1'
     ConnMysql().operate_mysql(del_sql)
     old_sql = 'select license from zdbm_license_infos where id=1'
     old_database_value = ConnMysql().select_mysql(old_sql)[0]
     content = RequestMethod().to_requests(self.request_method, 'license/update/license', data=data)
     new_sql = 'select license from zdbm_license_infos where id=1'
     new_database_value = ConnMysql().select_mysql(new_sql)[0]
     print(old_database_value, new_database_value)
     return {
         'actualresult': content, 'old_database_value': 'license:' + old_database_value,
         'new_database_value': 'license:' + new_database_value, 'database_assert_method': False
     }
コード例 #10
0
ファイル: initialize.py プロジェクト: yangleiqing0/ZDBM
    def reset_mysql():
        # 将docker-compose文件的mysql的端口设置为3306映射容器内的3306,然后重新加载通过docker-compose文件更新mysql
        GetLicense().linux_command(
            'cd /opt/zdbm/config && sed -i "51c     ports:"   docker-compose.yaml &&  sed -i "51s/^/    &/" docker-compose.yaml &&'
            'sed -i "52c        - 3306:3306"   docker-compose.yaml &&  sed -i "52s/^/    &/" docker-compose.yaml &&'
            '/usr/local/bin/docker-compose -f /opt/zdbm/config/docker-compose.yaml up -d && docker restart zdbm'
        )
        print('将zdbm的mysql端口暴露')

        sql = 'insert into zdbm_users values(999,"2019-05-17 09:15:37","2019-05-17 09:15:37",NULL,"yanglei",' \
              '"$2a$10$j0c7si1lQucFAUXIGysyWel4GB0RpEy3maVz2bW.7u5zuhy5JfaaS",NULL,"*****@*****.**",NULL,1,0) '
        ConnMysql().operate_mysql(sql)
        print('预设置用户yanglei')


if __name__ == '__main__':
    # Initialize().reset_mysql()
    GetLicense().linux_command(
        'cd /opt/zdbm/config && sed -i "51c     ports:"   docker-compose.yaml &&  sed -i "51s/^/    &/" docker-compose.yaml &&'
        'sed -i "52c        - 3306:3306"   docker-compose.yaml &&  sed -i "52s/^/    &/" docker-compose.yaml &&'
        '/usr/local/bin/docker-compose -f /opt/zdbm/config/docker-compose.yaml up -d && docker restart zdbm',
        ip='192.168.12.50',
        username='******',
        password='******',
        port='22')
    print('将zdbm的mysql端口暴露')
    # sql = 'insert into zdbm_users values(2,"2019-05-17 09:15:37","2019-05-17 09:15:37",NULL,"yanglei",' \
    #       '"$2a$10$j0c7si1lQucFAUXIGysyWel4GB0RpEy3maVz2bW.7u5zuhy5JfaaS",NULL,"*****@*****.**",NULL,1,0) '
    # ConnMysql().operate_mysql(sql)
    # print('预设置用户yanglei')
コード例 #11
0
ファイル: Auto_install.py プロジェクト: yangleiqing0/ZDBM
    def reset_vi(self):
        # 将/etc/ssh/ssh_config设置为不校验key
        is_centos = True
        version = GetLicense().linux_command_return(
            "hostnamectl | grep 'Kernel: Linux 3.10.0-957.el7.x86_64'")

        if version is None:
            print("当前版本是rhel7.6")
            is_centos = False
        else:
            print("当前版本是centos7.6")
        # time.sleep(50)
        GetLicense().linux_command(
            'sed -i "35c StrictHostKeyChecking no"   /etc/ssh/ssh_config &&  sed -i "35s/^/    &/"    '
            '/etc/ssh/ssh_config')
        print('将/etc/ssh/ssh_config设置为不校验key成功')
        GetLicense().linux_command('cd /opt && rm -rf auto_install*.sh %s ' %
                                   ZDBM_PACKAGE_NAME_TAR)
        print('清除/opt下的文件成功')
        time.sleep(1)
        GetLicense().linux_command(
            'sshpass  -p %s scp -P %s -o StrictHostKeychecking=no '
            '%s /soft/%s root@%s:/opt' %
            (ROOT_PASSWORD, SSH_PORT, ZDBM_PACKAGE_NAME, Install_Data, IP),
            ip=ZDBM_PACKAGE_IP,
            port=ZDBM_PACKAGE_PORT,
            password=ZDBM_PACKAGE_PWD)
        print('将安装脚本和安装包放入目标服务器成功')
        time.sleep(15)
        print('开始进行预安装')
        if Install_Data == 'auto_install_1014.sh':
            GetLicense().linux_command(
                'hwclock --hctosys && cd /opt &&sh %s %s %s %s' %
                (Install_Data, ZDBM_PACKAGE_NAME_TAR, IP, ROOT_PASSWORD))
        elif Install_Data == 'auto_install_2140.sh':
            if is_centos:
                GetLicense().linux_command(
                    'hwclock --hctosys && cd /opt &&sh %s %s %s %s %s %s' %
                    (Install_Data, ZDBM_PACKAGE_NAME_TAR, IP, SSH_PORT,
                     ROOT_PASSWORD, CENTOS_PRE_INSTALL_NAME))
            else:
                GetLicense().linux_command(
                    'hwclock --hctosys && cd /opt &&sh %s %s %s %s %s %s' %
                    (Install_Data, ZDBM_PACKAGE_NAME_TAR, IP, SSH_PORT,
                     ROOT_PASSWORD, RHEL_PRE_INSTALL_NAME))
        else:
            GetLicense().linux_command(
                'hwclock --hctosys && cd /opt &&sh %s %s %s %s %s' %
                (Install_Data, ZDBM_PACKAGE_NAME_TAR, IP, SSH_PORT,
                 ROOT_PASSWORD))
        print('预安装ZDBM所需软件结束')
        GetLicense().wait_host_start()
        # GetLicense().linux_command('echo nameserver 192.168.0.1 > /etc/resolv.conf')
        # print("设置DNS为192.168.0.1成功")
        time.sleep(100)
        print('开始进行安装ZDBM')
        if Install_Data == 'auto_install_2140.sh':
            if is_centos:
                GetLicense().linux_command(
                    'cd /opt/zdbm && sh {}'.format(CENTOS_INSTSALL_NAME))
            else:
                GetLicense().linux_command(
                    'cd /opt/zdbm && sh {}'.format(RHEL_INSTALL_NAME))
        else:
            GetLicense().linux_command(
                'cd /opt/zdbm && sh {}'.format(CENTOS_INSTSALL_NAME))
        print('安装ZDBM结束')

        print('开始创建存储池')
        self.add_mpool()
        print('存储池创建结束')
        GetLicense().linux_command('docker restart zdbm')
        GetLicense().linux_command('systemctl restart zdbm_server')
        print('重启zdbm')
        time.sleep(2)
        GetLicense().linux_command('rm -rf /opt/{}'.format(ZDBM_PACKAGE_NAME))
コード例 #12
0
ファイル: Auto_install.py プロジェクト: yangleiqing0/ZDBM
 def add_mpool(self):
     GetLicense().linux_command(
         'zpool  create -f  mpool sdc  &&zpool  create -f  mpool01 sdd sde')