Merge ~orndorffgrant/ubuntu/+source/ubuntu-advantage-tools:upload-27.11.3-kinetic into ubuntu/+source/ubuntu-advantage-tools:ubuntu/devel

Proposed by Grant Orndorff
Status: Merged
Merged at revision: 35d791d5611a4d10674b8c0934daad67859c2ec1
Proposed branch: ~orndorffgrant/ubuntu/+source/ubuntu-advantage-tools:upload-27.11.3-kinetic
Merge into: ubuntu/+source/ubuntu-advantage-tools:ubuntu/devel
Diff against target: 1047 lines (+302/-105)
27 files modified
apt-hook/20apt-esm-hook.conf (+1/-1)
apt-hook/json-hook.cc (+15/-5)
debian/changelog (+13/-0)
debian/ubuntu-advantage-tools.postinst (+32/-0)
features/api_full_auto_attach.feature (+1/-1)
features/apt_messages.feature (+88/-23)
features/cloud_pro_clone.feature (+0/-1)
features/daemon.feature (+3/-2)
features/docker.feature (+3/-1)
features/environment.py (+4/-4)
features/ubuntu_pro.feature (+3/-0)
features/unattached_commands.feature (+5/-6)
integration-requirements.txt (+1/-1)
uaclient/actions.py (+24/-16)
uaclient/cli.py (+9/-0)
uaclient/config.py (+12/-0)
uaclient/defaults.py (+2/-2)
uaclient/jobs/update_messaging.py (+17/-27)
uaclient/messages.py (+0/-4)
uaclient/system.py (+13/-0)
uaclient/tests/test_actions.py (+36/-1)
uaclient/tests/test_cli_config_set.py (+2/-1)
uaclient/tests/test_cli_config_show.py (+1/-0)
uaclient/tests/test_cli_config_unset.py (+1/-1)
uaclient/tests/test_config.py (+4/-1)
uaclient/tests/test_version.py (+5/-2)
uaclient/version.py (+7/-5)
Reviewer Review Type Date Requested Status
Robie Basak ubuntu-sru Approve
Paride Legovini (community) Approve
Canonical Server Reporter Pending
Review via email: mp+431701@code.launchpad.net

Description of the change

This is release 27.11.3 of ubuntu-advantage-tools.

You can find the description of changes in the overall SRU bug here: https://bugs.launchpad.net/ubuntu/+source/ubuntu-advantage-tools/+bug/1993006

To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote :

SRU review.

I flagged the entire "apt news" concept as needing leadership approval in https://bugs.launchpad.net/ubuntu/+source/ubuntu-advantage-tools/+bug/1992026/comments/17, and I don't think I should accept this into proposed until that is resolved.

Apart from that this looks fine from an SRU perspective, from a quick review to look for significant changes that would impact the system and/or existing users (I've not reviewed every line). I made a couple of comments inline, but I don't think we need to block on them.

Revision history for this message
Grant Orndorff (orndorffgrant) wrote :

Thanks racb!

I responded to the inline comments - I agree with them and have added bugs to our github to follow up with them in a future release.

Ack to the "apt news" status and thanks for flagging that formally on the bug. I agree that we can't move forward until that is fully resolved.

Revision history for this message
Paride Legovini (paride) wrote :

Following-up to my previous review: the new changes LGTM. I'm proceeding with the uploads.

review: Approve
Revision history for this message
Robie Basak (racb) wrote :

"apt news" resolved by https://bugs.launchpad.net/ubuntu/+source/ubuntu-advantage-tools/+bug/1992026/comments/18. Nothing else outstanding, so SRU +1.

review: Approve (ubuntu-sru)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/apt-hook/20apt-esm-hook.conf b/apt-hook/20apt-esm-hook.conf
index 0cc6823..07c3362 100644
--- a/apt-hook/20apt-esm-hook.conf
+++ b/apt-hook/20apt-esm-hook.conf
@@ -10,6 +10,6 @@ APT::Install::Pre-Invoke {
10 "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-hook ] || /usr/lib/ubuntu-advantage/apt-esm-hook pre-invoke || true";10 "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-hook ] || /usr/lib/ubuntu-advantage/apt-esm-hook pre-invoke || true";
11};11};
1212
13AptCli::Hooks::Upgrade {13binary::apt::AptCli::Hooks::Upgrade {
14 "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook || true";14 "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook || true";
15};15};
diff --git a/apt-hook/json-hook.cc b/apt-hook/json-hook.cc
index 0efaa81..16042f8 100644
--- a/apt-hook/json-hook.cc
+++ b/apt-hook/json-hook.cc
@@ -257,23 +257,33 @@ int run()
257257
258 json_object_put(hello_req.root_msg);258 json_object_put(hello_req.root_msg);
259259
260 jsonrpc_request stats_req;260 jsonrpc_request hook_req;
261 success = read_jsonrpc_request(socket_in, stats_req);261 success = read_jsonrpc_request(socket_in, hook_req);
262 if (!success) {262 if (!success) {
263 std::cerr << "ua-hook: failed to read hook msg" << std::endl;263 std::cerr << "ua-hook: failed to read hook msg" << std::endl;
264 return 0;264 return 0;
265 }265 }
266 if (stats_req.method == "org.debian.apt.hooks.install.statistics") {266 if (hook_req.method == "org.debian.apt.hooks.install.statistics") {
267 security_package_counts counts;267 security_package_counts counts;
268 success = count_security_packages_from_apt_stats_json(stats_req.params, counts);268 success = count_security_packages_from_apt_stats_json(hook_req.params, counts);
269 if (success) {269 if (success) {
270 std::string message = create_count_message(counts);270 std::string message = create_count_message(counts);
271 if (message != "") {271 if (message != "") {
272 std::cout << message << std::endl;272 std::cout << message << std::endl;
273 }273 }
274 }274 }
275 } else if (hook_req.method == "org.debian.apt.hooks.install.pre-prompt") {
276 std::ifstream apt_news_flag_file("/var/lib/ubuntu-advantage/flags/show-apt-news");
277 if (apt_news_flag_file.is_open()) {
278 std::cout << "#" << std::endl;
279 std::cout << "# News about significant security updates, features and services will" << std::endl;
280 std::cout << "# appear here to raise awareness and perhaps tease /r/Linux ;)" << std::endl;
281 std::cout << "# Use 'pro config set apt_news=false' to hide this and future APT news." << std::endl;
282 std::cout << "#" << std::endl;
283 apt_news_flag_file.close();
284 }
275 }285 }
276 json_object_put(stats_req.root_msg);286 json_object_put(hook_req.root_msg);
277287
278 jsonrpc_request bye_req;288 jsonrpc_request bye_req;
279 success = read_jsonrpc_request(socket_in, bye_req);289 success = read_jsonrpc_request(socket_in, bye_req);
diff --git a/debian/changelog b/debian/changelog
index a5acfc4..e0d5868 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,16 @@
1ubuntu-advantage-tools (27.11.3~22.10.1) kinetic; urgency=medium
2
3 * New upstream release 27.11.3: (LP: #1993006)
4 - d/postinst: remove the Ubuntu Pro beta apt message and set up the
5 configurable flag for "APT news" instead
6 - collect-logs: do not fail if a file cannot be read (LP: #1991858)
7 - config: add a flag to disable "APT news" (LP: 1992026)
8 - messaging: add announcement of "APT news" to apt output
9 - messaging: only show "APT news" when using apt binary (GH: #2288)
10 - version: use /run instead of /tmp for version file (GH: #2294)
11
12 -- Grant Orndorff <grant.orndorff@canonical.com> Fri, 14 Oct 2022 16:55:27 -0400
13
1ubuntu-advantage-tools (27.11.2~22.10.1) kinetic; urgency=medium14ubuntu-advantage-tools (27.11.2~22.10.1) kinetic; urgency=medium
215
3 * New upstream release 27.11.2: (LP: #1991173)16 * New upstream release 27.11.2: (LP: #1991173)
diff --git a/debian/ubuntu-advantage-tools.postinst b/debian/ubuntu-advantage-tools.postinst
index 4a677fc..73b914b 100644
--- a/debian/ubuntu-advantage-tools.postinst
+++ b/debian/ubuntu-advantage-tools.postinst
@@ -57,6 +57,13 @@ OLD_LICENSE_CHECK_MARKER_FILE="/var/lib/ubuntu-advantage/marker-license-check"
57MACHINE_TOKEN_FILE="/var/lib/ubuntu-advantage/private/machine-token.json"57MACHINE_TOKEN_FILE="/var/lib/ubuntu-advantage/private/machine-token.json"
58PUBLIC_MACHINE_TOKEN_FILE="/var/lib/ubuntu-advantage/machine-token.json"58PUBLIC_MACHINE_TOKEN_FILE="/var/lib/ubuntu-advantage/machine-token.json"
5959
60UA_MESSAGES_DIR="/var/lib/ubuntu-advantage/messages"
61APT_ESM_MESSAGE_FILE="$UA_MESSAGES_DIR/apt-pre-invoke-esm-service-status"
62ESM_APPS_APT_MSG_FILES="$UA_MESSAGES_DIR/apt-pre-invoke-no-packages-apps.tmpl $UA_MESSAGES_DIR/apt-pre-invoke-no-packages-apps $UA_MESSAGES_DIR/apt-pre-invoke-packages-apps.tmpl $UA_MESSAGES_DIR/apt-pre-invoke-packages-apps"
63UA_FLAGS_DIR="/var/lib/ubuntu-advantage/flags"
64APT_NEWS_FLAG_FILE="$UA_FLAGS_DIR/show-apt-news"
65
66TMP_CANDIDATE_CACHE_PATH="/tmp/ubuntu-advantage/candidate-version"
6067
61# Rename apt config files for ua services removing ubuntu release names68# Rename apt config files for ua services removing ubuntu release names
62redact_ubuntu_release_from_ua_apt_filenames() {69redact_ubuntu_release_from_ua_apt_filenames() {
@@ -384,6 +391,29 @@ machine_token_file.write(content=content)
384"391"
385}392}
386393
394migrate_ubuntu_pro_beta_banner() {
395 PREVIOUS_PKG_VER=$1
396 # This only shipped in 27.11.2~
397 if dpkg --compare-versions "$PREVIOUS_PKG_VER" ge "27.11.2~" \
398 && dpkg --compare-versions "$PREVIOUS_PKG_VER" lt "27.11.3~"; then
399 # if the banner was present, remove it and add the new flag file which is configurable
400 if [ -f $APT_ESM_MESSAGE_FILE ]; then
401 if cat $APT_ESM_MESSAGE_FILE | grep -q "Try Ubuntu Pro beta"; then
402 rm -f $APT_ESM_MESSAGE_FILE
403 rm -f $ESM_APPS_APT_MSG_FILES
404 mkdir -p $UA_FLAGS_DIR
405 touch $APT_NEWS_FLAG_FILE
406 fi
407 fi
408 fi
409}
410
411cleanup_candidate_version_stamp_permissions() {
412 if [ -f $TMP_CANDIDATE_CACHE_PATH ]; then
413 rm -f $TMP_CANDIDATE_CACHE_PATH
414 fi
415}
416
387case "$1" in417case "$1" in
388 configure)418 configure)
389 PREVIOUS_PKG_VER=$2419 PREVIOUS_PKG_VER=$2
@@ -462,6 +492,8 @@ case "$1" in
462 if [ -f $MACHINE_TOKEN_FILE ] && [ ! -f $PUBLIC_MACHINE_TOKEN_FILE ]; then492 if [ -f $MACHINE_TOKEN_FILE ] && [ ! -f $PUBLIC_MACHINE_TOKEN_FILE ]; then
463 create_public_machine_token_file493 create_public_machine_token_file
464 fi494 fi
495 migrate_ubuntu_pro_beta_banner $PREVIOUS_PKG_VER
496 cleanup_candidate_version_stamp_permissions
465 ;;497 ;;
466esac498esac
467499
diff --git a/features/api_full_auto_attach.feature b/features/api_full_auto_attach.feature
index 240e06f..c65fca5 100644
--- a/features/api_full_auto_attach.feature
+++ b/features/api_full_auto_attach.feature
@@ -27,7 +27,7 @@ Feature: Full Auto-Attach Endpoint
27 """27 """
28 Then stdout matches regexp:28 Then stdout matches regexp:
29 """29 """
30 livepatch +yes +disabled +Canonical Livepatch service30 livepatch +yes +(disabled|n/a) +Canonical Livepatch service
31 """31 """
32 Examples:32 Examples:
33 | release |33 | release |
diff --git a/features/apt_messages.feature b/features/apt_messages.feature
index 27d67cb..b03524f 100644
--- a/features/apt_messages.feature
+++ b/features/apt_messages.feature
@@ -9,7 +9,7 @@ Feature: APT Messages
9 When I run `apt-get upgrade -y` with sudo9 When I run `apt-get upgrade -y` with sudo
1010
11 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo11 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo
12 When I run `apt-get upgrade -y` with sudo12 When I run `apt upgrade -y` with sudo
13 Then stdout matches regexp:13 Then stdout matches regexp:
14 """14 """
15 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.15 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -18,7 +18,7 @@ Feature: APT Messages
18 """18 """
1919
20 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo20 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo
21 When I run `apt-get upgrade -y` with sudo21 When I run `apt upgrade -y` with sudo
22 Then stdout matches regexp:22 Then stdout matches regexp:
23 """23 """
24 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.24 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -27,7 +27,7 @@ Feature: APT Messages
27 """27 """
2828
29 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo29 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo
30 When I run `apt-get upgrade -y` with sudo30 When I run `apt upgrade -y` with sudo
31 Then stdout matches regexp:31 Then stdout matches regexp:
32 """32 """
33 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.33 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -37,7 +37,7 @@ Feature: APT Messages
3737
38 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo38 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo
39 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo39 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo
40 When I run `apt-get upgrade -y` with sudo40 When I run `apt upgrade -y` with sudo
41 Then stdout matches regexp:41 Then stdout matches regexp:
42 """42 """
43 4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.43 4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -47,7 +47,7 @@ Feature: APT Messages
4747
48 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo48 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo
49 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo49 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo
50 When I run `apt-get upgrade -y` with sudo50 When I run `apt upgrade -y` with sudo
51 Then stdout matches regexp:51 Then stdout matches regexp:
52 """52 """
53 3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.53 3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -57,7 +57,7 @@ Feature: APT Messages
5757
58 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo58 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo
59 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo59 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo
60 When I run `apt-get upgrade -y` with sudo60 When I run `apt upgrade -y` with sudo
61 Then stdout matches regexp:61 Then stdout matches regexp:
62 """62 """
63 3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.63 3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -68,7 +68,7 @@ Feature: APT Messages
68 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo68 When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo
69 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo69 When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo
70 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo70 When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo
71 When I run `apt-get upgrade -y` with sudo71 When I run `apt upgrade -y` with sudo
72 Then stdout matches regexp:72 Then stdout matches regexp:
73 """73 """
74 5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.74 5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -76,7 +76,7 @@ Feature: APT Messages
7676
77 """77 """
7878
79 When I run `apt-get upgrade -y` with sudo79 When I run `apt upgrade -y` with sudo
80 Then stdout matches regexp:80 Then stdout matches regexp:
81 """81 """
82 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.82 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
@@ -106,37 +106,52 @@ Feature: APT Messages
106 When I run `apt-get -y upgrade` with sudo106 When I run `apt-get -y upgrade` with sudo
107 When I run `apt-get -y autoremove` with sudo107 When I run `apt-get -y autoremove` with sudo
108 When I run `pro refresh messages` with sudo108 When I run `pro refresh messages` with sudo
109 When I run `apt-get upgrade` with sudo109 When I run `apt upgrade` with sudo
110 Then stdout matches regexp:110 Then stdout matches regexp:
111 """111 """
112 Reading package lists...112 Reading package lists...
113 Building dependency tree...113 Building dependency tree...
114 Reading state information...114 Reading state information...
115 Calculating upgrade...115 Calculating upgrade...
116 #
117 # News about significant security updates, features and services will
118 # appear here to raise awareness and perhaps tease /r/Linux ;\)
119 # Use 'pro config set apt_news=false' to hide this and future APT news\.
120 #
116 The following security updates require Ubuntu Pro with 'esm-infra' enabled:121 The following security updates require Ubuntu Pro with 'esm-infra' enabled:
117 .*122 .*
118 Learn more about Ubuntu Pro for 16\.04 at https:\/\/ubuntu\.com\/16-04123 Learn more about Ubuntu Pro for 16\.04 at https:\/\/ubuntu\.com\/16-04
119 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\.124 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\.
120 """125 """
121 When I attach `contract_token` with sudo126 When I attach `contract_token` with sudo
122 When I run `apt-get upgrade --dry-run` with sudo127 When I run `apt upgrade --dry-run` with sudo
123 Then stdout matches regexp:128 Then stdout matches regexp:
124 """129 """
125 Reading package lists...130 Reading package lists...
126 Building dependency tree...131 Building dependency tree...
127 Reading state information...132 Reading state information...
128 Calculating upgrade...133 Calculating upgrade...
134 #
135 # News about significant security updates, features and services will
136 # appear here to raise awareness and perhaps tease /r/Linux ;\)
137 # Use 'pro config set apt_news=false' to hide this and future APT news\.
138 #
129 The following packages will be upgraded:139 The following packages will be upgraded:
130 """140 """
131 When I update contract to use `effectiveTo` as `days=+2`141 When I update contract to use `effectiveTo` as `days=+2`
132 When I run `pro refresh messages` with sudo142 When I run `pro refresh messages` with sudo
133 When I run `apt-get upgrade --dry-run` with sudo143 When I run `apt upgrade --dry-run` with sudo
134 Then stdout matches regexp:144 Then stdout matches regexp:
135 """145 """
136 Reading package lists...146 Reading package lists...
137 Building dependency tree...147 Building dependency tree...
138 Reading state information...148 Reading state information...
139 Calculating upgrade...149 Calculating upgrade...
150 #
151 # News about significant security updates, features and services will
152 # appear here to raise awareness and perhaps tease /r/Linux ;\)
153 # Use 'pro config set apt_news=false' to hide this and future APT news\.
154 #
140155
141 CAUTION: Your Ubuntu Pro subscription will expire in 2 days.156 CAUTION: Your Ubuntu Pro subscription will expire in 2 days.
142 Renew your subscription at https:\/\/ubuntu.com\/pro to ensure continued security157 Renew your subscription at https:\/\/ubuntu.com\/pro to ensure continued security
@@ -146,13 +161,18 @@ Feature: APT Messages
146 """161 """
147 When I update contract to use `effectiveTo` as `days=-3`162 When I update contract to use `effectiveTo` as `days=-3`
148 When I run `pro refresh messages` with sudo163 When I run `pro refresh messages` with sudo
149 When I run `apt-get upgrade --dry-run` with sudo164 When I run `apt upgrade --dry-run` with sudo
150 Then stdout matches regexp:165 Then stdout matches regexp:
151 """166 """
152 Reading package lists...167 Reading package lists...
153 Building dependency tree...168 Building dependency tree...
154 Reading state information...169 Reading state information...
155 Calculating upgrade...170 Calculating upgrade...
171 #
172 # News about significant security updates, features and services will
173 # appear here to raise awareness and perhaps tease /r/Linux ;\)
174 # Use 'pro config set apt_news=false' to hide this and future APT news\.
175 #
156176
157 CAUTION: Your Ubuntu Pro subscription expired on \d+ \w+ \d+.177 CAUTION: Your Ubuntu Pro subscription expired on \d+ \w+ \d+.
158 Renew your subscription at https:\/\/ubuntu.com\/pro to ensure continued security178 Renew your subscription at https:\/\/ubuntu.com\/pro to ensure continued security
@@ -163,13 +183,18 @@ Feature: APT Messages
163 """183 """
164 When I update contract to use `effectiveTo` as `days=-20`184 When I update contract to use `effectiveTo` as `days=-20`
165 When I run `pro refresh messages` with sudo185 When I run `pro refresh messages` with sudo
166 When I run `apt-get upgrade --dry-run` with sudo186 When I run `apt upgrade --dry-run` with sudo
167 Then stdout matches regexp:187 Then stdout matches regexp:
168 """188 """
169 Reading package lists...189 Reading package lists...
170 Building dependency tree...190 Building dependency tree...
171 Reading state information...191 Reading state information...
172 Calculating upgrade...192 Calculating upgrade...
193 #
194 # News about significant security updates, features and services will
195 # appear here to raise awareness and perhaps tease /r/Linux ;\)
196 # Use 'pro config set apt_news=false' to hide this and future APT news\.
197 #
173198
174 \*Your Ubuntu Pro subscription has EXPIRED\*199 \*Your Ubuntu Pro subscription has EXPIRED\*
175 The following security updates require Ubuntu Pro with 'esm-infra' enabled:200 The following security updates require Ubuntu Pro with 'esm-infra' enabled:
@@ -179,13 +204,18 @@ Feature: APT Messages
179 The following packages will be upgraded:204 The following packages will be upgraded:
180 """205 """
181 When I run `apt-get upgrade -y` with sudo206 When I run `apt-get upgrade -y` with sudo
182 When I run `apt-get upgrade` with sudo207 When I run `apt upgrade` with sudo
183 Then stdout matches regexp:208 Then stdout matches regexp:
184 """209 """
185 Reading package lists...210 Reading package lists...
186 Building dependency tree...211 Building dependency tree...
187 Reading state information...212 Reading state information...
188 Calculating upgrade...213 Calculating upgrade...
214 #
215 # News about significant security updates, features and services will
216 # appear here to raise awareness and perhaps tease /r/Linux ;\)
217 # Use 'pro config set apt_news=false' to hide this and future APT news\.
218 #
189219
190 \*Your Ubuntu Pro subscription has EXPIRED\*220 \*Your Ubuntu Pro subscription has EXPIRED\*
191 Renew your service at https:\/\/ubuntu.com\/pro221 Renew your service at https:\/\/ubuntu.com\/pro
@@ -194,13 +224,18 @@ Feature: APT Messages
194 """224 """
195 When I run `pro detach --assume-yes` with sudo225 When I run `pro detach --assume-yes` with sudo
196 When I run `pro refresh messages` with sudo226 When I run `pro refresh messages` with sudo
197 When I run `apt-get upgrade` with sudo227 When I run `apt upgrade` with sudo
198 Then stdout matches regexp:228 Then stdout matches regexp:
199 """229 """
200 Reading package lists...230 Reading package lists...
201 Building dependency tree...231 Building dependency tree...
202 Reading state information...232 Reading state information...
203 Calculating upgrade...233 Calculating upgrade...
234 #
235 # News about significant security updates, features and services will
236 # appear here to raise awareness and perhaps tease /r/Linux ;\)
237 # Use 'pro config set apt_news=false' to hide this and future APT news\.
238 #
204 Receive additional future security updates with Ubuntu Pro.239 Receive additional future security updates with Ubuntu Pro.
205 Learn more about Ubuntu Pro for 16\.04 at https:\/\/ubuntu\.com\/16-04240 Learn more about Ubuntu Pro for 16\.04 at https:\/\/ubuntu\.com\/16-04
206 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\.241 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\.
@@ -218,31 +253,48 @@ Feature: APT Messages
218 When I run `apt-get -y autoremove` with sudo253 When I run `apt-get -y autoremove` with sudo
219 When I run `apt-get install hello` with sudo254 When I run `apt-get install hello` with sudo
220 When I run `pro refresh messages` with sudo255 When I run `pro refresh messages` with sudo
221 When I run `apt-get upgrade` with sudo256 When I run `apt upgrade` with sudo
222 Then I will see the following on stdout:257 Then I will see the following on stdout:
223 """258 """
224 Reading package lists...259 Reading package lists...
225 Building dependency tree...260 Building dependency tree...
226 Reading state information...261 Reading state information...
227 Calculating upgrade...262 Calculating upgrade...
228 Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.263 #
229 Learn more at https://ubuntu.com/pro264 # News about significant security updates, features and services will
265 # appear here to raise awareness and perhaps tease /r/Linux ;)
266 # Use 'pro config set apt_news=false' to hide this and future APT news.
267 #
230 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.268 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
231 """269 """
270 When I run `apt-get upgrade` with sudo
271 Then stdout does not match regexp:
272 """
273 #
274 # News about significant security updates, features and services will
275 # appear here to raise awareness and perhaps tease /r/Linux ;\)
276 # Use 'pro config set apt_news=false' to hide this and future APT news\.
277 #
278 """
232 When I attach `contract_token` with sudo279 When I attach `contract_token` with sudo
233 When I run `apt-get upgrade --dry-run` with sudo280 When I run `apt upgrade --dry-run` with sudo
234 Then stdout matches regexp:281 Then stdout matches regexp:
235 """282 """
236 Reading package lists...283 Reading package lists...
237 Building dependency tree...284 Building dependency tree...
238 Reading state information...285 Reading state information...
239 Calculating upgrade...286 Calculating upgrade...
287 #
288 # News about significant security updates, features and services will
289 # appear here to raise awareness and perhaps tease /r/Linux ;\)
290 # Use 'pro config set apt_news=false' to hide this and future APT news\.
291 #
240 The following packages will be upgraded:292 The following packages will be upgraded:
241 hello293 hello
242 """294 """
243# When I update contract to use `effectiveTo` as `days=-20`295# When I update contract to use `effectiveTo` as `days=-20`
244# When I run `pro refresh messages` with sudo296# When I run `pro refresh messages` with sudo
245# When I run `apt-get upgrade --dry-run` with sudo297# When I run `apt upgrade --dry-run` with sudo
246# Then stdout matches regexp:298# Then stdout matches regexp:
247# """299# """
248# Reading package lists...300# Reading package lists...
@@ -260,17 +312,30 @@ Feature: APT Messages
260 When I run `apt-get upgrade -y` with sudo312 When I run `apt-get upgrade -y` with sudo
261 When I run `pro detach --assume-yes` with sudo313 When I run `pro detach --assume-yes` with sudo
262 When I run `pro refresh messages` with sudo314 When I run `pro refresh messages` with sudo
263 When I run `apt-get upgrade` with sudo315 When I run `apt upgrade` with sudo
264 Then stdout matches regexp:316 Then stdout matches regexp:
265 """317 """
266 Reading package lists...318 Reading package lists...
267 Building dependency tree...319 Building dependency tree...
268 Reading state information...320 Reading state information...
269 Calculating upgrade...321 Calculating upgrade...
270 Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.322 #
271 Learn more at https:\/\/ubuntu.com\/pro323 # News about significant security updates, features and services will
324 # appear here to raise awareness and perhaps tease /r/Linux ;\)
325 # Use 'pro config set apt_news=false' to hide this and future APT news\.
326 #
272 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\.327 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\.
273 """328 """
329 When I run `pro config set apt_news=false` with sudo
330 And I run `apt upgrade` with sudo
331 Then stdout does not match regexp:
332 """
333 #
334 # News about significant security updates, features and services will
335 # appear here to raise awareness and perhaps tease /r/Linux ;\)
336 # Use 'pro config set apt_news=false' to hide this and future APT news\.
337 #
338 """
274 Examples: ubuntu release339 Examples: ubuntu release
275 | release |340 | release |
276 | focal |341 | focal |
diff --git a/features/cloud_pro_clone.feature b/features/cloud_pro_clone.feature
index f08bff0..48aa17a 100644
--- a/features/cloud_pro_clone.feature
+++ b/features/cloud_pro_clone.feature
@@ -2,7 +2,6 @@ Feature: Creating golden images based on Cloud Ubuntu Pro instances
22
3 @series.lts3 @series.lts
4 @uses.config.machine_type.aws.pro4 @uses.config.machine_type.aws.pro
5 @uses.config.machine_type.azure.pro
6 @uses.config.machine_type.gcp.pro5 @uses.config.machine_type.gcp.pro
7 Scenario Outline: Create a Pro fips-updates image and launch6 Scenario Outline: Create a Pro fips-updates image and launch
8 Given a `<release>` machine with ubuntu-advantage-tools installed7 Given a `<release>` machine with ubuntu-advantage-tools installed
diff --git a/features/daemon.feature b/features/daemon.feature
index 593c86d..0b33c37 100644
--- a/features/daemon.feature
+++ b/features/daemon.feature
@@ -104,9 +104,10 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary
104 """104 """
105 Active: active \(running\)105 Active: active \(running\)
106 """106 """
107 Then on `xenial`, systemd status output says memory usage is less than `14` MB107 # TODO find out what caused memory to go up, try to lower it again
108 Then on `xenial`, systemd status output says memory usage is less than `15` MB
108 Then on `bionic`, systemd status output says memory usage is less than `13` MB109 Then on `bionic`, systemd status output says memory usage is less than `13` MB
109 Then on `focal`, systemd status output says memory usage is less than `11` MB110 Then on `focal`, systemd status output says memory usage is less than `12` MB
110 Then on `jammy`, systemd status output says memory usage is less than `12` MB111 Then on `jammy`, systemd status output says memory usage is less than `12` MB
111112
112 When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo113 When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo
diff --git a/features/docker.feature b/features/docker.feature
index e4ac590..2e82266 100644
--- a/features/docker.feature
+++ b/features/docker.feature
@@ -19,7 +19,9 @@ Feature: Build docker images with pro services
19 apt-get update \19 apt-get update \
20 && apt-get install --no-install-recommends -y ubuntu-advantage-tools ca-certificates \20 && apt-get install --no-install-recommends -y ubuntu-advantage-tools ca-certificates \
2121
22 && dpkg -i /ua.deb \22 && ((dpkg -i /ua.deb || true)) \
23
24 && apt-get install -f \
2325
24 && pro attach --attach-config /run/secrets/ua-attach-config \26 && pro attach --attach-config /run/secrets/ua-attach-config \
2527
diff --git a/features/environment.py b/features/environment.py
index 39013d0..bfe0042 100644
--- a/features/environment.py
+++ b/features/environment.py
@@ -23,10 +23,6 @@ DEFAULT_UA_PPA_KEYID = "6E34E7116C0BC933"
2323
24USERDATA_BLOCK_AUTO_ATTACH_IMG = """\24USERDATA_BLOCK_AUTO_ATTACH_IMG = """\
25#cloud-config25#cloud-config
26[bootcmd, once]:
27 - cp /usr/bin/ua /usr/bin/ua.orig
28 - 'echo "#!/bin/sh\ndate >> /root/ua-calls\n" > /usr/bin/ua'
29 - chmod 755 /usr/bin/ua
30"""26"""
3127
32# we can't use write_files because it will clash with the28# we can't use write_files because it will clash with the
@@ -40,8 +36,10 @@ runcmd:
40USERDATA_RUNCMD_ENABLE_PROPOSED = """36USERDATA_RUNCMD_ENABLE_PROPOSED = """
41runcmd:37runcmd:
42 - printf \"deb http://archive.ubuntu.com/ubuntu/ {series}-proposed main\" > /etc/apt/sources.list.d/uaclient-proposed.list38 - printf \"deb http://archive.ubuntu.com/ubuntu/ {series}-proposed main\" > /etc/apt/sources.list.d/uaclient-proposed.list
39 - printf \"deb http://archive.ubuntu.com/ubuntu/ {series}-proposed universe\" > /etc/apt/sources.list.d/uaclient-proposed-universe.list
43 - "printf \\"Package: *\\nPin: release a={series}-proposed\\nPin-Priority: 400\\n\\" > /etc/apt/preferences.d/lower-proposed"40 - "printf \\"Package: *\\nPin: release a={series}-proposed\\nPin-Priority: 400\\n\\" > /etc/apt/preferences.d/lower-proposed"
44 - "printf \\"Package: ubuntu-advantage-tools\\nPin: release a={series}-proposed\\nPin-Priority: 1001\\n\\" > /etc/apt/preferences.d/uaclient-proposed"41 - "printf \\"Package: ubuntu-advantage-tools\\nPin: release a={series}-proposed\\nPin-Priority: 1001\\n\\" > /etc/apt/preferences.d/uaclient-proposed"
42 - "printf \\"Package: ubuntu-advantage-pro\\nPin: release a={series}-proposed\\nPin-Priority: 1001\\n\\" > /etc/apt/preferences.d/uaclientpro-proposed"
45""" # noqa: E50143""" # noqa: E501
4644
47USERDATA_APT_SOURCE_PPA = """\45USERDATA_APT_SOURCE_PPA = """\
@@ -333,6 +331,8 @@ class UAClientBehaveConfig:
333def before_all(context: Context) -> None:331def before_all(context: Context) -> None:
334 """behave will invoke this before anything else happens."""332 """behave will invoke this before anything else happens."""
335 context.config.setup_logging()333 context.config.setup_logging()
334 logging.getLogger("botocore").setLevel(logging.INFO)
335 logging.getLogger("boto3").setLevel(logging.INFO)
336 userdata = context.config.userdata336 userdata = context.config.userdata
337 if userdata:337 if userdata:
338 logging.debug("Userdata key / value pairs:")338 logging.debug("Userdata key / value pairs:")
diff --git a/features/ubuntu_pro.feature b/features/ubuntu_pro.feature
index f23dcde..c373a95 100644
--- a/features/ubuntu_pro.feature
+++ b/features/ubuntu_pro.feature
@@ -23,6 +23,7 @@ Feature: Command behaviour when auto-attached in an ubuntu PRO image
23 """23 """
24 And I verify `/var/log/squid/access.log` is empty on `proxy` machine24 And I verify `/var/log/squid/access.log` is empty on `proxy` machine
25 When I run `pro auto-attach` with sudo25 When I run `pro auto-attach` with sudo
26 When I run `pro status --all` with sudo
26 Then stdout matches regexp:27 Then stdout matches regexp:
27 """28 """
28 SERVICE +ENTITLED STATUS DESCRIPTION29 SERVICE +ENTITLED STATUS DESCRIPTION
@@ -94,6 +95,7 @@ Feature: Command behaviour when auto-attached in an ubuntu PRO image
94 """95 """
95 And I verify `/var/log/squid/access.log` is empty on `proxy` machine96 And I verify `/var/log/squid/access.log` is empty on `proxy` machine
96 When I run `pro auto-attach` with sudo97 When I run `pro auto-attach` with sudo
98 When I run `pro status --all` with sudo
97 Then stdout matches regexp:99 Then stdout matches regexp:
98 """100 """
99 SERVICE +ENTITLED STATUS DESCRIPTION101 SERVICE +ENTITLED STATUS DESCRIPTION
@@ -165,6 +167,7 @@ Feature: Command behaviour when auto-attached in an ubuntu PRO image
165 """167 """
166 And I verify `/var/log/squid/access.log` is empty on `proxy` machine168 And I verify `/var/log/squid/access.log` is empty on `proxy` machine
167 When I run `pro auto-attach` with sudo169 When I run `pro auto-attach` with sudo
170 When I run `pro status --all` with sudo
168 Then stdout matches regexp:171 Then stdout matches regexp:
169 """172 """
170 SERVICE +ENTITLED STATUS DESCRIPTION173 SERVICE +ENTITLED STATUS DESCRIPTION
diff --git a/features/unattached_commands.feature b/features/unattached_commands.feature
index 5f27952..d358c29 100644
--- a/features/unattached_commands.feature
+++ b/features/unattached_commands.feature
@@ -231,19 +231,18 @@ Feature: Command behaviour when unattached
231 Given a `<release>` machine with ubuntu-advantage-tools installed231 Given a `<release>` machine with ubuntu-advantage-tools installed
232 # Make sure we have a fresh, just rebooted, environment232 # Make sure we have a fresh, just rebooted, environment
233 When I reboot the machine233 When I reboot the machine
234 Then I verify that no files exist matching `/tmp/ubuntu-advantage/candidate-version`234 Then I verify that no files exist matching `/run/ubuntu-advantage/candidate-version`
235 When I run `pro status` as non-root235 When I run `pro status` with sudo
236 Then I will see the following on stderr236 Then I will see the following on stderr
237 """237 """
238 """238 """
239 And I verify that files exist matching `/tmp/ubuntu-advantage/candidate-version`239 And I verify that files exist matching `/run/ubuntu-advantage/candidate-version`
240 # We forge a candidate to see results240 # We forge a candidate to see results
241 When I delete the file `/tmp/ubuntu-advantage/candidate-version`241 When I delete the file `/run/ubuntu-advantage/candidate-version`
242 And I create the file `/tmp/ubuntu-advantage/candidate-version` with the following242 And I create the file `/run/ubuntu-advantage/candidate-version` with the following
243 """243 """
244 99.9.9244 99.9.9
245 """245 """
246 And I run `chmod 777 /tmp/ubuntu-advantage/candidate-version` with sudo
247 And I run `pro status` as non-root246 And I run `pro status` as non-root
248 Then stderr matches regexp:247 Then stderr matches regexp:
249 """248 """
diff --git a/integration-requirements.txt b/integration-requirements.txt
index 9eaf14f..de2698d 100644
--- a/integration-requirements.txt
+++ b/integration-requirements.txt
@@ -2,7 +2,7 @@
2behave2behave
3jsonschema3jsonschema
4PyHamcrest4PyHamcrest
5pycloudlib @ git+https://github.com/canonical/pycloudlib.git@25cca01b24d111e00e91a86eb1021b88592e069e5pycloudlib @ git+https://github.com/canonical/pycloudlib.git@e7c4a42eb98a914b084b253c3f96c960de42e8fa
6toml==0.106toml==0.10
77
88
diff --git a/uaclient/actions.py b/uaclient/actions.py
index 9b1af00..3f602e8 100644
--- a/uaclient/actions.py
+++ b/uaclient/actions.py
@@ -160,6 +160,23 @@ def _write_command_output_to_file(
160 system.write_file(filename, out)160 system.write_file(filename, out)
161161
162162
163def _get_state_files(cfg: config.UAConfig):
164 # include cfg log files here because they could be set to non default
165 return [
166 cfg.cfg_path or DEFAULT_CONFIG_FILE,
167 cfg.log_file,
168 cfg.timer_log_file,
169 cfg.daemon_log_file,
170 cfg.data_path("jobs-status"),
171 CLOUD_BUILD_INFO,
172 *(
173 entitlement.repo_list_file_tmpl.format(name=entitlement.name)
174 for entitlement in entitlements.ENTITLEMENT_CLASSES
175 if issubclass(entitlement, entitlements.repo.RepoEntitlement)
176 ),
177 ]
178
179
163def collect_logs(cfg: config.UAConfig, output_dir: str):180def collect_logs(cfg: config.UAConfig, output_dir: str):
164 """181 """
165 Write all relevant Ubuntu Pro logs to the specified directory182 Write all relevant Ubuntu Pro logs to the specified directory
@@ -199,28 +216,19 @@ def collect_logs(cfg: config.UAConfig, output_dir: str):
199 return_codes=[0, 3],216 return_codes=[0, 3],
200 )217 )
201218
202 # include cfg log files here because they could be set to non default219 state_files = _get_state_files(cfg)
203 state_files = [
204 cfg.cfg_path or DEFAULT_CONFIG_FILE,
205 cfg.log_file,
206 cfg.timer_log_file,
207 cfg.daemon_log_file,
208 cfg.data_path("jobs-status"),
209 CLOUD_BUILD_INFO,
210 *(
211 entitlement.repo_list_file_tmpl.format(name=entitlement.name)
212 for entitlement in entitlements.ENTITLEMENT_CLASSES
213 if issubclass(entitlement, entitlements.repo.RepoEntitlement)
214 ),
215 ]
216220
217 # also get default logrotated log files221 # also get default logrotated log files
218 for f in state_files + glob.glob(DEFAULT_LOG_PREFIX + "*"):222 for f in state_files + glob.glob(DEFAULT_LOG_PREFIX + "*"):
219 if os.path.isfile(f):223 if os.path.isfile(f):
220 try:224 try:
221 content = system.load_file(f)225 content = system.load_file(f)
222 except PermissionError as e:226 except Exception as e:
223 logging.warning(e)227 # If we fail to load that file for any reason we will
228 # not break the command, we will instead warn the user
229 # about the issue and try to process the other files
230 logging.warning("Failed to load file: %s\n%s", f, str(e))
231 continue
224 content = util.redact_sensitive_logs(content)232 content = util.redact_sensitive_logs(content)
225 if os.getuid() == 0:233 if os.getuid() == 0:
226 # if root, overwrite the original with redacted content234 # if root, overwrite the original with redacted content
diff --git a/uaclient/cli.py b/uaclient/cli.py
index 3473414..55f8bec 100644
--- a/uaclient/cli.py
+++ b/uaclient/cli.py
@@ -49,7 +49,9 @@ from uaclient.entitlements.entitlement_status import (
49 CanEnableFailureReason,49 CanEnableFailureReason,
50)50)
51from uaclient.jobs.update_messaging import (51from uaclient.jobs.update_messaging import (
52 clear_apt_news_flag,
52 refresh_motd,53 refresh_motd,
54 set_apt_news_flag,
53 update_apt_and_motd_messages,55 update_apt_and_motd_messages,
54)56)
5557
@@ -1022,6 +1024,13 @@ def action_config_set(args, *, cfg, **kwargs):
1022 "<value> for interval must be a positive integer."1024 "<value> for interval must be a positive integer."
1023 ).format(set_key, set_value)1025 ).format(set_key, set_value)
1024 )1026 )
1027 elif set_key == "apt_news":
1028 set_value = set_value.lower() == "true"
1029 if set_value:
1030 set_apt_news_flag(cfg)
1031 else:
1032 clear_apt_news_flag(cfg)
1033
1025 setattr(cfg, set_key, set_value)1034 setattr(cfg, set_key, set_value)
10261035
10271036
diff --git a/uaclient/config.py b/uaclient/config.py
index 2b43d55..bb7bb06 100644
--- a/uaclient/config.py
+++ b/uaclient/config.py
@@ -49,6 +49,7 @@ UA_CONFIGURABLE_KEYS = (
49 "update_messaging_timer",49 "update_messaging_timer",
50 "update_status_timer",50 "update_status_timer",
51 "metering_timer",51 "metering_timer",
52 "apt_news",
52)53)
5354
54# Basic schema validation top-level keys for parse_config handling55# Basic schema validation top-level keys for parse_config handling
@@ -304,6 +305,17 @@ class UAConfig:
304 self.cfg["ua_config"]["polling_error_retry_delay"] = value305 self.cfg["ua_config"]["polling_error_retry_delay"] = value
305 self.write_cfg()306 self.write_cfg()
306307
308 @property
309 def apt_news(self) -> bool:
310 return self.cfg.get("ua_config", {}).get("apt_news", True)
311
312 @apt_news.setter
313 def apt_news(self, value: bool):
314 if "ua_config" not in self.cfg:
315 self.cfg["ua_config"] = {}
316 self.cfg["ua_config"]["apt_news"] = value
317 self.write_cfg()
318
307 def check_lock_info(self) -> Tuple[int, str]:319 def check_lock_info(self) -> Tuple[int, str]:
308 """Return lock info if config lock file is present the lock is active.320 """Return lock info if config lock file is present the lock is active.
309321
diff --git a/uaclient/defaults.py b/uaclient/defaults.py
index a2fa11f..7ffb140 100644
--- a/uaclient/defaults.py
+++ b/uaclient/defaults.py
@@ -6,14 +6,14 @@ any of our dependencies installed.
6"""6"""
77
8UAC_ETC_PATH = "/etc/ubuntu-advantage/"8UAC_ETC_PATH = "/etc/ubuntu-advantage/"
9UAC_TMP_PATH = "/tmp/ubuntu-advantage/"9UAC_RUN_PATH = "/run/ubuntu-advantage/"
10DEFAULT_DATA_DIR = "/var/lib/ubuntu-advantage"10DEFAULT_DATA_DIR = "/var/lib/ubuntu-advantage"
11MACHINE_TOKEN_FILE = "machine-token.json"11MACHINE_TOKEN_FILE = "machine-token.json"
12PRIVATE_SUBDIR = "/private"12PRIVATE_SUBDIR = "/private"
13DEFAULT_PRIVATE_MACHINE_TOKEN_PATH = (13DEFAULT_PRIVATE_MACHINE_TOKEN_PATH = (
14 DEFAULT_DATA_DIR + PRIVATE_SUBDIR + "/" + MACHINE_TOKEN_FILE14 DEFAULT_DATA_DIR + PRIVATE_SUBDIR + "/" + MACHINE_TOKEN_FILE
15)15)
16CANDIDATE_CACHE_PATH = UAC_TMP_PATH + "candidate-version"16CANDIDATE_CACHE_PATH = UAC_RUN_PATH + "candidate-version"
17DEFAULT_CONFIG_FILE = UAC_ETC_PATH + "uaclient.conf"17DEFAULT_CONFIG_FILE = UAC_ETC_PATH + "uaclient.conf"
18DEFAULT_HELP_FILE = UAC_ETC_PATH + "help_data.yaml"18DEFAULT_HELP_FILE = UAC_ETC_PATH + "help_data.yaml"
19DEFAULT_UPGRADE_CONTRACT_FLAG_FILE = UAC_ETC_PATH + "request-update-contract"19DEFAULT_UPGRADE_CONTRACT_FLAG_FILE = UAC_ETC_PATH + "request-update-contract"
diff --git a/uaclient/jobs/update_messaging.py b/uaclient/jobs/update_messaging.py
index 4a3893f..41a027b 100644
--- a/uaclient/jobs/update_messaging.py
+++ b/uaclient/jobs/update_messaging.py
@@ -28,7 +28,6 @@ from uaclient.messages import (
28 CONTRACT_EXPIRED_MOTD_SOON_TMPL,28 CONTRACT_EXPIRED_MOTD_SOON_TMPL,
29 DISABLED_APT_NO_PKGS_TMPL,29 DISABLED_APT_NO_PKGS_TMPL,
30 DISABLED_APT_PKGS_TMPL,30 DISABLED_APT_PKGS_TMPL,
31 TRY_UBUNTU_PRO_BETA,
32)31)
3332
34XENIAL_ESM_URL = "https://ubuntu.com/16-04"33XENIAL_ESM_URL = "https://ubuntu.com/16-04"
@@ -68,6 +67,17 @@ UPDATE_NOTIFIER_MOTD_SCRIPT = (
68)67)
6968
7069
70def set_apt_news_flag(cfg: config.UAConfig):
71 if system.is_current_series_lts():
72 system.create_file(
73 os.path.join(cfg.data_dir, "flags", "show-apt-news")
74 )
75
76
77def clear_apt_news_flag(cfg: config.UAConfig):
78 system.remove_file(os.path.join(cfg.data_dir, "flags", "show-apt-news"))
79
80
71def get_contract_expiry_status(81def get_contract_expiry_status(
72 cfg: config.UAConfig,82 cfg: config.UAConfig,
73) -> Tuple[ContractExpiryStatus, int]:83) -> Tuple[ContractExpiryStatus, int]:
@@ -311,32 +321,6 @@ def write_apt_and_motd_templates(cfg: config.UAConfig, series: str) -> None:
311 ],321 ],
312 )322 )
313323
314 if (
315 system.is_current_series_lts()
316 and not system.is_active_esm(series)
317 and not cfg.is_attached
318 ):
319 _write_template_or_remove(
320 TRY_UBUNTU_PRO_BETA, os.path.join(msg_dir, apps_no_pkg_file)
321 )
322 _write_template_or_remove(
323 TRY_UBUNTU_PRO_BETA, os.path.join(msg_dir, apps_pkg_file)
324 )
325 _write_template_or_remove("", os.path.join(msg_dir, infra_no_pkg_file))
326 _write_template_or_remove("", os.path.join(msg_dir, infra_pkg_file))
327 _write_template_or_remove(
328 "", os.path.join(msg_dir, motd_apps_no_pkg_file)
329 )
330 _write_template_or_remove(
331 "", os.path.join(msg_dir, motd_apps_pkg_file)
332 )
333 _write_template_or_remove(
334 "", os.path.join(msg_dir, motd_infra_no_pkg_file)
335 )
336 _write_template_or_remove(
337 "", os.path.join(msg_dir, motd_infra_pkg_file)
338 )
339
340324
341def write_esm_announcement_message(cfg: config.UAConfig, series: str) -> None:325def write_esm_announcement_message(cfg: config.UAConfig, series: str) -> None:
342 """Write human-readable messages if ESM is offered on this LTS release.326 """Write human-readable messages if ESM is offered on this LTS release.
@@ -396,6 +380,12 @@ def update_apt_and_motd_messages(cfg: config.UAConfig) -> bool:
396380
397 # Announce ESM availabilty on active ESM LTS releases381 # Announce ESM availabilty on active ESM LTS releases
398 # write_esm_announcement_message(cfg, series)382 # write_esm_announcement_message(cfg, series)
383
384 if cfg.apt_news:
385 set_apt_news_flag(cfg)
386 else:
387 clear_apt_news_flag(cfg)
388
399 write_apt_and_motd_templates(cfg, series)389 write_apt_and_motd_templates(cfg, series)
400 # Now that we've setup/cleanedup templates render them with apt-hook390 # Now that we've setup/cleanedup templates render them with apt-hook
401 system.subp(391 system.subp(
diff --git a/uaclient/messages.py b/uaclient/messages.py
index 95f1605..e3061be 100644
--- a/uaclient/messages.py
+++ b/uaclient/messages.py
@@ -1034,7 +1034,3 @@ Package names in {bold}bold{end_bold} currently have an available update
1034with '{{service}}' enabled""".format(1034with '{{service}}' enabled""".format(
1035 bold=TxtColor.BOLD, end_bold=TxtColor.ENDC1035 bold=TxtColor.BOLD, end_bold=TxtColor.ENDC
1036)1036)
1037
1038TRY_UBUNTU_PRO_BETA = """\
1039Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.
1040Learn more at https://ubuntu.com/pro"""
diff --git a/uaclient/system.py b/uaclient/system.py
index ef48d0c..3983e84 100644
--- a/uaclient/system.py
+++ b/uaclient/system.py
@@ -1,6 +1,7 @@
1import datetime1import datetime
2import logging2import logging
3import os3import os
4import pathlib
4import re5import re
5import subprocess6import subprocess
6import time7import time
@@ -205,6 +206,11 @@ def is_active_esm(series: str) -> bool:
205206
206207
207@lru_cache(maxsize=None)208@lru_cache(maxsize=None)
209def is_current_series_active_esm() -> bool:
210 return is_active_esm(get_platform_info()["series"])
211
212
213@lru_cache(maxsize=None)
208def is_container(run_path: str = "/run") -> bool:214def is_container(run_path: str = "/run") -> bool:
209 """Checks to see if this code running in a container of some sort"""215 """Checks to see if this code running in a container of some sort"""
210216
@@ -350,6 +356,13 @@ def load_file(filename: str, decode: bool = True) -> str:
350 return content.decode("utf-8")356 return content.decode("utf-8")
351357
352358
359def create_file(filename: str, mode: int = 0o644) -> None:
360 logging.debug("Creating file: %s", filename)
361 os.makedirs(os.path.dirname(filename), exist_ok=True)
362 pathlib.Path(filename).touch()
363 os.chmod(filename, mode)
364
365
353def write_file(filename: str, content: str, mode: int = 0o644) -> None:366def write_file(filename: str, content: str, mode: int = 0o644) -> None:
354 """Write content to the provided filename encoding it if necessary.367 """Write content to the provided filename encoding it if necessary.
355368
diff --git a/uaclient/tests/test_actions.py b/uaclient/tests/test_actions.py
index 6f77d7f..12c05f1 100644
--- a/uaclient/tests/test_actions.py
+++ b/uaclient/tests/test_actions.py
@@ -1,8 +1,10 @@
1import logging
2
1import mock3import mock
2import pytest4import pytest
35
4from uaclient import exceptions, messages6from uaclient import exceptions, messages
5from uaclient.actions import attach_with_token, auto_attach7from uaclient.actions import attach_with_token, auto_attach, collect_logs
6from uaclient.exceptions import ContractAPIError, NonAutoAttachImageError8from uaclient.exceptions import ContractAPIError, NonAutoAttachImageError
7from uaclient.tests.test_cli_auto_attach import fake_instance_factory9from uaclient.tests.test_cli_auto_attach import fake_instance_factory
810
@@ -141,3 +143,36 @@ class TestAutoAttach:
141 auto_attach(cfg, fake_instance_factory())143 auto_attach(cfg, fake_instance_factory())
142144
143 assert unexpected_error == excinfo.value145 assert unexpected_error == excinfo.value
146
147
148@mock.patch("uaclient.actions._write_command_output_to_file")
149class TestCollectLogs:
150 @pytest.mark.parametrize("caplog_text", [logging.WARNING], indirect=True)
151 @mock.patch("os.getuid")
152 @mock.patch("uaclient.system.write_file")
153 @mock.patch("uaclient.system.load_file")
154 @mock.patch("uaclient.actions._get_state_files")
155 @mock.patch("glob.glob")
156 def test_collect_logs_invalid_file(
157 self,
158 m_glob,
159 m_get_state_files,
160 m_load_file,
161 m_write_file,
162 m_getuid,
163 m_write_cmd,
164 caplog_text,
165 ):
166 m_get_state_files.return_value = ["a", "b"]
167 m_load_file.side_effect = [UnicodeError("test"), "test"]
168 m_getuid.return_value = 1
169 m_glob.return_value = []
170
171 with mock.patch("os.path.isfile", return_value=True):
172 collect_logs(cfg=mock.MagicMock(), output_dir="test")
173
174 assert 2 == m_load_file.call_count
175 assert [mock.call("a"), mock.call("b")] == m_load_file.call_args_list
176 assert 1 == m_write_file.call_count
177 assert [mock.call("test/b", "test")] == m_write_file.call_args_list
178 assert "Failed to load file: a\n" in caplog_text()
diff --git a/uaclient/tests/test_cli_config_set.py b/uaclient/tests/test_cli_config_set.py
index 66aaf82..d8a7c49 100644
--- a/uaclient/tests/test_cli_config_set.py
+++ b/uaclient/tests/test_cli_config_set.py
@@ -16,7 +16,8 @@ positional arguments:
16 must be one of: http_proxy, https_proxy, apt_http_proxy,16 must be one of: http_proxy, https_proxy, apt_http_proxy,
17 apt_https_proxy, ua_apt_http_proxy, ua_apt_https_proxy,17 apt_https_proxy, ua_apt_http_proxy, ua_apt_https_proxy,
18 global_apt_http_proxy, global_apt_https_proxy,18 global_apt_http_proxy, global_apt_https_proxy,
19 update_messaging_timer, update_status_timer, metering_timer19 update_messaging_timer, update_status_timer, metering_timer,
20 apt_news
2021
21Flags:22Flags:
22 -h, --help show this help message and exit23 -h, --help show this help message and exit
diff --git a/uaclient/tests/test_cli_config_show.py b/uaclient/tests/test_cli_config_show.py
index d4582fd..ebf760c 100644
--- a/uaclient/tests/test_cli_config_show.py
+++ b/uaclient/tests/test_cli_config_show.py
@@ -117,6 +117,7 @@ global_apt_https_proxy http://global_apt_https_proxy
117update_messaging_timer None117update_messaging_timer None
118update_status_timer None118update_status_timer None
119metering_timer None119metering_timer None
120apt_news True
120"""121"""
121 == out122 == out
122 )123 )
diff --git a/uaclient/tests/test_cli_config_unset.py b/uaclient/tests/test_cli_config_unset.py
index 115bc86..42c3625 100644
--- a/uaclient/tests/test_cli_config_unset.py
+++ b/uaclient/tests/test_cli_config_unset.py
@@ -15,7 +15,7 @@ positional arguments:
15 http_proxy, https_proxy, apt_http_proxy, apt_https_proxy,15 http_proxy, https_proxy, apt_http_proxy, apt_https_proxy,
16 ua_apt_http_proxy, ua_apt_https_proxy, global_apt_http_proxy,16 ua_apt_http_proxy, ua_apt_https_proxy, global_apt_http_proxy,
17 global_apt_https_proxy, update_messaging_timer,17 global_apt_https_proxy, update_messaging_timer,
18 update_status_timer, metering_timer18 update_status_timer, metering_timer, apt_news
1919
20Flags:20Flags:
21 -h, --help show this help message and exit21 -h, --help show this help message and exit
diff --git a/uaclient/tests/test_config.py b/uaclient/tests/test_config.py
index bd8a49e..d3b493c 100644
--- a/uaclient/tests/test_config.py
+++ b/uaclient/tests/test_config.py
@@ -295,6 +295,7 @@ UA_CFG_DICT = {
295 "ua_config": {295 "ua_config": {
296 "apt_http_proxy": None,296 "apt_http_proxy": None,
297 "apt_https_proxy": None,297 "apt_https_proxy": None,
298 "apt_news": True,
298 "global_apt_http_proxy": None,299 "global_apt_http_proxy": None,
299 "global_apt_https_proxy": None,300 "global_apt_https_proxy": None,
300 "ua_apt_http_proxy": None,301 "ua_apt_http_proxy": None,
@@ -316,7 +317,9 @@ class TestUAConfigKeys:
316 ):317 ):
317 """Getters and settings are available fo UA_CONFIGURABLE_KEYS."""318 """Getters and settings are available fo UA_CONFIGURABLE_KEYS."""
318 cfg = FakeConfig()319 cfg = FakeConfig()
319 assert None is getattr(cfg, attr_name, None)320 assert UA_CFG_DICT["ua_config"][attr_name] == getattr(
321 cfg, attr_name, None
322 )
320 cfg_non_members = ("apt_http_proxy", "apt_https_proxy")323 cfg_non_members = ("apt_http_proxy", "apt_https_proxy")
321 if attr_name not in cfg_non_members:324 if attr_name not in cfg_non_members:
322 setattr(cfg, attr_name, attr_name + "value")325 setattr(cfg, attr_name, attr_name + "value")
diff --git a/uaclient/tests/test_version.py b/uaclient/tests/test_version.py
index f6fd890..369dbbb 100644
--- a/uaclient/tests/test_version.py
+++ b/uaclient/tests/test_version.py
@@ -59,9 +59,12 @@ class TestGetLastKnownCandidate:
59 m_open.side_effect = OSError()59 m_open.side_effect = OSError()
60 assert None is get_last_known_candidate()60 assert None is get_last_known_candidate()
6161
62 @mock.patch("os.makedirs")
62 @mock.patch("uaclient.version.get_apt_cache_policy_for_package")63 @mock.patch("uaclient.version.get_apt_cache_policy_for_package")
63 @mock.patch("os.path.exists", return_value=False)64 @mock.patch("os.path.exists", return_value=False)
64 def test_create_cache_before_returning(self, _m_exists, m_policy):65 def test_create_cache_before_returning(
66 self, _m_exists, m_policy, _m_makedirs
67 ):
65 m_policy.return_value = """68 m_policy.return_value = """
66 Installed: 1.1.269 Installed: 1.1.2
67 Candidate: 1.2.370 Candidate: 1.2.3
@@ -83,7 +86,7 @@ class TestGetLastKnownCandidate:
83 Version table:86 Version table:
84 """87 """
85 m_open.side_effect = OSError()88 m_open.side_effect = OSError()
86 assert None is get_last_known_candidate()89 assert "1.2.3" == get_last_known_candidate()
8790
8891
89class TestCheckForNewVersion:92class TestCheckForNewVersion:
diff --git a/uaclient/version.py b/uaclient/version.py
index 54776f6..6232b30 100644
--- a/uaclient/version.py
+++ b/uaclient/version.py
@@ -14,11 +14,11 @@ from uaclient.apt import (
14 get_apt_cache_policy_for_package,14 get_apt_cache_policy_for_package,
15 get_apt_cache_time,15 get_apt_cache_time,
16)16)
17from uaclient.defaults import CANDIDATE_CACHE_PATH, UAC_TMP_PATH17from uaclient.defaults import CANDIDATE_CACHE_PATH, UAC_RUN_PATH
18from uaclient.exceptions import ProcessExecutionError18from uaclient.exceptions import ProcessExecutionError
19from uaclient.system import subp19from uaclient.system import subp
2020
21__VERSION__ = "27.11.2"21__VERSION__ = "27.11.3"
22PACKAGED_VERSION = "@@PACKAGED_VERSION@@"22PACKAGED_VERSION = "@@PACKAGED_VERSION@@"
2323
24CANDIDATE_REGEX = r"Candidate: (?P<candidate>.*?)\n"24CANDIDATE_REGEX = r"Candidate: (?P<candidate>.*?)\n"
@@ -56,17 +56,19 @@ def get_last_known_candidate() -> Optional[str]:
56 not os.path.exists(CANDIDATE_CACHE_PATH)56 not os.path.exists(CANDIDATE_CACHE_PATH)
57 or os.stat(CANDIDATE_CACHE_PATH).st_mtime < last_apt_cache_update57 or os.stat(CANDIDATE_CACHE_PATH).st_mtime < last_apt_cache_update
58 ):58 ):
59 candidate_version = None
59 try:60 try:
60 policy = get_apt_cache_policy_for_package("ubuntu-advantage-tools")61 policy = get_apt_cache_policy_for_package("ubuntu-advantage-tools")
61 match = re.search(CANDIDATE_REGEX, policy)62 match = re.search(CANDIDATE_REGEX, policy)
62 if match:63 if match:
63 candidate_version = match.group("candidate")64 candidate_version = match.group("candidate")
64 os.makedirs(UAC_TMP_PATH, exist_ok=True)65 os.makedirs(UAC_RUN_PATH, exist_ok=True)
65 with open(CANDIDATE_CACHE_PATH, "w") as f:66 with open(CANDIDATE_CACHE_PATH, "w") as f:
66 f.write(candidate_version)67 f.write(candidate_version)
67 os.chmod(CANDIDATE_CACHE_PATH, 0o777)68 return candidate_version
68 except Exception:69 except Exception:
69 pass70 if candidate_version is not None:
71 return candidate_version
7072
71 try:73 try:
72 with open(CANDIDATE_CACHE_PATH, "r") as f:74 with open(CANDIDATE_CACHE_PATH, "r") as f:

Subscribers

People subscribed via source and target branches

to status/vote changes: