Refactor environment handling
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
99026776a6
commit
7c209509ed
37
scullery.py
37
scullery.py
@ -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):
|
||||||
fh = open('.scullery_env', 'w')
|
if dump:
|
||||||
if vagrantfile is not None:
|
log.debug('Writing environment variable file')
|
||||||
env['VAGRANT_VAGRANTFILE'] = vagrantfile
|
fh = open('.scullery_env', 'w')
|
||||||
fh.write('VAGRANT_VAGRANTFILE={}\n'.format(vagrantfile))
|
for variable, vlaue in envmap.items():
|
||||||
env['SCULLERY_BOX_NAME'] = box_name
|
if value is not None:
|
||||||
env['SCULLERY_BOX_IMAGE'] = box_image
|
if isinstance(value, list):
|
||||||
fh.write('SCULLERY_BOX_NAME={}\nSCULLERY_BOX_IMAGE={}\n'.format(box_name, box_image))
|
value = ','.join(value)
|
||||||
if masters is not None:
|
env[variable] = value
|
||||||
env_masters = ','.join(masters)
|
if dump:
|
||||||
env['SCULLERY_MASTERS'] = env_masters
|
fh.write(f'{variable}={value}\n')
|
||||||
fh.write('SCULLERY_MASTERS={}\n'.format(env_masters))
|
if dump:
|
||||||
if minions is not None:
|
fh.close()
|
||||||
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 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):
|
||||||
|
Loading…
Reference in New Issue
Block a user