summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-04-13 12:24:46 -0400
committerScott Moser <smoser@ubuntu.com>2016-04-13 12:24:46 -0400
commitac50733f77fef296e4af46aa55311a295e964136 (patch)
treee247180845a4aa77bd55faa81490d7539f26acc1 /tests/unittests
parent96cc3852d8126af2dba7cd778473c23bcd883ceb (diff)
parent2b3f56294576998246e13f9b07074bad7b4bf212 (diff)
downloadvyos-cloud-init-ac50733f77fef296e4af46aa55311a295e964136.tar.gz
vyos-cloud-init-ac50733f77fef296e4af46aa55311a295e964136.zip
chef: straighten out validation_cert and validation_key
Now, validation_key is always a path to a file, as it is in chef's client.rb syntax. validation_cert is always the *content* of that file that should be written. However, if validation_cert is the string "system", then we do not write that value, but rather assume the file exists. LP: #1568940
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_handler/test_handler_chef.py65
1 files changed, 63 insertions, 2 deletions
diff --git a/tests/unittests/test_handler/test_handler_chef.py b/tests/unittests/test_handler/test_handler_chef.py
index edad88cb..7763f23b 100644
--- a/tests/unittests/test_handler/test_handler_chef.py
+++ b/tests/unittests/test_handler/test_handler_chef.py
@@ -75,17 +75,28 @@ class TestChef(t_help.FilesystemMockingTestCase):
'chef': {
'server_url': 'localhost',
'validation_name': 'bob',
+ 'validation_key': "/etc/chef/vkey.pem",
+ 'validation_cert': "this is my cert",
},
}
cc_chef.handle('chef', cfg, self.fetch_cloud('ubuntu'), LOG, [])
for d in cc_chef.CHEF_DIRS:
self.assertTrue(os.path.isdir(d))
c = util.load_file(cc_chef.CHEF_RB_PATH)
+
+ # the content of these keys is not expected to be rendered to tmpl
+ unrendered_keys = ('validation_cert',)
for k, v in cfg['chef'].items():
+ if k in unrendered_keys:
+ continue
self.assertIn(v, c)
for k, v in cc_chef.CHEF_RB_TPL_DEFAULTS.items():
- if isinstance(v, six.string_types):
- self.assertIn(v, c)
+ if k in unrendered_keys:
+ continue
+ # the value from the cfg overrides that in the default
+ val = cfg['chef'].get(k, v)
+ if isinstance(val, six.string_types):
+ self.assertIn(val, c)
c = util.load_file(cc_chef.CHEF_FB_PATH)
self.assertEqual({}, json.loads(c))
@@ -131,3 +142,53 @@ class TestChef(t_help.FilesystemMockingTestCase):
c = util.load_file(cc_chef.CHEF_RB_PATH)
self.assertNotIn('json_attribs', c)
self.assertNotIn('Formatter.show_time', c)
+
+ @t_help.skipIf(not os.path.isfile(CLIENT_TEMPL),
+ 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')
+ self.patchUtils(self.tmp)
+ self.patchOS(self.tmp)
+
+ util.write_file('/etc/cloud/templates/chef_client.rb.tmpl', tpl_file)
+ v_path = '/etc/chef/vkey.pem'
+ v_cert = 'this is my cert'
+ cfg = {
+ 'chef': {
+ 'server_url': 'localhost',
+ 'validation_name': 'bob',
+ 'validation_key': v_path,
+ 'validation_cert': v_cert
+ },
+ }
+ cc_chef.handle('chef', cfg, self.fetch_cloud('ubuntu'), LOG, [])
+ content = util.load_file(cc_chef.CHEF_RB_PATH)
+ self.assertIn(v_path, content)
+ util.load_file(v_path)
+ self.assertEqual(v_cert, util.load_file(v_path))
+
+ 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')
+ self.patchUtils(self.tmp)
+ self.patchOS(self.tmp)
+
+ v_path = '/etc/chef/vkey.pem'
+ v_cert = "system"
+ expected_cert = "this is the system file certificate"
+ cfg = {
+ 'chef': {
+ 'server_url': 'localhost',
+ 'validation_name': 'bob',
+ 'validation_key': v_path,
+ 'validation_cert': v_cert
+ },
+ }
+ util.write_file('/etc/cloud/templates/chef_client.rb.tmpl', tpl_file)
+ util.write_file(v_path, expected_cert)
+ cc_chef.handle('chef', cfg, self.fetch_cloud('ubuntu'), LOG, [])
+ content = util.load_file(cc_chef.CHEF_RB_PATH)
+ self.assertIn(v_path, content)
+ util.load_file(v_path)
+ self.assertEqual(expected_cert, util.load_file(v_path))