Skip to content

Commit

Permalink
logging_revamp: removing timer,daemon log files mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvoM authored and orndorffgrant committed Aug 25, 2023
1 parent 0bfc766 commit 279114c
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 152 deletions.
5 changes: 1 addition & 4 deletions apport/source_ubuntu-advantage-tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ def add_info(report, ui=None):
"ua-status.json-error",
"livepatch-status.txt",
"livepatch-status.txt-error",
"pro-journal.txt",
os.path.basename(cfg.cfg_path),
os.path.basename(cfg.log_file),
os.path.basename(cfg.timer_log_file),
os.path.basename(cfg.daemon_log_file),
os.path.basename(cfg.data_path("jobs-status")),
os.path.basename(defaults.CONFIG_DEFAULTS["log_file"]),
os.path.basename(defaults.CONFIG_DEFAULTS["timer_log_file"]),
os.path.basename(defaults.CONFIG_DEFAULTS["daemon_log_file"]),
}
for f in auto_include_log_files:
attach_file_if_exists(report, os.path.join(output_dir, f), key=f)
7 changes: 2 additions & 5 deletions features/attached_commands.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
Then stdout matches regexp:
"""
/var/log/ubuntu-advantage.log
/var/log/ubuntu-advantage-timer.log
"""
When I run `logrotate --force /etc/logrotate.d/ubuntu-advantage-tools` with sudo
And I run `sh -c "ls /var/log/ubuntu-advantage* | sort -d"` as non-root
Then stdout matches regexp:
"""
/var/log/ubuntu-advantage.log
/var/log/ubuntu-advantage.log.1
/var/log/ubuntu-advantage-timer.log
/var/log/ubuntu-advantage-timer.log.1
"""

Examples: ubuntu release
Expand Down Expand Up @@ -744,8 +741,8 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
"""
{ "metering_timer": "notanumber", "update_messaging_timer": -10 }
"""
And I run `python3 /usr/lib/ubuntu-advantage/timer.py` with sudo
Then I verify that running `grep "Invalid value for update_messaging interval found in config." /var/log/ubuntu-advantage-timer.log` `with sudo` exits `0`
And I run `systemctl start ua-timer.service` with sudo
Then I verify that running `sh -c 'journalctl -u ua-timer.service | grep "Invalid value for update_messaging interval found in config."'` `with sudo` exits `0`
And I verify that the timer interval for `update_messaging` is `21600`
And I verify that the timer interval for `metering` is `14400`
When I create the file `/var/lib/ubuntu-advantage/jobs-status.json` with the following:
Expand Down
16 changes: 4 additions & 12 deletions features/collect_logs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
# simulate logrotate
When I run `touch /var/log/ubuntu-advantage.log.1` with sudo
When I run `touch /var/log/ubuntu-advantage.log.2.gz` with sudo
When I run `touch /var/log/ubuntu-advantage-timer.log.1` with sudo
When I run `touch /var/log/ubuntu-advantage-timer.log.2.gz` with sudo
When I run `pro collect-logs` with sudo
Then I verify that files exist matching `ua_logs.tar.gz`
When I run `tar zxf ua_logs.tar.gz` as non-root
Expand All @@ -21,9 +19,10 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
"""
build.info
cloud-id.txt
cloud-init-journal.txt
jobs-status.json
journalctl.txt
livepatch-status.txt-error
pro-journal.txt
systemd-timers.txt
ua-auto-attach.path.txt(-error)?
ua-auto-attach.service.txt(-error)?
Expand All @@ -36,9 +35,6 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
ubuntu-advantage.log.1
ubuntu-advantage.log.2.gz
ubuntu-advantage.service.txt
ubuntu-advantage-timer.log
ubuntu-advantage-timer.log.1
ubuntu-advantage-timer.log.2.gz
"""
Examples: ubuntu release
| release |
Expand All @@ -59,8 +55,6 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
# simulate logrotate
When I run `touch /var/log/ubuntu-advantage.log.1` with sudo
When I run `touch /var/log/ubuntu-advantage.log.2.gz` with sudo
When I run `touch /var/log/ubuntu-advantage-timer.log.1` with sudo
When I run `touch /var/log/ubuntu-advantage-timer.log.2.gz` with sudo
When I run `pro collect-logs` with sudo
Then I verify that files exist matching `ua_logs.tar.gz`
When I run `tar zxf ua_logs.tar.gz` as non-root
Expand All @@ -72,9 +66,10 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
"""
build.info
cloud-id.txt
cloud-init-journal.txt
jobs-status.json
journalctl.txt
livepatch-status.txt-error
pro-journal.txt
systemd-timers.txt
ua-auto-attach.path.txt(-error)?
ua-auto-attach.service.txt(-error)?
Expand All @@ -87,9 +82,6 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
ubuntu-advantage.log.1
ubuntu-advantage.log.2.gz
ubuntu-advantage.service.txt
ubuntu-advantage-timer.log
ubuntu-advantage-timer.log.1
ubuntu-advantage-timer.log.2.gz
ubuntu-esm-apps.list
ubuntu-esm-infra.list
"""
Expand Down
73 changes: 37 additions & 36 deletions features/daemon.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
Scenario Outline: daemon should run when appropriate on gcp generic lts
Given a `<release>` machine with ubuntu-advantage-tools installed
# verify its enabled, but stops itself when not configured to poll
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout matches regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout contains substring:
"""
daemon starting
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
Configured to not poll for pro license, shutting down
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
daemon ending
"""
Expand All @@ -94,7 +94,10 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
When I run `sed -i s/#DefaultMemoryAccounting=no/DefaultMemoryAccounting=yes/ /etc/systemd/system.conf` with sudo
When I run `systemctl daemon-reexec` with sudo

When I run `truncate -s 0 /var/log/ubuntu-advantage-daemon.log` with sudo
# on bionic, systemd version=237; which does not allow for log rotation + vacuum in same line e.g.
# journalctl --flush --rotate --vacuum-time=1s
When I run `journalctl --flush --rotate` with sudo
When I run `journalctl --vacuum-time=1s` with sudo
When I run `systemctl restart ubuntu-advantage.service` with sudo

# wait to get memory after it has settled/after startup checks
Expand All @@ -110,12 +113,12 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
Then on `focal`, systemd status output says memory usage is less than `13` MB
Then on `jammy`, systemd status output says memory usage is less than `14` MB

When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout matches regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout contains substring:
"""
daemon starting
"""
Then stdout does not match regexp:
Then stdout does not contain substring:
"""
daemon ending
"""
Expand Down Expand Up @@ -147,19 +150,20 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
"""

# verify detach starts it and it starts again after reboot
When I run `truncate -s 0 /var/log/ubuntu-advantage-daemon.log` with sudo
When I run `journalctl --flush --rotate` with sudo
When I run `journalctl --vacuum-time=1s` with sudo
When I run `pro detach --assume-yes` with sudo
Then I verify that running `systemctl status ubuntu-advantage.service` `with sudo` exits `0`
Then stdout matches regexp:
"""
Active: active \(running\)
"""
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout matches regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout contains substring:
"""
daemon starting
"""
Then stdout does not match regexp:
Then stdout does not contain substring:
"""
daemon ending
"""
Expand All @@ -169,12 +173,12 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
"""
Active: active \(running\)
"""
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout matches regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout contains substring:
"""
daemon starting
"""
Then stdout does not match regexp:
Then stdout does not contain substring:
"""
daemon ending
"""
Expand Down Expand Up @@ -214,16 +218,16 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
Scenario Outline: daemon should run when appropriate on azure generic lts
Given a `<release>` machine with ubuntu-advantage-tools installed
# verify its enabled, but stops itself when not configured to poll
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout matches regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout contains substring:
"""
daemon starting
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
Configured to not poll for pro license, shutting down
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
daemon ending
"""
Expand All @@ -246,16 +250,16 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
When I run `systemctl restart ubuntu-advantage.service` with sudo
# give it time to get past the initial request
When I wait `5` seconds
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout matches regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout contains substring:
"""
daemon starting
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
Cancelling polling
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
daemon ending
"""
Expand Down Expand Up @@ -283,16 +287,16 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
Scenario Outline: daemon does not start on gcp,azure generic non lts
Given a `<release>` machine with ubuntu-advantage-tools installed
When I wait `1` seconds
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout matches regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout contains substring:
"""
daemon starting
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
Not on LTS, shutting down
"""
Then stdout matches regexp:
Then stdout contains substring:
"""
daemon ending
"""
Expand All @@ -313,7 +317,6 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
Active: inactive \(dead\)
\s*Condition: start condition failed.*
"""
Then I verify that running `cat /var/log/ubuntu-advantage-daemon.log` `with sudo` exits `1`
When I attach `contract_token` with sudo
When I run `pro detach --assume-yes` with sudo
When I reboot the machine
Expand All @@ -323,7 +326,6 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
Active: inactive \(dead\)
\s*Condition: start condition failed.*
"""
Then I verify that running `cat /var/log/ubuntu-advantage-daemon.log` `with sudo` exits `1`
Examples: version
| release |
| xenial |
Expand Down Expand Up @@ -351,15 +353,13 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
Active: inactive \(dead\)
\s*Condition: start condition failed.*
"""
Then I verify that running `cat /var/log/ubuntu-advantage-daemon.log` `with sudo` exits `1`
When I reboot the machine
Then I verify that running `systemctl status ubuntu-advantage.service` `with sudo` exits `3`
Then stdout matches regexp:
"""
Active: inactive \(dead\)
\s*Condition: start condition failed.*
"""
Then I verify that running `cat /var/log/ubuntu-advantage-daemon.log` `with sudo` exits `1`
Examples: version
| release |
| xenial |
Expand All @@ -379,7 +379,8 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
log_file: /var/log/ubuntu-advantage.log
"""
When I run `pro auto-attach` with sudo
When I run `truncate -s 0 /var/log/ubuntu-advantage-daemon.log` with sudo
When I run `journalctl --flush --rotate` with sudo
When I run `journalctl --vacuum-time=1s` with sudo
When I run `systemctl restart ubuntu-advantage.service` with sudo
Then I verify that running `systemctl status ubuntu-advantage.service` `with sudo` exits `3`
Then stdout matches regexp:
Expand All @@ -388,8 +389,8 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
\s*Condition: start condition failed.*
.*ConditionPathExists=!/var/lib/ubuntu-advantage/private/machine-token.json was not met
"""
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout does not match regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout does not contain substring:
"""
daemon starting
"""
Expand All @@ -401,8 +402,8 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
\s*Condition: start condition failed.*
.*ConditionPathExists=!/var/lib/ubuntu-advantage/private/machine-token.json was not met
"""
When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
Then stdout does not match regexp:
When I run `journalctl -o cat -u ubuntu-advantage.service` with sudo
Then stdout does not contain substring:
"""
daemon starting
"""
Expand Down
6 changes: 0 additions & 6 deletions features/schemas/ua_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,6 @@
"log_file": {
"type": "string"
},
"timer_log_file": {
"type": "string"
},
"license_check_log_file": {
"type": "string"
},
"ua_config": {
"type": "object",
"properties": {
Expand Down
23 changes: 9 additions & 14 deletions lib/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@

from systemd.daemon import notify # type: ignore

from uaclient import defaults, http
from systemd import journal # type: ignore
from uaclient import http
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")
root_logger = logging.getLogger("ubuntupro")
LOG.addHandler(journal.JournalHandler(SYSLOG_IDENTIFIER="ubuntu-pro-client"))
root_logger.addHandler(
journal.JournalHandler(SYSLOG_IDENTIFIER="ubuntu-pro-client")
)


def main() -> int:
LOG.setLevel(logging.DEBUG)
cfg = UAConfig()
LOG.setLevel(logging.DEBUG)
# The ua-daemon logger should log everything to its file
# Make sure the ua-daemon logger does not generate double logging
# by propagating to the root logger
setup_journald_logging(logging.DEBUG, LOG)
# Make sure the ubuntupro.daemon logger does not generate double logging
LOG.propagate = False
root_logger.setLevel(logging.ERROR)
setup_journald_logging(logging.ERROR, logging.getLogger("ubuntupro"))

cfg = UAConfig()

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

LOG.debug("daemon starting")

Expand Down
2 changes: 0 additions & 2 deletions lib/migrate_user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ def create_new_uaclient_conffile(old_uaclient_conf):
"data_dir",
"log_file",
"security_url",
"timer_log_file",
"daemon_log_file",
):
old_val = old_uaclient_conf.get(field)
if old_val is not None and old_val != defaults.CONFIG_DEFAULTS.get(
Expand Down
Loading

0 comments on commit 279114c

Please sign in to comment.