diff options
author | Brett Holman <bholman.devel@gmail.com> | 2021-12-08 14:27:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-08 15:27:37 -0600 |
commit | 65c2cfd7f21758746444c8c79444994a4638d563 (patch) | |
tree | 3b4c91b0ba35dbd8f043f779a9ea6b41f4665a16 /tests/unittests/config/test_cc_chef.py | |
parent | b21afb0a8ab64543715dffff490253db8ecefb9f (diff) | |
download | vyos-cloud-init-65c2cfd7f21758746444c8c79444994a4638d563.tar.gz vyos-cloud-init-65c2cfd7f21758746444c8c79444994a4638d563.zip |
factor out function for getting top level directory of cloudinit (#1136)
Add a test helper to get top level directory
Many tests need to get the location of files & dirs within the cloud-init
project directory.
Tests implement this in various different ways, and often those ways
depend on the current working directory of the pytest invocation.
Create helper functions (and tests) that gets the path of the top
directory or any sub directory under the top directory. This function
does not depend on the environment.
Diffstat (limited to 'tests/unittests/config/test_cc_chef.py')
-rw-r--r-- | tests/unittests/config/test_cc_chef.py | 17 |
1 files changed, 11 insertions, 6 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) |