From d0b69e1815db131e893e64745a078780f33097af Mon Sep 17 00:00:00 2001 From: James Falcon Date: Thu, 4 Jun 2020 08:50:20 -0500 Subject: New feature flag functionality and fix includes failing silently (#367) Build time feature flags are now defined in cloudinit/features.py. Feature flags can be added to toggle configuration options or deprecated features. Feature flag overrides can be placed in cloudinit/feature_overrides.py. Further documentation can be found in HACKING.rst. Additionally, updated default behavior to exit with an exception if #include can't retrieve resources as expected. This behavior can be toggled with a feature flag. LP: #1734939 --- tests/unittests/test_data.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py index a4261609..7fb9c3ab 100644 --- a/tests/unittests/test_data.py +++ b/tests/unittests/test_data.py @@ -636,6 +636,31 @@ class TestConsumeUserDataHttp(TestConsumeUserData, helpers.HttprettyTestCase): blob = '#include\n%s\n%s' % (bad_url, included_url) + self.reRoot() + ci = stages.Init() + ci.datasource = FakeDataSource(blob) + ci.fetch() + with self.assertRaises(Exception) as context: + ci.consume_data() + self.assertIn('403', str(context.exception)) + + with self.assertRaises(FileNotFoundError): + util.load_file(ci.paths.get_ipath("cloud_config")) + + @mock.patch('cloudinit.url_helper.time.sleep') + @mock.patch('cloudinit.features.ERROR_ON_USER_DATA_FAILURE', False) + def test_include_bad_url_no_fail(self, mock_sleep): + """Test #include with a bad URL and failure disabled""" + bad_url = 'http://bad/forbidden' + bad_data = '#cloud-config\nbad: true\n' + httpretty.register_uri(httpretty.GET, bad_url, bad_data, status=403) + + included_url = 'http://hostname/path' + included_data = '#cloud-config\nincluded: true\n' + httpretty.register_uri(httpretty.GET, included_url, included_data) + + blob = '#include\n%s\n%s' % (bad_url, included_url) + self.reRoot() ci = stages.Init() ci.datasource = FakeDataSource(blob) -- cgit v1.2.3