diff options
author | James Falcon <TheRealFalcon@users.noreply.github.com> | 2020-06-04 08:50:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-04 09:50:20 -0400 |
commit | d0b69e1815db131e893e64745a078780f33097af (patch) | |
tree | 92c66268bc45784418f441eea1fb6d592c81195d /tests/unittests/test_data.py | |
parent | 56f1939061392c848268ae063908bf2188f07373 (diff) | |
download | vyos-cloud-init-d0b69e1815db131e893e64745a078780f33097af.tar.gz vyos-cloud-init-d0b69e1815db131e893e64745a078780f33097af.zip |
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
Diffstat (limited to 'tests/unittests/test_data.py')
-rw-r--r-- | tests/unittests/test_data.py | 25 |
1 files changed, 25 insertions, 0 deletions
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 @@ -639,6 +639,31 @@ class TestConsumeUserDataHttp(TestConsumeUserData, helpers.HttprettyTestCase): 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) log_file = self.capture_log(logging.WARNING) ci.fetch() ci.consume_data() |