Support test pillars #2

Open
Georg wants to merge 1 commits from test-pillars into main
2 changed files with 41 additions and 7 deletions

View File

@ -7,6 +7,7 @@ if ! ( ENV['SCULLERY_BOX_NAME'] && ENV['SCULLERY_BOX_IMAGE'] ) || ! ( ENV['SCULL
end end
salt_bootstrap = ENV['SCULLERY_BOOTSTRAP'] salt_bootstrap = ENV['SCULLERY_BOOTSTRAP']
salt_pillar = ENV['SCULLERY_PILLAR']
salt_file_roots = 'file_roots:\n base:\n - /srv/salt\n - /srv/formulas\n' salt_file_roots = 'file_roots:\n base:\n - /srv/salt\n - /srv/formulas\n'
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
@ -27,10 +28,21 @@ Vagrant.configure("2") do |config|
master_config.vm.provider :libvirt do |libvirt| master_config.vm.provider :libvirt do |libvirt|
libvirt.memory = 768 libvirt.memory = 768
end 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 'auto_accept: True\n' > /etc/salt/master.d/notsecure.conf
printf "$SALT_FILE_ROOTS" > /etc/salt/master.d/roots.conf printf "$SALT_FILE_ROOTS" > /etc/salt/master.d/roots.conf
systemctl enable --now salt-master 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 SHELL
if salt_bootstrap if salt_bootstrap
master_config.vm.provision "shell", path: salt_bootstrap master_config.vm.provision "shell", path: salt_bootstrap
@ -49,8 +61,19 @@ Vagrant.configure("2") do |config|
systemctl enable --now salt-minion systemctl enable --now salt-minion
SHELL SHELL
else 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 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 SHELL
if salt_bootstrap if salt_bootstrap
minion_config.vm.provision "shell", path: salt_bootstrap minion_config.vm.provision "shell", path: salt_bootstrap

View File

@ -111,9 +111,9 @@ def _setenv(envmap, dump=False):
if dump: if dump:
fh.close() 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, 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))) log.debug('Environment variable map: {}'.format(str(envmap)))
_setenv(envmap, args.env) _setenv(envmap, args.env)
v.env = env v.env = env
@ -207,7 +207,20 @@ def main_interactive():
minions = genvms('minion', suiteconf['minions']) minions = genvms('minion', suiteconf['minions'])
if suiteconf.get('masters', 0) > 0: if suiteconf.get('masters', 0) > 0:
masters = genvms('master', suiteconf['masters']) 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: if args.status:
log.info('Status report: {}'.format(v.status())) log.info('Status report: {}'.format(v.status()))
return True return True
@ -250,12 +263,10 @@ def main_interactive():
_cleanup() _cleanup()
if args.test: if args.test:
test = suiteconf.get('test', None)
if test is None: if test is None:
_abort('Tests requested but not declared in suite configuration') _abort('Tests requested but not declared in suite configuration')
if not test in tests: if not test in tests:
_abort('Specified test is not defined') _abort('Specified test is not defined')
testconf = tests[test]
if not 'test' in testconf: if not 'test' in testconf:
_abort('Incomplete test configuration') _abort('Incomplete test configuration')