Commit 74f0e70a authored by Maverick Chardet's avatar Maverick Chardet
Browse files

Simplified reserve_g5k file

Fixed wrong variable name in ssh scalability test
parent 7ebea4df
#!/usr/bin/env python
import logging
import time
import yaml
class G5kReservation:
def _g5k_deploy(g5k_config, force_deploy=False, **kwargs):
def _g5k_deploy(self, g5k_config, force_deploy=False):
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration
provider = G5k(Configuration.from_dictionnary(g5k_config))
roles, networks = provider.init(force_deploy=force_deploy)
env = {'roles': roles, 'networks': networks}'Wait 30 seconds for iface to be ready...')
return env, provider
def _allocate(conf, provider='g5k', force_deployment=False):
env = {}
self._g5k_job = G5k(Configuration.from_dictionnary(g5k_config))
self._roles, self._networks = self._g5k_job.init(force_deploy=force_deploy)
#'Wait 30 seconds for iface to be ready...')
# time.sleep(30)
def _allocate(self, conf, force_deployment=False):
if isinstance(conf, str):
# Get the config object from a yaml file
with open(conf) as f:
config = yaml.load(f)
elif isinstance(conf, dict):
# Get the config object from a dict
config = conf
# Data format error
raise Exception(
'conf is type {!r} while it should be a yaml file or a dict'.format(type(conf)))
env['db'] = config.get('database', 'mariadb')
env['monitoring'] = config.get('monitoring', False)
env['config'] = config
self._config = config
# Claim resources on Grid'5000
if not (provider == 'g5k' and 'g5k' in config):
raise Exception(
'The provider {!r} is not supported or it lacks a configuration'.format(provider))
env['provider'] = 'g5k'
updated_env, g5k_job = G5kReservation._g5k_deploy(config['g5k'], force_deploy=force_deployment)
return env, g5k_job
if 'g5k' not in config:
raise Exception("'g5k' key missing in configuration!")
self._g5k_deploy(config['g5k'], force_deploy=force_deployment)
def _get_ip(g5k_address):
from subprocess import run, PIPE
ip = run("dig +short %s" % g5k_address, shell=True, stdout=PIPE).stdout.decode('utf-8').strip(' \r\n')
return ip
......@@ -57,23 +39,23 @@ class G5kReservation:
return {"address": g5k_address, "ip": G5kReservation._get_ip(g5k_address)}
def __init__(self, conf, force_deployment=True, destroy=False):
from execo.action import Put, Get, Remote
from import Host
from json import dump
self._env, self._g5k_job = G5kReservation._allocate(conf, 'g5k', force_deployment)
self._config = None
self._g5k_job = None
self._roles = None
self._networks = None
self._destroy = destroy
self._allocate(conf, force_deployment)
self._alive = True
def get_roles(self):
if not self._alive:
raise Exception("G5k reservation not alive!")
return self._env['roles'].keys()
return self._roles.keys()
def get_hosts_info(self, role):
if not self._alive:
raise Exception("G5k reservation not alive!")
return [G5kReservation._get_host_dict(host.address) for host in self._env['roles'][role]]
return [G5kReservation._get_host_dict(host.address) for host in self._roles[role]]
def terminate(self):
if not self._alive:
......@@ -16,7 +16,7 @@ EXP_DIR = '%s/%s' % (ROOT_DIR, EXP_DIR_IN_GIT)
def run_experiment(list_nb_remote_ssh, nb_repeat, conf, working_directory=DEFAULT_WORKING_DIRECTORY,
def run_experiment(list_nb_remote_ssh, nb_repeats, conf, working_directory=DEFAULT_WORKING_DIRECTORY,
force_deployment=True, destroy=False):
from json import dump
......@@ -29,7 +29,7 @@ def run_experiment(list_nb_remote_ssh, nb_repeat, conf, working_directory=DEFAUL
"remote_hosts": remote_machines,
"concerto_host": concerto_machine,
"list_nb_remote_ssh": list_nb_remote_ssh,
"nb_repeat": nb_repeat
"nb_repeats": nb_repeats
with open(working_directory + "/concerto_config.json", "w") as concerto_config_file:
dump(concerto_config, concerto_config_file)
......@@ -62,7 +62,7 @@ def run_experiment(list_nb_remote_ssh, nb_repeat, conf, working_directory=DEFAUL
def perform_experiment(list_nb_remote_ssh, nb_repeat):
def perform_experiment(list_nb_remote_ssh, nb_repeats):
import yaml
from os import makedirs
......@@ -76,7 +76,7 @@ def perform_experiment(list_nb_remote_ssh, nb_repeat):
with open(wd + '/g5k_config.yaml', 'w') as g5k_config_file:
yaml.dump(conf, g5k_config_file)
run_experiment(list_nb_remote_ssh, nb_repeat, conf, wd)
run_experiment(list_nb_remote_ssh, nb_repeats, conf, wd)
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment