Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sources/azure: remove unused remnants related to agent command #1119

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions cloudinit/sources/DataSourceAzure.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@

DS_NAME = 'Azure'
DEFAULT_METADATA = {"instance-id": "iid-AZURE-NODE"}
AGENT_START = ['service', 'walinuxagent', 'start']
AGENT_START_BUILTIN = "__builtin__"
BOUNCE_COMMAND_IFUP = [
'sh', '-xc',
"i=$interface; x=0; ifdown $i || x=$?; ifup $i || x=$?; exit $x"
Expand Down Expand Up @@ -262,7 +260,6 @@ def get_resource_disk_on_freebsd(port_id):
PLATFORM_ENTROPY_SOURCE = None

BUILTIN_DS_CONFIG = {
'agent_command': AGENT_START_BUILTIN,
'data_dir': AGENT_SEED_DIR,
'set_hostname': True,
'hostname_bounce': {
Expand Down Expand Up @@ -1525,8 +1522,7 @@ def _negotiate(self):
dhclient_lease_file,
pubkey_info=pubkey_info)

LOG.debug("negotiating with fabric via agent command %s",
self.ds_cfg['agent_command'])
LOG.debug("negotiating with fabric")
try:
fabric_data = metadata_func()
except Exception as e:
Expand Down
1 change: 0 additions & 1 deletion doc/examples/cloud-config-datasources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ datasource:
local-hostname: myhost.internal

Azure:
agent_command: [service, walinuxagent, start]
set_hostname: True
hostname_bounce:
interface: eth0
Expand Down
46 changes: 12 additions & 34 deletions tests/unittests/test_datasource/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def _get_mockds(self):
])
return dsaz

def _get_ds(self, data, agent_command=None, distro='ubuntu',
def _get_ds(self, data, distro='ubuntu',
apply_network=None, instance_id=None):

def _wait_for_files(flist, _maxwait=None, _naplen=None):
Expand Down Expand Up @@ -722,8 +722,6 @@ def _dmi_mocks(key):
distro = distro_cls(distro, data.get('sys_cfg', {}), self.paths)
dsrc = dsaz.DataSourceAzure(
data.get('sys_cfg', {}), distro=distro, paths=self.paths)
if agent_command is not None:
dsrc.ds_cfg['agent_command'] = agent_command
if apply_network is not None:
dsrc.ds_cfg['apply_network_config'] = apply_network

Expand Down Expand Up @@ -921,7 +919,7 @@ def test_get_data_on_ubuntu_will_not_remove_network_scripts_disabled(self):

def test_crawl_metadata_returns_structured_data_and_caches_nothing(self):
"""Return all structured metadata and cache no class attributes."""
yaml_cfg = "{agent_command: my_command}\n"
yaml_cfg = ""
odata = {'HostName': "myhost", 'UserName': "myuser",
'UserData': {'text': 'FOOBAR', 'encoding': 'plain'},
'dscfg': {'text': yaml_cfg, 'encoding': 'plain'}}
Expand All @@ -931,7 +929,7 @@ def test_crawl_metadata_returns_structured_data_and_caches_nothing(self):
expected_cfg = {
'PreprovisionedVMType': None,
'PreprovisionedVm': False,
'datasource': {'Azure': {'agent_command': 'my_command'}},
'datasource': {'Azure': {}},
'system_info': {'default_user': {'name': 'myuser'}}}
expected_metadata = {
'azure_data': {
Expand Down Expand Up @@ -1449,19 +1447,16 @@ def test_ovf_can_include_unicode(self):
def test_dsaz_report_ready_returns_true_when_report_succeeds(
self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'
self.assertTrue(dsrc._report_ready(lease=mock.MagicMock()))

def test_dsaz_report_ready_returns_false_and_does_not_propagate_exc(
self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'
self.m_get_metadata_from_fabric.side_effect = Exception
self.assertFalse(dsrc._report_ready(lease=mock.MagicMock()))

def test_dsaz_report_failure_returns_true_when_report_succeeds(self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'

with mock.patch.object(dsrc, 'crawl_metadata') as m_crawl_metadata:
# mock crawl metadata failure to cause report failure
Expand All @@ -1475,7 +1470,6 @@ def test_dsaz_report_failure_returns_true_when_report_succeeds(self):
def test_dsaz_report_failure_returns_false_and_does_not_propagate_exc(
self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'

with mock.patch.object(dsrc, 'crawl_metadata') as m_crawl_metadata, \
mock.patch.object(dsrc, '_ephemeral_dhcp_ctx') \
Expand Down Expand Up @@ -1505,7 +1499,6 @@ def test_dsaz_report_failure_returns_false_and_does_not_propagate_exc(

def test_dsaz_report_failure_description_msg(self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'

with mock.patch.object(dsrc, 'crawl_metadata') as m_crawl_metadata:
# mock crawl metadata failure to cause report failure
Expand All @@ -1518,7 +1511,6 @@ def test_dsaz_report_failure_description_msg(self):

def test_dsaz_report_failure_no_description_msg(self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'

with mock.patch.object(dsrc, 'crawl_metadata') as m_crawl_metadata:
m_crawl_metadata.side_effect = Exception
Expand All @@ -1529,7 +1521,6 @@ def test_dsaz_report_failure_no_description_msg(self):

def test_dsaz_report_failure_uses_cached_ephemeral_dhcp_ctx_lease(self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'

with mock.patch.object(dsrc, 'crawl_metadata') as m_crawl_metadata, \
mock.patch.object(dsrc, '_ephemeral_dhcp_ctx') \
Expand Down Expand Up @@ -1558,7 +1549,6 @@ def test_dsaz_report_failure_uses_cached_ephemeral_dhcp_ctx_lease(self):

def test_dsaz_report_failure_no_net_uses_new_ephemeral_dhcp_lease(self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'

with mock.patch.object(dsrc, 'crawl_metadata') as m_crawl_metadata, \
mock.patch.object(dsrc.distro.networking, 'is_up') \
Expand All @@ -1584,7 +1574,6 @@ def test_dsaz_report_failure_no_net_uses_new_ephemeral_dhcp_lease(self):
def test_dsaz_report_failure_no_net_and_no_dhcp_uses_fallback_lease(
self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'

with mock.patch.object(dsrc, 'crawl_metadata') as m_crawl_metadata, \
mock.patch.object(dsrc.distro.networking, 'is_up') \
Expand All @@ -1609,14 +1598,12 @@ def test_dsaz_report_failure_no_net_and_no_dhcp_uses_fallback_lease(
def test_exception_fetching_fabric_data_doesnt_propagate(self):
"""Errors communicating with fabric should warn, but return True."""
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'
self.m_get_metadata_from_fabric.side_effect = Exception
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)

def test_fabric_data_included_in_metadata(self):
dsrc = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
dsrc.ds_cfg['agent_command'] = '__builtin__'
self.m_get_metadata_from_fabric.return_value = {'test': 'value'}
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
Expand Down Expand Up @@ -1672,7 +1659,6 @@ def test_instance_id_from_dmidecode_used(self):

def test_instance_id_from_dmidecode_used_for_builtin(self):
ds = self._get_ds({'ovfcontent': construct_valid_ovf_env()})
ds.ds_cfg['agent_command'] = '__builtin__'
ds.get_data()
self.assertEqual(self.instance_id, ds.metadata['instance-id'])

Expand Down Expand Up @@ -2099,13 +2085,11 @@ def tearDown(self):
self.patches.close()
super(TestAzureBounce, self).tearDown()

def _get_ds(self, ovfcontent=None, agent_command=None):
def _get_ds(self, ovfcontent=None):
if ovfcontent is not None:
populate_dir(os.path.join(self.paths.seed_dir, "azure"),
{'ovf-env.xml': ovfcontent})
dsrc = dsaz.DataSourceAzure({}, distro=mock.Mock(), paths=self.paths)
if agent_command is not None:
dsrc.ds_cfg['agent_command'] = agent_command
return dsrc

def _get_and_setup(self, dsrc):
Expand Down Expand Up @@ -2161,8 +2145,7 @@ def test_force_performs_bounce_regardless(self, perform_hostname_bounce):
host_name = 'unchanged-host-name'
self.get_hostname.return_value = host_name
cfg = {'hostname_bounce': {'policy': 'force'}}
dsrc = self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg),
agent_command=['not', '__builtin__'])
dsrc = self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg))
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
self.assertEqual(1, perform_hostname_bounce.call_count)
Expand All @@ -2171,8 +2154,7 @@ def test_bounce_skipped_on_ifupdown_absent(self):
host_name = 'unchanged-host-name'
self.get_hostname.return_value = host_name
cfg = {'hostname_bounce': {'policy': 'force'}}
dsrc = self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg),
agent_command=['not', '__builtin__'])
dsrc = self._get_ds(self.get_ovf_env_with_dscfg(host_name, cfg))
patch_path = MOCKPATH + 'subp.which'
with mock.patch(patch_path) as m_which:
m_which.return_value = None
Expand All @@ -2187,8 +2169,7 @@ def test_different_hostnames_sets_hostname(self):
expected_hostname = 'azure-expected-host-name'
self.get_hostname.return_value = 'default-host-name'
dsrc = self._get_ds(
self.get_ovf_env_with_dscfg(expected_hostname, {}),
agent_command=['not', '__builtin__'])
self.get_ovf_env_with_dscfg(expected_hostname, {}))
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
self.assertEqual(expected_hostname,
Expand All @@ -2200,8 +2181,7 @@ def test_different_hostnames_performs_bounce(
expected_hostname = 'azure-expected-host-name'
self.get_hostname.return_value = 'default-host-name'
dsrc = self._get_ds(
self.get_ovf_env_with_dscfg(expected_hostname, {}),
agent_command=['not', '__builtin__'])
self.get_ovf_env_with_dscfg(expected_hostname, {}))
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
self.assertEqual(1, perform_hostname_bounce.call_count)
Expand All @@ -2210,8 +2190,7 @@ def test_different_hostnames_sets_hostname_back(self):
initial_host_name = 'default-host-name'
self.get_hostname.return_value = initial_host_name
dsrc = self._get_ds(
self.get_ovf_env_with_dscfg('some-host-name', {}),
agent_command=['not', '__builtin__'])
self.get_ovf_env_with_dscfg('some-host-name', {}))
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
self.assertEqual(initial_host_name,
Expand All @@ -2224,8 +2203,7 @@ def test_failure_in_bounce_still_resets_host_name(
initial_host_name = 'default-host-name'
self.get_hostname.return_value = initial_host_name
dsrc = self._get_ds(
self.get_ovf_env_with_dscfg('some-host-name', {}),
agent_command=['not', '__builtin__'])
self.get_ovf_env_with_dscfg('some-host-name', {}))
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
self.assertEqual(initial_host_name,
Expand All @@ -2240,7 +2218,7 @@ def test_environment_correct_for_bounce_command(
self.get_hostname.return_value = old_hostname
cfg = {'hostname_bounce': {'interface': interface, 'policy': 'force'}}
data = self.get_ovf_env_with_dscfg(hostname, cfg)
dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
dsrc = self._get_ds(data)
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
self.assertEqual(1, self.subp.call_count)
Expand All @@ -2254,7 +2232,7 @@ def test_default_bounce_command_ifup_used_by_default(
self, mock_get_boot_telemetry):
cfg = {'hostname_bounce': {'policy': 'force'}}
data = self.get_ovf_env_with_dscfg('some-hostname', cfg)
dsrc = self._get_ds(data, agent_command=['not', '__builtin__'])
dsrc = self._get_ds(data)
ret = self._get_and_setup(dsrc)
self.assertTrue(ret)
self.assertEqual(1, self.subp.call_count)
Expand Down