From 7a8d7e38f9c31f7061cb57c0cd21b5c7b001be40 Mon Sep 17 00:00:00 2001 From: nick2wang Date: Fri, 4 Mar 2022 17:29:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=BF=9E=E6=8E=A5=E7=8A=B6=E6=80=81=E9=94=99?= =?UTF-8?q?=E8=AF=AFbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复实例测试连接状态错误bug --- common/check.py | 5 ++++- sql/engines/redis.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/check.py b/common/check.py index 64a4b05023..1ce0438019 100644 --- a/common/check.py +++ b/common/check.py @@ -129,7 +129,10 @@ def instance(request): try: engine = get_engine(instance=instance) engine.get_connection() - engine.get_all_databases() + dbs = engine.get_all_databases() + if dbs.error: + result['status'] = 1 + result['msg'] = '无法连接实例,\n{}'.format(dbs.error) except Exception as e: result['status'] = 1 result['msg'] = '无法连接实例,\n{}'.format(str(e)) diff --git a/sql/engines/redis.py b/sql/engines/redis.py index 564431d140..873ce0b1bc 100644 --- a/sql/engines/redis.py +++ b/sql/engines/redis.py @@ -52,6 +52,7 @@ def get_all_databases(self, **kwargs): except Exception as e: logger.warning(f"Redis CONFIG GET databases 执行报错,异常信息:{e}") rows = 16 + result.error = str(e) db_list = [str(x) for x in range(int(rows))] result.rows = db_list From 1c23e6679ce8181d4d0dd7c0608012609b9d0df5 Mon Sep 17 00:00:00 2001 From: nick2wang Date: Fri, 4 Mar 2022 17:51:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新测试用例 --- common/tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/tests.py b/common/tests.py index feb597cbfb..dc1a6d1b13 100644 --- a/common/tests.py +++ b/common/tests.py @@ -316,12 +316,13 @@ def testEmailCheck(self, send_email, mailsender): def testInstanceCheck(self, _get_engine, _conn): _get_engine.return_value.get_connection = _conn _get_engine.return_value.get_all_databases.return_value.rows.return_value = ResultSet( - rows=(('test1',), ('test2',))) + rows=((),), + error='Wrong password') c = Client() c.force_login(self.superuser1) r = c.post('/check/instance/', data={'instance_id': self.slave1.id}) r_json = r.json() - self.assertEqual(r_json['status'], 0) + self.assertEqual(r_json['status'], 1) @patch('MySQLdb.connect') def test_inception_check(self, _conn):