Skip to content

Commit

Permalink
Environment variables file created in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dheyay authored and orndorffgrant committed Feb 13, 2024
1 parent 8c46013 commit 0e6c391
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions features/collect_logs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
build.info
cloud-id.txt
cloud-init-journal.txt
environment_vars.json
esm-cache.service.txt
jobs-status.json
livepatch-status.txt-error
Expand Down Expand Up @@ -65,6 +66,7 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
build.info
cloud-id.txt
cloud-init-journal.txt
environment_vars.json
esm-cache.service.txt
jobs-status.json
livepatch-status.txt-error
Expand Down
7 changes: 6 additions & 1 deletion uaclient/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,12 @@ def collect_logs(cfg: config.UAConfig, output_dir: str):
pro_status, _ = status(cfg=cfg, show_all=False)
system.write_file(
"{}/pro-status.json".format(output_dir),
json.dumps(pro_status),
json.dumps(pro_status, cls=util.DatetimeAwareJSONEncoder),
)
env_vars = util.get_pro_environment()
system.write_file(
"{}/environment_vars.json".format(output_dir),
json.dumps(env_vars),
)

state_files = _get_state_files(cfg)
Expand Down
6 changes: 5 additions & 1 deletion uaclient/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def test_raise_unexpected_errors(
class TestCollectLogs:
@mock.patch("uaclient.actions.status")
@mock.patch("uaclient.actions.LOG.warning")
@mock.patch("uaclient.util.get_pro_environment")
@mock.patch("uaclient.util.we_are_currently_root", return_value=False)
@mock.patch("uaclient.system.write_file")
@mock.patch("uaclient.system.load_file")
Expand All @@ -382,11 +383,13 @@ def test_collect_logs_invalid_file(
m_load_file,
m_write_file,
m_we_are_currently_root,
m_env_vars,
m_log_warning,
m_status,
m_write_cmd,
tmpdir,
):
m_env_vars.return_value = {"test": "test"}
m_status.return_value = ({"test": "test"}, 0)
log_file = tmpdir.join("user-log").strpath
m_get_user.return_value = log_file
Expand All @@ -403,7 +406,7 @@ def test_collect_logs_invalid_file(
mock.call("a"),
mock.call("b"),
] == m_load_file.call_args_list
assert 4 == m_write_file.call_count
assert 5 == m_write_file.call_count

# apparmor checks
assert 1 == m_system_subp.call_count
Expand All @@ -414,6 +417,7 @@ def test_collect_logs_invalid_file(
print(m_write_file.call_args_list)
assert [
mock.call("test/pro-status.json", '{"test": "test"}'),
mock.call("test/environment_vars.json", '{"test": "test"}'),
mock.call("test/user0.log", "test"),
mock.call("test/b", "test"),
mock.call("test/apparmor_logs.txt", APPARMOR_DENIED),
Expand Down

0 comments on commit 0e6c391

Please sign in to comment.