diff options
Diffstat (limited to 'tests/unittests/config')
-rw-r--r-- | tests/unittests/config/test_cc_chef.py | 17 | ||||
-rw-r--r-- | tests/unittests/config/test_cc_resolv_conf.py | 2 | ||||
-rw-r--r-- | tests/unittests/config/test_cc_update_etc_hosts.py | 5 | ||||
-rw-r--r-- | tests/unittests/config/test_schema.py | 16 |
4 files changed, 27 insertions, 13 deletions
diff --git a/tests/unittests/config/test_cc_chef.py b/tests/unittests/config/test_cc_chef.py index 060293c8..1c90a4fc 100644 --- a/tests/unittests/config/test_cc_chef.py +++ b/tests/unittests/config/test_cc_chef.py @@ -9,13 +9,18 @@ from cloudinit.config import cc_chef from cloudinit import util from tests.unittests.helpers import ( - HttprettyTestCase, FilesystemMockingTestCase, mock, skipIf) + HttprettyTestCase, + FilesystemMockingTestCase, + mock, + skipIf, + cloud_init_project_dir, +) from tests.unittests.util import get_cloud LOG = logging.getLogger(__name__) -CLIENT_TEMPL = os.path.sep.join(["templates", "chef_client.rb.tmpl"]) +CLIENT_TEMPL = cloud_init_project_dir("templates/chef_client.rb.tmpl") # This is adjusted to use http because using with https causes issue # in some openssl/httpretty combinations. @@ -138,7 +143,7 @@ class TestChef(FilesystemMockingTestCase): Chef::Log::Formatter.show_time = true encrypted_data_bag_secret "/etc/chef/encrypted_data_bag_secret" """ - tpl_file = util.load_file('templates/chef_client.rb.tmpl') + tpl_file = util.load_file(CLIENT_TEMPL) self.patchUtils(self.tmp) self.patchOS(self.tmp) @@ -200,7 +205,7 @@ class TestChef(FilesystemMockingTestCase): @skipIf(not os.path.isfile(CLIENT_TEMPL), CLIENT_TEMPL + " is not available") def test_template_deletes(self): - tpl_file = util.load_file('templates/chef_client.rb.tmpl') + tpl_file = util.load_file(CLIENT_TEMPL) self.patchUtils(self.tmp) self.patchOS(self.tmp) @@ -222,7 +227,7 @@ class TestChef(FilesystemMockingTestCase): CLIENT_TEMPL + " is not available") def test_validation_cert_and_validation_key(self): # test validation_cert content is written to validation_key path - tpl_file = util.load_file('templates/chef_client.rb.tmpl') + tpl_file = util.load_file(CLIENT_TEMPL) self.patchUtils(self.tmp) self.patchOS(self.tmp) @@ -245,7 +250,7 @@ class TestChef(FilesystemMockingTestCase): def test_validation_cert_with_system(self): # test validation_cert content is not written over system file - tpl_file = util.load_file('templates/chef_client.rb.tmpl') + tpl_file = util.load_file(CLIENT_TEMPL) self.patchUtils(self.tmp) self.patchOS(self.tmp) diff --git a/tests/unittests/config/test_cc_resolv_conf.py b/tests/unittests/config/test_cc_resolv_conf.py index 0aa90a23..ab2de17a 100644 --- a/tests/unittests/config/test_cc_resolv_conf.py +++ b/tests/unittests/config/test_cc_resolv_conf.py @@ -114,7 +114,7 @@ class TestResolvConf(t_help.FilesystemMockingTestCase): class TestGenerateResolvConf: dist = MockDistro() - tmpl_fn = "templates/resolv.conf.tmpl" + tmpl_fn = t_help.cloud_init_project_dir("templates/resolv.conf.tmpl") @mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file") def test_dist_resolv_conf_fn(self, m_render_to_file): diff --git a/tests/unittests/config/test_cc_update_etc_hosts.py b/tests/unittests/config/test_cc_update_etc_hosts.py index 77a7f78f..35ad6413 100644 --- a/tests/unittests/config/test_cc_update_etc_hosts.py +++ b/tests/unittests/config/test_cc_update_etc_hosts.py @@ -55,7 +55,10 @@ class TestHostsFile(t_help.FilesystemMockingTestCase): 'manage_etc_hosts': 'template', 'hostname': 'cloud-init.test.us' } - shutil.copytree('templates', '%s/etc/cloud/templates' % self.tmp) + shutil.copytree( + t_help.cloud_init_project_dir('templates'), + '%s/etc/cloud/templates' % self.tmp, + ) distro = self._fetch_distro('sles') paths = helpers.Paths({}) paths.template_tpl = '%s' % self.tmp + '/etc/cloud/templates/%s.tmpl' diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py index f90e0f62..ed7ab527 100644 --- a/tests/unittests/config/test_schema.py +++ b/tests/unittests/config/test_schema.py @@ -12,7 +12,6 @@ from pathlib import Path from textwrap import dedent from yaml import safe_load -import cloudinit from cloudinit.config.schema import ( CLOUD_CONFIG_HEADER, SchemaValidationError, @@ -27,7 +26,12 @@ from cloudinit.config.schema import ( MetaSchema, ) from cloudinit.util import write_file -from tests.unittests.helpers import CiTestCase, mock, skipUnlessJsonSchema +from tests.unittests.helpers import ( + CiTestCase, + mock, + skipUnlessJsonSchema, + cloud_init_project_dir, +) def get_schemas() -> dict: @@ -50,7 +54,10 @@ def get_module_variable(var_name) -> dict: """Inspect modules and get variable from module matching var_name""" schemas = {} - files = list(Path("../../cloudinit/config/").glob("cc_*.py")) + files = list( + Path(cloud_init_project_dir("../../cloudinit/config/")).glob("cc_*.py") + ) + modules = [mod.stem for mod in files] for module in modules: @@ -616,8 +623,7 @@ class TestMain: def _get_meta_doc_examples(): - examples_dir = Path( - cloudinit.__file__).parent.parent / 'doc' / 'examples' + examples_dir = Path(cloud_init_project_dir('doc/examples')) assert examples_dir.is_dir() all_text_files = (f for f in examples_dir.glob('cloud-config*.txt') |