diff options
author | Chad Smith <chad.smith@canonical.com> | 2023-03-20 11:36:56 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-20 11:36:56 -0600 |
commit | 7382cb669e64545e9e05cd2bb2a0de6430708890 (patch) | |
tree | e7651904a4f97bac544761fec057a0346a311ab3 /cloudinit | |
parent | a60c0845806baff72c74603286d048efbafab664 (diff) | |
download | cloud-init-git-7382cb669e64545e9e05cd2bb2a0de6430708890.tar.gz |
apport: only prompt for cloud_name when instance-data.json is absent
Do not prompt for CloudName when instance-data.json exists and is valid
YAML.
When instance-data.json exists, general-hooks/cloud_init.py will add the
following fields to bug reports:
CloudName, CloudID, CloudPlatform and CloudSubplatform.
Downstream ubuntu packaging braches deliver:
debian/apport-general-hook.py to
/usr/share/apport/general-hooks/cloud-init.py
Only prompt in during apport bug when the general-hook can't
process instance-data.json.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/apport.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/cloudinit/apport.py b/cloudinit/apport.py index e42ecf8e..dead3059 100644 --- a/cloudinit/apport.py +++ b/cloudinit/apport.py @@ -4,6 +4,7 @@ """Cloud-init apport interface""" +import json import os from cloudinit.cmd.devel import read_cfg_paths @@ -101,8 +102,29 @@ def attach_hwinfo(report, ui=None): def attach_cloud_info(report, ui=None): - """Prompt for cloud details if available.""" + """Prompt for cloud details if instance-data unavailable. + + When we have valid _get_instance_data, apport/generic-hooks/cloud_init.py + provides CloudName, CloudID, CloudPlatform and CloudSubPlatform. + + Apport/generic-hooks are delivered by cloud-init's downstream branches + ubuntu/(devel|kinetic|jammy|focal|bionic) so they will not be represented + in upstream main. + + In absence of viable instance-data.json format, prompt for the cloud below. + """ + if ui: + paths = read_cfg_paths() + try: + with open(paths.get_runpath("instance_data")) as file: + instance_data = json.load(file) + assert instance_data.get("v1", {}).get("cloud_name") + return # Valid instance-data means generic-hooks will report + except (IOError, json.decoder.JSONDecodeError, AssertionError): + pass + + # No valid /run/cloud/instance-data.json on system. Prompt for cloud. prompt = "Is this machine running in a cloud environment?" response = ui.yesno(prompt) if response is None: |