summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Baur <m.baur@syseleven.de>2019-10-31 15:01:10 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-10-31 15:01:10 +0000
commitd3e71b5e843edf73eb7da511a032d987e314bd69 (patch)
tree37c243d9281477d9153ffd9dd5040e02079ed843 /tests
parent8888ca1af7f1fed33e79b56694834310ed35559a (diff)
downloadvyos-cloud-init-d3e71b5e843edf73eb7da511a032d987e314bd69.tar.gz
vyos-cloud-init-d3e71b5e843edf73eb7da511a032d987e314bd69.zip
cc_puppet: Implement csr_attributes.yaml support
This change adds two new parameters: * csr_attributes * csr_attributes_path Those parameters allow to configure the content of the csr_attributes.yaml file. See https://puppet.com/docs/puppet/latest/config_file_csr_attributes.html
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_handler/test_handler_puppet.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_handler_puppet.py b/tests/unittests/test_handler/test_handler_puppet.py
index 0b6e3b58..1494177d 100644
--- a/tests/unittests/test_handler/test_handler_puppet.py
+++ b/tests/unittests/test_handler/test_handler_puppet.py
@@ -6,6 +6,7 @@ from cloudinit import (distros, helpers, cloud, util)
from cloudinit.tests.helpers import CiTestCase, mock
import logging
+import textwrap
LOG = logging.getLogger(__name__)
@@ -64,6 +65,7 @@ class TestPuppetHandle(CiTestCase):
super(TestPuppetHandle, self).setUp()
self.new_root = self.tmp_dir()
self.conf = self.tmp_path('puppet.conf')
+ self.csr_attributes_path = self.tmp_path('csr_attributes.yaml')
def _get_cloud(self, distro):
paths = helpers.Paths({'templates_dir': self.new_root})
@@ -140,3 +142,35 @@ class TestPuppetHandle(CiTestCase):
content = util.load_file(self.conf)
expected = '[agent]\nserver = puppetmaster.example.org\nother = 3\n\n'
self.assertEqual(expected, content)
+
+ @mock.patch('cloudinit.config.cc_puppet.util.subp')
+ def test_handler_puppet_writes_csr_attributes_file(self, m_subp, m_auto):
+ """When csr_attributes is provided
+ creates file in PUPPET_CSR_ATTRIBUTES_PATH."""
+ mycloud = self._get_cloud('ubuntu')
+ mycloud.distro = mock.MagicMock()
+ cfg = {
+ 'puppet': {
+ 'csr_attributes': {
+ 'custom_attributes': {
+ '1.2.840.113549.1.9.7': '342thbjkt82094y0ut'
+ 'hhor289jnqthpc2290'},
+ 'extension_requests': {
+ 'pp_uuid': 'ED803750-E3C7-44F5-BB08-41A04433FE2E',
+ 'pp_image_name': 'my_ami_image',
+ 'pp_preshared_key': '342thbjkt82094y0uthhor289jnqthpc2290'}
+ }}}
+ csr_attributes = 'cloudinit.config.cc_puppet.' \
+ 'PUPPET_CSR_ATTRIBUTES_PATH'
+ with mock.patch(csr_attributes, self.csr_attributes_path):
+ cc_puppet.handle('notimportant', cfg, mycloud, LOG, None)
+ content = util.load_file(self.csr_attributes_path)
+ expected = textwrap.dedent("""\
+ custom_attributes:
+ 1.2.840.113549.1.9.7: 342thbjkt82094y0uthhor289jnqthpc2290
+ extension_requests:
+ pp_image_name: my_ami_image
+ pp_preshared_key: 342thbjkt82094y0uthhor289jnqthpc2290
+ pp_uuid: ED803750-E3C7-44F5-BB08-41A04433FE2E
+ """)
+ self.assertEqual(expected, content)