예제 #1
0
 def test_env_get(self):
     # 获取环境详细信息
     env_id_sql = 'select id from zdbm_orcl_envs where '
     content = RequestMethod().to_requests(self.request_method,
                                           'env/get/%s')
     print(content)
     return {'actualresult': content}
예제 #2
0
    def test_user_add(self):
        # 添加用户
        data = """
        {
  "username": "******",
  "password": "******",
  "name": "%s",
  "mail": "%s",
  "phone": "%s",
  "enable": true
}
        """ % (self.params['username'], self.params['password'],
               self.params['name'], self.params['mail'], self.params['phone'])

        ClearEnv().delete_exists_mysql("zdbm_users", "username",
                                       self.params['username'])
        # 如果用户存在就删除此用户信息
        query_sql = 'select name from zdbm_users where username="******";' % self.params[
            'username']
        old_database_value = ConnMysql().select_mysql(query_sql)[0]
        content = RequestMethod().to_requests(self.request_method,
                                              'user/add',
                                              data=data)
        new_database_value = ConnMysql().select_mysql(query_sql)[0]
        print(new_database_value, type(new_database_value),
              'name' + self.params['name'])
        return {
            'actualresult': content,
            'old_database_value': 'name:' + str(old_database_value),
            'new_database_value': 'name:' + str(new_database_value),
            'database_assert_method': False,
            'name': self.params['name']
        }
예제 #3
0
 def test_scan_archive(self):
     select_archive_sql = "select * from zdbm_orcl_source_db_archives order by sequence desc limit 1"
     archive = ConnMysql().select_mysql_new(select_archive_sql, ac_re=True)
     source_id, sequence = archive[4], archive[10]
     print(archive)
     archive = list(archive)
     now = get_now()
     _id = random.randint(10000, 99999)
     archive[0] = _id
     archive[1] = archive[2] = archive[12] = archive[13] = archive[25] = archive[26] = archive[27] = \
         archive[28] = archive[29] = archive[30] = archive[31] = now
     archive[10] += 2
     insert_sql = "insert into zdbm_orcl_source_db_archives values {}".format(
         tuple(archive))
     ConnMysql().operate_mysql(insert_sql)
     select_count_sql = "select count(*) from zdbm_orcl_source_db_archives where source_id={}".format(
         source_id)
     old_value = ConnMysql().select_mysql_new(select_count_sql)
     content = RequestMethod().to_requests(
         self.request_method, "source/archive/scan/{}".format(source_id))
     time.sleep(5)
     print(old_value, content)
     new_value = ConnMysql().select_mysql_new(select_count_sql)
     print(new_value)
     del_sql = "delete from zdbm_orcl_source_db_archives where id in ({},{})".format(
         _id, _id + 1)
     ConnMysql().operate_mysql(del_sql)
     return {
         'actualresult': content,
         'old_database_value': 'mysql_value: {}'.format(old_value),
         'new_database_value': 'mysql_value:{}'.format(new_value),
         'database_assert_method': False
     }
예제 #4
0
    def test_user_update(self):
        # 更新用户信息
        data = """
        {
  "password": "******",
  "name": "%s",
  "mail": "%s",
  "phone": "%s",
  "enable": true
}
        """ % (self.params['password'], self.params['name'],
               self.params['mail'], self.params['phone'])
        query_user_id_sql = 'select id from zdbm_users where username="******";' % self.params[
            'username']
        user_id = ConnMysql().select_mysql(query_user_id_sql)[0]
        query_user_name_sql = 'select name from zdbm_users where username="******";' % self.params[
            'username']
        old_database_value = ConnMysql().select_mysql(query_user_name_sql)[0]
        content = RequestMethod().to_requests(self.request_method,
                                              'user/update/%s' % user_id,
                                              data=data)
        new_database_value = ConnMysql().select_mysql(query_user_name_sql)[0]
        return {
            'actualresult': content,
            'old_database_value': 'name:' + old_database_value,
            'new_database_value': 'name:' + new_database_value,
            'database_assert_method': False,
            'name': self.params['name']
        }
예제 #5
0
 def test_env_test(self):
     # 测试目标主机连通性
     # Ce(IP).login()
     data = """
     {
     "ip":"%s",
     "port":%s,
     "username":"******",
     "password":"******",
     "envName":"%s"
     }
     """ % (self.params['ip'], self.params['port'], self.params['username'],
            self.params['password'], self.params['envName'])
     if 'clusterHome' in self.params:
         data = """
         {"ip":"%s",
         "port":%s,
         "username":"******",
         "password":"******",
         "envName":"%s",
         "clusterHome":"%s"
         }
         """ % (self.params['ip'], self.params['port'],
                self.params['username'], self.params['password'],
                self.params['envName'], self.params['clusterHome'])
     content = RequestMethod().to_requests(self.request_method,
                                           'env/test',
                                           data=data)
     print(content)
     return {'actualresult': content}
예제 #6
0
 def test_cell_update(self):
     # 修改节点信息
     data = """
     {
       "cellName": "%s",
       "description": "%s",
       "ip": "%s",
       "username": "******",
       "password": "******",
       "port": %s
     }
     """ % (self.params['cellName'], self.params['description'],
            self.params['ip'], self.params['username'],
            self.params['password'], self.params['port'])
     query_cell_id = 'select id from zdbm_cells where ip="%s"' % IP
     cell_id = ConnMysql().select_mysql(query_cell_id)[0]
     query_sql = 'select cell_name from zdbm_cells'
     old_database_value = ConnMysql().select_mysql(query_sql)[0]
     content = RequestMethod().to_requests(self.request_method,
                                           'cell/update/%s' % cell_id,
                                           data=data)
     new_database_value = ConnMysql().select_mysql(query_sql)[0]
     return {
         'actualresult': content,
         'old_database_value': 'cell_name:' + old_database_value,
         'new_database_value': 'cell_name:' + new_database_value,
         'database_assert_method': False
     }
예제 #7
0
    def test_cell_add(self):
        # 添加节点
        # 先清理zdbm_cells,zdbm_cell_services,zdbm_cell_network_cards表
        ClearEnv().clear_cell_mysql()
        data = """
{
  "cellName": "%s",
  "cellType": "%s",
  "description": "%s",
  "ip": "%s",
  "port": %s,
  "username": "******",
  "password": "******"
}
""" % (self.params['cellName'], self.params['cellType'],
        self.params['description'], self.params['ip'], self.params['port'],
        self.params['username'], self.params['password'])
        query_sql = 'select cell_name from zdbm_cells'
        old_database_value = ConnMysql().select_mysql(query_sql)[0]
        content = RequestMethod().to_requests(self.request_method,
                                              'cell/add',
                                              data=data)
        new_database_value = ConnMysql().select_mysql(query_sql)[0]
        return {
            'actualresult': content,
            'old_database_value': 'cell_name:' + old_database_value,
            'new_database_value': 'cell_name:' + new_database_value,
            'database_assert_method': False
        }
예제 #8
0
 def test_cell_get(self):
     # 获取节点详细信息
     query_cell_id = 'select id from zdbm_cells where ip="%s"' % IP
     cell_id = ConnMysql().select_mysql(query_cell_id)[0]
     content = RequestMethod().to_requests(self.request_method,
                                           'cell/get/%s' % cell_id)
     return {'actualresult': content}
예제 #9
0
    def test_user_self(self):
        # 更新当前用户信息

        data = """
        {
  "name": "%s",
  "mail": "%s",
  "phone": "%s",
  "oldPassword": "******",
  "newPassword": "******"
}
        """ % (self.params['name'], self.params['mail'], self.params['phone'],
               self.params['oldPassword'], self.params['newPassword'])
        query_user_name_sql = 'select name from zdbm_users where username="******";' % USERNAME
        old_database_value = ConnMysql().select_mysql(query_user_name_sql)[0]
        content = RequestMethod().to_requests(self.request_method,
                                              'user/self',
                                              data=data)
        new_database_value = ConnMysql().select_mysql(query_user_name_sql)[0]
        return {
            'actualresult': content,
            'old_database_value': 'name:' + old_database_value,
            'new_database_value': 'name:' + new_database_value,
            'database_assert_method': False,
            'name': self.params['name']
        }
예제 #10
0
 def test_recovery_preset_by_vdb(self):
     # 预生成通过vdb全量恢复源库需要的参数
     data = '{"vdbID":%s,"targetDir":"%s", "targetEnvID": %s}' % (NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_id'],
                                                                  MDB1_V2P_PATH, NEED_PARAMETER[self.params['envName']+'_id'])
     content = RequestMethod().to_requests(self.request_method, 'recovery/preset/by/vdb', data=data)
     print(content)
     return {
         'actualresult': content
     }
예제 #11
0
 def test_source(self):
     # 测试数据库参数
     data = """{"databaseID": %s,"username": "******", "password": "******",
     "datafileZpoolID":1,"storageType": "FILE_SYSTEM"}""" \
             % (NEED_PARAMETER[self.params['envName'] + '_' + self.params['dbName']+'_database_id'],
                self.params['ORACLE_USER'], self.params['ORACLE_PASSWORD'])
     content = RequestMethod().to_requests(self.request_method,
                                           'source/test',
                                           data=data)
     return {'actualresult': content}
예제 #12
0
 def test_license_update_name(self):
     # 设置客户名称
     name = self.params['name']
     data = '{"name":"%s"}' % name
     sql = 'select name from zdbm_license_infos where id=1'
     old_database_value = ConnMysql().select_mysql(sql)[0]
     content = RequestMethod().to_requests(self.request_method, 'license/update/name', data=data)
     new_database_value = ConnMysql().select_mysql(sql)[0]
     return {
         'actualresult': content, 'name': name, 'old_database_value': 'name:' + old_database_value,
         'new_database_value': 'name:' + new_database_value, 'database_assert_method': False
     }
예제 #13
0
    def test_cell_test(self):
        # 测试节点功能支持,比如vt
        ip = self.params['ip']
        port = self.params['port']
        username = self.params['username']
        password = self.params['password']
        data = """{
  "ip": "%s",
  "port": %s,
  "username": "******",
  "password": "******"
}""" % (ip, port, username, password)
        content = RequestMethod().to_requests(self.request_method,
                                              'cell/test',
                                              data=data)
        return {'actualresult': content}
예제 #14
0
 def test_vdb_snapshot_add(self):
     # 添加VDB快照,先获取一次DEPT表内的时间戳
     snap_name = "快照 ".encode('utf-8').decode('latin1') + (time.strftime("%Y-%m-%d %H:%M:%S"))
     vdb_id_sql = 'select id,vdb_name from zdbm_orcl_virtual_dbs where open_mode="READ WRITE" and deleted_at is ' \
                  'null and db_name= "%s" order by id desc' % self.params['dbName']
     name = self.params['description'].encode('utf-8').decode('latin1')
     vdb_id, vdb_name = ConnMysql().select_mysql_new(vdb_id_sql, ac_re=True)
     data = '{"vdbID":%s,"name":"%s","description":"%s"}' % \
            (vdb_id, snap_name, name)
     content = RequestMethod().to_requests(self.request_method, 'vdb/snapshot/add', data=data)
     result = json.loads(content)
     NEED_PARAMETER.update({
         'vdb'+'_' + self.params['dbName']+'_name': vdb_name, 'snapshot'+'_' + self.params['dbName']+'_id': result['data']['snapshot']['id'], 'vdb'+'_' + self.params['dbName']+'_id': vdb_id
     })
     return {
         'actualresult': content, 'description': self.params['description']
     }
예제 #15
0
    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
        }
예제 #16
0
 def test_user_delete(self):
     # 删除目标用户
     query_user_id = 'select id from zdbm_users where username="******";' % self.params[
         'username']
     user_id = ConnMysql().select_mysql(query_user_id)[0]
     query_sql = 'select deleted_at from zdbm_users where username="******";' % self.params[
         'username']
     old_database_value = ConnMysql().select_mysql(query_sql)[0]
     content = RequestMethod().to_requests(self.request_method,
                                           'user/delete/%s' % user_id)
     new_database_value = ConnMysql().select_mysql(query_sql)[0]
     return {
         'actualresult': content,
         'old_database_value': 'deleted_at:' + str(old_database_value),
         'new_database_value': 'deleted_at:' + str(new_database_value),
         'database_assert_method': False
     }
예제 #17
0
    def test_vdb_refresh(self):
        mode = "READ WRITE"
        status = "RUNNING"
        select_sql = "select id,target_time from zdbm_orcl_virtual_dbs where deleted_at is null and " \
                     "open_mode='{}' and vdb_status='{}'".format(mode, status)
        vdb_id, target_time = ConnMysql().select_mysql(select_sql)
        print(vdb_id, str(target_time))
        data = json.dumps({"timestamp": str(target_time)})

        print(data)
        content = RequestMethod().to_requests(self.request_method, "vdb/refresh/{}".format(vdb_id), data=data)
        select_status_sql = "select vdb_status from zdbm_orcl_virtual_dbs where id={}".format(vdb_id)
        result = wait_for(look_select, select_status_sql, status)

        return {
            'actualresult': content, 'old_database_value': 'value:{}'.format(True),
            'new_database_value': 'value:{}'.format(result), 'database_assert_method': True
        }
예제 #18
0
 def test_user_enable(self):
     # 设置用户有效性
     data = '{"enable": false}'
     user_id_sql = 'select id from zdbm_users where username="******";' % USERNAME
     user_id = ConnMysql().select_mysql(user_id_sql)[0]
     query_user_enable_sql = 'select enable from zdbm_users where username="******";' % USERNAME
     old_database_value = ConnMysql().select_mysql(query_user_enable_sql)[0]
     content = RequestMethod().to_requests(self.request_method,
                                           'user/enable/%s' % user_id,
                                           data=data)
     new_database_value = ConnMysql().select_mysql(query_user_enable_sql)[0]
     ClearEnv().update_user_enable()
     # 将用户有效性重置为1
     return {
         'actualresult': content,
         'old_database_value': 'enable:' + str(old_database_value),
         'new_database_value': 'enable:' + str(new_database_value),
         'database_assert_method': False
     }
예제 #19
0
 def test_increment_backup(self):
     source_id = NEED_PARAMETER["increment_source_id"]
     select_status_sql = 'select source_status from zdbm_orcl_source_dbs where id = {}'.format(
         source_id)
     status = ConnMysql().select_mysql_new(select_status_sql)
     print("status:", status)
     data = json.dumps(
         {"nodeID": NEED_PARAMETER[self.params["envName"] + '_node_id']})
     content = RequestMethod().to_requests(
         self.request_method,
         "source/increment/backup/{}".format(source_id),
         data=data)
     wait_for(look_select, select_status_sql, status)
     new_status = ConnMysql().select_mysql_new(select_status_sql)
     return {
         'actualresult': content,
         'old_database_value': 'mysql_value:{}'.format(status),
         'new_database_value': 'mysql_value:{}'.format(new_status),
         'database_assert_method': True
     }
예제 #20
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}
예제 #21
0
 def test_cell_update_service(self):
     # 修改节点服务信息
     data = '{"serviceName":"%s","operateType":"%s","operateValue":"%s"}' % (
         self.params['serviceName'], self.params['operateType'],
         self.params['operateValue'])
     query_cell_id = 'select id from zdbm_cells where ip="%s"' % IP
     cell_id = ConnMysql().select_mysql(query_cell_id)[0]
     query_sql = 'select auto_start from zdbm_cell_services where service_type="%s" and cell_id=%s ' % \
                 (self.params['serviceName'], cell_id)
     old_database_value = ConnMysql().select_mysql(query_sql)[0]
     content = RequestMethod().to_requests(self.request_method,
                                           'cell/updateService/%s' %
                                           cell_id,
                                           data=data)
     new_database_value = ConnMysql().select_mysql(query_sql)[0]
     return {
         'actualresult': content,
         'old_database_value': 'auto_start:' + str(old_database_value),
         'new_database_value': 'auto_start:' + str(new_database_value),
         'database_assert_method': False
     }
예제 #22
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
     }
예제 #23
0
    def test_vdb_reset(self):
        # 重置VDB
        ConnOracle(ip=self.params['MDB_IP'], user=self.params['ORACLE_USER'], pwd=self.params['ORACLE_PASSWORD'],
                   oracle_name=NEED_PARAMETER['vdb' + '_' + self.params['dbName'] + '_name']).init_operate()
        ConnOracle(ip=self.params['MDB_IP'], user=self.params['ORACLE_USER'],pwd=self.params['ORACLE_PASSWORD'],
                   oracle_name=NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name']).new_table()

        old_database_value = ConnOracle(ip=self.params['MDB_IP'], user=self.params['ORACLE_USER'], pwd=self.params['ORACLE_PASSWORD'],
                                        oracle_name=NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name']).selcet_oracle('select content from DEPT')[0]
        data = '{"snapshotID":%s}' % NEED_PARAMETER['snapshot'+'_' + self.params['dbName']+'_id']
        content = RequestMethod().to_requests(self.request_method, 'vdb/reset/%s' % NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_id'], data=data)
        status_sql = 'select job_status from zdbm_jobs where vdb_name="%s" order by id desc limit 1' % (NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name'])
        archive_time = 5 * 60  # 5分钟
        content_sql = 'select err_msg from zdbm_jobs where vdb_name="%s" order by id desc limit 1' % (NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name'])
        time.sleep(2)
        while 1:
            status = ConnMysql().select_mysql(status_sql)[0]
            print(NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name'], 'VDB重置状态:', status,'时间过去:', 300-archive_time, '秒')
            archive_time -=2
            if status == 'PROCESSING':
                time.sleep(2)
                continue
            elif status == 'FAILURE':
                content = ConnMysql().select_mysql(content_sql)[0]
                break
            elif status == 'SUCCESS':
                break
            if archive_time == 0:
                content = '归档状态异常,5分钟未恢复'
                break
        ConnOracle(ip=self.params['MDB_IP'], user=self.params['ORACLE_USER'], pwd=self.params['ORACLE_PASSWORD'],
                   oracle_name=NEED_PARAMETER['vdb' + '_' + self.params['dbName'] + '_name']).init_operate()
        ConnOracle(ip=self.params['MDB_IP'], user=self.params['ORACLE_USER'],pwd=self.params['ORACLE_PASSWORD'],
                   oracle_name=NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name']).insert_dept()
        new_database_value = \
        ConnOracle(ip=self.params['MDB_IP'], user=self.params['ORACLE_USER'],pwd=self.params['ORACLE_PASSWORD'], oracle_name=NEED_PARAMETER['vdb'+'_' + self.params['dbName']+'_name']).selcet_oracle('select content from (select * from DEPT order by id desc) where rownum < 2')[0]
        return {
            'actualresult': content, 'old_database_value': 'oracle_value:' + old_database_value,
            'new_database_value': 'oracle_value:' + new_database_value, 'database_assert_method': False
        }
예제 #24
0
    def test_delete_cell(self):
        # 删除节点
        query_cell_id = 'select id from zdbm_cells where ip="%s"' % IP
        cell_id = ConnMysql().select_mysql(query_cell_id)[0]
        data = """{
  "ids": [
    %s
  ]
}""" % cell_id
        query_sql = 'select deleted_at from zdbm_cells where ip="%s"' % IP
        old_database_value = ConnMysql().select_mysql(query_sql)[0]
        content = RequestMethod().to_requests(self.request_method,
                                              'cell/delete',
                                              data=data)
        new_database_value = ConnMysql().select_mysql(query_sql)[0]
        return {
            'actualresult': content,
            'cell_id': cell_id,
            'old_database_value': 'deleted_at:' + str(old_database_value),
            'new_database_value': 'deleted_at:' + str(new_database_value),
            'database_assert_method': False
        }
예제 #25
0
 def test_env_refresh(self):
     env_id = self.del_env_soft()
     content = RequestMethod().to_requests(self.request_method,
                                           'env/fresh/{}'.format(env_id))
     print(content)
     #
     sql = "select software_count from zdbm_orcl_envs where id={}".format(
         env_id)
     time.sleep(2)
     new_database_value = self.mysql.select_mysql(sql)[0]
     # print(new_database_value)
     sql1 = 'delete from zdbm_orcl_env_softwares where env_id={} and deleted_at is null'.format(
         env_id)
     sql2 = 'update zdbm_orcl_env_softwares set deleted_at =null where env_id={}'.format(
         env_id)
     self.mysql.operate_mysql(sql1)
     self.mysql.operate_mysql(sql2)
     return {
         'actualresult': content,
         'old_database_value': 'mysql_value:' + str(0),
         'new_database_value': 'mysql_value:' + str(new_database_value),
         'database_assert_method': False
     }
예제 #26
0
 def test_cell_default_network(self):
     # 设置节点主网卡
     query_cell_id = 'select id from zdbm_cells where ip="%s"' % IP
     cell_id = ConnMysql().select_mysql(query_cell_id)[0]
     query_net_card_name = 'select name from zdbm_cell_network_cards where type="bridge" and ' \
                           'running_status="connected"'
     net_card_name = ConnMysql().select_mysql(query_net_card_name)[0]
     data = '{"netCardName":"%s","used":true}' % net_card_name
     query_sql = 'select virtual_net_used from zdbm_cell_network_cards where name="%s"' % net_card_name
     old_database_value = ConnMysql().select_mysql(query_sql)[0]
     content = RequestMethod().to_requests(self.request_method,
                                           'cell/default/network/%s' %
                                           cell_id,
                                           data=data)
     new_database_value = ConnMysql().select_mysql(query_sql)[0]
     return {
         'actualresult': content,
         'old_database_value':
         'virtual_net_used:' + str(old_database_value),
         'new_database_value':
         'virtual_net_used:' + str(new_database_value),
         'database_assert_method': False
     }
예제 #27
0
 def test_source_recover_time(self):
     sql = "select id, snapshot_time, source_id from zdbm_orcl_source_db_snapshots " \
           "where is_cleanup=0 and unavailable=0 order by source_id desc"
     snap_id, snapshot_time, source_id = ConnMysql().select_mysql(sql)
     print(snapshot_time, source_id)
     new_time = "2020-03-18 17:00:00"
     update_sql = "update zdbm_orcl_source_db_snapshots set snapshot_time='{}' where id={}".format(
         new_time, snap_id)
     ConnMysql().operate_mysql(update_sql)
     content = RequestMethod().to_requests(
         self.request_method, "source/get/{}".format(source_id))
     print(content)
     show_start_time = json.loads(content)["data"]["source"]["startTime"]
     print("show_start_time", show_start_time)
     ConnMysql().operate_mysql(
         "update zdbm_orcl_source_db_snapshots set snapshot_time='{}' where id={}"
         .format(snapshot_time, snap_id))
     new_time = "2020-03-18T17:00:00+08:00"
     return {
         'actualresult': content,
         'old_database_value': 'value:{}'.format(new_time),
         'new_database_value': 'value:{}'.format(show_start_time),
         'database_assert_method': True
     }
예제 #28
0
    def test_user_password(self):
        # 更新当前用户密码
        data = """
        {
  "oldPassword": "******",
  "newPassword": "******"
}
        """ % (PASSWORD, NEWPASSWORD)
        query_user_password_sql = 'select password from zdbm_users where username="******";' % USERNAME
        old_database_value = ConnMysql().select_mysql(
            query_user_password_sql)[0]
        content = RequestMethod().to_requests(self.request_method,
                                              'user/password',
                                              data=data)
        new_database_value = ConnMysql().select_mysql(
            query_user_password_sql)[0]
        ClearEnv().update_user_password()
        # 将密码重置为yanglei1
        return {
            'actualresult': content,
            'old_database_value': 'password:'******'new_database_value': 'password:'******'database_assert_method': False
        }
예제 #29
0
    def test_vdb_add(self):
        #  添加VDB
        env_tag_name_sql = 'select tag from zdbm_orcl_envs where id=%s and deleted_at is null'% NEED_PARAMETER[self.params['MDB_NAME'] + '_id']
        env_tag_name = ConnMysql().select_mysql(env_tag_name_sql)[0]
        TAGNAME = ORACLE_TOOLPATH+'/'+env_tag_name
        vdbName = "vdb_" + self.params['vdbName']
        print('路径', TAGNAME)
        time.sleep(1)
        TIME_STAMP_sql = 'select full_backup_ended_at from zdbm_orcl_source_dbs where db_name="%s" and deleted_at is null' % self.params['dbName']
        TIME_STAMP = ConnMysql().select_mysql(TIME_STAMP_sql)[0]
        word = "白银".encode('utf-8').decode('latin1')
        data = '{"envID":%s,"softwareID":%s,"sourceID":%s,"timestamp":"%s","vdbName":"%s",' \
               '"tacticParam":{"name":"%s_%s","vdbRetainDay":60,"snapshotIntervalHour":12,"snapshotRetainDay":60},"contactID":0,"parameters":' \
               '[{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_files","value":"4000","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"compatible","value":"11.2.0.4.0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_create_file_dest","value":"%s/%s/datafile","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_recovery_file_dest_size","value":"500G","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"sga_max_size","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"sga_target","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_cache_advice","value":"off","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_cache_size","value":"4G","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"shared_pool_size","value":"3G","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"streams_pool_size","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"java_pool_size","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"large_pool_size","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"pga_aggregate_target","value":"1G","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"open_cursors","value":"300","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"remote_listener","value":"","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_domain","value":"","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"dispatchers","value":"(PROTOCOL=TCP) (SERVICE=orclXDB)","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"fast_start_mttr_target","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"log_archive_dest_1","value":"","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"log_archive_dest_state_1","value":"enable","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"processes","value":"5000","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"global_names","value":"FALSE","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"local_listener","value":"","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"open_links","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_file_multiblock_read_count","value":"128","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"fast_start_parallel_rollback","value":"LOW","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"job_queue_processes","value":"0","parameterType":"ADVISE_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_name","value":"%s","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_block_size","value":"8192","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"control_files","value":"%s/%s/datafile/controlfile.ctl","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_unique_name","value":"%s","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"instance_name","value":"%s","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"undo_tablespace","value":"UNDOTBS1","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"core_dump_dest","value":"%s/%s/cdump","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"diagnostic_dest","value":"%s/%s/diagnostic","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"audit_file_dest","value":"%s/%s/adump","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"audit_trail","value":"NONE","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"audit_sys_operations","value":"FALSE","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"db_recovery_file_dest","value":"%s/%s/datafile","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"remote_login_passwordfile","value":"EXCLUSIVE","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"instance_number","value":"1","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"cluster_database","value":"FALSE","parameterType":"CANNOT_EDIT"},' \
               '{"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","name":"thread","value":"0","parameterType":"CANNOT_EDIT"}]}' % \
               (
                NEED_PARAMETER[self.params['MDB_NAME'] + '_id'], NEED_PARAMETER[self.params['MDB_NAME'] + '_softwares_id'],
                NEED_PARAMETER[self.params['envName'] +'_'+self.params['dbName'] + '_source_id'],TIME_STAMP, vdbName, word, vdbName, TAGNAME,vdbName,self.params['dbName'], TAGNAME, vdbName, vdbName, vdbName,
                TAGNAME, vdbName, TAGNAME, vdbName, TAGNAME, vdbName, TAGNAME, vdbName
                )
        content = RequestMethod().to_requests(self.request_method, 'vdb/add', data=data)
        result = json.loads(content)
        NEED_PARAMETER.update({
            self.params['envName'] + '_' + self.params['dbName'] + '_vdb_id': result['data']['vdb']['id']
        })
        vdb_status_sql = 'select open_mode from zdbm_orcl_virtual_dbs where id=%s' % NEED_PARAMETER[self.params['envName'] + '_' + self.params['dbName'] + '_vdb_id']
        archive_time = 5 * 60  # 5分钟
        time.sleep(2)
        while 1:
            vdb_status = ConnMysql().select_mysql(vdb_status_sql)[0]
            print(self.params['vdbName'], 'vdb状态:', vdb_status, '时间过去:', 300-archive_time, '秒')
            if vdb_status == 'READ WRITE':
                break
            if archive_time == 0:
                content = self.params['vdbName']+'VDB状态是%s 非READ WRITE' % vdb_status
                break
            archive_time -= 2
            time.sleep(2)

        time.sleep(5)
        return {
            'actualresult': content, 'vdbName': self.params['vdbName']
        }
예제 #30
0
 def test_vdb_stop(self):
     vdb_id = NEED_PARAMETER['vdb_' + self.params['dbName'] + '_id']
     content = RequestMethod().to_requests(self.request_method, 'vdb/stop/{}'.format(vdb_id))
     return {
         'actualresult': content
     }