Ejemplo n.º 1
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']
        }
Ejemplo n.º 2
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
        }
Ejemplo n.º 3
0
 def clear_cell_mysql():
     delete_sql = 'delete from zdbm_cells'
     delete_zdbm_cell_services = 'delete from zdbm_cell_services'
     delete_zdbm_cell_network_cards = 'delete from zdbm_cell_network_cards'
     ConnMysql().operate_mysql(delete_sql)
     ConnMysql().operate_mysql(delete_zdbm_cell_services)
     ConnMysql().operate_mysql(delete_zdbm_cell_network_cards)
Ejemplo n.º 4
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
     }
Ejemplo n.º 5
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']
        }
Ejemplo n.º 6
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
     }
Ejemplo n.º 7
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']
        }
Ejemplo n.º 8
0
    def delete_exists_mysql(table_name, col_name, exsits_name):
        query_sql = 'select * from %s where %s="%s"' % (table_name, col_name, exsits_name)
        r = ConnMysql().select_mysql(query_sql)
        if r[0] == ' ':
            print('%s表 不存在 %s' % (table_name, exsits_name))

        else:
            delete_sql = 'delete from %s where %s="%s"' % (table_name, col_name, exsits_name)
            ConnMysql().operate_mysql(delete_sql)
            print('%s表 删除 %s' % (table_name, exsits_name))
Ejemplo n.º 9
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
     }
Ejemplo n.º 10
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}
Ejemplo n.º 11
0
 def listen_nodes_online(self, times=10):
     url1 = '{}login'.format(self.ip)
     data1 = '{"username":"******","password":"******","captchaID":"","captchaText":""}' % (
         self.username, self.password)
     login_html = self.session.post(url1,
                                    data1,
                                    headers=self.headers,
                                    verify=False).text
     login_html = json.loads(login_html)
     token = login_html['data']['token']
     self.headers.update({'token': token})
     url = '{}env/list'.format(self.ip)
     envs = self.session.get(url, headers=self.headers, verify=False).text
     print(envs)
     envs = json.loads(envs)['data']['envs']
     for env in envs:
         min_time = times * 60
         is_online = False
         select_sql = 'select is_online from zdbm_orcl_env_nodes where env_id="%s"' % env[
             'id']
         while min_time > 0:
             is_online = ConnMysql().select_mysql(select_sql)[0]
             print(
                 str(env['id']) + '节点', '在线状态:' + str(is_online), '时间过去了',
                 600 - min_time, '秒')
             if is_online == 1:
                 break
             time.sleep(2)
             min_time = min_time - 2
         if is_online is False:
             return env['id'], is_online
     return 0, True
Ejemplo n.º 12
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
     }
Ejemplo n.º 13
0
 def listen_nodes_online(node_name, times=2):
     min_time = times * 60
     is_online = False
     select_sql = 'select is_online from zdbm_orcl_env_nodes where node_name="%s"' % node_name
     while min_time > 0 or is_online is True:
         is_online = ConnMysql().select_mysql(select_sql)
         time.sleep(2)
         min_time = min_time - 2
     return is_online
Ejemplo n.º 14
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
     }
Ejemplo n.º 15
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
     }
Ejemplo n.º 16
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}
Ejemplo n.º 17
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
     }
Ejemplo n.º 18
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
     }
Ejemplo n.º 19
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
        }
Ejemplo n.º 20
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
        }
Ejemplo n.º 21
0
    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')
Ejemplo n.º 22
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
     }
Ejemplo n.º 23
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
     }
Ejemplo n.º 24
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
        }
Ejemplo n.º 25
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']
     }
Ejemplo n.º 26
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
        }
Ejemplo n.º 27
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
        }
Ejemplo n.º 28
0
def look_select(sql, success):
    re = ConnMysql().select_mysql_new(sql)
    return re == success
Ejemplo n.º 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']
        }
Ejemplo n.º 30
0
 def __init__(self, params=None):
     print(params)
     self.params = params
     if self.params:
         self.request_method = self.params['request_method']
         self.mysql = ConnMysql()