Skip to content

Commit ded22fb

Browse files
authored
feat(cloud-init): add support for azure-proxy-agent (#9878)
Adds preliminary support for azure-proxy-agent into cloud-init. This is opt-in only with fallbacks if the command isn't available.
1 parent 298bda4 commit ded22fb

4 files changed

Lines changed: 588 additions & 1 deletion
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
From 402e9331a72d543e779898667488a51ad3e3ec13 Mon Sep 17 00:00:00 2001
2+
From: Ksenija Stanojevic <KsenijaS@users.noreply.github.com>
3+
Date: Fri, 9 Feb 2024 13:32:19 -0800
4+
Subject: [PATCH 1/3] feat(azure): Add ProvisionGuestProxyAgent OVF setting
5+
(#4860)
6+
7+
Add ProvisionGuestProxyAgent Boolean configuration setting into the OvfEnv class.
8+
This PR is only logging the value of ProvisionGuestProxyAgent.
9+
---
10+
cloudinit/sources/DataSourceAzure.py | 6 ++++++
11+
cloudinit/sources/helpers/azure.py | 8 ++++++++
12+
tests/unittests/sources/test_azure.py | 15 +++++++++++++++
13+
3 files changed, 29 insertions(+)
14+
15+
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
16+
index 5a82aa34e..dc2b79a3a 100644
17+
--- a/cloudinit/sources/DataSourceAzure.py
18+
+++ b/cloudinit/sources/DataSourceAzure.py
19+
@@ -1784,6 +1784,12 @@ def read_azure_ovf(contents):
20+
"PreprovisionedVMType: %s" % ovf_env.preprovisioned_vm_type,
21+
logger_func=LOG.info,
22+
)
23+
+
24+
+ cfg["ProvisionGuestProxyAgent"] = ovf_env.provision_guest_proxy_agent
25+
+ report_diagnostic_event(
26+
+ "ProvisionGuestProxyAgent: %s" % ovf_env.provision_guest_proxy_agent,
27+
+ logger_func=LOG.info,
28+
+ )
29+
return (md, ud, cfg)
30+
31+
32+
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
33+
index 6e5c1f433..2847a9e53 100644
34+
--- a/cloudinit/sources/helpers/azure.py
35+
+++ b/cloudinit/sources/helpers/azure.py
36+
@@ -1064,6 +1064,7 @@ class OvfEnvXml:
37+
public_keys: Optional[List[dict]] = None,
38+
preprovisioned_vm: bool = False,
39+
preprovisioned_vm_type: Optional[str] = None,
40+
+ provision_guest_proxy_agent: bool = False,
41+
) -> None:
42+
self.username = username
43+
self.password = password
44+
@@ -1073,6 +1074,7 @@ class OvfEnvXml:
45+
self.public_keys: List[dict] = public_keys or []
46+
self.preprovisioned_vm = preprovisioned_vm
47+
self.preprovisioned_vm_type = preprovisioned_vm_type
48+
+ self.provision_guest_proxy_agent = provision_guest_proxy_agent
49+
50+
def __eq__(self, other) -> bool:
51+
return self.__dict__ == other.__dict__
52+
@@ -1216,6 +1218,12 @@ class OvfEnvXml:
53+
"PreprovisionedVMType",
54+
required=False,
55+
)
56+
+ self.provision_guest_proxy_agent = self._parse_property(
57+
+ platform_settings,
58+
+ "ProvisionGuestProxyAgent",
59+
+ default=False,
60+
+ required=False,
61+
+ )
62+
63+
def _parse_ssh_section(self, config_set):
64+
self.public_keys = []
65+
diff --git a/tests/unittests/sources/test_azure.py b/tests/unittests/sources/test_azure.py
66+
index 1ddbd3f39..6afde95fd 100644
67+
--- a/tests/unittests/sources/test_azure.py
68+
+++ b/tests/unittests/sources/test_azure.py
69+
@@ -356,6 +356,7 @@ def construct_ovf_env(
70+
disable_ssh_password_auth=None,
71+
preprovisioned_vm=None,
72+
preprovisioned_vm_type=None,
73+
+ provision_guest_proxy_agent=None,
74+
):
75+
content = [
76+
'<?xml version="1.0" encoding="utf-8"?>',
77+
@@ -426,6 +427,11 @@ def construct_ovf_env(
78+
"<ns1:PreprovisionedVMType>%s</ns1:PreprovisionedVMType>"
79+
% preprovisioned_vm_type
80+
)
81+
+ if provision_guest_proxy_agent is not None:
82+
+ content.append(
83+
+ "<ns1:ProvisionGuestProxyAgent>%s</ns1:ProvisionGuestProxyAgent>"
84+
+ % provision_guest_proxy_agent
85+
+ )
86+
content += [
87+
"</ns1:PlatformSettings>",
88+
"</ns1:PlatformSettingsSection>",
89+
@@ -1316,6 +1322,7 @@ scbus-1 on xpt0 bus 0
90+
expected_cfg = {
91+
"PreprovisionedVMType": None,
92+
"PreprovisionedVm": False,
93+
+ "ProvisionGuestProxyAgent": False,
94+
"system_info": {"default_user": {"name": "myuser"}},
95+
}
96+
expected_metadata = {
97+
@@ -2668,6 +2675,14 @@ class TestPreprovisioningReadAzureOvfFlag(CiTestCase):
98+
self.assertTrue(cfg["PreprovisionedVm"])
99+
self.assertEqual("Savable", cfg["PreprovisionedVMType"])
100+
101+
+ def test_read_azure_ovf_with_proxy_guest_agent(self):
102+
+ """The read_azure_ovf method should set ProvisionGuestProxyAgent
103+
+ cfg flag to True."""
104+
+ content = construct_ovf_env(provision_guest_proxy_agent=True)
105+
+ ret = dsaz.read_azure_ovf(content)
106+
+ cfg = ret[2]
107+
+ self.assertTrue(cfg["ProvisionGuestProxyAgent"])
108+
+
109+
110+
@pytest.mark.parametrize(
111+
"ovf_cfg,imds_md,pps_type",
112+
--
113+
2.34.1
114+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
From e3ba5800d26065df9ce03ee2ac58ec6f08506423 Mon Sep 17 00:00:00 2001
2+
From: Ksenija Stanojevic <KsenijaS@users.noreply.github.com>
3+
Date: Fri, 5 Apr 2024 16:52:26 -0700
4+
Subject: [PATCH 2/3] feat(azure): parse ProvisionGuestProxyAgent as bool
5+
(#5126)
6+
7+
---
8+
cloudinit/sources/helpers/azure.py | 1 +
9+
tests/unittests/sources/test_azure.py | 12 ++++++++++--
10+
2 files changed, 11 insertions(+), 2 deletions(-)
11+
12+
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
13+
index 2847a9e53..165f47429 100644
14+
--- a/cloudinit/sources/helpers/azure.py
15+
+++ b/cloudinit/sources/helpers/azure.py
16+
@@ -1221,6 +1221,7 @@ class OvfEnvXml:
17+
self.provision_guest_proxy_agent = self._parse_property(
18+
platform_settings,
19+
"ProvisionGuestProxyAgent",
20+
+ parse_bool=True,
21+
default=False,
22+
required=False,
23+
)
24+
diff --git a/tests/unittests/sources/test_azure.py b/tests/unittests/sources/test_azure.py
25+
index 6afde95fd..255991ec3 100644
26+
--- a/tests/unittests/sources/test_azure.py
27+
+++ b/tests/unittests/sources/test_azure.py
28+
@@ -2675,13 +2675,21 @@ class TestPreprovisioningReadAzureOvfFlag(CiTestCase):
29+
self.assertTrue(cfg["PreprovisionedVm"])
30+
self.assertEqual("Savable", cfg["PreprovisionedVMType"])
31+
32+
- def test_read_azure_ovf_with_proxy_guest_agent(self):
33+
+ def test_read_azure_ovf_with_proxy_guest_agent_true(self):
34+
"""The read_azure_ovf method should set ProvisionGuestProxyAgent
35+
cfg flag to True."""
36+
content = construct_ovf_env(provision_guest_proxy_agent=True)
37+
ret = dsaz.read_azure_ovf(content)
38+
cfg = ret[2]
39+
- self.assertTrue(cfg["ProvisionGuestProxyAgent"])
40+
+ assert cfg["ProvisionGuestProxyAgent"] is True
41+
+
42+
+ def test_read_azure_ovf_with_proxy_guest_agent_false(self):
43+
+ """The read_azure_ovf method should set ProvisionGuestProxyAgent
44+
+ cfg flag to False."""
45+
+ content = construct_ovf_env(provision_guest_proxy_agent=False)
46+
+ ret = dsaz.read_azure_ovf(content)
47+
+ cfg = ret[2]
48+
+ assert cfg["ProvisionGuestProxyAgent"] is False
49+
50+
51+
@pytest.mark.parametrize(
52+
--
53+
2.34.1
54+

0 commit comments

Comments
 (0)