diff options
-rw-r--r-- | cloudinit/distros/__init__.py | 31 | ||||
-rw-r--r-- | cloudinit/distros/freebsd.py | 39 | ||||
-rw-r--r-- | cloudinit/sources/DataSourceOpenStack.py | 39 | ||||
-rw-r--r-- | cloudinit/sources/__init__.py | 29 | ||||
-rw-r--r-- | doc/examples/cloud-config-datasources.txt | 5 | ||||
-rw-r--r-- | tests/unittests/distros/test__init__.py | 96 | ||||
-rw-r--r-- | tests/unittests/sources/test_openstack.py | 132 | ||||
-rw-r--r-- | tests/unittests/test_ds_identify.py | 7 | ||||
-rw-r--r-- | tests/unittests/util.py | 5 | ||||
-rwxr-xr-x | tools/ds-identify | 7 |
10 files changed, 78 insertions, 312 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 940b689e..12fae0ac 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -992,37 +992,6 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta): **kwargs, ) - @property - def is_virtual(self) -> Optional[bool]: - """Detect if running on a virtual machine or bare metal. - - If the detection fails, it returns None. - """ - if not uses_systemd(): - # For non systemd systems the method should be - # implemented in the distro class. - LOG.warning("is_virtual should be implemented on distro class") - return None - - try: - detect_virt_path = subp.which("systemd-detect-virt") - if detect_virt_path: - out, _ = subp.subp( - [detect_virt_path], capture=True, rcs=[0, 1] - ) - - return not out.strip() == "none" - else: - err_msg = "detection binary not found" - except subp.ProcessExecutionError as e: - err_msg = str(e) - - LOG.warning( - "Failed to detect virtualization with systemd-detect-virt: %s", - err_msg, - ) - return None - def _apply_hostname_transformations_to_url(url: str, transformations: list): """ diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 706d0743..4268abe6 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -6,9 +6,7 @@ import os import re -from functools import lru_cache from io import StringIO -from typing import Optional import cloudinit.distros.bsd from cloudinit import log as logging @@ -194,40 +192,5 @@ class Distro(cloudinit.distros.bsd.BSD): freq=PER_INSTANCE, ) - @lru_cache() - def is_container(self) -> bool: - """return whether we're running in a container. - Cached, because it's unlikely to change.""" - jailed, _ = subp.subp(["sysctl", "-n", "security.jail.jailed"]) - if jailed.strip() == "0": - return False - return True - - @lru_cache() - def virtual(self) -> str: - """return the kind of virtualisation system we're running under. - Cached, because it's unlikely to change.""" - if self.is_container(): - return "jail" - # map FreeBSD's kern.vm_guest to systemd-detect-virt, just like we do - # in ds-identify - VM_GUEST_TO_SYSTEMD = { - "hv": "microsoft", - "vbox": "oracle", - "generic": "vm-other", - } - vm, _ = subp.subp(["sysctl", "-n", "kern.vm_guest"]) - vm = vm.strip() - if vm in VM_GUEST_TO_SYSTEMD: - return VM_GUEST_TO_SYSTEMD[vm] - return vm - - @property - def is_virtual(self) -> Optional[bool]: - """Detect if running on a virtual machine or bare metal. - This can fail on some platforms, so the signature is Optional[bool] - """ - if self.virtual() == "none": - return False - return True +# vi: ts=4 expandtab diff --git a/cloudinit/sources/DataSourceOpenStack.py b/cloudinit/sources/DataSourceOpenStack.py index 86ed3dd5..6a5012b5 100644 --- a/cloudinit/sources/DataSourceOpenStack.py +++ b/cloudinit/sources/DataSourceOpenStack.py @@ -73,7 +73,7 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): mstr = "%s [%s,ver=%s]" % (root, self.dsmode, self.version) return mstr - def wait_for_metadata_service(self, max_wait=None, timeout=None): + def wait_for_metadata_service(self): urls = self.ds_cfg.get("metadata_urls", DEF_MD_URLS) filtered = [x for x in urls if util.is_resolvable_url(x)] if set(filtered) != set(urls): @@ -90,23 +90,16 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): md_urls = [] url2base = {} for url in urls: - # Wait for a specific openstack metadata url md_url = url_helper.combine_url(url, "openstack") md_urls.append(md_url) url2base[md_url] = url url_params = self.get_url_params() - if max_wait is None: - max_wait = url_params.max_wait_seconds - - if timeout is None: - timeout = url_params.timeout_seconds - start_time = time.time() avail_url, _response = url_helper.wait_for_url( urls=md_urls, - max_wait=max_wait, - timeout=timeout, + max_wait=url_params.max_wait_seconds, + timeout=url_params.timeout_seconds, connect_synchronously=False, ) if avail_url: @@ -157,7 +150,6 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): False when unable to contact metadata service or when metadata format is invalid or disabled. """ - oracle_considered = "Oracle" in self.sys_cfg.get("datasource_list") if self.perform_dhcp_setup: # Setup networking in init-local stage. try: @@ -165,14 +157,6 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): self.fallback_interface, tmp_dir=self.distro.get_tmp_exec_path(), ): - if not self.detect_openstack( - accept_oracle=not oracle_considered - ): - LOG.debug( - "OpenStack datasource not running" - " on OpenStack (dhcp)" - ) - return False results = util.log_time( logfunc=LOG.debug, @@ -183,13 +167,6 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): util.logexc(LOG, str(e)) return False else: - if not self.detect_openstack(accept_oracle=not oracle_considered): - LOG.debug( - "OpenStack datasource not running" - " on OpenStack (non-dhcp)" - ) - return False - try: results = self._crawl_metadata() except sources.InvalidMetaDataException as e: @@ -268,8 +245,9 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): raise sources.InvalidMetaDataException(msg) from e return result - def detect_openstack(self, accept_oracle=False): + def ds_detect(self): """Return True when a potential OpenStack platform is detected.""" + accept_oracle = "Oracle" in self.sys_cfg.get("datasource_list") if not util.is_x86(): # Non-Intel cpus don't properly report dmi product names return True @@ -283,13 +261,6 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource): return True elif util.get_proc_env(1).get("product_name") == DMI_PRODUCT_NOVA: return True - # On bare metal hardware, the product name is not set like - # in a virtual OpenStack vm. We check if the system is virtual - # and if the openstack specific metadata service has been found. - elif not self.distro.is_virtual and self.wait_for_metadata_service( - max_wait=15, timeout=5 - ): - return True return False diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index 12430401..565e1754 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -307,6 +307,33 @@ class DataSource(CloudInitPickleMixin, metaclass=abc.ABCMeta): def __str__(self): return type_utils.obj_name(self) + def ds_detect(self) -> bool: + """Check if running on this datasource""" + return True + + def override_ds_detect(self): + """Override if either: + - only a single datasource defined (nothing to fall back to) + - TODO: commandline argument is used (ci.ds=OpenStack) + """ + return self.sys_cfg.get("datasource_list", []) in ( + [self.dsname], + [self.dsname, "None"], + ) + + def _check_and_get_data(self): + """Overrides runtime datasource detection""" + if self.override_ds_detect(): + LOG.debug( + "Machine is configured to run on single datasource %s.", self + ) + elif self.ds_detect(): + LOG.debug("Machine is running on %s.", self) + else: + LOG.debug("Datasource type %s is not detected.", self) + return False + return self._get_data() + def _get_standardized_metadata(self, instance_data): """Return a dictionary of standardized metadata keys.""" local_hostname = self.get_hostname().hostname @@ -370,7 +397,7 @@ class DataSource(CloudInitPickleMixin, metaclass=abc.ABCMeta): Minimally, the datasource should return a boolean True on success. """ self._dirty_cache = True - return_value = self._get_data() + return_value = self._check_and_get_data() if not return_value: return return_value self.persist_instance_data() diff --git a/doc/examples/cloud-config-datasources.txt b/doc/examples/cloud-config-datasources.txt index 9b5df6b0..43b34418 100644 --- a/doc/examples/cloud-config-datasources.txt +++ b/doc/examples/cloud-config-datasources.txt @@ -16,11 +16,6 @@ datasource: - http://169.254.169.254:80 - http://instance-data:8773 - OpenStack: - # The default list of metadata services to check for OpenStack. - metadata_urls: - - http://169.254.169.254 - MAAS: timeout : 50 max_wait : 120 diff --git a/tests/unittests/distros/test__init__.py b/tests/unittests/distros/test__init__.py index ea017d58..7c5187fd 100644 --- a/tests/unittests/distros/test__init__.py +++ b/tests/unittests/distros/test__init__.py @@ -221,102 +221,6 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase): ["pw", "usermod", "myuser", "-p", "01-Jan-1970"] ) - @mock.patch("cloudinit.distros.uses_systemd") - @mock.patch( - "cloudinit.distros.subp.which", - ) - @mock.patch( - "cloudinit.distros.subp.subp", - ) - def test_virtualization_detected(self, m_subp, m_which, m_uses_systemd): - m_uses_systemd.return_value = True - m_which.return_value = "/usr/bin/systemd-detect-virt" - m_subp.return_value = ("kvm", None) - - cls = distros.fetch("ubuntu") - d = cls("ubuntu", {}, None) - self.assertTrue(d.is_virtual) - - @mock.patch("cloudinit.distros.uses_systemd") - @mock.patch( - "cloudinit.distros.subp.subp", - ) - def test_virtualization_not_detected(self, m_subp, m_uses_systemd): - m_uses_systemd.return_value = True - m_subp.return_value = ("none", None) - - cls = distros.fetch("ubuntu") - d = cls("ubuntu", {}, None) - self.assertFalse(d.is_virtual) - - @mock.patch("cloudinit.distros.uses_systemd") - def test_virtualization_unknown(self, m_uses_systemd): - m_uses_systemd.return_value = True - - from cloudinit.subp import ProcessExecutionError - - cls = distros.fetch("ubuntu") - d = cls("ubuntu", {}, None) - with mock.patch( - "cloudinit.distros.subp.which", - return_value=None, - ): - self.assertIsNone( - d.is_virtual, - "Reflect unknown state when detection" - " binary cannot be found", - ) - - with mock.patch( - "cloudinit.distros.subp.subp", - side_effect=ProcessExecutionError(), - ): - self.assertIsNone( - d.is_virtual, "Reflect unknown state on ProcessExecutionError" - ) - - def test_virtualization_on_freebsd(self): - # This test function is a bit unusual: - # We need to first mock away the `ifconfig -a` subp call - # Then, we can use side-effects to get the results of two subp calls - # needed for is_container()/virtual() which is_virtual depends on. - # We also have to clear cache between each of those assertions. - - cls = distros.fetch("freebsd") - with mock.patch( - "cloudinit.distros.subp.subp", return_value=("", None) - ): - d = cls("freebsd", {}, None) - # This mock is called by `sysctl -n security.jail.jailed` - with mock.patch( - "cloudinit.distros.subp.subp", - side_effect=[("0\n", None), ("literaly any truthy value", None)], - ): - self.assertFalse(d.is_container()) - d.is_container.cache_clear() - self.assertTrue(d.is_container()) - d.is_container.cache_clear() - - # This mock is called by `sysctl -n kern.vm_guest` - with mock.patch( - "cloudinit.distros.subp.subp", - # fmt: off - side_effect=[ - ("0\n", None), ("hv\n", None), # virtual - ("0\n", None), ("none\n", None), # physical - ("0\n", None), ("hv\n", None) # virtual - ], - # fmt: on - ): - self.assertEqual(d.virtual(), "microsoft") - d.is_container.cache_clear() - d.virtual.cache_clear() - self.assertEqual(d.virtual(), "none") - d.is_container.cache_clear() - d.virtual.cache_clear() - - self.assertTrue(d.is_virtual) - class TestGetPackageMirrors: def return_first(self, mlist): diff --git a/tests/unittests/sources/test_openstack.py b/tests/unittests/sources/test_openstack.py index 02516772..2b3d83f4 100644 --- a/tests/unittests/sources/test_openstack.py +++ b/tests/unittests/sources/test_openstack.py @@ -301,12 +301,12 @@ class TestOpenStackDataSource(test_helpers.ResponsesTestCase): responses_mock=self.responses, ) distro = mock.MagicMock(spec=Distro) - distro.is_virtual = False ds_os = ds.DataSourceOpenStack( settings.CFG_BUILTIN, distro, helpers.Paths({"run_dir": self.tmp}) ) self.assertIsNone(ds_os.version) - self.assertTrue(ds_os.get_data()) + with mock.patch.object(ds_os, "ds_detect", return_value=True): + self.assertTrue(ds_os.get_data()) self.assertEqual(2, ds_os.version) md = dict(ds_os.metadata) md.pop("instance-id", None) @@ -351,7 +351,7 @@ class TestOpenStackDataSource(test_helpers.ResponsesTestCase): self.assertIsNone(ds_os_local.version) with test_helpers.mock.patch.object( - ds_os_local, "detect_openstack" + ds_os_local, "ds_detect" ) as m_detect_os: m_detect_os.return_value = True found = ds_os_local.get_data() @@ -383,9 +383,7 @@ class TestOpenStackDataSource(test_helpers.ResponsesTestCase): settings.CFG_BUILTIN, distro, helpers.Paths({"run_dir": self.tmp}) ) self.assertIsNone(ds_os.version) - with test_helpers.mock.patch.object( - ds_os, "detect_openstack" - ) as m_detect_os: + with test_helpers.mock.patch.object(ds_os, "ds_detect") as m_detect_os: m_detect_os.return_value = True found = ds_os.get_data() self.assertFalse(found) @@ -414,7 +412,8 @@ class TestOpenStackDataSource(test_helpers.ResponsesTestCase): "timeout": 0, } self.assertIsNone(ds_os.version) - self.assertFalse(ds_os.get_data()) + with mock.patch.object(ds_os, "ds_detect", return_value=True): + self.assertFalse(ds_os.get_data()) self.assertIsNone(ds_os.version) def test_network_config_disabled_by_datasource_config(self): @@ -489,9 +488,7 @@ class TestOpenStackDataSource(test_helpers.ResponsesTestCase): "timeout": 0, } self.assertIsNone(ds_os.version) - with test_helpers.mock.patch.object( - ds_os, "detect_openstack" - ) as m_detect_os: + with test_helpers.mock.patch.object(ds_os, "ds_detect") as m_detect_os: m_detect_os.return_value = True found = ds_os.get_data() self.assertFalse(found) @@ -589,53 +586,17 @@ class TestDetectOpenStack(test_helpers.CiTestCase): settings.CFG_BUILTIN, distro, helpers.Paths({"run_dir": self.tmp}) ) - def test_detect_openstack_non_intel_x86(self, m_is_x86): + def test_ds_detect_non_intel_x86(self, m_is_x86): """Return True on non-intel platforms because dmi isn't conclusive.""" m_is_x86.return_value = False self.assertTrue( - self._fake_ds().detect_openstack(), - "Expected detect_openstack == True", + self._fake_ds().ds_detect(), + "Expected ds_detect == True", ) - def test_detect_openstack_bare_metal(self, m_is_x86): - """Return True if the distro is non-virtual.""" - m_is_x86.return_value = True - - distro = mock.MagicMock(spec=Distro) - distro.is_virtual = False - - fake_ds = self._fake_ds() - fake_ds.distro = distro - - self.assertFalse( - fake_ds.distro.is_virtual, - "Expected distro.is_virtual == False", - ) - - with test_helpers.mock.patch.object( - fake_ds, "wait_for_metadata_service" - ) as m_wait_for_metadata_service: - m_wait_for_metadata_service.return_value = True - - self.assertTrue( - fake_ds.wait_for_metadata_service(), - "Expected wait_for_metadata_service == True", - ) - - self.assertTrue( - fake_ds.detect_openstack(), "Expected detect_openstack == True" - ) - - self.assertTrue( - m_wait_for_metadata_service.called, - "Expected wait_for_metadata_service to be called", - ) - @test_helpers.mock.patch(MOCK_PATH + "util.get_proc_env") @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_not_detect_openstack_intel_x86_ec2( - self, m_dmi, m_proc_env, m_is_x86 - ): + def test_not_ds_detect_intel_x86_ec2(self, m_dmi, m_proc_env, m_is_x86): """Return False on EC2 platforms.""" m_is_x86.return_value = True # No product_name in proc/1/environ @@ -650,15 +611,13 @@ class TestDetectOpenStack(test_helpers.CiTestCase): m_dmi.side_effect = fake_dmi_read self.assertFalse( - self._fake_ds().detect_openstack(), - "Expected detect_openstack == False on EC2", + self._fake_ds().ds_detect(), + "Expected ds_detect == False on EC2", ) m_proc_env.assert_called_with(1) @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_intel_product_name_compute( - self, m_dmi, m_is_x86 - ): + def test_ds_detect_intel_product_name_compute(self, m_dmi, m_is_x86): """Return True on OpenStack compute and nova instances.""" m_is_x86.return_value = True openstack_product_names = ["OpenStack Nova", "OpenStack Compute"] @@ -666,12 +625,12 @@ class TestDetectOpenStack(test_helpers.CiTestCase): for product_name in openstack_product_names: m_dmi.return_value = product_name self.assertTrue( - self._fake_ds().detect_openstack(), - "Failed to detect_openstack", + self._fake_ds().ds_detect(), + "Failed to ds_detect", ) @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_opentelekomcloud_chassis_asset_tag( + def test_ds_detect_opentelekomcloud_chassis_asset_tag( self, m_dmi, m_is_x86 ): """Return True on OpenStack reporting OpenTelekomCloud asset-tag.""" @@ -686,14 +645,12 @@ class TestDetectOpenStack(test_helpers.CiTestCase): m_dmi.side_effect = fake_dmi_read self.assertTrue( - self._fake_ds().detect_openstack(), - "Expected detect_openstack == True on OpenTelekomCloud", + self._fake_ds().ds_detect(), + "Expected ds_detect == True on OpenTelekomCloud", ) @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_sapccloud_chassis_asset_tag( - self, m_dmi, m_is_x86 - ): + def test_ds_detect_sapccloud_chassis_asset_tag(self, m_dmi, m_is_x86): """Return True on OpenStack reporting SAP CCloud VM asset-tag.""" m_is_x86.return_value = True @@ -706,14 +663,12 @@ class TestDetectOpenStack(test_helpers.CiTestCase): m_dmi.side_effect = fake_dmi_read self.assertTrue( - self._fake_ds().detect_openstack(), - "Expected detect_openstack == True on SAP CCloud VM", + self._fake_ds().ds_detect(), + "Expected ds_detect == True on SAP CCloud VM", ) @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_huaweicloud_chassis_asset_tag( - self, m_dmi, m_is_x86 - ): + def test_ds_detect_huaweicloud_chassis_asset_tag(self, m_dmi, m_is_x86): """Return True on OpenStack reporting Huawei Cloud VM asset-tag.""" m_is_x86.return_value = True @@ -726,14 +681,12 @@ class TestDetectOpenStack(test_helpers.CiTestCase): m_dmi.side_effect = fake_asset_tag_dmi_read self.assertTrue( - self._fake_ds().detect_openstack(), - "Expected detect_openstack == True on Huawei Cloud VM", + self._fake_ds().ds_detect(), + "Expected ds_detect == True on Huawei Cloud VM", ) @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_oraclecloud_chassis_asset_tag( - self, m_dmi, m_is_x86 - ): + def test_ds_detect_oraclecloud_chassis_asset_tag(self, m_dmi, m_is_x86): """Return True on OpenStack reporting Oracle cloud asset-tag.""" m_is_x86.return_value = True @@ -745,16 +698,19 @@ class TestDetectOpenStack(test_helpers.CiTestCase): assert False, "Unexpected dmi read of %s" % dmi_key m_dmi.side_effect = fake_dmi_read + ds = self._fake_ds() + ds.sys_cfg = {"datasource_list": ["Oracle"]} self.assertTrue( - self._fake_ds().detect_openstack(accept_oracle=True), - "Expected detect_openstack == True on OracleCloud.com", + ds.ds_detect(), + "Expected ds_detect == True on OracleCloud.com", ) + ds.sys_cfg = {"datasource_list": []} self.assertFalse( - self._fake_ds().detect_openstack(accept_oracle=False), - "Expected detect_openstack == False.", + ds.ds_detect(), + "Expected ds_detect == False.", ) - def _test_detect_openstack_nova_compute_chassis_asset_tag( + def _test_ds_detect_nova_compute_chassis_asset_tag( self, m_dmi, m_is_x86, chassis_tag ): """Return True on OpenStack reporting generic asset-tag.""" @@ -769,27 +725,25 @@ class TestDetectOpenStack(test_helpers.CiTestCase): m_dmi.side_effect = fake_dmi_read self.assertTrue( - self._fake_ds().detect_openstack(), - "Expected detect_openstack == True on Generic OpenStack Platform", + self._fake_ds().ds_detect(), + "Expected ds_detect == True on Generic OpenStack Platform", ) @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_nova_chassis_asset_tag(self, m_dmi, m_is_x86): - self._test_detect_openstack_nova_compute_chassis_asset_tag( + def test_ds_detect_nova_chassis_asset_tag(self, m_dmi, m_is_x86): + self._test_ds_detect_nova_compute_chassis_asset_tag( m_dmi, m_is_x86, "OpenStack Nova" ) @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_compute_chassis_asset_tag(self, m_dmi, m_is_x86): - self._test_detect_openstack_nova_compute_chassis_asset_tag( + def test_ds_detect_compute_chassis_asset_tag(self, m_dmi, m_is_x86): + self._test_ds_detect_nova_compute_chassis_asset_tag( m_dmi, m_is_x86, "OpenStack Compute" ) @test_helpers.mock.patch(MOCK_PATH + "util.get_proc_env") @test_helpers.mock.patch(MOCK_PATH + "dmi.read_dmi_data") - def test_detect_openstack_by_proc_1_environ( - self, m_dmi, m_proc_env, m_is_x86 - ): + def test_ds_detect_by_proc_1_environ(self, m_dmi, m_proc_env, m_is_x86): """Return True when nova product_name specified in /proc/1/environ.""" m_is_x86.return_value = True # Nova product_name in proc/1/environ @@ -807,8 +761,8 @@ class TestDetectOpenStack(test_helpers.CiTestCase): m_dmi.side_effect = fake_dmi_read self.assertTrue( - self._fake_ds().detect_openstack(), - "Expected detect_openstack == True on OpenTelekomCloud", + self._fake_ds().ds_detect(), + "Expected ds_detect == True on OpenTelekomCloud", ) m_proc_env.assert_called_with(1) diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py index 03be0c92..cc75209e 100644 --- a/tests/unittests/test_ds_identify.py +++ b/tests/unittests/test_ds_identify.py @@ -950,7 +950,7 @@ class TestOracle(DsIdentifyBase): """Simple negative test of Oracle.""" mycfg = copy.deepcopy(VALID_CFG["Oracle"]) mycfg["files"][P_CHASSIS_ASSET_TAG] = "Not Oracle" - self._check_via_dict(mycfg, ds=["openstack", "none"], rc=RC_FOUND) + self._check_via_dict(mycfg, rc=RC_NOT_FOUND) def blkid_out(disks=None): @@ -1056,7 +1056,6 @@ VALID_CFG = { "Ec2-brightbox-negative": { "ds": "Ec2", "files": {P_PRODUCT_SERIAL: "tricky-host.bobrightbox.com\n"}, - "mocks": [MOCK_VIRT_IS_KVM], }, "GCE": { "ds": "GCE", @@ -1598,7 +1597,6 @@ VALID_CFG = { "Ec2-E24Cloud-negative": { "ds": "Ec2", "files": {P_SYS_VENDOR: "e24cloudyday\n"}, - "mocks": [MOCK_VIRT_IS_KVM], }, "VMware-NoValidTransports": { "ds": "VMware", @@ -1757,7 +1755,6 @@ VALID_CFG = { "VMware-GuestInfo-NoVirtID": { "ds": "VMware", "mocks": [ - MOCK_VIRT_IS_KVM, { "name": "vmware_has_rpctool", "ret": 0, @@ -1863,7 +1860,6 @@ VALID_CFG = { P_PRODUCT_NAME: "3DS Outscale VM\n", P_SYS_VENDOR: "Not 3DS Outscale\n", }, - "mocks": [MOCK_VIRT_IS_KVM], }, "Ec2-Outscale-negative-productname": { "ds": "Ec2", @@ -1871,7 +1867,6 @@ VALID_CFG = { P_PRODUCT_NAME: "Not 3DS Outscale VM\n", P_SYS_VENDOR: "3DS Outscale\n", }, - "mocks": [MOCK_VIRT_IS_KVM], }, } diff --git a/tests/unittests/util.py b/tests/unittests/util.py index da04c6b2..e7094ec5 100644 --- a/tests/unittests/util.py +++ b/tests/unittests/util.py @@ -1,5 +1,4 @@ # This file is part of cloud-init. See LICENSE file for license information. -from typing import Optional from unittest import mock from cloudinit import cloud, distros, helpers @@ -146,10 +145,6 @@ class MockDistro(distros.Distro): def package_command(self, command, args=None, pkgs=None): pass - @property - def is_virtual(self) -> Optional[bool]: - return True - def update_package_sources(self): return (True, "yay") diff --git a/tools/ds-identify b/tools/ds-identify index da23e836..cd07565d 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -1262,13 +1262,6 @@ dscheck_OpenStack() { *) return ${DS_MAYBE};; esac - # If we are on bare metal, then we maybe are on a - # bare metal Ironic environment. - detect_virt - if [ "${_RET}" = "none" ]; then - return ${DS_MAYBE} - fi - return ${DS_NOT_FOUND} } |