Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging: use journald logging for all systemd services #2779

Merged
merged 4 commits into from
Mar 21, 2024
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
15 changes: 7 additions & 8 deletions features/unattached_commands.feature
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,18 @@ Feature: Command behaviour when unattached
esm-cache\.service
"""
When I run `journalctl -o cat -u esm-cache.service` with sudo
Then stdout does not match regexp:
Then stdout does not contain substring:
"""
raise FetchFailedException\(\)
raise FetchFailedException()
"""
When I run `ls /var/crash/` with sudo
Then stdout does not match regexp:
Then stdout matches regexp:
"""
_usr_lib_ubuntu-advantage_esm_cache
"WARNING", "ubuntupro.apt", "fail", \d+, "Failed to fetch ESM Apt Cache item: https://esm.ubuntu.com/apps/ubuntu/dists/<release>-apps-security/InRelease", {}]
"""
When I run `cat /var/log/ubuntu-advantage.log` with sudo
Then stdout matches regexp:
When I run `ls /var/crash/` with sudo
Then stdout does not contain substring:
"""
Failed to fetch ESM Apt Cache item:
_usr_lib_ubuntu-advantage_esm_cache
"""

Examples: ubuntu release
Expand Down
15 changes: 2 additions & 13 deletions lib/apt_news.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/python3

import logging
from datetime import datetime, timedelta, timezone

from uaclient import apt, defaults
from uaclient import apt, log
from uaclient.apt_news import update_apt_news
from uaclient.config import UAConfig
from uaclient.daemon import setup_logging


def main(cfg: UAConfig):
Expand All @@ -22,15 +20,6 @@ def main(cfg: UAConfig):


if __name__ == "__main__":
setup_logging(
logging.INFO,
logging.DEBUG,
defaults.CONFIG_DEFAULTS["log_file"],
)
log.setup_journald_logging()
cfg = UAConfig()
setup_logging(
logging.INFO,
logging.DEBUG,
cfg.log_file,
)
main(cfg)
19 changes: 3 additions & 16 deletions lib/auto_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging
import sys

from uaclient import defaults, http, messages, system
from uaclient import http, log, messages, system
from uaclient.api.exceptions import (
AlreadyAttachedError,
AutoAttachDisabledError,
Expand All @@ -24,11 +24,7 @@
full_auto_attach,
)
from uaclient.config import UAConfig
from uaclient.daemon import (
AUTO_ATTACH_STATUS_MOTD_FILE,
retry_auto_attach,
setup_logging,
)
from uaclient.daemon import AUTO_ATTACH_STATUS_MOTD_FILE, retry_auto_attach
from uaclient.files import state_files

LOG = logging.getLogger("ubuntupro.lib.auto_attach")
Expand Down Expand Up @@ -105,16 +101,7 @@ def main(cfg: UAConfig):


if __name__ == "__main__":
setup_logging(
logging.INFO,
logging.DEBUG,
defaults.CONFIG_DEFAULTS["log_file"],
)
log.setup_journald_logging()
cfg = UAConfig()
setup_logging(
logging.INFO,
logging.DEBUG,
cfg.log_file,
)
http.configure_web_proxy(cfg.http_proxy, cfg.https_proxy)
sys.exit(main(cfg))
6 changes: 3 additions & 3 deletions lib/convert_list_to_deb822.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

from aptsources.sourceslist import SourceEntry # type: ignore

from uaclient import entitlements
from uaclient import defaults, entitlements
from uaclient.apt import _get_sources_file_content
from uaclient.cli import setup_logging
from uaclient.config import UAConfig
from uaclient.log import setup_cli_logging
from uaclient.system import (
ensure_file_absent,
get_release_info,
Expand All @@ -28,7 +28,7 @@
if series != "noble":
sys.exit(0)

setup_logging(logging.DEBUG)
setup_cli_logging(logging.DEBUG, defaults.CONFIG_DEFAULTS["log_file"])
cfg = UAConfig()

for entitlement_class in entitlements.ENTITLEMENT_CLASSES:
Expand Down
12 changes: 4 additions & 8 deletions lib/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import sys
import time

from uaclient import http, system
from uaclient import http, log, system
from uaclient.config import UAConfig
from uaclient.daemon import poll_for_pro_license, retry_auto_attach
from uaclient.log import setup_journald_logging

LOG = logging.getLogger("ubuntupro.daemon")

Expand Down Expand Up @@ -40,16 +39,13 @@ def _wait_for_cloud_config():


def main() -> int:
setup_journald_logging(logging.DEBUG, LOG)
# Make sure the ubuntupro.daemon logger does not generate double logging
LOG.propagate = False
setup_journald_logging(logging.ERROR, logging.getLogger("ubuntupro"))
log.setup_journald_logging()

cfg = UAConfig()

http.configure_web_proxy(cfg.http_proxy, cfg.https_proxy)

LOG.debug("daemon starting")
LOG.info("daemon starting")

_wait_for_cloud_config()

Expand All @@ -70,7 +66,7 @@ def main() -> int:
LOG.info("mode: retry auto attach")
retry_auto_attach.retry_auto_attach(cfg)

LOG.debug("daemon ending")
LOG.info("daemon ending")
return 0


Expand Down
14 changes: 2 additions & 12 deletions lib/esm_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import logging

from uaclient import defaults
from uaclient import log
from uaclient.apt import update_esm_caches
from uaclient.config import UAConfig
from uaclient.daemon import setup_logging

LOG = logging.getLogger("ubuntupro.lib.esm_cache")

Expand All @@ -19,15 +18,6 @@ def main(cfg: UAConfig) -> None:


if __name__ == "__main__":
setup_logging(
logging.INFO,
logging.DEBUG,
defaults.CONFIG_DEFAULTS["log_file"],
)
log.setup_journald_logging()
cfg = UAConfig()
setup_logging(
logging.INFO,
logging.DEBUG,
cfg.log_file,
)
main(cfg)
7 changes: 4 additions & 3 deletions lib/patch_status_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import json
import logging

from uaclient import system, util
from uaclient.cli import setup_logging
from uaclient import config, defaults, log, system, util

LOG = logging.getLogger("ubuntupro.lib.patch_status_json")

Expand Down Expand Up @@ -64,7 +63,9 @@ def patch_status_json_schema_0_1(status_file: str):


if __name__ == "__main__":
setup_logging(logging.DEBUG)
log.setup_cli_logging(logging.DEBUG, defaults.CONFIG_DEFAULTS["log_level"])
cfg = config.UAConfig()
log.setup_cli_logging(cfg.log_level, cfg.log_file)
patch_status_json_schema_0_1(
status_file="/var/lib/ubuntu-advantage/status.json"
)
21 changes: 8 additions & 13 deletions lib/reboot_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
from uaclient import (
config,
contract,
defaults,
exceptions,
http,
lock,
log,
upgrade_lts_contract,
)
from uaclient.api.u.pro.status.is_attached.v1 import _is_attached
from uaclient.cli import setup_logging
from uaclient.entitlements.fips import FIPSEntitlement
from uaclient.files import notices, state_files

Expand All @@ -47,11 +46,11 @@ def fix_pro_pkg_holds(cfg: config.UAConfig):
# fips was not enabled, don't do anything
return

LOG.debug("Attempting to remove Ubuntu Pro FIPS package holds")
LOG.info("Attempting to remove Ubuntu Pro FIPS package holds")
fips = FIPSEntitlement(cfg)
try:
fips.setup_apt_config() # Removes package holds
LOG.debug("Successfully removed Ubuntu Pro FIPS package holds")
LOG.info("Successfully removed Ubuntu Pro FIPS package holds")
except Exception as e:
LOG.error(e)
LOG.warning("Could not remove Ubuntu Pro FIPS package holds")
Expand All @@ -73,17 +72,17 @@ def refresh_contract(cfg: config.UAConfig):

def main(cfg: config.UAConfig) -> int:
if not state_files.reboot_cmd_marker_file.is_present:
LOG.debug("Skipping reboot_cmds. Marker file not present")
LOG.info("Skipping reboot_cmds. Marker file not present")
notices.remove(notices.Notice.REBOOT_SCRIPT_FAILED)
return 0

if not _is_attached(cfg).is_attached:
LOG.debug("Skipping reboot_cmds. Machine is unattached")
LOG.info("Skipping reboot_cmds. Machine is unattached")
state_files.reboot_cmd_marker_file.delete()
notices.remove(notices.Notice.REBOOT_SCRIPT_FAILED)
return 0

LOG.debug("Running reboot commands...")
LOG.info("Running reboot commands...")
try:
with lock.RetryLock(lock_holder="pro-reboot-cmds"):
fix_pro_pkg_holds(cfg)
Expand All @@ -108,16 +107,12 @@ def main(cfg: config.UAConfig) -> int:
notices.add(notices.Notice.REBOOT_SCRIPT_FAILED)
return 1

LOG.debug("Successfully ran all commands on reboot.")
LOG.info("Successfully ran all commands on reboot.")
return 0


if __name__ == "__main__":
setup_logging(
logging.DEBUG,
defaults.CONFIG_DEFAULTS["log_file"],
)
log.setup_journald_logging()
cfg = config.UAConfig()
setup_logging(logging.DEBUG, log_file=cfg.log_file)
http.configure_web_proxy(cfg.http_proxy, cfg.https_proxy)
sys.exit(main(cfg=cfg))
12 changes: 4 additions & 8 deletions lib/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
from datetime import datetime, timedelta, timezone
from typing import Callable, Optional

from uaclient import http
from uaclient import http, log
from uaclient.config import UAConfig
from uaclient.exceptions import InvalidFileFormatError
from uaclient.files.state_files import (
AllTimerJobsState,
TimerJobState,
timer_jobs_state_file,
)
from uaclient.log import setup_journald_logging
from uaclient.timer.metering import metering_enabled_resources
from uaclient.timer.update_contract_info import update_contract_info
from uaclient.timer.update_messaging import update_motd_messages
Expand Down Expand Up @@ -49,9 +48,9 @@ def run(self, cfg: UAConfig) -> bool:
return False

try:
LOG.debug("Running job: %s", self.name)
LOG.info("Running job: %s", self.name)
if self._job_func(cfg=cfg):
LOG.debug("Executed job: %s", self.name)
LOG.info("Executed job: %s", self.name)
except Exception as e:
LOG.error("Error executing job %s: %s", self.name, str(e))
return False
Expand Down Expand Up @@ -180,10 +179,7 @@ def run_jobs(cfg: UAConfig, current_time: datetime):


if __name__ == "__main__":
setup_journald_logging(logging.DEBUG, LOG)
# Make sure the ubuntupro.timer logger does not generate double logging
LOG.propagate = False
setup_journald_logging(logging.ERROR, logging.getLogger("ubuntupro"))
log.setup_journald_logging()

cfg = UAConfig()
current_time = datetime.now(timezone.utc)
Expand Down
9 changes: 4 additions & 5 deletions lib/upgrade_lts_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import logging

from uaclient import http, upgrade_lts_contract
from uaclient.cli import setup_logging
from uaclient.config import UAConfig
from uaclient import config, defaults, http, log, upgrade_lts_contract

if __name__ == "__main__":
setup_logging(logging.DEBUG)
cfg = UAConfig()
log.setup_cli_logging(logging.DEBUG, defaults.CONFIG_DEFAULTS["log_level"])
cfg = config.UAConfig()
log.setup_cli_logging(cfg.log_level, cfg.log_file)
http.configure_web_proxy(cfg.http_proxy, cfg.https_proxy)
upgrade_lts_contract.process_contract_delta_after_apt_lock(cfg)
upgrade_lts_contract.remove_private_esm_apt_cache()
Loading
Loading