From 776ebb9f5471d88c0539d31276a8d0f6d43e6572 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Thu, 8 Jun 2023 17:41:14 +0200 Subject: [PATCH] Support test pillars Allow directories to be specified in suite and test configuration sections which will be linked to /srv/pillar on either the master or the minion. Signed-off-by: Georg Pfuetzenreuter --- Vagrantfile-Template | 27 +++++++++++++++++++++++++-- scullery.py | 21 ++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Vagrantfile-Template b/Vagrantfile-Template index 55db829..77850a5 100644 --- a/Vagrantfile-Template +++ b/Vagrantfile-Template @@ -7,6 +7,7 @@ if ! ( ENV['SCULLERY_BOX_NAME'] && ENV['SCULLERY_BOX_IMAGE'] ) || ! ( ENV['SCULL end salt_bootstrap = ENV['SCULLERY_BOOTSTRAP'] +salt_pillar = ENV['SCULLERY_PILLAR'] salt_file_roots = 'file_roots:\n base:\n - /srv/salt\n - /srv/formulas\n' Vagrant.configure("2") do |config| @@ -27,10 +28,21 @@ Vagrant.configure("2") do |config| master_config.vm.provider :libvirt do |libvirt| libvirt.memory = 768 end - master_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots}, inline: <<-SHELL + master_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots, 'SALT_PILLAR': salt_pillar}, inline: <<-SHELL printf 'auto_accept: True\n' > /etc/salt/master.d/notsecure.conf printf "$SALT_FILE_ROOTS" > /etc/salt/master.d/roots.conf systemctl enable --now salt-master + if [ -n "$SALT_PILLAR" -a -d "/vagrant/$SALT_PILLAR" ] + then + if [ -d '/srv/pillar' ] + then + rm -r /srv/pillar + fi + if [ ! -L '/srv/pillar' ] + then + ln -sv "/vagrant/$SALT_PILLAR" /srv/pillar + fi + fi SHELL if salt_bootstrap master_config.vm.provision "shell", path: salt_bootstrap @@ -49,8 +61,19 @@ Vagrant.configure("2") do |config| systemctl enable --now salt-minion SHELL else - minion_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots}, inline: <<-SHELL + minion_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots, 'SALT_PILLAR': salt_pillar}, inline: <<-SHELL printf "$SALT_FILE_ROOTS" > /etc/salt/minion.d/roots.conf + if [ -n "$SALT_PILLAR" -a -d "/vagrant/$SALT_PILLAR" ] + then + if [ -d '/srv/pillar' ] + then + rm -r /srv/pillar + fi + if [ ! -L '/srv/pillar' ] + then + ln -sv "/vagrant/$SALT_PILLAR" /srv/pillar + fi + fi SHELL if salt_bootstrap minion_config.vm.provision "shell", path: salt_bootstrap diff --git a/scullery.py b/scullery.py index 8718481..367236c 100755 --- a/scullery.py +++ b/scullery.py @@ -111,9 +111,9 @@ def _setenv(envmap, dump=False): if dump: fh.close() -def vagrant_env(box_name, box_image, minions=None, masters=None, vagrantfile=None, bootstrap=None): +def vagrant_env(box_name, box_image, minions=None, masters=None, vagrantfile=None, bootstrap=None, pillar=None): envmap = {'VAGRANT_VAGRANTFILE': vagrantfile, 'SCULLERY_BOX_NAME': box_name, 'SCULLERY_BOX_IMAGE': box_image, - 'SCULLERY_MASTERS': masters, 'SCULLERY_MINIONS': minions, 'SCULLERY_BOOTSTRAP': bootstrap} + 'SCULLERY_MASTERS': masters, 'SCULLERY_MINIONS': minions, 'SCULLERY_BOOTSTRAP': bootstrap, 'SCULLERY_PILLAR': pillar} log.debug('Environment variable map: {}'.format(str(envmap))) _setenv(envmap, args.env) v.env = env @@ -207,7 +207,20 @@ def main_interactive(): minions = genvms('minion', suiteconf['minions']) if suiteconf.get('masters', 0) > 0: masters = genvms('master', suiteconf['masters']) - vagrant_env(box_name, box_image, minions, masters, box_file, box_bootstrap) + test = suiteconf.get('test', None) + if test is not None: + testconf = tests[test] + pillar_test = testconf.get('pillar', None) + else: + pillar_test = None + pillar_suite = suiteconf.get('pillar', None) + if pillar_suite is None and pillar_test is None: + pillar = None + elif pillar_test: + pillar = pillar_test + elif pillar_suite: + pillar = pillar_suite + vagrant_env(box_name, box_image, minions, masters, box_file, box_bootstrap, pillar) if args.status: log.info('Status report: {}'.format(v.status())) return True @@ -250,12 +263,10 @@ def main_interactive(): _cleanup() if args.test: - test = suiteconf.get('test', None) if test is None: _abort('Tests requested but not declared in suite configuration') if not test in tests: _abort('Specified test is not defined') - testconf = tests[test] if not 'test' in testconf: _abort('Incomplete test configuration') -- 2.35.3