summaryrefslogtreecommitdiff
path: root/tests/unittests/test_ds_identify.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_ds_identify.py')
-rw-r--r--tests/unittests/test_ds_identify.py148
1 files changed, 141 insertions, 7 deletions
diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
index 756b4fb4..36d7fbbf 100644
--- a/tests/unittests/test_ds_identify.py
+++ b/tests/unittests/test_ds_identify.py
@@ -140,7 +140,8 @@ class DsIdentifyBase(CiTestCase):
{'name': 'blkid', 'out': BLKID_EFI_ROOT},
{'name': 'ovf_vmware_transport_guestinfo',
'out': 'No value found', 'ret': 1},
-
+ {'name': 'dmi_decode', 'ret': 1,
+ 'err': 'No dmidecode program. ERROR.'},
]
written = [d['name'] for d in mocks]
@@ -195,6 +196,10 @@ class DsIdentifyBase(CiTestCase):
return self._check_via_dict(
data, RC_FOUND, dslist=[data.get('ds'), DS_NONE])
+ def _test_ds_not_found(self, name):
+ data = copy.deepcopy(VALID_CFG[name])
+ return self._check_via_dict(data, RC_NOT_FOUND)
+
def _check_via_dict(self, data, rc, dslist=None, **kwargs):
ret = self._call_via_dict(data, **kwargs)
good = False
@@ -244,9 +249,13 @@ class TestDsIdentify(DsIdentifyBase):
self._test_ds_found('Ec2-xen')
def test_brightbox_is_ec2(self):
- """EC2: product_serial ends with 'brightbox.com'"""
+ """EC2: product_serial ends with '.brightbox.com'"""
self._test_ds_found('Ec2-brightbox')
+ def test_bobrightbox_is_not_brightbox(self):
+ """EC2: bobrightbox.com in product_serial is not brightbox'"""
+ self._test_ds_not_found('Ec2-brightbox-negative')
+
def test_gce_by_product_name(self):
"""GCE identifies itself with product_name."""
self._test_ds_found('GCE')
@@ -259,10 +268,13 @@ class TestDsIdentify(DsIdentifyBase):
"""ConfigDrive datasource has a disk with LABEL=config-2."""
self._test_ds_found('ConfigDrive')
+ def test_rbx_cloud(self):
+ """Rbx datasource has a disk with LABEL=CLOUDMD."""
+ self._test_ds_found('RbxCloud')
+
def test_config_drive_upper(self):
"""ConfigDrive datasource has a disk with LABEL=CONFIG-2."""
self._test_ds_found('ConfigDriveUpper')
- return
def test_config_drive_seed(self):
"""Config Drive seed directory."""
@@ -435,13 +447,21 @@ class TestDsIdentify(DsIdentifyBase):
"""Open Telecom identification."""
self._test_ds_found('OpenStack-OpenTelekom')
+ def test_openstack_asset_tag_nova(self):
+ """OpenStack identification via asset tag OpenStack Nova."""
+ self._test_ds_found('OpenStack-AssetTag-Nova')
+
+ def test_openstack_asset_tag_copute(self):
+ """OpenStack identification via asset tag OpenStack Compute."""
+ self._test_ds_found('OpenStack-AssetTag-Compute')
+
def test_openstack_on_non_intel_is_maybe(self):
"""On non-Intel, openstack without dmi info is maybe.
nova does not identify itself on platforms other than intel.
https://bugs.launchpad.net/cloud-init/+bugs?field.tag=dsid-nova"""
- data = VALID_CFG['OpenStack'].copy()
+ data = copy.deepcopy(VALID_CFG['OpenStack'])
del data['files'][P_PRODUCT_NAME]
data.update({'policy_dmi': POLICY_FOUND_OR_MAYBE,
'policy_no_dmi': POLICY_FOUND_OR_MAYBE})
@@ -516,10 +536,38 @@ class TestDsIdentify(DsIdentifyBase):
self._check_via_dict(
ovf_cdrom_by_label, rc=RC_FOUND, dslist=['OVF', DS_NONE])
+ def test_ovf_on_vmware_iso_found_by_cdrom_with_different_size(self):
+ """OVF is identified by well-known iso9660 labels."""
+ ovf_cdrom_with_size = copy.deepcopy(VALID_CFG['OVF'])
+
+ # Set cdrom size to 20480 (10MB in 512 byte units)
+ ovf_cdrom_with_size['files']['sys/class/block/sr0/size'] = '20480\n'
+ self._check_via_dict(
+ ovf_cdrom_with_size, rc=RC_NOT_FOUND, policy_dmi="disabled")
+
+ # Set cdrom size to 204800 (100MB in 512 byte units)
+ ovf_cdrom_with_size['files']['sys/class/block/sr0/size'] = '204800\n'
+ self._check_via_dict(
+ ovf_cdrom_with_size, rc=RC_NOT_FOUND, policy_dmi="disabled")
+
+ # Set cdrom size to 18432 (9MB in 512 byte units)
+ ovf_cdrom_with_size['files']['sys/class/block/sr0/size'] = '18432\n'
+ self._check_via_dict(
+ ovf_cdrom_with_size, rc=RC_FOUND, dslist=['OVF', DS_NONE])
+
+ # Set cdrom size to 2048 (1MB in 512 byte units)
+ ovf_cdrom_with_size['files']['sys/class/block/sr0/size'] = '2048\n'
+ self._check_via_dict(
+ ovf_cdrom_with_size, rc=RC_FOUND, dslist=['OVF', DS_NONE])
+
def test_default_nocloud_as_vdb_iso9660(self):
"""NoCloud is found with iso9660 filesystem on non-cdrom disk."""
self._test_ds_found('NoCloud')
+ def test_nocloud_upper(self):
+ """NoCloud is found with uppercase filesystem label."""
+ self._test_ds_found('NoCloudUpper')
+
def test_nocloud_seed(self):
"""Nocloud seed directory."""
self._test_ds_found('NoCloud-seed')
@@ -565,6 +613,33 @@ class TestDsIdentify(DsIdentifyBase):
self.assertEqual(expected, [p for p in expected if p in toks],
"path did not have expected tokens")
+ def test_zstack_is_ec2(self):
+ """EC2: chassis asset tag ends with 'zstack.io'"""
+ self._test_ds_found('Ec2-ZStack')
+
+ def test_e24cloud_is_ec2(self):
+ """EC2: e24cloud identified by sys_vendor"""
+ self._test_ds_found('Ec2-E24Cloud')
+
+ def test_e24cloud_not_active(self):
+ """EC2: bobrightbox.com in product_serial is not brightbox'"""
+ self._test_ds_not_found('Ec2-E24Cloud-negative')
+
+
+class TestBSDNoSys(DsIdentifyBase):
+ """Test *BSD code paths
+
+ FreeBSD doesn't have /sys so we use dmidecode(8) here
+ It also doesn't have systemd-detect-virt(8), so we use sysctl(8) to query
+ kern.vm_guest, and optionally map it"""
+
+ def test_dmi_decode(self):
+ """Test that dmidecode(8) works on systems which don't have /sys
+
+ This will be used on *BSD systems.
+ """
+ self._test_ds_found('Hetzner-dmidecode')
+
class TestIsIBMProvisioning(DsIdentifyBase):
"""Test the is_ibm_provisioning method in ds-identify."""
@@ -688,7 +763,11 @@ VALID_CFG = {
},
'Ec2-brightbox': {
'ds': 'Ec2',
- 'files': {P_PRODUCT_SERIAL: 'facc6e2f.brightbox.com\n'},
+ 'files': {P_PRODUCT_SERIAL: 'srv-otuxg.gb1.brightbox.com\n'},
+ },
+ 'Ec2-brightbox-negative': {
+ 'ds': 'Ec2',
+ 'files': {P_PRODUCT_SERIAL: 'tricky-host.bobrightbox.com\n'},
},
'GCE': {
'ds': 'GCE',
@@ -713,6 +792,19 @@ VALID_CFG = {
'dev/vdb': 'pretend iso content for cidata\n',
}
},
+ 'NoCloudUpper': {
+ 'ds': 'NoCloud',
+ 'mocks': [
+ MOCK_VIRT_IS_KVM,
+ {'name': 'blkid', 'ret': 0,
+ 'out': blkid_out(
+ BLKID_UEFI_UBUNTU +
+ [{'DEVNAME': 'vdb', 'TYPE': 'iso9660', 'LABEL': 'CIDATA'}])},
+ ],
+ 'files': {
+ 'dev/vdb': 'pretend iso content for cidata\n',
+ }
+ },
'NoCloud-seed': {
'ds': 'NoCloud',
'files': {
@@ -742,6 +834,18 @@ VALID_CFG = {
'files': {P_CHASSIS_ASSET_TAG: 'OpenTelekomCloud\n'},
'mocks': [MOCK_VIRT_IS_XEN],
},
+ 'OpenStack-AssetTag-Nova': {
+ # VMware vSphere can't modify product-name, LP: #1669875
+ 'ds': 'OpenStack',
+ 'files': {P_CHASSIS_ASSET_TAG: 'OpenStack Nova\n'},
+ 'mocks': [MOCK_VIRT_IS_XEN],
+ },
+ 'OpenStack-AssetTag-Compute': {
+ # VMware vSphere can't modify product-name, LP: #1669875
+ 'ds': 'OpenStack',
+ 'files': {P_CHASSIS_ASSET_TAG: 'OpenStack Compute\n'},
+ 'mocks': [MOCK_VIRT_IS_XEN],
+ },
'OVF-seed': {
'ds': 'OVF',
'files': {
@@ -778,6 +882,7 @@ VALID_CFG = {
],
'files': {
'dev/sr0': 'pretend ovf iso has ' + OVF_MATCH_STRING + '\n',
+ 'sys/class/block/sr0/size': '2048\n',
}
},
'OVF-guestinfo': {
@@ -818,10 +923,28 @@ VALID_CFG = {
os.path.join(P_SEED_DIR, 'config_drive', 'openstack',
'latest', 'meta_data.json'): 'md\n'},
},
+ 'RbxCloud': {
+ 'ds': 'RbxCloud',
+ 'mocks': [
+ {'name': 'blkid', 'ret': 0,
+ 'out': blkid_out(
+ [{'DEVNAME': 'vda1', 'TYPE': 'vfat', 'PARTUUID': uuid4()},
+ {'DEVNAME': 'vda2', 'TYPE': 'ext4',
+ 'LABEL': 'cloudimg-rootfs', 'PARTUUID': uuid4()},
+ {'DEVNAME': 'vdb', 'TYPE': 'vfat', 'LABEL': 'CLOUDMD'}]
+ )},
+ ],
+ },
'Hetzner': {
'ds': 'Hetzner',
'files': {P_SYS_VENDOR: 'Hetzner\n'},
},
+ 'Hetzner-dmidecode': {
+ 'ds': 'Hetzner',
+ 'mocks': [
+ {'name': 'dmi_decode', 'ret': 0, 'RET': 'Hetzner'}
+ ],
+ },
'IBMCloud-metadata': {
'ds': 'IBMCloud',
'mocks': [
@@ -897,8 +1020,19 @@ VALID_CFG = {
{'name': 'blkid', 'ret': 2, 'out': ''},
],
'files': {ds_smartos.METADATA_SOCKFILE: 'would be a socket\n'},
- }
-
+ },
+ 'Ec2-ZStack': {
+ 'ds': 'Ec2',
+ 'files': {P_CHASSIS_ASSET_TAG: '123456.zstack.io\n'},
+ },
+ 'Ec2-E24Cloud': {
+ 'ds': 'Ec2',
+ 'files': {P_SYS_VENDOR: 'e24cloud\n'},
+ },
+ 'Ec2-E24Cloud-negative': {
+ 'ds': 'Ec2',
+ 'files': {P_SYS_VENDOR: 'e24cloudyday\n'},
+ }
}
# vi: ts=4 expandtab