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() 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('--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('--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) 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('--stop', help='Stop running machines', action='store_true')
arggroup.add_argument('--test', help='Start machines and run tests', 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)) vms.append('{}-{}{}'.format(vmprefix, flavor, i))
return vms return vms
def vagrant_env(box_name, box_image, minions=None, masters=None, vagrantfile=None): def _setenv(envmap, dump=False):
if dump:
log.debug('Writing environment variable file')
fh = open('.scullery_env', 'w') fh = open('.scullery_env', 'w')
if vagrantfile is not None: for variable, vlaue in envmap.items():
env['VAGRANT_VAGRANTFILE'] = vagrantfile if value is not None:
fh.write('VAGRANT_VAGRANTFILE={}\n'.format(vagrantfile)) if isinstance(value, list):
env['SCULLERY_BOX_NAME'] = box_name value = ','.join(value)
env['SCULLERY_BOX_IMAGE'] = box_image env[variable] = value
fh.write('SCULLERY_BOX_NAME={}\nSCULLERY_BOX_IMAGE={}\n'.format(box_name, box_image)) if dump:
if masters is not None: fh.write(f'{variable}={value}\n')
env_masters = ','.join(masters) if dump:
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() 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 v.env = env
def vagrant_isup(suite): def vagrant_isup(suite):