summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Jorgensen <ajorgens@amazon.com>2017-11-27 21:54:09 +0000
committerScott Moser <smoser@ubuntu.com>2017-12-11 18:18:08 -0500
commit703241a3c50f2cfec21e7c8e90616c3378ebbea2 (patch)
treec62cb25d76ca784c953a23ffa9c0f80db17b4b08 /tests
parentbd0ffd1e115c4f895c82e1115f1f586849925d88 (diff)
downloadvyos-cloud-init-703241a3c50f2cfec21e7c8e90616c3378ebbea2.tar.gz
vyos-cloud-init-703241a3c50f2cfec21e7c8e90616c3378ebbea2.zip
ec2: Use instance-identity doc for region and instance-id
The instance identity document is a better source for region information, partly because region isn't actually in meta-data at all, only availability-zone, which happens to be named similarly. Reviewed-by: Ethan Faust <efaust@amazon.com> Reviewed-by: Cyle Riggs <cyler@amazon.com> Reviewed-by: Tom Kirchner <tjk@amazon.com> Reviewed-by: Matt Nierzwicki <nierzwic@amazon.com> [ajorgens@amazon.com: rebase onto 0.7.9] [ajorgens@amazon.com: changes per merge proposal discussions]
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_datasource/test_aliyun.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_aliyun.py b/tests/unittests/test_datasource/test_aliyun.py
index 714f5dac..4fa9616b 100644
--- a/tests/unittests/test_datasource/test_aliyun.py
+++ b/tests/unittests/test_datasource/test_aliyun.py
@@ -47,6 +47,9 @@ def register_mock_metaserver(base_url, data):
elif isinstance(body, list):
register(base_url.rstrip('/'), '\n'.join(body) + '\n')
elif isinstance(body, dict):
+ if not body:
+ register(base_url.rstrip('/') + '/', 'not found',
+ status_code=404)
vals = []
for k, v in body.items():
if isinstance(v, (str, list)):
@@ -91,9 +94,22 @@ class TestAliYunDatasource(test_helpers.HttprettyTestCase):
self.metadata_address,
self.ds.min_metadata_version, 'user-data')
+ # EC2 provides an instance-identity document which must return 404 here
+ # for this test to pass.
+ @property
+ def default_identity(self):
+ return {}
+
+ @property
+ def identity_url(self):
+ return os.path.join(self.metadata_address,
+ self.ds.min_metadata_version,
+ 'dynamic', 'instance-identity')
+
def regist_default_server(self):
register_mock_metaserver(self.metadata_url, self.default_metadata)
register_mock_metaserver(self.userdata_url, self.default_userdata)
+ register_mock_metaserver(self.identity_url, self.default_identity)
def _test_get_data(self):
self.assertEqual(self.ds.metadata, self.default_metadata)