Skip to content

Commit

Permalink
apt-hook: append errors to a log file
Browse files Browse the repository at this point in the history
The previous method of only keeping the latest potential error output in
a state file was unnecessarily confusing. This new method appends errors
to a log file in /var/log. The already existing logrotate config will
rotate this new file if necessary because of it's wildcard. pro
collect-logs also uses a wildcard and so will also collect this file if
it exists.
  • Loading branch information
orndorffgrant committed Sep 5, 2024
1 parent 5c8a067 commit d19af14
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apt-hook/20apt-esm-hook.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ APT::Update::Pre-Invoke {
};

binary::apt::AptCli::Hooks::Upgrade {
"[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook 2> /var/lib/ubuntu-advantage/apt-upgrade-hook-err.txt || true";
"[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook 2>> /var/log/ubuntu-advantage-apt-hook.log || true";
};
1 change: 1 addition & 0 deletions debian/ubuntu-pro-client.postrm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ remove_logs(){
rm -f /var/log/ubuntu-advantage-timer.log*
rm -f /var/log/ubuntu-advantage-license-check.log*
rm -f /var/log/ubuntu-advantage-daemon.log*
rm -f /var/log/ubuntu-advantage-apt-hook.log*
}

remove_gpg_files(){
Expand Down
2 changes: 0 additions & 2 deletions uaclient/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from uaclient import system, timer, util
from uaclient.defaults import (
APPARMOR_PROFILES,
APT_UPGRADE_HOOK_ERR,
CLOUD_BUILD_INFO,
DEFAULT_CONFIG_FILE,
DEFAULT_LOG_PREFIX,
Expand Down Expand Up @@ -340,7 +339,6 @@ def _get_state_files(cfg: config.UAConfig):
cfg.cfg_path or DEFAULT_CONFIG_FILE,
cfg.log_file,
timer_jobs_state_file.ua_file.path,
APT_UPGRADE_HOOK_ERR,
CLOUD_BUILD_INFO,
*(
entitlement_cls(cfg).repo_file
Expand Down
3 changes: 1 addition & 2 deletions uaclient/cli/tests/test_cli_collect_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_collect_logs(
tmpdir.join("user1-log").strpath,
tmpdir.join("user2-log").strpath,
]
is_file_calls = 18 + len(APPARMOR_PROFILES)
is_file_calls = 17 + len(APPARMOR_PROFILES)
user_log_files = [mock.call(m_get_user())]
if util_we_are_currently_root():
user_log_files = [
Expand Down Expand Up @@ -143,7 +143,6 @@ def test_collect_logs(
mock.call("/etc/ubuntu-advantage/uaclient.conf"),
mock.call(cfg.log_file),
mock.call("/var/lib/ubuntu-advantage/jobs-status.json"),
mock.call("/var/lib/ubuntu-advantage/apt-upgrade-hook-err.txt"),
mock.call("/etc/cloud/build.info"),
mock.call(
"/etc/apt/sources.list.d/ubuntu-anbox-cloud.{}".format(
Expand Down
3 changes: 0 additions & 3 deletions uaclient/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
ESM_APT_ROOTDIR = os.path.join(DEFAULT_DATA_DIR, PRIVATE_ESM_CACHE_SUBDIR)
NOTICES_PERMANENT_DIRECTORY = os.path.join(DEFAULT_DATA_DIR, NOTICES_SUBDIR)
NOTICES_TEMPORARY_DIRECTORY = os.path.join(UAC_RUN_PATH, NOTICES_SUBDIR)
APT_UPGRADE_HOOK_ERR = os.path.join(
DEFAULT_DATA_DIR, "apt-upgrade-hook-err.txt"
)


# URLs
Expand Down

0 comments on commit d19af14

Please sign in to comment.