|
| 1 | +# Copyright 2026 Canonical Ltd. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import unit_tests.utils as ut_utils |
| 16 | + |
| 17 | +import zaza.openstack.configure.guest as guest |
| 18 | + |
| 19 | + |
| 20 | +class TestGetDefaultUserdata(ut_utils.BaseTestCase): |
| 21 | + |
| 22 | + EXPECTED_NO_PACKAGES = """#cloud-config |
| 23 | +apt: |
| 24 | + http_proxy: http://proxy.example.com:3128 |
| 25 | +
|
| 26 | +write_files: |
| 27 | + - path: /etc/environment |
| 28 | + content: | |
| 29 | + http_proxy=http://proxy.example.com:3128 |
| 30 | + https_proxy=http://proxy.example.com:3128 |
| 31 | + no_proxy=localhost,127.0.0.1 |
| 32 | + append: true |
| 33 | +
|
| 34 | +""" |
| 35 | + |
| 36 | + EXPECTED_PACKAGES = """#cloud-config |
| 37 | +apt: |
| 38 | + http_proxy: http://proxy.example.com:3128 |
| 39 | +
|
| 40 | +write_files: |
| 41 | + - path: /etc/environment |
| 42 | + content: | |
| 43 | + http_proxy=http://proxy.example.com:3128 |
| 44 | + https_proxy=http://proxy.example.com:3128 |
| 45 | + no_proxy=localhost,127.0.0.1 |
| 46 | + append: true |
| 47 | +
|
| 48 | +packages: |
| 49 | +- nfs-common |
| 50 | +- curl |
| 51 | +""" |
| 52 | + |
| 53 | + def setUp(self): |
| 54 | + super().setUp() |
| 55 | + self.patch_object( |
| 56 | + guest.deployment_env, 'get_deployment_context', |
| 57 | + return_value={ |
| 58 | + 'TEST_HTTP_PROXY': 'http://proxy.example.com:3128', |
| 59 | + 'TEST_NO_PROXY': 'localhost,127.0.0.1', |
| 60 | + }) |
| 61 | + |
| 62 | + def test_without_packages(self): |
| 63 | + """Test get_default_userdata without packages.""" |
| 64 | + result = guest.get_default_userdata() |
| 65 | + self.assertEqual(result, self.EXPECTED_NO_PACKAGES) |
| 66 | + |
| 67 | + def test_with_packages(self): |
| 68 | + """Test get_default_userdata with multiple packages.""" |
| 69 | + result = guest.get_default_userdata(packages=['nfs-common', 'curl']) |
| 70 | + self.assertEqual(result, self.EXPECTED_PACKAGES) |
| 71 | + |
| 72 | + def test_with_empty_packages(self): |
| 73 | + """Test get_default_userdata with empty packages list.""" |
| 74 | + result = guest.get_default_userdata(packages=[]) |
| 75 | + self.assertEqual(result, self.EXPECTED_NO_PACKAGES) |
| 76 | + |
| 77 | + def test_with_none_packages(self): |
| 78 | + """Test get_default_userdata with packages=None.""" |
| 79 | + result = guest.get_default_userdata(packages=None) |
| 80 | + self.assertEqual(result, self.EXPECTED_NO_PACKAGES) |
0 commit comments