84
def livepatch_is_enabled():
85
""" Check to see if livepatch is enabled on the system"""
87
"""Return dict of active ua status information from ubuntu-advantage-tools
89
Prefer to obtain status information from cache on disk to avoid costly
90
roundtrips to contracts.canonical.com to check on available services.
92
Fallback to call ua status --format=json.
94
If there are errors running: ua status --format=json or if the status on
95
disk is unparseable, return an empty dict.
97
if os.path.exists(UA_STATUS_FILE):
98
with open(UA_STATUS_FILE, "r") as stream:
99
status = stream.read()
102
status = subprocess.check_output(
103
['ua', 'status', '--format=json']
105
except subprocess.CalledProcessError as e:
106
print_debug('failed to run ua status: %s' % e)
87
c_livepatch = subprocess.run(["/snap/bin/canonical-livepatch",
89
stdout=subprocess.PIPE,
90
stderr=subprocess.PIPE)
91
# it can't be enabled if it isn't installed
92
except FileNotFoundError:
94
if c_livepatch.returncode == 0:
96
elif c_livepatch.returncode == 1:
100
def esm_is_enabled():
101
""" Check to see if esm is an available source"""
102
acp = subprocess.Popen(["apt-cache", "policy"],
103
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
104
grep = subprocess.run(["grep", "-F", "-q", "https://%s" % esm_site],
105
stdin=acp.stdout, stdout=subprocess.PIPE)
106
if grep.returncode == 0:
108
elif grep.returncode == -1:
109
return json.loads(status)
110
except json.decoder.JSONDecodeError as e:
111
print_debug('failed to parse JSON from ua status output: %s' % e)
115
def is_ua_service_enabled(service_name: str) -> bool:
116
"""Check to see if named esm service is enabled.
118
:return: True if UA status reports service as enabled.
120
status = get_ua_status()
121
for service in status.get("services", []):
122
if service["name"] == service_name:
123
# Machines unattached to UA will not provide service 'status' key.
124
return service.get("status") == "enabled"
112
128
def trim_archive(archive):
353
369
"%s-apps-security" % codename,
356
livepatch_enabled = livepatch_is_enabled()
357
esm_enabled = esm_is_enabled()
358
is_esm_infra_used = (suite_esm_main in all_origins) or \
359
(suite_esm_main_security in all_origins)
360
is_esm_apps_used = (suite_esm_universe in all_origins) or \
361
(suite_esm_universe_security in all_origins)
372
livepatch_enabled = is_ua_service_enabled("livepatch")
373
esm_enabled = is_ua_service_enabled("esm-infra")
374
ua_attached = get_ua_status().get("attached", False)
363
376
# Now do the final loop through
364
377
for pkg in cache: