Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复实例check返回连接状态错误bug fix #1179 #1407

Merged
merged 4 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions sql/engines/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down