Skip to content

Commit

Permalink
added redshift and postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Apr 14, 2021
1 parent 7d23ad5 commit 2e9a3e1
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 18 deletions.
3 changes: 2 additions & 1 deletion superset/db_engine_specs/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class MySQLEngineSpec(BaseEngineSpec):
),
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: (
__(
'We were unable to connect to your database named "%(database)s". Please verify your database name and try again.'
'We were unable to connect to your database named "%(database)s". '
"Please verify your database name and try again."
),
SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
),
Expand Down
10 changes: 10 additions & 0 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class FixedOffsetTimezone(_FixedOffset):
r'host "(?P<hostname>.*?)" (\(.*?\) )?and accepting\s+TCP/IP '
r"connections on port (?P<port>.*?)\?"
)
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile(
'database "(?P<database>.*?)" does not exist'
)


class PostgresBaseEngineSpec(BaseEngineSpec):
Expand Down Expand Up @@ -120,6 +123,13 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
),
SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
),
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: (
__(
'We were unable to connect to your database named "%(database)s".'
" Please verify your database name and try again."
),
SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
),
}

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions superset/db_engine_specs/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
r'host "(?P<hostname>.*?)" (\(.*?\) )?and accepting\s+TCP/IP '
r"connections on port (?P<port>.*?)\?"
)
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile(
'database "(?P<database>.*?)" does not exist'
)


class RedshiftEngineSpec(PostgresBaseEngineSpec):
Expand Down Expand Up @@ -66,6 +69,13 @@ class RedshiftEngineSpec(PostgresBaseEngineSpec):
),
SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
),
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: (
__(
'We were unable to connect to your database named "%(database)s".'
" Please verify your database name and try again."
),
SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
),
}

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion superset/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ class SupersetErrorType(str, Enum):
{
"code": 1015,
"message": _(
"Issue 1015 - Either the database is spelled incorrectly or does not exist."
"Issue 1015 - Either the database is "
"spelled incorrectly or does not exist."
),
}
],
Expand Down
21 changes: 14 additions & 7 deletions tests/db_engine_specs/mysql_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1014,
"message": "Issue 1014 - Either the username or the password is wrong.",
"message": "Issue 1014 - Either the"
" username or the password is wrong.",
}
],
},
Expand All @@ -141,7 +142,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname"
" provided can't be resolved.",
}
],
},
Expand All @@ -153,14 +155,16 @@ def test_extract_errors(self):
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
message='The host "badconnection.com" might be down and can\'t be reached.',
message='The host "badconnection.com" might be '
"down and can't be reached.",
level=ErrorLevel.ERROR,
extra={
"engine_name": "MySQL",
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided"
" can't be resolved.",
}
],
},
Expand All @@ -179,7 +183,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 10007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided "
"can't be resolved.",
}
],
},
Expand All @@ -191,14 +196,16 @@ def test_extract_errors(self):
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
message='We were unable to connect to your database named "badDB". Please verify your database name and try again.',
message='We were unable to connect to your database named "badDB".'
" Please verify your database name and try again.",
level=ErrorLevel.ERROR,
extra={
"engine_name": "MySQL",
"issue_codes": [
{
"code": 10015,
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.",
"message": "Issue 1015 - Either the database is "
"spelled incorrectly or does not exist.",
}
],
},
Expand Down
35 changes: 31 additions & 4 deletions tests/db_engine_specs/postgres_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ def test_extract_errors(self):
)
]

msg = 'psql: error: could not translate host name "locahost" to address: nodename nor servname provided, or not known'
msg = (
'psql: error: could not translate host name "locahost" to address: '
"nodename nor servname provided, or not known"
)
result = PostgresEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
Expand All @@ -250,7 +253,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided "
"can't be resolved.",
}
],
},
Expand Down Expand Up @@ -303,7 +307,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
Expand Down Expand Up @@ -332,7 +337,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
Expand Down Expand Up @@ -360,3 +366,24 @@ def test_extract_errors(self):
},
)
]

msg = 'database "badDB" does not exist'
result = PostgresEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
message='We were unable to connect to your database named "badDB".'
" Please verify your database name and try again.",
level=ErrorLevel.ERROR,
extra={
"engine_name": "PostgreSQL",
"issue_codes": [
{
"code": 10015,
"message": "Issue 1015 - Either the database is "
"spelled incorrectly or does not exist.",
}
],
},
)
]
38 changes: 33 additions & 5 deletions tests/db_engine_specs/redshift_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1014,
"message": "Issue 1014 - Either the username or the password is wrong",
"message": "Issue 1014 - Either the username or "
"the password is wrong",
}
],
},
)
]

msg = 'redshift: error: could not translate host name "badhost" to address: nodename nor servname provided, or not known'
msg = (
'redshift: error: could not translate host name "badhost" '
"to address: nodename nor servname provided, or not known"
)
result = RedshiftEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
Expand All @@ -58,7 +62,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided "
"can't be resolved.",
}
],
},
Expand Down Expand Up @@ -110,7 +115,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
Expand Down Expand Up @@ -139,7 +145,29 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
)
]

msg = 'database "badDB" does not exist'
result = RedshiftEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
message='We were unable to connect to your database named "badDB".'
" Please verify your database name and try again.",
level=ErrorLevel.ERROR,
extra={
"engine_name": "Amazon Redshift",
"issue_codes": [
{
"code": 10015,
"message": "Issue 1015 - Either the database is "
"spelled incorrectly or does not exist.",
}
],
},
Expand Down

0 comments on commit 2e9a3e1

Please sign in to comment.