diff --git a/features/collect_logs.feature b/features/collect_logs.feature index 651d49f8ac..7201ce2003 100644 --- a/features/collect_logs.feature +++ b/features/collect_logs.feature @@ -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 @@ -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 diff --git a/uaclient/actions.py b/uaclient/actions.py index a13d18eff9..e9a0e68fd1 100644 --- a/uaclient/actions.py +++ b/uaclient/actions.py @@ -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) diff --git a/uaclient/tests/test_actions.py b/uaclient/tests/test_actions.py index 7c1c480fb6..bdcce414e1 100644 --- a/uaclient/tests/test_actions.py +++ b/uaclient/tests/test_actions.py @@ -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") @@ -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 @@ -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 @@ -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),