diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-05-27 09:55:10 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-05-27 09:55:10 -0400 |
commit | 318bd66461cba2f480b2ef6be119d2fcd5c6e9c0 (patch) | |
tree | 1817b310efc0190c92c5c95b15df6491119233ce /tests/unittests/test_datasource | |
parent | 949cebd48c9100d4fd00b74232bcf048980e6e0d (diff) | |
parent | 0dbe69aa34948d73d5709a7ddc19389e05e1a268 (diff) | |
download | vyos-cloud-init-318bd66461cba2f480b2ef6be119d2fcd5c6e9c0.tar.gz vyos-cloud-init-318bd66461cba2f480b2ef6be119d2fcd5c6e9c0.zip |
merge from trunk
Diffstat (limited to 'tests/unittests/test_datasource')
-rw-r--r-- | tests/unittests/test_datasource/test_altcloud.py | 48 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_azure.py | 18 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_azure_helper.py | 3 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_cloudstack.py | 1 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_configdrive.py | 8 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_digitalocean.py | 2 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_gce.py | 2 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_maas.py | 4 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_nocloud.py | 2 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_openstack.py | 102 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_smartos.py | 110 |
11 files changed, 151 insertions, 149 deletions
diff --git a/tests/unittests/test_datasource/test_altcloud.py b/tests/unittests/test_datasource/test_altcloud.py index 85759c68..12966563 100644 --- a/tests/unittests/test_datasource/test_altcloud.py +++ b/tests/unittests/test_datasource/test_altcloud.py @@ -134,7 +134,7 @@ class TestGetCloudType(TestCase): ''' util.read_dmi_data = _dmi_data('RHEV') dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals('RHEV', dsrc.get_cloud_type()) + self.assertEqual('RHEV', dsrc.get_cloud_type()) def test_vsphere(self): ''' @@ -143,7 +143,7 @@ class TestGetCloudType(TestCase): ''' util.read_dmi_data = _dmi_data('VMware Virtual Platform') dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals('VSPHERE', dsrc.get_cloud_type()) + self.assertEqual('VSPHERE', dsrc.get_cloud_type()) def test_unknown(self): ''' @@ -152,7 +152,7 @@ class TestGetCloudType(TestCase): ''' util.read_dmi_data = _dmi_data('Unrecognized Platform') dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals('UNKNOWN', dsrc.get_cloud_type()) + self.assertEqual('UNKNOWN', dsrc.get_cloud_type()) class TestGetDataCloudInfoFile(TestCase): @@ -187,7 +187,7 @@ class TestGetDataCloudInfoFile(TestCase): _write_cloud_info_file('RHEV') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: True - self.assertEquals(True, dsrc.get_data()) + self.assertEqual(True, dsrc.get_data()) def test_vsphere(self): '''Success Test module get_data() forcing VSPHERE.''' @@ -195,7 +195,7 @@ class TestGetDataCloudInfoFile(TestCase): _write_cloud_info_file('VSPHERE') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: True - self.assertEquals(True, dsrc.get_data()) + self.assertEqual(True, dsrc.get_data()) def test_fail_rhev(self): '''Failure Test module get_data() forcing RHEV.''' @@ -203,7 +203,7 @@ class TestGetDataCloudInfoFile(TestCase): _write_cloud_info_file('RHEV') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: False - self.assertEquals(False, dsrc.get_data()) + self.assertEqual(False, dsrc.get_data()) def test_fail_vsphere(self): '''Failure Test module get_data() forcing VSPHERE.''' @@ -211,14 +211,14 @@ class TestGetDataCloudInfoFile(TestCase): _write_cloud_info_file('VSPHERE') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: False - self.assertEquals(False, dsrc.get_data()) + self.assertEqual(False, dsrc.get_data()) def test_unrecognized(self): '''Failure Test module get_data() forcing unrecognized.''' _write_cloud_info_file('unrecognized') dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.get_data()) + self.assertEqual(False, dsrc.get_data()) class TestGetDataNoCloudInfoFile(TestCase): @@ -250,7 +250,7 @@ class TestGetDataNoCloudInfoFile(TestCase): util.read_dmi_data = _dmi_data('RHEV Hypervisor') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_rhevm = lambda: True - self.assertEquals(True, dsrc.get_data()) + self.assertEqual(True, dsrc.get_data()) def test_vsphere_no_cloud_file(self): '''Test No cloud info file module get_data() forcing VSPHERE.''' @@ -258,14 +258,14 @@ class TestGetDataNoCloudInfoFile(TestCase): util.read_dmi_data = _dmi_data('VMware Virtual Platform') dsrc = DataSourceAltCloud({}, None, self.paths) dsrc.user_data_vsphere = lambda: True - self.assertEquals(True, dsrc.get_data()) + self.assertEqual(True, dsrc.get_data()) def test_failure_no_cloud_file(self): '''Test No cloud info file module get_data() forcing unrecognized.''' util.read_dmi_data = _dmi_data('Unrecognized Platform') dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.get_data()) + self.assertEqual(False, dsrc.get_data()) class TestUserDataRhevm(TestCase): @@ -305,7 +305,7 @@ class TestUserDataRhevm(TestCase): dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.user_data_rhevm()) + self.assertEqual(False, dsrc.user_data_rhevm()) def test_modprobe_fails(self): '''Test user_data_rhevm() where modprobe fails.''' @@ -315,7 +315,7 @@ class TestUserDataRhevm(TestCase): dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.user_data_rhevm()) + self.assertEqual(False, dsrc.user_data_rhevm()) def test_no_modprobe_cmd(self): '''Test user_data_rhevm() with no modprobe command.''' @@ -325,7 +325,7 @@ class TestUserDataRhevm(TestCase): dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.user_data_rhevm()) + self.assertEqual(False, dsrc.user_data_rhevm()) def test_udevadm_fails(self): '''Test user_data_rhevm() where udevadm fails.''' @@ -335,7 +335,7 @@ class TestUserDataRhevm(TestCase): dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.user_data_rhevm()) + self.assertEqual(False, dsrc.user_data_rhevm()) def test_no_udevadm_cmd(self): '''Test user_data_rhevm() with no udevadm command.''' @@ -345,7 +345,7 @@ class TestUserDataRhevm(TestCase): dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.user_data_rhevm()) + self.assertEqual(False, dsrc.user_data_rhevm()) class TestUserDataVsphere(TestCase): @@ -380,7 +380,7 @@ class TestUserDataVsphere(TestCase): dsrc = DataSourceAltCloud({}, None, self.paths) - self.assertEquals(False, dsrc.user_data_vsphere()) + self.assertEqual(False, dsrc.user_data_vsphere()) class TestReadUserDataCallback(TestCase): @@ -408,8 +408,8 @@ class TestReadUserDataCallback(TestCase): def test_callback_both(self): '''Test read_user_data_callback() with both files.''' - self.assertEquals('test user data', - read_user_data_callback(self.mount_dir)) + self.assertEqual('test user data', + read_user_data_callback(self.mount_dir)) def test_callback_dc(self): '''Test read_user_data_callback() with only DC file.''' @@ -418,8 +418,8 @@ class TestReadUserDataCallback(TestCase): dc_file=False, non_dc_file=True) - self.assertEquals('test user data', - read_user_data_callback(self.mount_dir)) + self.assertEqual('test user data', + read_user_data_callback(self.mount_dir)) def test_callback_non_dc(self): '''Test read_user_data_callback() with only non-DC file.''' @@ -428,14 +428,14 @@ class TestReadUserDataCallback(TestCase): dc_file=True, non_dc_file=False) - self.assertEquals('test user data', - read_user_data_callback(self.mount_dir)) + self.assertEqual('test user data', + read_user_data_callback(self.mount_dir)) def test_callback_none(self): '''Test read_user_data_callback() no files are found.''' _remove_user_data_files(self.mount_dir) - self.assertEquals(None, read_user_data_callback(self.mount_dir)) + self.assertEqual(None, read_user_data_callback(self.mount_dir)) def force_arch(arch=None): diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py index 444e2799..5f3eb31f 100644 --- a/tests/unittests/test_datasource/test_azure.py +++ b/tests/unittests/test_datasource/test_azure.py @@ -14,11 +14,11 @@ except ImportError: import crypt import os -import stat -import yaml import shutil +import stat import tempfile import xml.etree.ElementTree as ET +import yaml def construct_valid_ovf_env(data=None, pubkeys=None, userdata=None): @@ -165,7 +165,7 @@ class TestAzureDataSource(TestCase): def tags_equal(x, y): for x_tag, x_val in x.items(): y_val = y.get(x_val.tag) - self.assertEquals(x_val.text, y_val.text) + self.assertEqual(x_val.text, y_val.text) old_cnt = create_tag_index(oxml) new_cnt = create_tag_index(nxml) @@ -354,8 +354,8 @@ class TestAzureDataSource(TestCase): self.assertTrue(ret) cfg = dsrc.get_config_obj() - self.assertEquals(dsrc.device_name_to_device("ephemeral0"), - "/dev/sdb") + self.assertEqual(dsrc.device_name_to_device("ephemeral0"), + "/dev/sdb") assert 'disk_setup' in cfg assert 'fs_setup' in cfg self.assertIsInstance(cfg['disk_setup'], dict) @@ -404,15 +404,15 @@ class TestAzureDataSource(TestCase): self.xml_notequals(data['ovfcontent'], on_disk_ovf) # Make sure that the redacted password on disk is not used by CI - self.assertNotEquals(dsrc.cfg.get('password'), - DataSourceAzure.DEF_PASSWD_REDACTION) + self.assertNotEqual(dsrc.cfg.get('password'), + DataSourceAzure.DEF_PASSWD_REDACTION) # Make sure that the password was really encrypted et = ET.fromstring(on_disk_ovf) for elem in et.iter(): if 'UserPassword' in elem.tag: - self.assertEquals(DataSourceAzure.DEF_PASSWD_REDACTION, - elem.text) + self.assertEqual(DataSourceAzure.DEF_PASSWD_REDACTION, + elem.text) def test_ovf_env_arrives_in_waagent_dir(self): xml = construct_valid_ovf_env(data={}, userdata="FOODATA") diff --git a/tests/unittests/test_datasource/test_azure_helper.py b/tests/unittests/test_datasource/test_azure_helper.py index 1134199b..d07a1f07 100644 --- a/tests/unittests/test_datasource/test_azure_helper.py +++ b/tests/unittests/test_datasource/test_azure_helper.py @@ -1,6 +1,7 @@ import os from cloudinit.sources.helpers import azure as azure_helper + from ..helpers import TestCase try: @@ -70,7 +71,7 @@ class TestFindEndpoint(TestCase): def test_missing_special_azure_line(self): self.load_file.return_value = '' - self.assertRaises(Exception, + self.assertRaises(ValueError, azure_helper.WALinuxAgentShim.find_endpoint) @staticmethod diff --git a/tests/unittests/test_datasource/test_cloudstack.py b/tests/unittests/test_datasource/test_cloudstack.py index 656d80d1..974b3704 100644 --- a/tests/unittests/test_datasource/test_cloudstack.py +++ b/tests/unittests/test_datasource/test_cloudstack.py @@ -1,5 +1,6 @@ from cloudinit import helpers from cloudinit.sources.DataSourceCloudStack import DataSourceCloudStack + from ..helpers import TestCase try: diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py index 89b15f54..195b8207 100644 --- a/tests/unittests/test_datasource/test_configdrive.py +++ b/tests/unittests/test_datasource/test_configdrive.py @@ -151,7 +151,7 @@ class TestConfigDriveDataSource(TestCase): mock.patch.object(os.path, 'exists', side_effect=exists_side_effect())) device = cfg_ds.device_name_to_device(name) - self.assertEquals(dev_name, device) + self.assertEqual(dev_name, device) find_mock.assert_called_once_with(mock.ANY) self.assertEqual(exists_mock.call_count, 2) @@ -179,7 +179,7 @@ class TestConfigDriveDataSource(TestCase): mock.patch.object(os.path, 'exists', return_value=True)) device = cfg_ds.device_name_to_device(name) - self.assertEquals(dev_name, device) + self.assertEqual(dev_name, device) find_mock.assert_called_once_with(mock.ANY) exists_mock.assert_called_once_with(mock.ANY) @@ -214,7 +214,7 @@ class TestConfigDriveDataSource(TestCase): with mock.patch.object(os.path, 'exists', side_effect=exists_side_effect()): device = cfg_ds.device_name_to_device(name) - self.assertEquals(dev_name, device) + self.assertEqual(dev_name, device) # We don't assert the call count for os.path.exists() because # not all of the entries in name_tests results in two calls to # that function. Specifically, 'root2k' doesn't seem to call @@ -242,7 +242,7 @@ class TestConfigDriveDataSource(TestCase): for name, dev_name in name_tests.items(): with mock.patch.object(os.path, 'exists', return_value=True): device = cfg_ds.device_name_to_device(name) - self.assertEquals(dev_name, device) + self.assertEqual(dev_name, device) def test_dir_valid(self): """Verify a dir is read as such.""" diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py index 679d1b82..8936a1e3 100644 --- a/tests/unittests/test_datasource/test_digitalocean.py +++ b/tests/unittests/test_datasource/test_digitalocean.py @@ -19,8 +19,8 @@ import re from six.moves.urllib_parse import urlparse -from cloudinit import settings from cloudinit import helpers +from cloudinit import settings from cloudinit.sources import DataSourceDigitalOcean from .. import helpers as test_helpers diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py index fa714070..1f7eb99e 100644 --- a/tests/unittests/test_datasource/test_gce.py +++ b/tests/unittests/test_datasource/test_gce.py @@ -20,8 +20,8 @@ import re from base64 import b64encode, b64decode from six.moves.urllib_parse import urlparse -from cloudinit import settings from cloudinit import helpers +from cloudinit import settings from cloudinit.sources import DataSourceGCE from .. import helpers as test_helpers diff --git a/tests/unittests/test_datasource/test_maas.py b/tests/unittests/test_datasource/test_maas.py index 77d15cac..f66f1c6d 100644 --- a/tests/unittests/test_datasource/test_maas.py +++ b/tests/unittests/test_datasource/test_maas.py @@ -104,13 +104,13 @@ class TestMAASDataSource(TestCase): 'meta-data/local-hostname': 'test-hostname', 'meta-data/public-keys': 'test-hostname', 'user-data': b'foodata', - } + } valid_order = [ 'meta-data/local-hostname', 'meta-data/instance-id', 'meta-data/public-keys', 'user-data', - ] + ] my_seed = "http://example.com/xmeta" my_ver = "1999-99-99" my_headers = {'header1': 'value1', 'header2': 'value2'} diff --git a/tests/unittests/test_datasource/test_nocloud.py b/tests/unittests/test_datasource/test_nocloud.py index 2d5fc37c..3c528c23 100644 --- a/tests/unittests/test_datasource/test_nocloud.py +++ b/tests/unittests/test_datasource/test_nocloud.py @@ -4,10 +4,10 @@ from cloudinit import util from ..helpers import TestCase, populate_dir import os -import yaml import shutil import tempfile import unittest +import yaml try: from unittest import mock diff --git a/tests/unittests/test_datasource/test_openstack.py b/tests/unittests/test_datasource/test_openstack.py index 0aa1ba84..5c8592c5 100644 --- a/tests/unittests/test_datasource/test_openstack.py +++ b/tests/unittests/test_datasource/test_openstack.py @@ -22,8 +22,8 @@ import re from .. import helpers as test_helpers -from six import StringIO from six.moves.urllib.parse import urlparse +from six import StringIO from cloudinit import helpers from cloudinit import settings @@ -135,41 +135,45 @@ def _register_uris(version, ec2_files, ec2_meta, os_files): body=get_request_callback) +def _read_metadata_service(): + return ds.read_metadata_service(BASE_URL, retries=0, timeout=0.1) + + class TestOpenStackDataSource(test_helpers.HttprettyTestCase): VERSION = 'latest' @hp.activate def test_successful(self): _register_uris(self.VERSION, EC2_FILES, EC2_META, OS_FILES) - f = ds.read_metadata_service(BASE_URL) - self.assertEquals(VENDOR_DATA, f.get('vendordata')) - self.assertEquals(CONTENT_0, f['files']['/etc/foo.cfg']) - self.assertEquals(CONTENT_1, f['files']['/etc/bar/bar.cfg']) - self.assertEquals(2, len(f['files'])) - self.assertEquals(USER_DATA, f.get('userdata')) - self.assertEquals(EC2_META, f.get('ec2-metadata')) - self.assertEquals(2, f.get('version')) + f = _read_metadata_service() + self.assertEqual(VENDOR_DATA, f.get('vendordata')) + self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg']) + self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg']) + self.assertEqual(2, len(f['files'])) + self.assertEqual(USER_DATA, f.get('userdata')) + self.assertEqual(EC2_META, f.get('ec2-metadata')) + self.assertEqual(2, f.get('version')) metadata = f['metadata'] - self.assertEquals('nova', metadata.get('availability_zone')) - self.assertEquals('sm-foo-test.novalocal', metadata.get('hostname')) - self.assertEquals('sm-foo-test.novalocal', - metadata.get('local-hostname')) - self.assertEquals('sm-foo-test', metadata.get('name')) - self.assertEquals('b0fa911b-69d4-4476-bbe2-1c92bff6535c', - metadata.get('uuid')) - self.assertEquals('b0fa911b-69d4-4476-bbe2-1c92bff6535c', - metadata.get('instance-id')) + self.assertEqual('nova', metadata.get('availability_zone')) + self.assertEqual('sm-foo-test.novalocal', metadata.get('hostname')) + self.assertEqual('sm-foo-test.novalocal', + metadata.get('local-hostname')) + self.assertEqual('sm-foo-test', metadata.get('name')) + self.assertEqual('b0fa911b-69d4-4476-bbe2-1c92bff6535c', + metadata.get('uuid')) + self.assertEqual('b0fa911b-69d4-4476-bbe2-1c92bff6535c', + metadata.get('instance-id')) @hp.activate def test_no_ec2(self): _register_uris(self.VERSION, {}, {}, OS_FILES) - f = ds.read_metadata_service(BASE_URL) - self.assertEquals(VENDOR_DATA, f.get('vendordata')) - self.assertEquals(CONTENT_0, f['files']['/etc/foo.cfg']) - self.assertEquals(CONTENT_1, f['files']['/etc/bar/bar.cfg']) - self.assertEquals(USER_DATA, f.get('userdata')) - self.assertEquals({}, f.get('ec2-metadata')) - self.assertEquals(2, f.get('version')) + f = _read_metadata_service() + self.assertEqual(VENDOR_DATA, f.get('vendordata')) + self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg']) + self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg']) + self.assertEqual(USER_DATA, f.get('userdata')) + self.assertEqual({}, f.get('ec2-metadata')) + self.assertEqual(2, f.get('version')) @hp.activate def test_bad_metadata(self): @@ -178,8 +182,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): if k.endswith('meta_data.json'): os_files.pop(k, None) _register_uris(self.VERSION, {}, {}, os_files) - self.assertRaises(openstack.NonReadable, ds.read_metadata_service, - BASE_URL) + self.assertRaises(openstack.NonReadable, _read_metadata_service) @hp.activate def test_bad_uuid(self): @@ -190,8 +193,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): if k.endswith('meta_data.json'): os_files[k] = json.dumps(os_meta) _register_uris(self.VERSION, {}, {}, os_files) - self.assertRaises(openstack.BrokenMetadata, ds.read_metadata_service, - BASE_URL) + self.assertRaises(openstack.BrokenMetadata, _read_metadata_service) @hp.activate def test_userdata_empty(self): @@ -200,10 +202,10 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): if k.endswith('user_data'): os_files.pop(k, None) _register_uris(self.VERSION, {}, {}, os_files) - f = ds.read_metadata_service(BASE_URL) - self.assertEquals(VENDOR_DATA, f.get('vendordata')) - self.assertEquals(CONTENT_0, f['files']['/etc/foo.cfg']) - self.assertEquals(CONTENT_1, f['files']['/etc/bar/bar.cfg']) + f = _read_metadata_service() + self.assertEqual(VENDOR_DATA, f.get('vendordata')) + self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg']) + self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg']) self.assertFalse(f.get('userdata')) @hp.activate @@ -213,9 +215,9 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): if k.endswith('vendor_data.json'): os_files.pop(k, None) _register_uris(self.VERSION, {}, {}, os_files) - f = ds.read_metadata_service(BASE_URL) - self.assertEquals(CONTENT_0, f['files']['/etc/foo.cfg']) - self.assertEquals(CONTENT_1, f['files']['/etc/bar/bar.cfg']) + f = _read_metadata_service() + self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg']) + self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg']) self.assertFalse(f.get('vendordata')) @hp.activate @@ -225,8 +227,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): if k.endswith('vendor_data.json'): os_files[k] = '{' # some invalid json _register_uris(self.VERSION, {}, {}, os_files) - self.assertRaises(openstack.BrokenMetadata, ds.read_metadata_service, - BASE_URL) + self.assertRaises(openstack.BrokenMetadata, _read_metadata_service) @hp.activate def test_metadata_invalid(self): @@ -235,8 +236,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): if k.endswith('meta_data.json'): os_files[k] = '{' # some invalid json _register_uris(self.VERSION, {}, {}, os_files) - self.assertRaises(openstack.BrokenMetadata, ds.read_metadata_service, - BASE_URL) + self.assertRaises(openstack.BrokenMetadata, _read_metadata_service) @hp.activate def test_datasource(self): @@ -245,18 +245,18 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): None, helpers.Paths({})) self.assertIsNone(ds_os.version) - found = ds_os.get_data() + found = ds_os.get_data(timeout=0.1, retries=0) self.assertTrue(found) - self.assertEquals(2, ds_os.version) + self.assertEqual(2, ds_os.version) md = dict(ds_os.metadata) md.pop('instance-id', None) md.pop('local-hostname', None) - self.assertEquals(OSTACK_META, md) - self.assertEquals(EC2_META, ds_os.ec2_metadata) - self.assertEquals(USER_DATA, ds_os.userdata_raw) - self.assertEquals(2, len(ds_os.files)) - self.assertEquals(VENDOR_DATA, ds_os.vendordata_pure) - self.assertEquals(ds_os.vendordata_raw, None) + self.assertEqual(OSTACK_META, md) + self.assertEqual(EC2_META, ds_os.ec2_metadata) + self.assertEqual(USER_DATA, ds_os.userdata_raw) + self.assertEqual(2, len(ds_os.files)) + self.assertEqual(VENDOR_DATA, ds_os.vendordata_pure) + self.assertEqual(ds_os.vendordata_raw, None) @hp.activate def test_bad_datasource_meta(self): @@ -269,7 +269,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): None, helpers.Paths({})) self.assertIsNone(ds_os.version) - found = ds_os.get_data() + found = ds_os.get_data(timeout=0.1, retries=0) self.assertFalse(found) self.assertIsNone(ds_os.version) @@ -288,7 +288,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): 'timeout': 0, } self.assertIsNone(ds_os.version) - found = ds_os.get_data() + found = ds_os.get_data(timeout=0.1, retries=0) self.assertFalse(found) self.assertIsNone(ds_os.version) @@ -311,7 +311,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase): 'timeout': 0, } self.assertIsNone(ds_os.version) - found = ds_os.get_data() + found = ds_os.get_data(timeout=0.1, retries=0) self.assertFalse(found) self.assertIsNone(ds_os.version) diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py index 1ee64d60..ea20777a 100644 --- a/tests/unittests/test_datasource/test_smartos.py +++ b/tests/unittests/test_datasource/test_smartos.py @@ -24,6 +24,7 @@ from __future__ import print_function +from binascii import crc32 import json import os import os.path @@ -32,7 +33,6 @@ import shutil import stat import tempfile import uuid -from binascii import crc32 import serial import six @@ -201,16 +201,16 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds() ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals('kvm', dsrc.smartos_type) - self.assertEquals('/dev/ttyS1', dsrc.seed) + self.assertEqual('kvm', dsrc.smartos_type) + self.assertEqual('/dev/ttyS1', dsrc.seed) def test_seed_lxbrand(self): # default seed should be /dev/ttyS1 dsrc = self._get_ds(is_lxbrand=True) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals('lx-brand', dsrc.smartos_type) - self.assertEquals('/native/.zonecontrol/metadata.sock', dsrc.seed) + self.assertEqual('lx-brand', dsrc.smartos_type) + self.assertEqual('/native/.zonecontrol/metadata.sock', dsrc.seed) def test_issmartdc(self): dsrc = self._get_ds() @@ -234,29 +234,29 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['sdc:uuid'], - dsrc.metadata['instance-id']) + self.assertEqual(MOCK_RETURNS['sdc:uuid'], + dsrc.metadata['instance-id']) def test_root_keys(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['root_authorized_keys'], - dsrc.metadata['public-keys']) + self.assertEqual(MOCK_RETURNS['root_authorized_keys'], + dsrc.metadata['public-keys']) def test_hostname_b64(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['hostname'], - dsrc.metadata['local-hostname']) + self.assertEqual(MOCK_RETURNS['hostname'], + dsrc.metadata['local-hostname']) def test_hostname(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['hostname'], - dsrc.metadata['local-hostname']) + self.assertEqual(MOCK_RETURNS['hostname'], + dsrc.metadata['local-hostname']) def test_base64_all(self): # metadata provided base64_all of true @@ -268,16 +268,16 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=my_returns) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['hostname'], - dsrc.metadata['local-hostname']) - self.assertEquals(MOCK_RETURNS['cloud-init:user-data'], - dsrc.userdata_raw) - self.assertEquals(MOCK_RETURNS['root_authorized_keys'], - dsrc.metadata['public-keys']) - self.assertEquals(MOCK_RETURNS['disable_iptables_flag'], - dsrc.metadata['iptables_disable']) - self.assertEquals(MOCK_RETURNS['enable_motd_sys_info'], - dsrc.metadata['motd_sys_info']) + self.assertEqual(MOCK_RETURNS['hostname'], + dsrc.metadata['local-hostname']) + self.assertEqual(MOCK_RETURNS['cloud-init:user-data'], + dsrc.userdata_raw) + self.assertEqual(MOCK_RETURNS['root_authorized_keys'], + dsrc.metadata['public-keys']) + self.assertEqual(MOCK_RETURNS['disable_iptables_flag'], + dsrc.metadata['iptables_disable']) + self.assertEqual(MOCK_RETURNS['enable_motd_sys_info'], + dsrc.metadata['motd_sys_info']) def test_b64_userdata(self): my_returns = MOCK_RETURNS.copy() @@ -289,12 +289,12 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=my_returns) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['hostname'], - dsrc.metadata['local-hostname']) - self.assertEquals(MOCK_RETURNS['cloud-init:user-data'], - dsrc.userdata_raw) - self.assertEquals(MOCK_RETURNS['root_authorized_keys'], - dsrc.metadata['public-keys']) + self.assertEqual(MOCK_RETURNS['hostname'], + dsrc.metadata['local-hostname']) + self.assertEqual(MOCK_RETURNS['cloud-init:user-data'], + dsrc.userdata_raw) + self.assertEqual(MOCK_RETURNS['root_authorized_keys'], + dsrc.metadata['public-keys']) def test_b64_keys(self): my_returns = MOCK_RETURNS.copy() @@ -305,19 +305,19 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=my_returns) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['hostname'], - dsrc.metadata['local-hostname']) - self.assertEquals(MOCK_RETURNS['cloud-init:user-data'], - dsrc.userdata_raw) + self.assertEqual(MOCK_RETURNS['hostname'], + dsrc.metadata['local-hostname']) + self.assertEqual(MOCK_RETURNS['cloud-init:user-data'], + dsrc.userdata_raw) def test_userdata(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['user-data'], - dsrc.metadata['legacy-user-data']) - self.assertEquals(MOCK_RETURNS['cloud-init:user-data'], - dsrc.userdata_raw) + self.assertEqual(MOCK_RETURNS['user-data'], + dsrc.metadata['legacy-user-data']) + self.assertEqual(MOCK_RETURNS['cloud-init:user-data'], + dsrc.userdata_raw) def test_sdc_nics(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) @@ -330,21 +330,21 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['user-script'], - dsrc.metadata['user-script']) + self.assertEqual(MOCK_RETURNS['user-script'], + dsrc.metadata['user-script']) legacy_script_f = "%s/user-script" % self.legacy_user_d self.assertTrue(os.path.exists(legacy_script_f)) self.assertTrue(os.path.islink(legacy_script_f)) user_script_perm = oct(os.stat(legacy_script_f)[stat.ST_MODE])[-3:] - self.assertEquals(user_script_perm, '700') + self.assertEqual(user_script_perm, '700') def test_scripts_shebanged(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['user-script'], - dsrc.metadata['user-script']) + self.assertEqual(MOCK_RETURNS['user-script'], + dsrc.metadata['user-script']) legacy_script_f = "%s/user-script" % self.legacy_user_d self.assertTrue(os.path.exists(legacy_script_f)) @@ -352,9 +352,9 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): shebang = None with open(legacy_script_f, 'r') as f: shebang = f.readlines()[0].strip() - self.assertEquals(shebang, "#!/bin/bash") + self.assertEqual(shebang, "#!/bin/bash") user_script_perm = oct(os.stat(legacy_script_f)[stat.ST_MODE])[-3:] - self.assertEquals(user_script_perm, '700') + self.assertEqual(user_script_perm, '700') def test_scripts_shebang_not_added(self): """ @@ -370,8 +370,8 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=my_returns) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(my_returns['user-script'], - dsrc.metadata['user-script']) + self.assertEqual(my_returns['user-script'], + dsrc.metadata['user-script']) legacy_script_f = "%s/user-script" % self.legacy_user_d self.assertTrue(os.path.exists(legacy_script_f)) @@ -379,7 +379,7 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): shebang = None with open(legacy_script_f, 'r') as f: shebang = f.readlines()[0].strip() - self.assertEquals(shebang, "#!/usr/bin/perl") + self.assertEqual(shebang, "#!/usr/bin/perl") def test_userdata_removed(self): """ @@ -409,7 +409,7 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): if re.match(r'.*\/mdata-user-data$', name_f): found_new = True print(name_f) - self.assertEquals(permissions, '400') + self.assertEqual(permissions, '400') self.assertFalse(found_new) @@ -417,8 +417,8 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['sdc:vendor-data'], - dsrc.metadata['vendor-data']) + self.assertEqual(MOCK_RETURNS['sdc:vendor-data'], + dsrc.metadata['vendor-data']) def test_default_vendor_data(self): my_returns = MOCK_RETURNS.copy() @@ -427,7 +427,7 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=my_returns) ret = dsrc.get_data() self.assertTrue(ret) - self.assertNotEquals(def_op_script, dsrc.metadata['vendor-data']) + self.assertNotEqual(def_op_script, dsrc.metadata['vendor-data']) # we expect default vendor-data is a boothook self.assertTrue(dsrc.vendordata_raw.startswith("#cloud-boothook")) @@ -436,15 +436,15 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['disable_iptables_flag'], - dsrc.metadata['iptables_disable']) + self.assertEqual(MOCK_RETURNS['disable_iptables_flag'], + dsrc.metadata['iptables_disable']) def test_motd_sys_info(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() self.assertTrue(ret) - self.assertEquals(MOCK_RETURNS['enable_motd_sys_info'], - dsrc.metadata['motd_sys_info']) + self.assertEqual(MOCK_RETURNS['enable_motd_sys_info'], + dsrc.metadata['motd_sys_info']) def test_default_ephemeral(self): # Test to make sure that the builtin config has the ephemeral |