diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-08-23 21:34:36 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-08-23 21:34:36 -0400 |
commit | aab21187a193b541ff009003b7337042a1d9d5c9 (patch) | |
tree | b6355f15731c097756a407c40a3a3bbec2872c59 /tests | |
parent | 5d57d93ff5e505e081abf2ff98569aa00fe679da (diff) | |
download | vyos-cloud-init-aab21187a193b541ff009003b7337042a1d9d5c9.tar.gz vyos-cloud-init-aab21187a193b541ff009003b7337042a1d9d5c9.zip |
some more tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_datasource/test_configdrive.py | 127 |
1 files changed, 35 insertions, 92 deletions
diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py index a801826b..c5d678f9 100644 --- a/tests/unittests/test_datasource/test_configdrive.py +++ b/tests/unittests/test_datasource/test_configdrive.py @@ -82,101 +82,44 @@ class TestConfigDriveDataSource(MockerTestCase): my_d = os.path.join(self.tmp, "valid_extra") data = copy(CFG_DRIVE_FILES_V2) - data["myfoofile"] = "myfoocontent" + data["myfoofile.txt"] = "myfoocontent" + data["openstack/latest/random-file.txt"] = "random-content" populate_dir(my_d, data) -# (userdata, metadata) = DataSourceMAAS.read_maas_seed_dir(my_d) -# -# self.assertEqual(userdata, data['user-data']) -# for key in ('instance-id', 'local-hostname'): -# self.assertEqual(data[key], metadata[key]) -# -# # additional files should not just appear as keys in metadata atm -# self.assertFalse(('foo' in metadata)) -# -# def test_seed_dir_invalid(self): -# """Verify that invalid seed_dir raises MAASSeedDirMalformed.""" -# -# valid = {'instance-id': 'i-instanceid', -# 'local-hostname': 'test-hostname', 'user-data': ''} -# -# my_based = os.path.join(self.tmp, "valid_extra") -# -# # missing 'userdata' file -# my_d = "%s-01" % my_based -# invalid_data = copy(valid) -# del invalid_data['local-hostname'] -# populate_dir(my_d, invalid_data) -# self.assertRaises(DataSourceMAAS.MAASSeedDirMalformed, -# DataSourceMAAS.read_maas_seed_dir, my_d) -# -# # missing 'instance-id' -# my_d = "%s-02" % my_based -# invalid_data = copy(valid) -# del invalid_data['instance-id'] -# populate_dir(my_d, invalid_data) -# self.assertRaises(DataSourceMAAS.MAASSeedDirMalformed, -# DataSourceMAAS.read_maas_seed_dir, my_d) -# -# def test_seed_dir_none(self): -# """Verify that empty seed_dir raises MAASSeedDirNone.""" -# -# my_d = os.path.join(self.tmp, "valid_empty") -# self.assertRaises(DataSourceMAAS.MAASSeedDirNone, -# DataSourceMAAS.read_maas_seed_dir, my_d) -# -# def test_seed_dir_missing(self): -# """Verify that missing seed_dir raises MAASSeedDirNone.""" -# self.assertRaises(DataSourceMAAS.MAASSeedDirNone, -# DataSourceMAAS.read_maas_seed_dir, -# os.path.join(self.tmp, "nonexistantdirectory")) -# -# def test_seed_url_valid(self): -# """Verify that valid seed_url is read as such.""" -# valid = {'meta-data/instance-id': 'i-instanceid', -# 'meta-data/local-hostname': 'test-hostname', -# 'meta-data/public-keys': 'test-hostname', -# 'user-data': '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'} -# -# def my_headers_cb(url): -# return my_headers -# -# mock_request = self.mocker.replace(url_helper.readurl, -# passthrough=False) -# -# for key in valid_order: -# url = "%s/%s/%s" % (my_seed, my_ver, key) -# mock_request(url, headers=my_headers, timeout=None) -# resp = valid.get(key) -# self.mocker.result(url_helper.UrlResponse(200, resp)) -# self.mocker.replay() -# -# (userdata, metadata) = DataSourceMAAS.read_maas_seed_url(my_seed, -# header_cb=my_headers_cb, version=my_ver) -# -# self.assertEqual("foodata", userdata) -# self.assertEqual(metadata['instance-id'], -# valid['meta-data/instance-id']) -# self.assertEqual(metadata['local-hostname'], -# valid['meta-data/local-hostname']) -# -# def test_seed_url_invalid(self): -# """Verify that invalid seed_url raises MAASSeedDirMalformed.""" -# pass -# -# def test_seed_url_missing(self): -# """Verify seed_url with no found entries raises MAASSeedDirNone.""" -# pass + found = DataSourceConfigDrive.read_config_drive_dir(my_d) + self.assertEqual(OSTACK_META, found['metadata']) + + def test_seed_dir_bad_json_metadata(self): + """Verify that bad json in metadata raises BrokenConfigDriveDir.""" + my_d = os.path.join(self.tmp, "bad-json-metadata") + data = copy(CFG_DRIVE_FILES_V2) + + data["openstack/2012-08-10/meta_data.json"] = "non-json garbage {}" + data["openstack/latest/meta_data.json"] = "non-json garbage {}" + + populate_dir(my_d, data) + + self.assertRaises(DataSourceConfigDrive.BrokenConfigDriveDir, + DataSourceConfigDrive.read_config_drive_dir, my_d) + + def test_seed_dir_no_configdrive(self): + """Verify that no metadata raises NonConfigDriveDir.""" + + my_d = os.path.join(self.tmp, "non-configdrive") + data = copy(CFG_DRIVE_FILES_V2) + data["myfoofile.txt"] = "myfoocontent" + data["openstack/latest/random-file.txt"] = "random-content" + data["content/foo"] = "foocontent" + + self.assertRaises(DataSourceConfigDrive.NonConfigDriveDir, + DataSourceConfigDrive.read_config_drive_dir, my_d) + + def test_seed_dir_missing(self): + """Verify that missing seed_dir raises NonConfigDriveDir.""" + my_d = os.path.join(self.tmp, "nonexistantdirectory") + self.assertRaises(DataSourceConfigDrive.NonConfigDriveDir, + DataSourceConfigDrive.read_config_drive_dir, my_d) def populate_dir(seed_dir, files): |