diff options
author | Chris Patterson <cpatterson@microsoft.com> | 2023-04-25 13:14:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-25 12:14:45 -0500 |
commit | 6e380dd68c32555d54f6ecbd9adff0b3248b679d (patch) | |
tree | 9add4a30751890b169f785b2a7f028deec1de3de /cloudinit | |
parent | 34637a49df13a054c4355de675b7cf286450b2f5 (diff) | |
download | cloud-init-git-6e380dd68c32555d54f6ecbd9adff0b3248b679d.tar.gz |
sources/azure: report failures to host via kvp (#2136)
Azure can report provisioning failures via the Wireserver health
endpoint. However, in the event of networking failures or Wireserver
issues, this report cannot be made and the VM will result in an OS
provisioning timeout and a generic error is presented to the user.
Report the failure via KVP using the "PROVISIONING_REPORT" key so
that the host can relay the provisioning error report to the user
when the VM fails to provision.
The format used is subject to change and/or removal.
Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/reporting/handlers.py | 15 | ||||
-rw-r--r-- | cloudinit/sources/DataSourceAzure.py | 16 |
2 files changed, 30 insertions, 1 deletions
diff --git a/cloudinit/reporting/handlers.py b/cloudinit/reporting/handlers.py index 2c1f4998..ff07f940 100644 --- a/cloudinit/reporting/handlers.py +++ b/cloudinit/reporting/handlers.py @@ -347,6 +347,21 @@ class HyperVKvpReportingHandler(ReportingHandler): break return result_array + def write_key(self, key: str, value: str) -> None: + """Write KVP key-value. + + Values will be truncated as needed. + """ + if len(value) >= self.HV_KVP_AZURE_MAX_VALUE_SIZE: + value = value[0 : self.HV_KVP_AZURE_MAX_VALUE_SIZE - 1] + + data = [self._encode_kvp_item(key, value)] + + try: + self._append_kvp_item(data) + except (OSError, IOError): + LOG.warning("failed posting kvp=%s value=%s", key, value) + def _encode_event(self, event): """ encode the event into kvp data bytes. diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index d0af2089..969cb376 100644 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -25,7 +25,7 @@ from cloudinit.net.dhcp import ( NoDHCPLeaseMissingDhclientError, ) from cloudinit.net.ephemeral import EphemeralDHCPv4 -from cloudinit.reporting import events +from cloudinit.reporting import events, handlers, instantiated_handler_registry from cloudinit.sources.azure import errors, identity, imds from cloudinit.sources.helpers import netlink from cloudinit.sources.helpers.azure import ( @@ -1175,6 +1175,20 @@ class DataSourceAzure(sources.DataSource): return reprovision_data @azure_ds_telemetry_reporter + def _report_failure_to_host(self, error: errors.ReportableError) -> bool: + """Report failure to host via well-known key.""" + value = error.as_description() + kvp_handler = instantiated_handler_registry.registered_items.get( + "telemetry" + ) + if not isinstance(kvp_handler, handlers.HyperVKvpReportingHandler): + LOG.debug("KVP handler not enabled, skipping host report.") + return False + + kvp_handler.write_key("PROVISIONING_REPORT", value) + return True + + @azure_ds_telemetry_reporter def _report_failure(self, error: errors.ReportableError) -> bool: """Tells the Azure fabric that provisioning has failed. |