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_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 test_main_submit_parser(self, submit_exp): """ Run experiment_parser.main.submit """ submit_exp.return_value = {} # Physical tests experiment_parser.main([ 'submit', '--name', 'exp_name', '--duration', '20', '--reservation', '314159', '--list', 'grenoble,m3,1-5' ]) resources = [ experiment.exp_resources( [f'm3-{i}.grenoble.iot-lab.info' for i in range(1, 6)], None, None) ] submit_exp.assert_called_with(self.api, 'exp_name', 20, resources, 314159, False, None) # print with simple options nodes = [experiment.exp_resources(['m3-1.grenoble.iot-lab.info'])] experiment_parser.main( ['submit', '-p', '-d', '20', '-l', 'grenoble,m3,1']) submit_exp.assert_called_with(self.api, None, 20, nodes, None, True, None) # Alias tests experiment_parser.main([ 'submit', '-d', '20', '-l', '1,archi=m3:at86rf231+site=grenoble,firmware.elf,profile1', '-l', '2,archi=m3:at86rf231+site=grenoble,firmware.elf,profile1', '-l', '3,archi=m3:at86rf231+site=grenoble,firmware_2.elf,profile2', ]) experiment.AliasNodes._alias = 0 # pylint:disable=protected-access resources = [ experiment.exp_resources( experiment.AliasNodes(1, 'grenoble', 'm3:at86rf231', False), 'firmware.elf', 'profile1'), experiment.exp_resources( experiment.AliasNodes(2, 'grenoble', 'm3:at86rf231', False), 'firmware.elf', 'profile1'), experiment.exp_resources( experiment.AliasNodes(3, 'grenoble', 'm3:at86rf231', False), 'firmware_2.elf', 'profile2'), ] submit_exp.assert_called_with(self.api, None, 20, resources, None, False, None)
def _extract_firmware_nodes_list(param_list): """ Extract a firmware nodes list from param_list param_list is modified by the function call :param param_list: can have following formats * ['9', 'archi=wsn430:cc1101+site=grenoble', ...] Alias type * ['grenoble', 'm3', '1-4+8-12+7', ...] Physical type """ # list in iotlab-experiment (alias or physical) if param_list[0].isdigit(): # alias selection # extract parameters nb_nodes, properties_str = param_list[0:2] param_list = param_list[2:] # parse parameters site, archi, _mobile = get_alias_properties(properties_str) mobile = mobile_from_mobile_str(_mobile) nodes = experiment.AliasNodes(int(nb_nodes), site, archi, mobile) else: # physical selection # extract parameters site, archi, nodes_str = param_list[0:3] param_list = param_list[3:] # parse parameters nodes = common.nodes_list_from_info(site, archi, nodes_str) common.check_site_with_server(site) return nodes, param_list
def test_exp_submit_types_detect(self): """ Try experiment submit types detection""" # Physical tests and Alias Nodes resources = [] resources.append(experiment.exp_resources( ['m3-%u.grenoble.iot-lab.info' % i for i in range(1, 6)])) resources.append(experiment.exp_resources( experiment.AliasNodes(1, 'grenoble', 'm3:at86rf231', False), tests.resource_file('firmware.elf'), 'profile1')) self.assertRaises(ValueError, experiment.submit_experiment, self.api, 'exp_name', 20, resources)
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