|
| 1 | +From 19442eedae2a3f96d424626dad20e037f10f147b Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ksenija Stanojevic <ksenija.stanojevic@gmail.com> |
| 3 | +Date: Tue, 13 Aug 2024 09:44:25 -0700 |
| 4 | +Subject: [PATCH] add PPS support for azure-proxy-agent |
| 5 | + |
| 6 | +--- |
| 7 | + cloudinit/sources/DataSourceAzure.py | 23 +++++++++++++++++++++-- |
| 8 | + cloudinit/sources/azure/errors.py | 5 +---- |
| 9 | + tests/unittests/sources/test_azure.py | 5 ++++- |
| 10 | + 3 files changed, 26 insertions(+), 7 deletions(-) |
| 11 | + |
| 12 | +diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py |
| 13 | +index c2f74e173..aed740b89 100644 |
| 14 | +--- a/cloudinit/sources/DataSourceAzure.py |
| 15 | ++++ b/cloudinit/sources/DataSourceAzure.py |
| 16 | +@@ -504,15 +504,31 @@ class DataSourceAzure(sources.DataSource): |
| 17 | + ] |
| 18 | + out, err = subp.subp(cmd) |
| 19 | + report_diagnostic_event( |
| 20 | +- "Running azure-proxy-agent %s resulted" |
| 21 | +- "in stderr output: %s with stdout: %s" % (cmd, err, out), |
| 22 | ++ "Executing %s resulted " |
| 23 | ++ "in stderr=%r with stdout=%r" % (cmd, err, out), |
| 24 | + logger_func=LOG.debug, |
| 25 | + ) |
| 26 | + except subp.ProcessExecutionError as error: |
| 27 | + if isinstance(error.reason, FileNotFoundError): |
| 28 | ++ LOG.error( |
| 29 | ++ "Failed to activate Azure Guest Proxy Agent: " |
| 30 | ++ "azure-proxy-agent not found" |
| 31 | ++ ) |
| 32 | + report_error = errors.ReportableErrorProxyAgentNotFound() |
| 33 | + self._report_failure(report_error) |
| 34 | + else: |
| 35 | ++ report_diagnostic_event( |
| 36 | ++ "Failed to activate Azure Guest Proxy Agent: " |
| 37 | ++ "status check failed " |
| 38 | ++ "cmd=%r stderr=%r stdout=%r exit_code=%s" |
| 39 | ++ % ( |
| 40 | ++ error.cmd, |
| 41 | ++ error.stderr, |
| 42 | ++ error.stdout, |
| 43 | ++ error.exit_code, |
| 44 | ++ ), |
| 45 | ++ logger_func=LOG.error, |
| 46 | ++ ) |
| 47 | + reportable_error = ( |
| 48 | + errors.ReportableErrorProxyAgentStatusFailure(error) |
| 49 | + ) |
| 50 | +@@ -637,6 +653,9 @@ class DataSourceAzure(sources.DataSource): |
| 51 | + self._wait_for_pps_unknown_reuse() |
| 52 | + |
| 53 | + md, userdata_raw, cfg, files = self._reprovision() |
| 54 | ++ if cfg.get("ProvisionGuestProxyAgent"): |
| 55 | ++ self._check_azure_proxy_agent_status() |
| 56 | ++ |
| 57 | + # fetch metadata again as it has changed after reprovisioning |
| 58 | + imds_md = self.get_metadata_from_imds(report_failure=True) |
| 59 | + |
| 60 | +diff --git a/cloudinit/sources/azure/errors.py b/cloudinit/sources/azure/errors.py |
| 61 | +index b331cd686..6595ceda9 100644 |
| 62 | +--- a/cloudinit/sources/azure/errors.py |
| 63 | ++++ b/cloudinit/sources/azure/errors.py |
| 64 | +@@ -155,10 +155,7 @@ class ReportableErrorUnhandledException(ReportableError): |
| 65 | + |
| 66 | + class ReportableErrorProxyAgentNotFound(ReportableError): |
| 67 | + def __init__(self) -> None: |
| 68 | +- super().__init__( |
| 69 | +- "Unable to activate Azure Guest Proxy Agent." |
| 70 | +- "azure-proxy-agent not found" |
| 71 | +- ) |
| 72 | ++ super().__init__("azure-proxy-agent not found") |
| 73 | + |
| 74 | + |
| 75 | + class ReportableErrorProxyAgentStatusFailure(ReportableError): |
| 76 | +diff --git a/tests/unittests/sources/test_azure.py b/tests/unittests/sources/test_azure.py |
| 77 | +index 9b6672e1e..446d5bf31 100644 |
| 78 | +--- a/tests/unittests/sources/test_azure.py |
| 79 | ++++ b/tests/unittests/sources/test_azure.py |
| 80 | +@@ -4532,7 +4532,10 @@ class TestCheckAzureProxyAgent: |
| 81 | + subp.SubpResult("Guest Proxy Agent running", ""), |
| 82 | + ] |
| 83 | + self.azure_ds._check_azure_proxy_agent_status() |
| 84 | +- assert "Running azure-proxy-agent" in self.caplog.text |
| 85 | ++ assert ( |
| 86 | ++ "Executing ['azure-proxy-agent', '--status', '--wait', '120']" |
| 87 | ++ in self.caplog.text |
| 88 | ++ ) |
| 89 | + assert self.mock_wrapping_report_failure.mock_calls == [] |
| 90 | + |
| 91 | + def test_check_azure_proxy_agent_status_notfound(self): |
| 92 | +-- |
| 93 | +2.34.1 |
| 94 | + |
0 commit comments