Merge ~orndorffgrant/ubuntu/+source/ubuntu-advantage-tools:upload-27.11.3-kinetic into ubuntu/+source/ubuntu-advantage-tools:ubuntu/devel
- Git
- lp:~orndorffgrant/ubuntu/+source/ubuntu-advantage-tools
- upload-27.11.3-kinetic
- Merge into 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) |
||||||||
Related bugs: |
|
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 |
Commit message
Description of the change
This is release 27.11.3 of ubuntu-
You can find the description of changes in the overall SRU bug here: https:/
To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote : | # |
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:/
review:
Approve
(ubuntu-sru)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/apt-hook/20apt-esm-hook.conf b/apt-hook/20apt-esm-hook.conf |
2 | index 0cc6823..07c3362 100644 |
3 | --- a/apt-hook/20apt-esm-hook.conf |
4 | +++ b/apt-hook/20apt-esm-hook.conf |
5 | @@ -10,6 +10,6 @@ APT::Install::Pre-Invoke { |
6 | "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-hook ] || /usr/lib/ubuntu-advantage/apt-esm-hook pre-invoke || true"; |
7 | }; |
8 | |
9 | -AptCli::Hooks::Upgrade { |
10 | +binary::apt::AptCli::Hooks::Upgrade { |
11 | "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook || true"; |
12 | }; |
13 | diff --git a/apt-hook/json-hook.cc b/apt-hook/json-hook.cc |
14 | index 0efaa81..16042f8 100644 |
15 | --- a/apt-hook/json-hook.cc |
16 | +++ b/apt-hook/json-hook.cc |
17 | @@ -257,23 +257,33 @@ int run() |
18 | |
19 | json_object_put(hello_req.root_msg); |
20 | |
21 | - jsonrpc_request stats_req; |
22 | - success = read_jsonrpc_request(socket_in, stats_req); |
23 | + jsonrpc_request hook_req; |
24 | + success = read_jsonrpc_request(socket_in, hook_req); |
25 | if (!success) { |
26 | std::cerr << "ua-hook: failed to read hook msg" << std::endl; |
27 | return 0; |
28 | } |
29 | - if (stats_req.method == "org.debian.apt.hooks.install.statistics") { |
30 | + if (hook_req.method == "org.debian.apt.hooks.install.statistics") { |
31 | security_package_counts counts; |
32 | - success = count_security_packages_from_apt_stats_json(stats_req.params, counts); |
33 | + success = count_security_packages_from_apt_stats_json(hook_req.params, counts); |
34 | if (success) { |
35 | std::string message = create_count_message(counts); |
36 | if (message != "") { |
37 | std::cout << message << std::endl; |
38 | } |
39 | } |
40 | + } else if (hook_req.method == "org.debian.apt.hooks.install.pre-prompt") { |
41 | + std::ifstream apt_news_flag_file("/var/lib/ubuntu-advantage/flags/show-apt-news"); |
42 | + if (apt_news_flag_file.is_open()) { |
43 | + std::cout << "#" << std::endl; |
44 | + std::cout << "# News about significant security updates, features and services will" << std::endl; |
45 | + std::cout << "# appear here to raise awareness and perhaps tease /r/Linux ;)" << std::endl; |
46 | + std::cout << "# Use 'pro config set apt_news=false' to hide this and future APT news." << std::endl; |
47 | + std::cout << "#" << std::endl; |
48 | + apt_news_flag_file.close(); |
49 | + } |
50 | } |
51 | - json_object_put(stats_req.root_msg); |
52 | + json_object_put(hook_req.root_msg); |
53 | |
54 | jsonrpc_request bye_req; |
55 | success = read_jsonrpc_request(socket_in, bye_req); |
56 | diff --git a/debian/changelog b/debian/changelog |
57 | index a5acfc4..e0d5868 100644 |
58 | --- a/debian/changelog |
59 | +++ b/debian/changelog |
60 | @@ -1,3 +1,16 @@ |
61 | +ubuntu-advantage-tools (27.11.3~22.10.1) kinetic; urgency=medium |
62 | + |
63 | + * New upstream release 27.11.3: (LP: #1993006) |
64 | + - d/postinst: remove the Ubuntu Pro beta apt message and set up the |
65 | + configurable flag for "APT news" instead |
66 | + - collect-logs: do not fail if a file cannot be read (LP: #1991858) |
67 | + - config: add a flag to disable "APT news" (LP: 1992026) |
68 | + - messaging: add announcement of "APT news" to apt output |
69 | + - messaging: only show "APT news" when using apt binary (GH: #2288) |
70 | + - version: use /run instead of /tmp for version file (GH: #2294) |
71 | + |
72 | + -- Grant Orndorff <grant.orndorff@canonical.com> Fri, 14 Oct 2022 16:55:27 -0400 |
73 | + |
74 | ubuntu-advantage-tools (27.11.2~22.10.1) kinetic; urgency=medium |
75 | |
76 | * New upstream release 27.11.2: (LP: #1991173) |
77 | diff --git a/debian/ubuntu-advantage-tools.postinst b/debian/ubuntu-advantage-tools.postinst |
78 | index 4a677fc..73b914b 100644 |
79 | --- a/debian/ubuntu-advantage-tools.postinst |
80 | +++ b/debian/ubuntu-advantage-tools.postinst |
81 | @@ -57,6 +57,13 @@ OLD_LICENSE_CHECK_MARKER_FILE="/var/lib/ubuntu-advantage/marker-license-check" |
82 | MACHINE_TOKEN_FILE="/var/lib/ubuntu-advantage/private/machine-token.json" |
83 | PUBLIC_MACHINE_TOKEN_FILE="/var/lib/ubuntu-advantage/machine-token.json" |
84 | |
85 | +UA_MESSAGES_DIR="/var/lib/ubuntu-advantage/messages" |
86 | +APT_ESM_MESSAGE_FILE="$UA_MESSAGES_DIR/apt-pre-invoke-esm-service-status" |
87 | +ESM_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" |
88 | +UA_FLAGS_DIR="/var/lib/ubuntu-advantage/flags" |
89 | +APT_NEWS_FLAG_FILE="$UA_FLAGS_DIR/show-apt-news" |
90 | + |
91 | +TMP_CANDIDATE_CACHE_PATH="/tmp/ubuntu-advantage/candidate-version" |
92 | |
93 | # Rename apt config files for ua services removing ubuntu release names |
94 | redact_ubuntu_release_from_ua_apt_filenames() { |
95 | @@ -384,6 +391,29 @@ machine_token_file.write(content=content) |
96 | " |
97 | } |
98 | |
99 | +migrate_ubuntu_pro_beta_banner() { |
100 | + PREVIOUS_PKG_VER=$1 |
101 | + # This only shipped in 27.11.2~ |
102 | + if dpkg --compare-versions "$PREVIOUS_PKG_VER" ge "27.11.2~" \ |
103 | + && dpkg --compare-versions "$PREVIOUS_PKG_VER" lt "27.11.3~"; then |
104 | + # if the banner was present, remove it and add the new flag file which is configurable |
105 | + if [ -f $APT_ESM_MESSAGE_FILE ]; then |
106 | + if cat $APT_ESM_MESSAGE_FILE | grep -q "Try Ubuntu Pro beta"; then |
107 | + rm -f $APT_ESM_MESSAGE_FILE |
108 | + rm -f $ESM_APPS_APT_MSG_FILES |
109 | + mkdir -p $UA_FLAGS_DIR |
110 | + touch $APT_NEWS_FLAG_FILE |
111 | + fi |
112 | + fi |
113 | + fi |
114 | +} |
115 | + |
116 | +cleanup_candidate_version_stamp_permissions() { |
117 | + if [ -f $TMP_CANDIDATE_CACHE_PATH ]; then |
118 | + rm -f $TMP_CANDIDATE_CACHE_PATH |
119 | + fi |
120 | +} |
121 | + |
122 | case "$1" in |
123 | configure) |
124 | PREVIOUS_PKG_VER=$2 |
125 | @@ -462,6 +492,8 @@ case "$1" in |
126 | if [ -f $MACHINE_TOKEN_FILE ] && [ ! -f $PUBLIC_MACHINE_TOKEN_FILE ]; then |
127 | create_public_machine_token_file |
128 | fi |
129 | + migrate_ubuntu_pro_beta_banner $PREVIOUS_PKG_VER |
130 | + cleanup_candidate_version_stamp_permissions |
131 | ;; |
132 | esac |
133 | |
134 | diff --git a/features/api_full_auto_attach.feature b/features/api_full_auto_attach.feature |
135 | index 240e06f..c65fca5 100644 |
136 | --- a/features/api_full_auto_attach.feature |
137 | +++ b/features/api_full_auto_attach.feature |
138 | @@ -27,7 +27,7 @@ Feature: Full Auto-Attach Endpoint |
139 | """ |
140 | Then stdout matches regexp: |
141 | """ |
142 | - livepatch +yes +disabled +Canonical Livepatch service |
143 | + livepatch +yes +(disabled|n/a) +Canonical Livepatch service |
144 | """ |
145 | Examples: |
146 | | release | |
147 | diff --git a/features/apt_messages.feature b/features/apt_messages.feature |
148 | index 27d67cb..b03524f 100644 |
149 | --- a/features/apt_messages.feature |
150 | +++ b/features/apt_messages.feature |
151 | @@ -9,7 +9,7 @@ Feature: APT Messages |
152 | When I run `apt-get upgrade -y` with sudo |
153 | |
154 | When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo |
155 | - When I run `apt-get upgrade -y` with sudo |
156 | + When I run `apt upgrade -y` with sudo |
157 | Then stdout matches regexp: |
158 | """ |
159 | 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
160 | @@ -18,7 +18,7 @@ Feature: APT Messages |
161 | """ |
162 | |
163 | When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo |
164 | - When I run `apt-get upgrade -y` with sudo |
165 | + When I run `apt upgrade -y` with sudo |
166 | Then stdout matches regexp: |
167 | """ |
168 | 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
169 | @@ -27,7 +27,7 @@ Feature: APT Messages |
170 | """ |
171 | |
172 | When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo |
173 | - When I run `apt-get upgrade -y` with sudo |
174 | + When I run `apt upgrade -y` with sudo |
175 | Then stdout matches regexp: |
176 | """ |
177 | 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
178 | @@ -37,7 +37,7 @@ Feature: APT Messages |
179 | |
180 | When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo |
181 | When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo |
182 | - When I run `apt-get upgrade -y` with sudo |
183 | + When I run `apt upgrade -y` with sudo |
184 | Then stdout matches regexp: |
185 | """ |
186 | 4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
187 | @@ -47,7 +47,7 @@ Feature: APT Messages |
188 | |
189 | When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo |
190 | When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo |
191 | - When I run `apt-get upgrade -y` with sudo |
192 | + When I run `apt upgrade -y` with sudo |
193 | Then stdout matches regexp: |
194 | """ |
195 | 3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
196 | @@ -57,7 +57,7 @@ Feature: APT Messages |
197 | |
198 | When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo |
199 | When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo |
200 | - When I run `apt-get upgrade -y` with sudo |
201 | + When I run `apt upgrade -y` with sudo |
202 | Then stdout matches regexp: |
203 | """ |
204 | 3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
205 | @@ -68,7 +68,7 @@ Feature: APT Messages |
206 | When I run `apt-get install -y --allow-downgrades <standard-pkg>` with sudo |
207 | When I run `apt-get install -y --allow-downgrades <infra-pkg>` with sudo |
208 | When I run `apt-get install -y --allow-downgrades <apps-pkg>` with sudo |
209 | - When I run `apt-get upgrade -y` with sudo |
210 | + When I run `apt upgrade -y` with sudo |
211 | Then stdout matches regexp: |
212 | """ |
213 | 5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
214 | @@ -76,7 +76,7 @@ Feature: APT Messages |
215 | |
216 | """ |
217 | |
218 | - When I run `apt-get upgrade -y` with sudo |
219 | + When I run `apt upgrade -y` with sudo |
220 | Then stdout matches regexp: |
221 | """ |
222 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
223 | @@ -106,37 +106,52 @@ Feature: APT Messages |
224 | When I run `apt-get -y upgrade` with sudo |
225 | When I run `apt-get -y autoremove` with sudo |
226 | When I run `pro refresh messages` with sudo |
227 | - When I run `apt-get upgrade` with sudo |
228 | + When I run `apt upgrade` with sudo |
229 | Then stdout matches regexp: |
230 | """ |
231 | Reading package lists... |
232 | Building dependency tree... |
233 | Reading state information... |
234 | Calculating upgrade... |
235 | + # |
236 | + # News about significant security updates, features and services will |
237 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
238 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
239 | + # |
240 | The following security updates require Ubuntu Pro with 'esm-infra' enabled: |
241 | .* |
242 | Learn more about Ubuntu Pro for 16\.04 at https:\/\/ubuntu\.com\/16-04 |
243 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\. |
244 | """ |
245 | When I attach `contract_token` with sudo |
246 | - When I run `apt-get upgrade --dry-run` with sudo |
247 | + When I run `apt upgrade --dry-run` with sudo |
248 | Then stdout matches regexp: |
249 | """ |
250 | Reading package lists... |
251 | Building dependency tree... |
252 | Reading state information... |
253 | Calculating upgrade... |
254 | + # |
255 | + # News about significant security updates, features and services will |
256 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
257 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
258 | + # |
259 | The following packages will be upgraded: |
260 | """ |
261 | When I update contract to use `effectiveTo` as `days=+2` |
262 | When I run `pro refresh messages` with sudo |
263 | - When I run `apt-get upgrade --dry-run` with sudo |
264 | + When I run `apt upgrade --dry-run` with sudo |
265 | Then stdout matches regexp: |
266 | """ |
267 | Reading package lists... |
268 | Building dependency tree... |
269 | Reading state information... |
270 | Calculating upgrade... |
271 | + # |
272 | + # News about significant security updates, features and services will |
273 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
274 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
275 | + # |
276 | |
277 | CAUTION: Your Ubuntu Pro subscription will expire in 2 days. |
278 | Renew your subscription at https:\/\/ubuntu.com\/pro to ensure continued security |
279 | @@ -146,13 +161,18 @@ Feature: APT Messages |
280 | """ |
281 | When I update contract to use `effectiveTo` as `days=-3` |
282 | When I run `pro refresh messages` with sudo |
283 | - When I run `apt-get upgrade --dry-run` with sudo |
284 | + When I run `apt upgrade --dry-run` with sudo |
285 | Then stdout matches regexp: |
286 | """ |
287 | Reading package lists... |
288 | Building dependency tree... |
289 | Reading state information... |
290 | Calculating upgrade... |
291 | + # |
292 | + # News about significant security updates, features and services will |
293 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
294 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
295 | + # |
296 | |
297 | CAUTION: Your Ubuntu Pro subscription expired on \d+ \w+ \d+. |
298 | Renew your subscription at https:\/\/ubuntu.com\/pro to ensure continued security |
299 | @@ -163,13 +183,18 @@ Feature: APT Messages |
300 | """ |
301 | When I update contract to use `effectiveTo` as `days=-20` |
302 | When I run `pro refresh messages` with sudo |
303 | - When I run `apt-get upgrade --dry-run` with sudo |
304 | + When I run `apt upgrade --dry-run` with sudo |
305 | Then stdout matches regexp: |
306 | """ |
307 | Reading package lists... |
308 | Building dependency tree... |
309 | Reading state information... |
310 | Calculating upgrade... |
311 | + # |
312 | + # News about significant security updates, features and services will |
313 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
314 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
315 | + # |
316 | |
317 | \*Your Ubuntu Pro subscription has EXPIRED\* |
318 | The following security updates require Ubuntu Pro with 'esm-infra' enabled: |
319 | @@ -179,13 +204,18 @@ Feature: APT Messages |
320 | The following packages will be upgraded: |
321 | """ |
322 | When I run `apt-get upgrade -y` with sudo |
323 | - When I run `apt-get upgrade` with sudo |
324 | + When I run `apt upgrade` with sudo |
325 | Then stdout matches regexp: |
326 | """ |
327 | Reading package lists... |
328 | Building dependency tree... |
329 | Reading state information... |
330 | Calculating upgrade... |
331 | + # |
332 | + # News about significant security updates, features and services will |
333 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
334 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
335 | + # |
336 | |
337 | \*Your Ubuntu Pro subscription has EXPIRED\* |
338 | Renew your service at https:\/\/ubuntu.com\/pro |
339 | @@ -194,13 +224,18 @@ Feature: APT Messages |
340 | """ |
341 | When I run `pro detach --assume-yes` with sudo |
342 | When I run `pro refresh messages` with sudo |
343 | - When I run `apt-get upgrade` with sudo |
344 | + When I run `apt upgrade` with sudo |
345 | Then stdout matches regexp: |
346 | """ |
347 | Reading package lists... |
348 | Building dependency tree... |
349 | Reading state information... |
350 | Calculating upgrade... |
351 | + # |
352 | + # News about significant security updates, features and services will |
353 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
354 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
355 | + # |
356 | Receive additional future security updates with Ubuntu Pro. |
357 | Learn more about Ubuntu Pro for 16\.04 at https:\/\/ubuntu\.com\/16-04 |
358 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\. |
359 | @@ -218,31 +253,48 @@ Feature: APT Messages |
360 | When I run `apt-get -y autoremove` with sudo |
361 | When I run `apt-get install hello` with sudo |
362 | When I run `pro refresh messages` with sudo |
363 | - When I run `apt-get upgrade` with sudo |
364 | + When I run `apt upgrade` with sudo |
365 | Then I will see the following on stdout: |
366 | """ |
367 | Reading package lists... |
368 | Building dependency tree... |
369 | Reading state information... |
370 | Calculating upgrade... |
371 | - Try Ubuntu Pro beta with a free personal subscription on up to 5 machines. |
372 | - Learn more at https://ubuntu.com/pro |
373 | + # |
374 | + # News about significant security updates, features and services will |
375 | + # appear here to raise awareness and perhaps tease /r/Linux ;) |
376 | + # Use 'pro config set apt_news=false' to hide this and future APT news. |
377 | + # |
378 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. |
379 | """ |
380 | + When I run `apt-get upgrade` with sudo |
381 | + Then stdout does not match regexp: |
382 | + """ |
383 | + # |
384 | + # News about significant security updates, features and services will |
385 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
386 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
387 | + # |
388 | + """ |
389 | When I attach `contract_token` with sudo |
390 | - When I run `apt-get upgrade --dry-run` with sudo |
391 | + When I run `apt upgrade --dry-run` with sudo |
392 | Then stdout matches regexp: |
393 | """ |
394 | Reading package lists... |
395 | Building dependency tree... |
396 | Reading state information... |
397 | Calculating upgrade... |
398 | + # |
399 | + # News about significant security updates, features and services will |
400 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
401 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
402 | + # |
403 | The following packages will be upgraded: |
404 | hello |
405 | """ |
406 | # When I update contract to use `effectiveTo` as `days=-20` |
407 | # When I run `pro refresh messages` with sudo |
408 | -# When I run `apt-get upgrade --dry-run` with sudo |
409 | +# When I run `apt upgrade --dry-run` with sudo |
410 | # Then stdout matches regexp: |
411 | # """ |
412 | # Reading package lists... |
413 | @@ -260,17 +312,30 @@ Feature: APT Messages |
414 | When I run `apt-get upgrade -y` with sudo |
415 | When I run `pro detach --assume-yes` with sudo |
416 | When I run `pro refresh messages` with sudo |
417 | - When I run `apt-get upgrade` with sudo |
418 | + When I run `apt upgrade` with sudo |
419 | Then stdout matches regexp: |
420 | """ |
421 | Reading package lists... |
422 | Building dependency tree... |
423 | Reading state information... |
424 | Calculating upgrade... |
425 | - Try Ubuntu Pro beta with a free personal subscription on up to 5 machines. |
426 | - Learn more at https:\/\/ubuntu.com\/pro |
427 | + # |
428 | + # News about significant security updates, features and services will |
429 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
430 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
431 | + # |
432 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded\. |
433 | """ |
434 | + When I run `pro config set apt_news=false` with sudo |
435 | + And I run `apt upgrade` with sudo |
436 | + Then stdout does not match regexp: |
437 | + """ |
438 | + # |
439 | + # News about significant security updates, features and services will |
440 | + # appear here to raise awareness and perhaps tease /r/Linux ;\) |
441 | + # Use 'pro config set apt_news=false' to hide this and future APT news\. |
442 | + # |
443 | + """ |
444 | Examples: ubuntu release |
445 | | release | |
446 | | focal | |
447 | diff --git a/features/cloud_pro_clone.feature b/features/cloud_pro_clone.feature |
448 | index f08bff0..48aa17a 100644 |
449 | --- a/features/cloud_pro_clone.feature |
450 | +++ b/features/cloud_pro_clone.feature |
451 | @@ -2,7 +2,6 @@ Feature: Creating golden images based on Cloud Ubuntu Pro instances |
452 | |
453 | @series.lts |
454 | @uses.config.machine_type.aws.pro |
455 | - @uses.config.machine_type.azure.pro |
456 | @uses.config.machine_type.gcp.pro |
457 | Scenario Outline: Create a Pro fips-updates image and launch |
458 | Given a `<release>` machine with ubuntu-advantage-tools installed |
459 | diff --git a/features/daemon.feature b/features/daemon.feature |
460 | index 593c86d..0b33c37 100644 |
461 | --- a/features/daemon.feature |
462 | +++ b/features/daemon.feature |
463 | @@ -104,9 +104,10 @@ Feature: Pro Upgrade Daemon only runs in environments where necessary |
464 | """ |
465 | Active: active \(running\) |
466 | """ |
467 | - Then on `xenial`, systemd status output says memory usage is less than `14` MB |
468 | + # TODO find out what caused memory to go up, try to lower it again |
469 | + Then on `xenial`, systemd status output says memory usage is less than `15` MB |
470 | Then on `bionic`, systemd status output says memory usage is less than `13` MB |
471 | - Then on `focal`, systemd status output says memory usage is less than `11` MB |
472 | + Then on `focal`, systemd status output says memory usage is less than `12` MB |
473 | Then on `jammy`, systemd status output says memory usage is less than `12` MB |
474 | |
475 | When I run `cat /var/log/ubuntu-advantage-daemon.log` with sudo |
476 | diff --git a/features/docker.feature b/features/docker.feature |
477 | index e4ac590..2e82266 100644 |
478 | --- a/features/docker.feature |
479 | +++ b/features/docker.feature |
480 | @@ -19,7 +19,9 @@ Feature: Build docker images with pro services |
481 | apt-get update \ |
482 | && apt-get install --no-install-recommends -y ubuntu-advantage-tools ca-certificates \ |
483 | |
484 | - && dpkg -i /ua.deb \ |
485 | + && ((dpkg -i /ua.deb || true)) \ |
486 | + |
487 | + && apt-get install -f \ |
488 | |
489 | && pro attach --attach-config /run/secrets/ua-attach-config \ |
490 | |
491 | diff --git a/features/environment.py b/features/environment.py |
492 | index 39013d0..bfe0042 100644 |
493 | --- a/features/environment.py |
494 | +++ b/features/environment.py |
495 | @@ -23,10 +23,6 @@ DEFAULT_UA_PPA_KEYID = "6E34E7116C0BC933" |
496 | |
497 | USERDATA_BLOCK_AUTO_ATTACH_IMG = """\ |
498 | #cloud-config |
499 | -[bootcmd, once]: |
500 | - - cp /usr/bin/ua /usr/bin/ua.orig |
501 | - - 'echo "#!/bin/sh\ndate >> /root/ua-calls\n" > /usr/bin/ua' |
502 | - - chmod 755 /usr/bin/ua |
503 | """ |
504 | |
505 | # we can't use write_files because it will clash with the |
506 | @@ -40,8 +36,10 @@ runcmd: |
507 | USERDATA_RUNCMD_ENABLE_PROPOSED = """ |
508 | runcmd: |
509 | - printf \"deb http://archive.ubuntu.com/ubuntu/ {series}-proposed main\" > /etc/apt/sources.list.d/uaclient-proposed.list |
510 | + - printf \"deb http://archive.ubuntu.com/ubuntu/ {series}-proposed universe\" > /etc/apt/sources.list.d/uaclient-proposed-universe.list |
511 | - "printf \\"Package: *\\nPin: release a={series}-proposed\\nPin-Priority: 400\\n\\" > /etc/apt/preferences.d/lower-proposed" |
512 | - "printf \\"Package: ubuntu-advantage-tools\\nPin: release a={series}-proposed\\nPin-Priority: 1001\\n\\" > /etc/apt/preferences.d/uaclient-proposed" |
513 | + - "printf \\"Package: ubuntu-advantage-pro\\nPin: release a={series}-proposed\\nPin-Priority: 1001\\n\\" > /etc/apt/preferences.d/uaclientpro-proposed" |
514 | """ # noqa: E501 |
515 | |
516 | USERDATA_APT_SOURCE_PPA = """\ |
517 | @@ -333,6 +331,8 @@ class UAClientBehaveConfig: |
518 | def before_all(context: Context) -> None: |
519 | """behave will invoke this before anything else happens.""" |
520 | context.config.setup_logging() |
521 | + logging.getLogger("botocore").setLevel(logging.INFO) |
522 | + logging.getLogger("boto3").setLevel(logging.INFO) |
523 | userdata = context.config.userdata |
524 | if userdata: |
525 | logging.debug("Userdata key / value pairs:") |
526 | diff --git a/features/ubuntu_pro.feature b/features/ubuntu_pro.feature |
527 | index f23dcde..c373a95 100644 |
528 | --- a/features/ubuntu_pro.feature |
529 | +++ b/features/ubuntu_pro.feature |
530 | @@ -23,6 +23,7 @@ Feature: Command behaviour when auto-attached in an ubuntu PRO image |
531 | """ |
532 | And I verify `/var/log/squid/access.log` is empty on `proxy` machine |
533 | When I run `pro auto-attach` with sudo |
534 | + When I run `pro status --all` with sudo |
535 | Then stdout matches regexp: |
536 | """ |
537 | SERVICE +ENTITLED STATUS DESCRIPTION |
538 | @@ -94,6 +95,7 @@ Feature: Command behaviour when auto-attached in an ubuntu PRO image |
539 | """ |
540 | And I verify `/var/log/squid/access.log` is empty on `proxy` machine |
541 | When I run `pro auto-attach` with sudo |
542 | + When I run `pro status --all` with sudo |
543 | Then stdout matches regexp: |
544 | """ |
545 | SERVICE +ENTITLED STATUS DESCRIPTION |
546 | @@ -165,6 +167,7 @@ Feature: Command behaviour when auto-attached in an ubuntu PRO image |
547 | """ |
548 | And I verify `/var/log/squid/access.log` is empty on `proxy` machine |
549 | When I run `pro auto-attach` with sudo |
550 | + When I run `pro status --all` with sudo |
551 | Then stdout matches regexp: |
552 | """ |
553 | SERVICE +ENTITLED STATUS DESCRIPTION |
554 | diff --git a/features/unattached_commands.feature b/features/unattached_commands.feature |
555 | index 5f27952..d358c29 100644 |
556 | --- a/features/unattached_commands.feature |
557 | +++ b/features/unattached_commands.feature |
558 | @@ -231,19 +231,18 @@ Feature: Command behaviour when unattached |
559 | Given a `<release>` machine with ubuntu-advantage-tools installed |
560 | # Make sure we have a fresh, just rebooted, environment |
561 | When I reboot the machine |
562 | - Then I verify that no files exist matching `/tmp/ubuntu-advantage/candidate-version` |
563 | - When I run `pro status` as non-root |
564 | + Then I verify that no files exist matching `/run/ubuntu-advantage/candidate-version` |
565 | + When I run `pro status` with sudo |
566 | Then I will see the following on stderr |
567 | """ |
568 | """ |
569 | - And I verify that files exist matching `/tmp/ubuntu-advantage/candidate-version` |
570 | + And I verify that files exist matching `/run/ubuntu-advantage/candidate-version` |
571 | # We forge a candidate to see results |
572 | - When I delete the file `/tmp/ubuntu-advantage/candidate-version` |
573 | - And I create the file `/tmp/ubuntu-advantage/candidate-version` with the following |
574 | + When I delete the file `/run/ubuntu-advantage/candidate-version` |
575 | + And I create the file `/run/ubuntu-advantage/candidate-version` with the following |
576 | """ |
577 | 99.9.9 |
578 | """ |
579 | - And I run `chmod 777 /tmp/ubuntu-advantage/candidate-version` with sudo |
580 | And I run `pro status` as non-root |
581 | Then stderr matches regexp: |
582 | """ |
583 | diff --git a/integration-requirements.txt b/integration-requirements.txt |
584 | index 9eaf14f..de2698d 100644 |
585 | --- a/integration-requirements.txt |
586 | +++ b/integration-requirements.txt |
587 | @@ -2,7 +2,7 @@ |
588 | behave |
589 | jsonschema |
590 | PyHamcrest |
591 | -pycloudlib @ git+https://github.com/canonical/pycloudlib.git@25cca01b24d111e00e91a86eb1021b88592e069e |
592 | +pycloudlib @ git+https://github.com/canonical/pycloudlib.git@e7c4a42eb98a914b084b253c3f96c960de42e8fa |
593 | toml==0.10 |
594 | |
595 | |
596 | diff --git a/uaclient/actions.py b/uaclient/actions.py |
597 | index 9b1af00..3f602e8 100644 |
598 | --- a/uaclient/actions.py |
599 | +++ b/uaclient/actions.py |
600 | @@ -160,6 +160,23 @@ def _write_command_output_to_file( |
601 | system.write_file(filename, out) |
602 | |
603 | |
604 | +def _get_state_files(cfg: config.UAConfig): |
605 | + # include cfg log files here because they could be set to non default |
606 | + return [ |
607 | + cfg.cfg_path or DEFAULT_CONFIG_FILE, |
608 | + cfg.log_file, |
609 | + cfg.timer_log_file, |
610 | + cfg.daemon_log_file, |
611 | + cfg.data_path("jobs-status"), |
612 | + CLOUD_BUILD_INFO, |
613 | + *( |
614 | + entitlement.repo_list_file_tmpl.format(name=entitlement.name) |
615 | + for entitlement in entitlements.ENTITLEMENT_CLASSES |
616 | + if issubclass(entitlement, entitlements.repo.RepoEntitlement) |
617 | + ), |
618 | + ] |
619 | + |
620 | + |
621 | def collect_logs(cfg: config.UAConfig, output_dir: str): |
622 | """ |
623 | Write all relevant Ubuntu Pro logs to the specified directory |
624 | @@ -199,28 +216,19 @@ def collect_logs(cfg: config.UAConfig, output_dir: str): |
625 | return_codes=[0, 3], |
626 | ) |
627 | |
628 | - # include cfg log files here because they could be set to non default |
629 | - state_files = [ |
630 | - cfg.cfg_path or DEFAULT_CONFIG_FILE, |
631 | - cfg.log_file, |
632 | - cfg.timer_log_file, |
633 | - cfg.daemon_log_file, |
634 | - cfg.data_path("jobs-status"), |
635 | - CLOUD_BUILD_INFO, |
636 | - *( |
637 | - entitlement.repo_list_file_tmpl.format(name=entitlement.name) |
638 | - for entitlement in entitlements.ENTITLEMENT_CLASSES |
639 | - if issubclass(entitlement, entitlements.repo.RepoEntitlement) |
640 | - ), |
641 | - ] |
642 | + state_files = _get_state_files(cfg) |
643 | |
644 | # also get default logrotated log files |
645 | for f in state_files + glob.glob(DEFAULT_LOG_PREFIX + "*"): |
646 | if os.path.isfile(f): |
647 | try: |
648 | content = system.load_file(f) |
649 | - except PermissionError as e: |
650 | - logging.warning(e) |
651 | + except Exception as e: |
652 | + # If we fail to load that file for any reason we will |
653 | + # not break the command, we will instead warn the user |
654 | + # about the issue and try to process the other files |
655 | + logging.warning("Failed to load file: %s\n%s", f, str(e)) |
656 | + continue |
657 | content = util.redact_sensitive_logs(content) |
658 | if os.getuid() == 0: |
659 | # if root, overwrite the original with redacted content |
660 | diff --git a/uaclient/cli.py b/uaclient/cli.py |
661 | index 3473414..55f8bec 100644 |
662 | --- a/uaclient/cli.py |
663 | +++ b/uaclient/cli.py |
664 | @@ -49,7 +49,9 @@ from uaclient.entitlements.entitlement_status import ( |
665 | CanEnableFailureReason, |
666 | ) |
667 | from uaclient.jobs.update_messaging import ( |
668 | + clear_apt_news_flag, |
669 | refresh_motd, |
670 | + set_apt_news_flag, |
671 | update_apt_and_motd_messages, |
672 | ) |
673 | |
674 | @@ -1022,6 +1024,13 @@ def action_config_set(args, *, cfg, **kwargs): |
675 | "<value> for interval must be a positive integer." |
676 | ).format(set_key, set_value) |
677 | ) |
678 | + elif set_key == "apt_news": |
679 | + set_value = set_value.lower() == "true" |
680 | + if set_value: |
681 | + set_apt_news_flag(cfg) |
682 | + else: |
683 | + clear_apt_news_flag(cfg) |
684 | + |
685 | setattr(cfg, set_key, set_value) |
686 | |
687 | |
688 | diff --git a/uaclient/config.py b/uaclient/config.py |
689 | index 2b43d55..bb7bb06 100644 |
690 | --- a/uaclient/config.py |
691 | +++ b/uaclient/config.py |
692 | @@ -49,6 +49,7 @@ UA_CONFIGURABLE_KEYS = ( |
693 | "update_messaging_timer", |
694 | "update_status_timer", |
695 | "metering_timer", |
696 | + "apt_news", |
697 | ) |
698 | |
699 | # Basic schema validation top-level keys for parse_config handling |
700 | @@ -304,6 +305,17 @@ class UAConfig: |
701 | self.cfg["ua_config"]["polling_error_retry_delay"] = value |
702 | self.write_cfg() |
703 | |
704 | + @property |
705 | + def apt_news(self) -> bool: |
706 | + return self.cfg.get("ua_config", {}).get("apt_news", True) |
707 | + |
708 | + @apt_news.setter |
709 | + def apt_news(self, value: bool): |
710 | + if "ua_config" not in self.cfg: |
711 | + self.cfg["ua_config"] = {} |
712 | + self.cfg["ua_config"]["apt_news"] = value |
713 | + self.write_cfg() |
714 | + |
715 | def check_lock_info(self) -> Tuple[int, str]: |
716 | """Return lock info if config lock file is present the lock is active. |
717 | |
718 | diff --git a/uaclient/defaults.py b/uaclient/defaults.py |
719 | index a2fa11f..7ffb140 100644 |
720 | --- a/uaclient/defaults.py |
721 | +++ b/uaclient/defaults.py |
722 | @@ -6,14 +6,14 @@ any of our dependencies installed. |
723 | """ |
724 | |
725 | UAC_ETC_PATH = "/etc/ubuntu-advantage/" |
726 | -UAC_TMP_PATH = "/tmp/ubuntu-advantage/" |
727 | +UAC_RUN_PATH = "/run/ubuntu-advantage/" |
728 | DEFAULT_DATA_DIR = "/var/lib/ubuntu-advantage" |
729 | MACHINE_TOKEN_FILE = "machine-token.json" |
730 | PRIVATE_SUBDIR = "/private" |
731 | DEFAULT_PRIVATE_MACHINE_TOKEN_PATH = ( |
732 | DEFAULT_DATA_DIR + PRIVATE_SUBDIR + "/" + MACHINE_TOKEN_FILE |
733 | ) |
734 | -CANDIDATE_CACHE_PATH = UAC_TMP_PATH + "candidate-version" |
735 | +CANDIDATE_CACHE_PATH = UAC_RUN_PATH + "candidate-version" |
736 | DEFAULT_CONFIG_FILE = UAC_ETC_PATH + "uaclient.conf" |
737 | DEFAULT_HELP_FILE = UAC_ETC_PATH + "help_data.yaml" |
738 | DEFAULT_UPGRADE_CONTRACT_FLAG_FILE = UAC_ETC_PATH + "request-update-contract" |
739 | diff --git a/uaclient/jobs/update_messaging.py b/uaclient/jobs/update_messaging.py |
740 | index 4a3893f..41a027b 100644 |
741 | --- a/uaclient/jobs/update_messaging.py |
742 | +++ b/uaclient/jobs/update_messaging.py |
743 | @@ -28,7 +28,6 @@ from uaclient.messages import ( |
744 | CONTRACT_EXPIRED_MOTD_SOON_TMPL, |
745 | DISABLED_APT_NO_PKGS_TMPL, |
746 | DISABLED_APT_PKGS_TMPL, |
747 | - TRY_UBUNTU_PRO_BETA, |
748 | ) |
749 | |
750 | XENIAL_ESM_URL = "https://ubuntu.com/16-04" |
751 | @@ -68,6 +67,17 @@ UPDATE_NOTIFIER_MOTD_SCRIPT = ( |
752 | ) |
753 | |
754 | |
755 | +def set_apt_news_flag(cfg: config.UAConfig): |
756 | + if system.is_current_series_lts(): |
757 | + system.create_file( |
758 | + os.path.join(cfg.data_dir, "flags", "show-apt-news") |
759 | + ) |
760 | + |
761 | + |
762 | +def clear_apt_news_flag(cfg: config.UAConfig): |
763 | + system.remove_file(os.path.join(cfg.data_dir, "flags", "show-apt-news")) |
764 | + |
765 | + |
766 | def get_contract_expiry_status( |
767 | cfg: config.UAConfig, |
768 | ) -> Tuple[ContractExpiryStatus, int]: |
769 | @@ -311,32 +321,6 @@ def write_apt_and_motd_templates(cfg: config.UAConfig, series: str) -> None: |
770 | ], |
771 | ) |
772 | |
773 | - if ( |
774 | - system.is_current_series_lts() |
775 | - and not system.is_active_esm(series) |
776 | - and not cfg.is_attached |
777 | - ): |
778 | - _write_template_or_remove( |
779 | - TRY_UBUNTU_PRO_BETA, os.path.join(msg_dir, apps_no_pkg_file) |
780 | - ) |
781 | - _write_template_or_remove( |
782 | - TRY_UBUNTU_PRO_BETA, os.path.join(msg_dir, apps_pkg_file) |
783 | - ) |
784 | - _write_template_or_remove("", os.path.join(msg_dir, infra_no_pkg_file)) |
785 | - _write_template_or_remove("", os.path.join(msg_dir, infra_pkg_file)) |
786 | - _write_template_or_remove( |
787 | - "", os.path.join(msg_dir, motd_apps_no_pkg_file) |
788 | - ) |
789 | - _write_template_or_remove( |
790 | - "", os.path.join(msg_dir, motd_apps_pkg_file) |
791 | - ) |
792 | - _write_template_or_remove( |
793 | - "", os.path.join(msg_dir, motd_infra_no_pkg_file) |
794 | - ) |
795 | - _write_template_or_remove( |
796 | - "", os.path.join(msg_dir, motd_infra_pkg_file) |
797 | - ) |
798 | - |
799 | |
800 | def write_esm_announcement_message(cfg: config.UAConfig, series: str) -> None: |
801 | """Write human-readable messages if ESM is offered on this LTS release. |
802 | @@ -396,6 +380,12 @@ def update_apt_and_motd_messages(cfg: config.UAConfig) -> bool: |
803 | |
804 | # Announce ESM availabilty on active ESM LTS releases |
805 | # write_esm_announcement_message(cfg, series) |
806 | + |
807 | + if cfg.apt_news: |
808 | + set_apt_news_flag(cfg) |
809 | + else: |
810 | + clear_apt_news_flag(cfg) |
811 | + |
812 | write_apt_and_motd_templates(cfg, series) |
813 | # Now that we've setup/cleanedup templates render them with apt-hook |
814 | system.subp( |
815 | diff --git a/uaclient/messages.py b/uaclient/messages.py |
816 | index 95f1605..e3061be 100644 |
817 | --- a/uaclient/messages.py |
818 | +++ b/uaclient/messages.py |
819 | @@ -1034,7 +1034,3 @@ Package names in {bold}bold{end_bold} currently have an available update |
820 | with '{{service}}' enabled""".format( |
821 | bold=TxtColor.BOLD, end_bold=TxtColor.ENDC |
822 | ) |
823 | - |
824 | -TRY_UBUNTU_PRO_BETA = """\ |
825 | -Try Ubuntu Pro beta with a free personal subscription on up to 5 machines. |
826 | -Learn more at https://ubuntu.com/pro""" |
827 | diff --git a/uaclient/system.py b/uaclient/system.py |
828 | index ef48d0c..3983e84 100644 |
829 | --- a/uaclient/system.py |
830 | +++ b/uaclient/system.py |
831 | @@ -1,6 +1,7 @@ |
832 | import datetime |
833 | import logging |
834 | import os |
835 | +import pathlib |
836 | import re |
837 | import subprocess |
838 | import time |
839 | @@ -205,6 +206,11 @@ def is_active_esm(series: str) -> bool: |
840 | |
841 | |
842 | @lru_cache(maxsize=None) |
843 | +def is_current_series_active_esm() -> bool: |
844 | + return is_active_esm(get_platform_info()["series"]) |
845 | + |
846 | + |
847 | +@lru_cache(maxsize=None) |
848 | def is_container(run_path: str = "/run") -> bool: |
849 | """Checks to see if this code running in a container of some sort""" |
850 | |
851 | @@ -350,6 +356,13 @@ def load_file(filename: str, decode: bool = True) -> str: |
852 | return content.decode("utf-8") |
853 | |
854 | |
855 | +def create_file(filename: str, mode: int = 0o644) -> None: |
856 | + logging.debug("Creating file: %s", filename) |
857 | + os.makedirs(os.path.dirname(filename), exist_ok=True) |
858 | + pathlib.Path(filename).touch() |
859 | + os.chmod(filename, mode) |
860 | + |
861 | + |
862 | def write_file(filename: str, content: str, mode: int = 0o644) -> None: |
863 | """Write content to the provided filename encoding it if necessary. |
864 | |
865 | diff --git a/uaclient/tests/test_actions.py b/uaclient/tests/test_actions.py |
866 | index 6f77d7f..12c05f1 100644 |
867 | --- a/uaclient/tests/test_actions.py |
868 | +++ b/uaclient/tests/test_actions.py |
869 | @@ -1,8 +1,10 @@ |
870 | +import logging |
871 | + |
872 | import mock |
873 | import pytest |
874 | |
875 | from uaclient import exceptions, messages |
876 | -from uaclient.actions import attach_with_token, auto_attach |
877 | +from uaclient.actions import attach_with_token, auto_attach, collect_logs |
878 | from uaclient.exceptions import ContractAPIError, NonAutoAttachImageError |
879 | from uaclient.tests.test_cli_auto_attach import fake_instance_factory |
880 | |
881 | @@ -141,3 +143,36 @@ class TestAutoAttach: |
882 | auto_attach(cfg, fake_instance_factory()) |
883 | |
884 | assert unexpected_error == excinfo.value |
885 | + |
886 | + |
887 | +@mock.patch("uaclient.actions._write_command_output_to_file") |
888 | +class TestCollectLogs: |
889 | + @pytest.mark.parametrize("caplog_text", [logging.WARNING], indirect=True) |
890 | + @mock.patch("os.getuid") |
891 | + @mock.patch("uaclient.system.write_file") |
892 | + @mock.patch("uaclient.system.load_file") |
893 | + @mock.patch("uaclient.actions._get_state_files") |
894 | + @mock.patch("glob.glob") |
895 | + def test_collect_logs_invalid_file( |
896 | + self, |
897 | + m_glob, |
898 | + m_get_state_files, |
899 | + m_load_file, |
900 | + m_write_file, |
901 | + m_getuid, |
902 | + m_write_cmd, |
903 | + caplog_text, |
904 | + ): |
905 | + m_get_state_files.return_value = ["a", "b"] |
906 | + m_load_file.side_effect = [UnicodeError("test"), "test"] |
907 | + m_getuid.return_value = 1 |
908 | + m_glob.return_value = [] |
909 | + |
910 | + with mock.patch("os.path.isfile", return_value=True): |
911 | + collect_logs(cfg=mock.MagicMock(), output_dir="test") |
912 | + |
913 | + assert 2 == m_load_file.call_count |
914 | + assert [mock.call("a"), mock.call("b")] == m_load_file.call_args_list |
915 | + assert 1 == m_write_file.call_count |
916 | + assert [mock.call("test/b", "test")] == m_write_file.call_args_list |
917 | + assert "Failed to load file: a\n" in caplog_text() |
918 | diff --git a/uaclient/tests/test_cli_config_set.py b/uaclient/tests/test_cli_config_set.py |
919 | index 66aaf82..d8a7c49 100644 |
920 | --- a/uaclient/tests/test_cli_config_set.py |
921 | +++ b/uaclient/tests/test_cli_config_set.py |
922 | @@ -16,7 +16,8 @@ positional arguments: |
923 | must be one of: http_proxy, https_proxy, apt_http_proxy, |
924 | apt_https_proxy, ua_apt_http_proxy, ua_apt_https_proxy, |
925 | global_apt_http_proxy, global_apt_https_proxy, |
926 | - update_messaging_timer, update_status_timer, metering_timer |
927 | + update_messaging_timer, update_status_timer, metering_timer, |
928 | + apt_news |
929 | |
930 | Flags: |
931 | -h, --help show this help message and exit |
932 | diff --git a/uaclient/tests/test_cli_config_show.py b/uaclient/tests/test_cli_config_show.py |
933 | index d4582fd..ebf760c 100644 |
934 | --- a/uaclient/tests/test_cli_config_show.py |
935 | +++ b/uaclient/tests/test_cli_config_show.py |
936 | @@ -117,6 +117,7 @@ global_apt_https_proxy http://global_apt_https_proxy |
937 | update_messaging_timer None |
938 | update_status_timer None |
939 | metering_timer None |
940 | +apt_news True |
941 | """ |
942 | == out |
943 | ) |
944 | diff --git a/uaclient/tests/test_cli_config_unset.py b/uaclient/tests/test_cli_config_unset.py |
945 | index 115bc86..42c3625 100644 |
946 | --- a/uaclient/tests/test_cli_config_unset.py |
947 | +++ b/uaclient/tests/test_cli_config_unset.py |
948 | @@ -15,7 +15,7 @@ positional arguments: |
949 | http_proxy, https_proxy, apt_http_proxy, apt_https_proxy, |
950 | ua_apt_http_proxy, ua_apt_https_proxy, global_apt_http_proxy, |
951 | global_apt_https_proxy, update_messaging_timer, |
952 | - update_status_timer, metering_timer |
953 | + update_status_timer, metering_timer, apt_news |
954 | |
955 | Flags: |
956 | -h, --help show this help message and exit |
957 | diff --git a/uaclient/tests/test_config.py b/uaclient/tests/test_config.py |
958 | index bd8a49e..d3b493c 100644 |
959 | --- a/uaclient/tests/test_config.py |
960 | +++ b/uaclient/tests/test_config.py |
961 | @@ -295,6 +295,7 @@ UA_CFG_DICT = { |
962 | "ua_config": { |
963 | "apt_http_proxy": None, |
964 | "apt_https_proxy": None, |
965 | + "apt_news": True, |
966 | "global_apt_http_proxy": None, |
967 | "global_apt_https_proxy": None, |
968 | "ua_apt_http_proxy": None, |
969 | @@ -316,7 +317,9 @@ class TestUAConfigKeys: |
970 | ): |
971 | """Getters and settings are available fo UA_CONFIGURABLE_KEYS.""" |
972 | cfg = FakeConfig() |
973 | - assert None is getattr(cfg, attr_name, None) |
974 | + assert UA_CFG_DICT["ua_config"][attr_name] == getattr( |
975 | + cfg, attr_name, None |
976 | + ) |
977 | cfg_non_members = ("apt_http_proxy", "apt_https_proxy") |
978 | if attr_name not in cfg_non_members: |
979 | setattr(cfg, attr_name, attr_name + "value") |
980 | diff --git a/uaclient/tests/test_version.py b/uaclient/tests/test_version.py |
981 | index f6fd890..369dbbb 100644 |
982 | --- a/uaclient/tests/test_version.py |
983 | +++ b/uaclient/tests/test_version.py |
984 | @@ -59,9 +59,12 @@ class TestGetLastKnownCandidate: |
985 | m_open.side_effect = OSError() |
986 | assert None is get_last_known_candidate() |
987 | |
988 | + @mock.patch("os.makedirs") |
989 | @mock.patch("uaclient.version.get_apt_cache_policy_for_package") |
990 | @mock.patch("os.path.exists", return_value=False) |
991 | - def test_create_cache_before_returning(self, _m_exists, m_policy): |
992 | + def test_create_cache_before_returning( |
993 | + self, _m_exists, m_policy, _m_makedirs |
994 | + ): |
995 | m_policy.return_value = """ |
996 | Installed: 1.1.2 |
997 | Candidate: 1.2.3 |
998 | @@ -83,7 +86,7 @@ class TestGetLastKnownCandidate: |
999 | Version table: |
1000 | """ |
1001 | m_open.side_effect = OSError() |
1002 | - assert None is get_last_known_candidate() |
1003 | + assert "1.2.3" == get_last_known_candidate() |
1004 | |
1005 | |
1006 | class TestCheckForNewVersion: |
1007 | diff --git a/uaclient/version.py b/uaclient/version.py |
1008 | index 54776f6..6232b30 100644 |
1009 | --- a/uaclient/version.py |
1010 | +++ b/uaclient/version.py |
1011 | @@ -14,11 +14,11 @@ from uaclient.apt import ( |
1012 | get_apt_cache_policy_for_package, |
1013 | get_apt_cache_time, |
1014 | ) |
1015 | -from uaclient.defaults import CANDIDATE_CACHE_PATH, UAC_TMP_PATH |
1016 | +from uaclient.defaults import CANDIDATE_CACHE_PATH, UAC_RUN_PATH |
1017 | from uaclient.exceptions import ProcessExecutionError |
1018 | from uaclient.system import subp |
1019 | |
1020 | -__VERSION__ = "27.11.2" |
1021 | +__VERSION__ = "27.11.3" |
1022 | PACKAGED_VERSION = "@@PACKAGED_VERSION@@" |
1023 | |
1024 | CANDIDATE_REGEX = r"Candidate: (?P<candidate>.*?)\n" |
1025 | @@ -56,17 +56,19 @@ def get_last_known_candidate() -> Optional[str]: |
1026 | not os.path.exists(CANDIDATE_CACHE_PATH) |
1027 | or os.stat(CANDIDATE_CACHE_PATH).st_mtime < last_apt_cache_update |
1028 | ): |
1029 | + candidate_version = None |
1030 | try: |
1031 | policy = get_apt_cache_policy_for_package("ubuntu-advantage-tools") |
1032 | match = re.search(CANDIDATE_REGEX, policy) |
1033 | if match: |
1034 | candidate_version = match.group("candidate") |
1035 | - os.makedirs(UAC_TMP_PATH, exist_ok=True) |
1036 | + os.makedirs(UAC_RUN_PATH, exist_ok=True) |
1037 | with open(CANDIDATE_CACHE_PATH, "w") as f: |
1038 | f.write(candidate_version) |
1039 | - os.chmod(CANDIDATE_CACHE_PATH, 0o777) |
1040 | + return candidate_version |
1041 | except Exception: |
1042 | - pass |
1043 | + if candidate_version is not None: |
1044 | + return candidate_version |
1045 | |
1046 | try: |
1047 | with open(CANDIDATE_CACHE_PATH, "r") as f: |
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.