Skip to content
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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ run-connection-tests-with-docker: # run connection tests from local docker insta
docker run -v ./.env:/.env carbon-dev --run_connection_tests

run-connection-tests-with-ecs-stage: # use after the Data Warehouse password is changed every year to confirm that the new password works
aws ecs run-task --cluster carbon-ecs-stage --task-definition carbon-ecs-stage-people --launch-type="FARGATE" --region us-east-1 --network-configuration '{"awsvpcConfiguration": {"subnets": ["subnet-05df31ac28dd1a4b0","subnet-04cfa272d4f41dc8a"], "securityGroups": ["sg-0f11e2619db7da196"],"assignPublicIp": "DISABLED"}}' --overrides '{"containerOverrides": [ {"name": "carbon-ecs-stage", "command": ["--run_connection_tests"]}]}'
aws ecs run-task --cluster carbon-ecs-stage --task-definition carbon-ecs-stage-people --launch-type="FARGATE" --region us-east-1 --network-configuration '{"awsvpcConfiguration": {"subnets": ["subnet-05df31ac28dd1a4b0","subnet-04cfa272d4f41dc8a"], "securityGroups": ["sg-0f11e2619db7da196"],"assignPublicIp": "DISABLED"}}' --overrides '{"containerOverrides": [ {"name": "carbon-ecs-stage", "command": ["--run_connection_tests", "--ignore_sns_logging"]}]}'

run-articles-feed-with-ecs-stage: # run 'articles' feed
aws ecs run-task --cluster carbon-ecs-stage --task-definition carbon-ecs-stage-articles --launch-type="FARGATE" --region us-east-1 --network-configuration '{"awsvpcConfiguration": {"subnets": ["subnet-05df31ac28dd1a4b0","subnet-04cfa272d4f41dc8a"], "securityGroups": ["sg-0f11e2619db7da196"],"assignPublicIp": "DISABLED"}}' --overrides '{"containerOverrides": [ {"name": "carbon-ecs-stage", "command": ["--ignore_sns_logging"]}]}'

run-people-feed-with-ecs-stage: # run 'people' feed
aws ecs run-task --cluster carbon-ecs-stage --task-definition carbon-ecs-stage-people --launch-type="FARGATE" --region us-east-1 --network-configuration '{"awsvpcConfiguration": {"subnets": ["subnet-05df31ac28dd1a4b0","subnet-04cfa272d4f41dc8a"], "securityGroups": ["sg-0f11e2619db7da196"],"assignPublicIp": "DISABLED"}}' --overrides '{"containerOverrides": [ {"name": "carbon-ecs-stage", "command": ["--ignore_sns_logging"]}]}'
1 change: 1 addition & 0 deletions carbon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def run_connection_test(self) -> None:
f"Failed to connect to the Symplectic Elements FTP server: {error}"
)
logger.exception(error_message)
raise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - think it's good that application bails given a connection error, as it cannot really do its work without it

else:
logger.info("Successfully connected to the Symplectic Elements FTP server")
ftps.quit()
1 change: 1 addition & 0 deletions carbon/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def run_connection_test(self) -> None:
except Exception as error:
error_message = f"Failed to connect to the Data Warehouse: {error}"
logger.exception(error_message)
raise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

else:
dbapi_connection = connection.connection
version = (
Expand Down
20 changes: 14 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,19 @@ def test_cli_connection_tests_success(caplog, functional_engine, runner):
assert "Successfully connected to the Symplectic Elements FTP server" in caplog.text


def test_cli_connection_tests_fail(
caplog, ftp_server, monkeypatch, nonfunctional_engine, runner
def test_cli_database_connection_test_fails(caplog, nonfunctional_engine, runner):
with patch("carbon.cli.DatabaseEngine") as mocked_engine:
mocked_engine.return_value = nonfunctional_engine
result = runner.invoke(main, ["--run_connection_tests"])
assert result.exit_code == 1

assert "Failed to connect to the Data Warehouse" in caplog.text
Comment on lines +191 to +197
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, this is a nice test. The fixture nonfunctional_engine is clearly worded, indicating that it's doomed from the get-go, and the test confirms it.



def test_cli_ftp_connection_test_fails(
caplog, ftp_server, functional_engine, monkeypatch, runner
):
ftp_socket, _ = ftp_server

monkeypatch.setenv(
"SYMPLECTIC_FTP_JSON",
(
Expand All @@ -202,10 +210,10 @@ def test_cli_connection_tests_fail(
'"SYMPLECTIC_FTP_PASS": "invalid_password"}'
),
)

with patch("carbon.cli.DatabaseEngine") as mocked_engine:
mocked_engine.return_value = nonfunctional_engine
mocked_engine.return_value = functional_engine
result = runner.invoke(main, ["--run_connection_tests"])
assert result.exit_code == 0
assert result.exit_code == 1

assert "Failed to connect to the Data Warehouse" in caplog.text
assert "Failed to connect to the Symplectic Elements FTP server" in caplog.text