def flash_nodes(experiment_id): all_nodes = experiment.get_experiment(request, experiment_id)['nodes'] np.random.shuffle(all_nodes) # sink is always the first element sink = [all_nodes[0]] nodes = all_nodes[1:len(all_nodes)] print_log("Sink: {}".format(" ".join(sink)), header=False) print_log("Nodes: {}".format(" ".join(nodes)), header=False) print_log("Flashing nodes", header=False) node.node_command(request, 'update', experiment_id, nodes, node_firmware_filepath) # flash again node.node_command(request, 'update', experiment_id, nodes, node_firmware_filepath) print_log("Flashing sink", header=False) node.node_command(request, 'update', experiment_id, sink, sink_firmware_filepath) # flash again node.node_command(request, 'update', experiment_id, sink, sink_firmware_filepath)
def test_node_command(self, read_file_mock): """ Test 'node_command' """ nodes_list = ["m3-1", "m3-2", "m3-3"] read_file_mock.return_value = 'file_data' api = my_mock.api_mock() api.reset_mock() res = node.node_command(api, 'start', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('start', 123, nodes_list) api.reset_mock() res = node.node_command(api, 'stop', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('stop', 123, nodes_list) api.reset_mock() res = node.node_command(api, 'reset', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('reset', 123, nodes_list) api.reset_mock() res = node.node_command(api, 'profile', 123, nodes_list, 'p_m3') self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('profile', 123, nodes_list, '&name=p_m3') api.reset_mock() res = node.node_command(api, 'update', 123, nodes_list, '~/../filename.elf') self.assertEqual(my_mock.API_RET, res) self.assertEqual(1, api.node_update.call_count) api.node_update.assert_called_with(123, { "filename.elf": "file_data", 'nodes.json': '["m3-1", "m3-2", "m3-3"]', }) # no firmware for update command self.assertRaises(AssertionError, node.node_command, api, 'update', 123, nodes_list)
def test_node_command(self, read_file_mock): """ Test 'node_command' """ nodes_list = ["m3-1", "m3-2", "m3-3"] read_file_mock.return_value = 'file_data' api = my_mock.api_mock() api.reset_mock() res = node.node_command(api, 'start', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('start', 123, nodes_list) api.reset_mock() res = node.node_command(api, 'stop', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('stop', 123, nodes_list) api.reset_mock() res = node.node_command(api, 'reset', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('reset', 123, nodes_list) api.reset_mock() res = node.node_command(api, 'profile', 123, nodes_list, 'p_m3') self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('monitoring', 123, nodes_list, 'p_m3') api.reset_mock() res = node.node_command(api, 'flash', 123, nodes_list, '~/../filename.elf') self.assertEqual(my_mock.API_RET, res) self.assertEqual(1, api.node_update.call_count) api.node_update.assert_called_with( 123, { "filename.elf": "file_data", 'nodes.json': '["m3-1", "m3-2", "m3-3"]', }) api.reset_mock() res = node.node_command(api, 'flash', 123, nodes_list, '~/../filename.bin') self.assertEqual(my_mock.API_RET, res) self.assertEqual(1, api.node_update.call_count) api.node_update.assert_called_once() args = api.node_update.call_args.args kwargs = api.node_update.call_args.kwargs assert args[0] == 123 assert 'experiment.json' in args[1] data_dict = json.loads(args[1]['experiment.json']) assert 'offset' in data_dict assert data_dict['offset'] == 0 assert 'nodes' in data_dict assert data_dict['nodes'] == ["m3-1", "m3-2", "m3-3"] assert kwargs == {'binary': True} # no firmware for update command self.assertRaises(AssertionError, node.node_command, api, 'flash', 123, nodes_list) api.reset_mock() res = node.node_command(api, 'flash-idle', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('flash-idle', 123, nodes_list) # profile-load read_file_mock.return_value = '{profilejson}' # no local content check json_file = { 'profile.json': '{profilejson}', 'nodes.json': '["m3-1", "m3-2", "m3-3"]', } api.reset_mock() res = node.node_command(api, 'profile-load', 123, nodes_list, 'profile.json') self.assertEqual(my_mock.API_RET, res) api.node_profile_load.assert_called_with(123, json_file) # profile-load without profile self.assertRaises(AssertionError, node.node_command, api, 'profile-load', 123, nodes_list) # profile-reset api.reset_mock() res = node.node_command(api, 'profile-reset', 123, nodes_list) self.assertEqual(my_mock.API_RET, res) api.node_command.assert_called_with('profile-reset', 123, nodes_list)
def _reset_cb(self, mote): logfile.debug('restarting mote {0}'.format(mote.serialport)) mote_url = ".".join([mote.serialport, self.site, "iot-lab.info"]) node.node_command(self.api, 'reset', self.experiment_id, [mote_url]) logfile.debug('mote {0} restarted'.format(mote.serialport))