Refactor environment handling

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2023-05-20 15:02:28 +02:00
parent 99026776a6
commit 7c209509ed
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57

View File

@ -31,6 +31,7 @@ env = os.environ.copy()
arggroup = argparser.add_mutually_exclusive_group()
argparser.add_argument('--debug', help='Print extremely verbose output', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO)
argparser.add_argument('--config', help='Specify the configuration file to use', default='{}/scullery.ini'.format(os.path.abspath(os.path.dirname(__file__))))
argparser.add_argument('--env', help='Write environment file for direct use of Vagrant', action='store_true')
argparser.add_argument('--suite', help='Specify the suite to run', required=True)
arggroup.add_argument('--stop', help='Stop running machines', action='store_true')
arggroup.add_argument('--test', help='Start machines and run tests', action='store_true')
@ -76,25 +77,25 @@ def genvms(flavor, amount):
vms.append('{}-{}{}'.format(vmprefix, flavor, i))
return vms
def vagrant_env(box_name, box_image, minions=None, masters=None, vagrantfile=None):
fh = open('.scullery_env', 'w')
if vagrantfile is not None:
env['VAGRANT_VAGRANTFILE'] = vagrantfile
fh.write('VAGRANT_VAGRANTFILE={}\n'.format(vagrantfile))
env['SCULLERY_BOX_NAME'] = box_name
env['SCULLERY_BOX_IMAGE'] = box_image
fh.write('SCULLERY_BOX_NAME={}\nSCULLERY_BOX_IMAGE={}\n'.format(box_name, box_image))
if masters is not None:
env_masters = ','.join(masters)
env['SCULLERY_MASTERS'] = env_masters
fh.write('SCULLERY_MASTERS={}\n'.format(env_masters))
if minions is not None:
env_minions = ','.join(minions)
env['SCULLERY_MINIONS'] = env_minions
fh.write('SCULLERY_MINIONS={}\n'.format(env_minions))
#log.debug('Environment is: {}'.format(str(env)))
fh.close()
def _setenv(envmap, dump=False):
if dump:
log.debug('Writing environment variable file')
fh = open('.scullery_env', 'w')
for variable, vlaue in envmap.items():
if value is not None:
if isinstance(value, list):
value = ','.join(value)
env[variable] = value
if dump:
fh.write(f'{variable}={value}\n')
if dump:
fh.close()
def vagrant_env(box_name, box_image, minions=None, masters=None, vagrantfile=None):
envmap = {'VAGRANT_VAGRANTFILE': vagrantfile, 'SCULLERY_BOX_NAME': box_name, 'SCULLERY_BOX_IMAGE': box_image,
'SCULLERY_MASTERS': masters, 'SCULLERY_MINIONS': minions}
log.debug('Environment variable map: {}'.format(str(envmap)))
_setenv(envmap, args.env)
v.env = env
def vagrant_isup(suite):