def test_experiment_submit_physical(self): """ Run experiment_submit physical """ # Physical tests resources = [experiment.exp_resources( ['m3-%u.grenoble.iot-lab.info' % i for i in range(1, 6)])] experiment.submit_experiment(self.api, 'exp_name', 20, resources, start_time=314159) call_dict = self.api.submit_experiment.call_args[0][0] expected = { 'name': 'exp_name', 'duration': 20, 'type': 'physical', 'nodes': [ 'm3-%u.grenoble.iot-lab.info' % num for num in range(1, 6) ], 'reservation': 314159, 'profileassociations': None, 'firmwareassociations': None } self.assertEqual(expected, json.loads(call_dict['new_exp.json'])) # Try 'print', should return exp_dict ret = experiment.submit_experiment(self.api, 'exp_name', 20, resources, start_time=314159, print_json=True) self.assertEqual(ret.__dict__, expected)
def test_experiment_submit_physical(self): """ Run experiment_submit physical """ # Physical tests nodes_list = [ experiment.exp_resources( ['m3-%u.grenoble.iot-lab.info' % i for i in range(1, 6)]) ] experiment.submit_experiment(self.api, 'exp_name', 20, nodes_list, start_time=314159) call_dict = self.api.submit_experiment.call_args[0][0] expected = { 'name': 'exp_name', 'duration': 20, 'type': 'physical', 'nodes': ['m3-%u.grenoble.iot-lab.info' % num for num in range(1, 6)], 'reservation': 314159, 'profileassociations': None, 'firmwareassociations': None } self.assertEquals(expected, json.loads(call_dict['new_exp.json'])) # Try 'print', should return exp_dict ret = experiment.submit_experiment(self.api, 'exp_name', 20, nodes_list, start_time=314159, print_json=True) self.assertEquals(ret.__dict__, expected)
def test_exp_submit_associations(self): """Test experiment submission with associations.""" nodes = ['m3-1.grenoble.iot-lab.info'] assocs = {'mobility': 'controlled', 'kernel': 'linux'} resources = [ experiment.exp_resources(nodes, tests.resource_file('firmware.elf'), None, **assocs), ] experiment.submit_experiment(self.api, None, 20, resources) call_dict = self.api.submit_experiment.call_args[0][0] expected = { 'name': None, 'duration': 20, 'type': 'physical', 'nodes': nodes, 'reservation': None, 'profileassociations': None, 'firmwareassociations': [ {'firmwarename': 'firmware.elf', 'nodes': nodes}], 'associations': { 'mobility': [ {'mobilityname': 'controlled', 'nodes': nodes}], 'kernel': [ {'kernelname': 'linux', 'nodes': nodes}], }, 'siteassociations': None, 'profiles': None, 'mobilities': None, } self.assertEqual(expected, json.loads(call_dict['new_exp.json']))
def test_exp_physical_new_types(self): """Test submiting physical experiments with 'new' nodes types.""" resources = [ experiment.exp_resources(['custom-1.grenoble.iot-lab.info']), experiment.exp_resources(['berlin-1.berlin.iot-lab.info']), ] experiment.submit_experiment(self.api, None, 20, resources) self.assertEqual(1, self.api.submit_experiment.call_count)
def test_exp_alias_new_types(self): """Test submiting alias experiments with 'new' nodes types.""" resources = [ experiment.exp_resources( experiment.AliasNodes(1, 'berlin', 'des:wifi-cc1100')), experiment.exp_resources( experiment.AliasNodes(1, 'grenoble', 'custom:leonardo:')), ] experiment.submit_experiment(self.api, None, 20, resources) self.assertEqual(1, self.api.submit_experiment.call_count)
def test_experiment_submit_duplicated_basenames(self): """ Run experiment_submit physical """ # Physical tests resources = [ experiment.exp_resources(['m3-1.grenoble.iot-lab.info'], tests.resource_file('firmware.elf')), experiment.exp_resources( ['m3-2.grenoble.iot-lab.info'], tests.resource_file('other/firmware.elf')), ] experiment.submit_experiment(self.api, 'exp_name', 20, resources, start_time=314159) call_dict = self.api.submit_experiment.call_args[0][0] expected = { 'name': 'exp_name', 'duration': 20, 'type': 'physical', 'nodes': [ 'm3-1.grenoble.iot-lab.info', 'm3-2.grenoble.iot-lab.info', ], 'reservation': 314159, 'profileassociations': None, 'firmwareassociations': [ { 'firmwarename': 'e77d9b8dcb84d1fcd21187b03eac74f1_firmware.elf', 'nodes': ['m3-2.grenoble.iot-lab.info'] }, { 'firmwarename': 'firmware.elf', 'nodes': ['m3-1.grenoble.iot-lab.info'] }, ], 'associations': None, 'siteassociations': None, 'profiles': None, 'mobilities': None, } self.assertEqual(expected, json.loads(call_dict['new_exp.json']))
def test_experiment_submit_alias(self): """ Run experiment_submit alias """ # Alias tests resources = [ experiment.exp_resources( experiment.AliasNodes(1, 'grenoble', 'm3:at86rf231', False), tests.resource_file('firmware.elf'), 'profile1'), experiment.exp_resources( experiment.AliasNodes(2, 'grenoble', 'm3:at86rf231', False), tests.resource_file('firmware.elf'), 'profile1'), experiment.exp_resources( experiment.AliasNodes(4, 'grenoble', 'm3:at86rf231', False), tests.resource_file('firmware_2.elf'), 'profile2'), ] experiment.submit_experiment(self.api, None, 20, resources) files_dict = self.api.submit_experiment.call_args[0][0] exp_desc = json.loads(files_dict['new_exp.json']) expected = { 'name': None, 'duration': 20, 'type': 'alias', 'nodes': [ {"alias": '1', "nbnodes": 1, "properties": { "archi": "m3:at86rf231", "site": "grenoble", "mobile": False }}, {"alias": '2', "nbnodes": 2, "properties": { "archi": "m3:at86rf231", "site": "grenoble", "mobile": False }}, {"alias": '3', "nbnodes": 4, "properties": { "archi": "m3:at86rf231", "site": "grenoble", "mobile": False }}, ], 'reservation': None, 'profileassociations': [ {'profilename': 'profile1', 'nodes': ['1', '2']}, {'profilename': 'profile2', 'nodes': ['3']}, ], 'firmwareassociations': [ {'firmwarename': 'firmware.elf', 'nodes': ['1', '2']}, {'firmwarename': 'firmware_2.elf', 'nodes': ['3']} ], 'associations': None, 'siteassociations': None, 'profiles': None, 'mobilities': None, } self.assertEqual(expected, exp_desc) self.assertTrue('firmware.elf' in files_dict)
def submit_experiment(testbed_name, board, firmware, duration): """ Reserve nodes in the given site. The function uses the json experiment file corresponding to the site. :param str firmware: the name of the firmware as it is in the code/firmware/ folder :param str board: the type of board (ex: m3) :param str testbed_name: The name of the testbed (ex: grenoble) :param int duration: The duration of the experiment in minutes :return: The id of the experiment """ # use the file created by auth-cli command usr, pwd = iotlab.get_user_credentials() # authenticate through the REST interface api = iotlab.rest.Api(usr, pwd) # load the experiment tb_file = open("{0}states.json".format(METAS_PATH)) tb_json = json.load(tb_file) nodes = [x for x in tb_json[testbed_name] if board in x] firmware = FIRMWARE_PATH + firmware profile = "mercator" resources = [experiment.exp_resources(nodes, firmware, profile)] # submit experiment logconsole.info("Submitting experiment.") expid = experiment.submit_experiment(api, "mercatorExp", duration, resources)["id"] logconsole.info("Experiment submited with id: %u", expid) logconsole.info("Waiting for experiment to be running.") experiment.wait_experiment(api, expid) return expid
def launch_experiment(deployment_site, number_of_nodes, experiment_time, corridor): settings = settings_reader.SettingsReader(deployment_site) ids_text = extract_nodes_ids(str(settings.get_parameter(corridor))) nodes_ids = [] for item in ids_text: id_begin, id_end = (int(x) for x in item.split("-")) nodes_ids.extend(np.arange(id_begin, id_end + 1, 1).tolist()) json_data = json.loads( experiment.info_experiment(request, site=deployment_site)) nodes_to_reserve = select_candidates(json_data, nodes_ids, number_of_nodes, deployment_site) resources = experiment.exp_resources(nodes_to_reserve) experiment_id = json.loads( experiment.submit_experiment( request, '', experiment_time + int( settings_reader.SettingsReader('experiment').get_parameter( "extra_time")), resources))["id"] print_log("Starting new Experiment ({})".format(experiment_id)) print_log("Selected nodes: {}".format(" ".join(nodes_to_reserve)), header=False) experiment.wait_experiment(request, experiment_id) return experiment_id
def submit_experiment_a8(api, duration, nb_nodes, site="grenoble", name="test_exp_A8"): resources = exp_resources_from_str( "{},archi=a8:at86rf231+site={}".format(nb_nodes, site)) exp = experiment.submit_experiment(api, name, duration, [resources]) exp_id = exp['id'] return exp_id
def submit_experiment_parser(opts): """ Parse namespace 'opts' and execute requested 'submit' command """ user, passwd = auth.get_user_credentials(opts.username, opts.password) api = rest.Api(user, passwd) return experiment.submit_experiment(api, opts.name, opts.duration, opts.nodes_list, opts.reservation, opts.print_json)
def submit_experiment_parser(opts): """ Parse namespace 'opts' and execute requested 'submit' command """ user, passwd = auth.get_user_credentials(opts.username, opts.password) api = rest.Api(user, passwd) return experiment.submit_experiment(api, opts.name, opts.duration, opts.nodes_list, opts.reservation, opts.print_json, opts.site_association)
def test_submit_experiment_a8_physical(api): resources = exp_resources_from_str("grenoble,a8,1-2") name = "test_exp_A8" duration = 2 exp = experiment.submit_experiment(api, name, duration, [resources]) exp_id = exp['id'] experiment.wait_experiment(api, exp_id) state = experiment.get_experiment(api, exp_id, 'state') assert state['state'] == "Running"
def test_submit_experiment_a8_logical(api, exp): name = "test_exp_A8" duration = 2 resources = exp_resources_from_str("2,archi=a8:at86rf231+site=grenoble") ret = experiment.submit_experiment(api, name, duration, [resources]) exp.id = ret['id'] exp_id = exp.id experiment.wait_experiment(api, exp_id) state = experiment.get_experiment(api, exp_id, 'state') assert state['state'] == "Running"
def submit_exp(self, name, duration): """ Submit experiment with name and duration """ fabric.utils.puts("submit_exp") self.nodes = self._get_nodes_list(self.site, self.archi) if not self.nodes: raise ValueError("Empty nodes list") firmware = None if self.archi == 'a8:at86rf231' else self.firmware resources = [experiment.exp_resources(self.nodes, firmware)] self.exp_id = experiment.submit_experiment(self.api, name, duration, resources)["id"] fabric.utils.puts("Exp-id:%d" % self.exp_id)
def _submit(self, site, duration): """Submit an experiment with required nodes""" api = Api(*self.user_credentials()) resources = [] for ctrl in self.ctrls: if ctrl.env.get('IOTLAB_NODE') is not None: resources.append(exp_resources([ctrl.env.get('IOTLAB_NODE')])) elif ctrl.board() is not None: board = IoTLABExperiment._archi_from_board(ctrl.board()) alias = AliasNodes(1, site, board) resources.append(exp_resources(alias)) else: raise ValueError("neither BOARD or IOTLAB_NODE are set") return submit_experiment(api, self.name, duration, resources)['id']
def submit(self): """" Submit an experiment using class attribute for parametrization : self.nodename self.profile self.time """ qexp = experiment.submit_experiment( self.api, 'test', self.time, [{'firmware': None, 'profile': self.profile, 'type': 'physical', 'nodes': [self.nodename]}]) self.idexpe = qexp['id']
def submit(self): """" Submit an experiment using class attribute for parametrization : self.nodename self.profile self.time """ qexp = experiment.submit_experiment(self.api, 'test', self.time, [{ 'firmware': None, 'profile': self.profile, 'type': 'physical', 'nodes': [self.nodename] }]) self.idexpe = qexp['id']
def submit_experiment(args): """ Reserve nodes in the given site. The function uses the json experiment file corresponding to the site. :param str firmware: the name of the firmware as it is in the code/firmware/ folder :param str board: the type of board (ex: m3) :param str testbed: The name of the testbed (ex: grenoble) :param int duration: The duration of the experiment in minutes :param int nbnodes: The number of nodes to use :return: The id of the experiment """ # use the file created by auth-cli command usr, pwd = iotlab.get_user_credentials() # authenticate through the REST interface api = iotlab.rest.Api(usr, pwd) # load the experiment firmware = FIRMWARE_PATH + args.firmware profile = "mercator" if args.nbnodes != 0: if args.board == "m3": args.board = "m3:at86rf231" nodes = experiment.AliasNodes(args.nbnodes, args.testbed, args.board) else: tb_file = open("{0}states.json".format(METAS_PATH)) tb_json = json.load(tb_file) nodes = [x for x in tb_json[args.testbed] if args.board in x] resources = [experiment.exp_resources(nodes, firmware, profile)] # submit experiment logconsole.info("Submitting experiment.") expid = experiment.submit_experiment( api, "mercatorExp", args.duration, resources)["id"] logconsole.info("Experiment submited with id: %u", expid) logconsole.info("Waiting for experiment to be running.") experiment.wait_experiment(api, expid) return expid
def push_iotlab(name): experiment_path = pj(EXPERIMENT_FOLDER, name) results_folder = pj(experiment_path, "results", "iotlab") if not os.path.exists(results_folder): os.makedirs(results_folder) # gets user password from credentials file None, None user, passwd = iotlabcli.get_user_credentials() api = iotlabcli.Api(user, passwd) # describe the resources resources = None with open(pj(experiment_path, "iotlab.json")) as f: config = json.loads(f.read()) resources = [experiment.exp_resources(**c) for c in config] print(resources) # actually submit the experiment exp_id = None # We move to the folder to have a portable iotlab.json with lcd(experiment_path): exp_res = experiment.submit_experiment( api, 'dummy_experiment', 1, resources) exp_id = exp_wres["id"] with open("results/iotlab/iotlab.json", "w") as f: f.write(json.dumps({"id": exp_id})) # get the content print("Exp submited with id: %u" % exp_id) run("experiment-cli wait -i %d" % exp_id) with open(pj(results_folder, "serial.log"), 'w') as f: run("./iot-lab/tools_and_scripts/serial_aggregator.py -i %d" % exp_id, stdout=f) print("Written serial logs to %s" % pj(results_folder, "serial.log"))
def test_exp_submit_site_association(self): """Test experiment submission with site associations.""" nodes = ['m3-1.grenoble.iot-lab.info', 'a8-1.strasbourg.iot-lab.info'] resources = [experiment.exp_resources(nodes)] site_assocs = [ experiment.site_association( 'grenoble', script=tests.resource_file('script.sh'), ipv6='aaaa::/64', ), experiment.site_association( 'strasbourg', script=tests.resource_file('script_2.sh'), scriptconfig=tests.resource_file('scriptconfig'), ), ] experiment.submit_experiment(self.api, None, 20, resources, sites_assocs=site_assocs) files_dict = self.api.submit_experiment.call_args[0][0] expected = { 'name': None, 'duration': 20, 'type': 'physical', 'nodes': nodes, 'reservation': None, 'profileassociations': None, 'firmwareassociations': None, 'associations': None, 'siteassociations': { 'script': [ { 'scriptname': 'script.sh', 'sites': ['grenoble'] }, { 'scriptname': 'script_2.sh', 'sites': ['strasbourg'] }, ], 'scriptconfig': [ { 'scriptconfigname': 'scriptconfig', 'sites': ['strasbourg'] }, ], 'ipv6': [ { 'ipv6name': 'aaaa::/64', 'sites': ['grenoble'] }, ], }, 'profiles': None, 'mobilities': None, } self.assertEqual(expected, json.loads(files_dict['new_exp.json'])) self.assertEqual(files_dict['script.sh'], SCRIPTS['script.sh']) self.assertEqual(files_dict['script_2.sh'], SCRIPTS['script_2.sh']) self.assertEqual(files_dict['scriptconfig'], SCRIPTCONFIG['scriptconfig'])
def _submit_exp(api, name, duration, resources): """ Submit experiment """ return experiment.submit_experiment(api, name, duration, resources)['id']