Skip to content

Commit

Permalink
license-check: remove timer-based license-check
Browse files Browse the repository at this point in the history
  • Loading branch information
orndorffgrant committed Feb 9, 2022
1 parent d450658 commit f6879e3
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 482 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,13 @@ Current jobs being checked and executed are:
| --- | ----------- | -------- |
| update_messaging | Update MOTD and APT messages | 6 hours |
| update_status | Update UA status | 12 hours |
| gcp_auto_attach | Try to auto-attach on a GCP instance | 5 minutes |

- The `update_messaging` job makes sure that the MOTD and APT messages match the
available/enabled services on the system, showing information about available
packages or security updates. See [MOTD messages](#motd-messages).
- The `update_status` job makes sure the `ua status` command will have the latest
information even when executed by a non-root user, updating the
`/var/lib/ubuntu-advantage/status.json` file.
- The `gcp_auto_attach` job is only operable on Google Cloud Platform (GCP) generic
Ubuntu VMs without an active Ubuntu Advantage license. It polls GCP metadata every 5
minutes to discover if a license has been attached to the VM through Google Cloud and
will perform `ua auto-attach` in that case.

The timer intervals can be changed using the `ua config set` command.
```bash
Expand Down
4 changes: 0 additions & 4 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ override_dh_systemd_enable:
dh_systemd_enable -pubuntu-advantage-tools ua-reboot-cmds.service
dh_systemd_enable -pubuntu-advantage-tools ua-timer.timer
dh_systemd_enable -pubuntu-advantage-tools ua-timer.service
dh_systemd_enable -pubuntu-advantage-tools ua-license-check.timer
dh_systemd_enable -pubuntu-advantage-tools ua-license-check.service
dh_systemd_enable -pubuntu-advantage-tools ua-license-check.path
dh_systemd_enable -pubuntu-advantage-tools ubuntu-advantage.service

override_dh_systemd_start:
dh_systemd_start -pubuntu-advantage-tools ua-timer.timer
dh_systemd_start -pubuntu-advantage-tools ua-license-check.path
dh_systemd_start -pubuntu-advantage-tools ubuntu-advantage.service

override_dh_auto_install:
Expand Down
37 changes: 24 additions & 13 deletions debian/ubuntu-advantage-tools.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ OLD_CLIENT_FIPS_PPA="private-ppa.launchpad.net/ubuntu-advantage/fips/ubuntu"
UA_TIMER_NAME="ua-timer.timer"
OLD_MESSAGING_TIMER="ua-messaging.timer"
OLD_MESSAGING_TIMER_MASKED_LOCATION="/etc/systemd/system/timers.target.wants/$OLD_MESSAGING_TIMER"
OLD_LICENSE_CHECK_PATH="ua-license-check.path"
OLD_LICENSE_CHECK_PATH_MASKED_LOCATION="/etc/systemd/system/multi-user.target.wants/$OLD_LICENSE_CHECK_PATH"

ESM_APT_PREF_FILE_TRUSTY="$APT_PREFERENCES_DIR/ubuntu-esm-trusty"
ESM_INFRA_OLD_APT_PREF_FILE_TRUSTY="$APT_PREFERENCES_DIR/ubuntu-esm-infra-trusty"
Expand All @@ -49,7 +51,7 @@ SYSTEMD_HELPER_ENABLED_AUTO_ATTACH_DSH="/var/lib/systemd/deb-systemd-helper-enab
SYSTEMD_HELPER_ENABLED_WANTS_LINK="/var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/ua-auto-attach.service"

REBOOT_CMD_MARKER_FILE="/var/lib/ubuntu-advantage/marker-reboot-cmds-required"
LICENSE_CHECK_MARKER_FILE="/var/lib/ubuntu-advantage/marker-license-check"
OLD_LICENSE_CHECK_MARKER_FILE="/var/lib/ubuntu-advantage/marker-license-check"

MACHINE_TOKEN_FILE="/var/lib/ubuntu-advantage/private/machine-token.json"

Expand Down Expand Up @@ -308,14 +310,9 @@ notify_wrong_fips_metapackage_on_cloud() {
fi
}

enable_periodic_license_check() {
cloud_id=$(cloud-id 2>/dev/null) || cloud_id=""
if echo "$cloud_id" | grep -q "^gce"; then
if check_is_lts "${UBUNTU_CODENAME}"; then
if [ ! -f $MACHINE_TOKEN_FILE ]; then
touch $LICENSE_CHECK_MARKER_FILE
fi
fi
rm_old_license_check_marker() {
if [ -f $OLD_LICENSE_CHECK_MARKER_FILE ]; then
rm -f $OLD_LICENSE_CHECK_MARKER_FILE
fi
}

Expand Down Expand Up @@ -355,10 +352,24 @@ remove_old_systemd_timers() {
# Since we actually want to remove this service from now on
# we have replicated that behavior here
if [ -L $OLD_MESSAGING_TIMER_MASKED_LOCATION ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge ua-messaging.timer > /dev/null || true
deb-systemd-helper unmask ua-messaging.timer > /dev/null || true
deb-systemd-helper purge ua-messaging.timer > /dev/null || true
deb-systemd-helper unmask ua-messaging.timer > /dev/null || true
fi
if [ -L $OLD_LICENSE_CHECK_PATH_MASKED_LOCATION ]; then
if [ -d /run/systemd/system ]; then
# If the old ua-license-check.timer was running during upgrade
# then it will be in a failed state because the files were removed
# The failed state is ephemeral and only needs to be cleared if
# it is there so that the system doesn't say it is degraded.
# If the old timer was not running, then this is a noop.
systemctl --system daemon-reload > /dev/null || true
systemctl reset-failed ua-license-check.timer > /dev/null 2>&1 || true
# In rare race-condition scenarios, the service can also get into
# the same failed state.
systemctl reset-failed ua-license-check.service > /dev/null 2>&1 || true
fi
deb-systemd-helper purge ua-license-check.path > /dev/null || true
deb-systemd-helper unmask ua-license-check.path > /dev/null || true
fi
}

Expand Down Expand Up @@ -444,7 +455,7 @@ case "$1" in
fi
fi
mark_reboot_for_fips_pro
enable_periodic_license_check
rm_old_license_check_marker
disable_new_timer_if_old_timer_already_disabled $PREVIOUS_PKG_VER
remove_old_systemd_timers
;;
Expand Down
3 changes: 0 additions & 3 deletions features/attached_commands.feature
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,6 @@ Feature: Command behaviour when attached to an UA subscription
ua-auto-attach.path.txt(-error)?
ua-auto-attach.service.txt(-error)?
uaclient.conf
ua-license-check.path.txt
ua-license-check.service.txt
ua-license-check.timer.txt
ua-reboot-cmds.service.txt
ua-status.json
ua-timer.service.txt
Expand Down
122 changes: 0 additions & 122 deletions features/license_check.feature

This file was deleted.

3 changes: 0 additions & 3 deletions features/unattached_commands.feature
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,6 @@ Feature: Command behaviour when unattached
ua-auto-attach.path.txt-error
ua-auto-attach.service.txt-error
uaclient.conf
ua-license-check.path.txt
ua-license-check.service.txt
ua-license-check.timer.txt
ua-reboot-cmds.service.txt
ua-status.json
ua-timer.service.txt
Expand Down
28 changes: 0 additions & 28 deletions lib/license_check.py

This file was deleted.

57 changes: 57 additions & 0 deletions sru/release-27.7/cleanup_failed_old_license_check_timer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
series=$1
deb=$2

set -e

GREEN="\e[32m"
RED="\e[31m"
BLUE="\e[36m"
END_COLOR="\e[0m"

function cleanup {
lxc delete test --force
}

function on_err {
echo -e "${RED}Test Failed${END_COLOR}"
cleanup
exit 1
}

trap on_err ERR

function print_and_run_cmd {
echo -e "${BLUE}Running:${END_COLOR}" "$@"
echo -e "${BLUE}Output:${END_COLOR}"
lxc exec test -- sh -c "$@"
echo
}

function explanatory_message {
echo -e "${BLUE}$@${END_COLOR}"
}

explanatory_message "Starting $series container and updating ubuntu-advantage-tools"
lxc launch ubuntu-daily:$series test >/dev/null 2>&1
sleep 10

lxc exec test -- apt-get update >/dev/null
lxc exec test -- apt-get install -y ubuntu-advantage-tools locate >/dev/null
print_and_run_cmd "ua version"
explanatory_message "Start the timer to make sure its state is fixed on upgrade"
print_and_run_cmd "systemctl start ua-license-check.timer"
print_and_run_cmd "systemctl status ua-license-check.timer"

explanatory_message "installing new version of ubuntu-advantage-tools from local copy"
lxc file push $deb test/tmp/ua.deb > /dev/null
print_and_run_cmd "dpkg -i /tmp/ua.deb"
print_and_run_cmd "ua version"

explanatory_message "systemd should not list the timer as failed"
print_and_run_cmd "systemctl status ua-license-check.timer || true"
print_and_run_cmd "systemctl --no-pager | grep ua-license-check || true"
result=$(lxc exec test -- sh -c "systemctl --no-pager | grep ua-license-check.timer" || true)
echo "$result" | grep -qv "ua-license-check.timer\s\+not-found\s\+failed"

echo -e "${GREEN}Test Passed${END_COLOR}"
cleanup
57 changes: 57 additions & 0 deletions sru/release-27.7/remove_old_license_check_timer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
series=$1
deb=$2

set -e

GREEN="\e[32m"
RED="\e[31m"
BLUE="\e[36m"
END_COLOR="\e[0m"

function cleanup {
lxc delete test --force
}

function on_err {
echo -e "${RED}Test Failed${END_COLOR}"
cleanup
exit 1
}

trap on_err ERR

function print_and_run_cmd {
echo -e "${BLUE}Running:${END_COLOR}" "$@"
echo -e "${BLUE}Output:${END_COLOR}"
lxc exec test -- sh -c "$@"
echo
}

function explanatory_message {
echo -e "${BLUE}$@${END_COLOR}"
}

explanatory_message "Starting $series container and updating ubuntu-advantage-tools"
lxc launch ubuntu-daily:$series test >/dev/null 2>&1
sleep 10

lxc exec test -- apt-get update >/dev/null
lxc exec test -- apt-get install -y ubuntu-advantage-tools locate >/dev/null
print_and_run_cmd "ua version"
explanatory_message "Note where all license-check artifacts are before upgrade"
print_and_run_cmd "updatedb"
print_and_run_cmd "locate ua-license-check"

explanatory_message "installing new version of ubuntu-advantage-tools from local copy"
lxc file push $deb test/tmp/ua.deb > /dev/null
print_and_run_cmd "dpkg -i /tmp/ua.deb"
print_and_run_cmd "ua version"

explanatory_message "license-check artifacts should be gone"
print_and_run_cmd "updatedb"
print_and_run_cmd "locate ua-license-check || true"
result=$(lxc exec test -- locate ua-license-check || true)
test -z "$result"

echo -e "${GREEN}Test Passed${END_COLOR}"
cleanup
Loading

0 comments on commit f6879e3

Please sign in to comment.