Ejemplo n.º 1
0
    def test_list_nodes(self, g_nodes_list):
        """ Run the different list_nodes cases """
        api = api_mock()
        g_nodes_list.return_value = [
            "m3-1.grenoble.iot-lab.info", "m3-2.grenoble.iot-lab.info",
            "m3-3.grenoble.iot-lab.info",
            "m3-1.strasbourg.iot-lab.info", "m3-2.strasbourg.iot-lab.info",
            "m3-3.strasbourg.iot-lab.info"
        ]

        nodes_ll = [
            ["m3-1.grenoble.iot-lab.info", "m3-2.grenoble.iot-lab.info"],
            ["m3-1.strasbourg.iot-lab.info", "m3-2.strasbourg.iot-lab.info"],
        ]

        # No nodes provided => all nodes, no external requests
        res = common.list_nodes(api, 123)
        self.assertEqual(res, [])
        self.assertFalse(g_nodes_list.called)

        # Normal case, no external requests, only list of all provided nodes
        res = common.list_nodes(api, 123, nodes_ll=nodes_ll)
        self.assertEqual(res, ["m3-1.grenoble.iot-lab.info",
                               "m3-2.grenoble.iot-lab.info",
                               "m3-1.strasbourg.iot-lab.info",
                               "m3-2.strasbourg.iot-lab.info"])
        self.assertFalse(g_nodes_list.called)

        res = common.list_nodes(api, 123, excl_nodes_ll=nodes_ll)
        self.assertEqual(res, ["m3-3.grenoble.iot-lab.info",
                               "m3-3.strasbourg.iot-lab.info"])
        self.assertTrue(g_nodes_list.called)
Ejemplo n.º 2
0
    def test_list_nodes(self, g_nodes_list):
        """ Run the different list_nodes cases """
        api = api_mock()
        g_nodes_list.return_value = [
            "m3-1.grenoble.iot-lab.info", "m3-2.grenoble.iot-lab.info",
            "m3-3.grenoble.iot-lab.info", "m3-1.strasbourg.iot-lab.info",
            "m3-2.strasbourg.iot-lab.info", "m3-3.strasbourg.iot-lab.info"
        ]

        nodes_ll = [
            ["m3-1.grenoble.iot-lab.info", "m3-2.grenoble.iot-lab.info"],
            ["m3-1.strasbourg.iot-lab.info", "m3-2.strasbourg.iot-lab.info"],
        ]

        # No nodes provided => all nodes, no external requests
        res = common.list_nodes(api, 123)
        self.assertEqual(res, [])
        self.assertFalse(g_nodes_list.called)

        # Normal case, no external requests, only list of all provided nodes
        res = common.list_nodes(api, 123, nodes_ll=nodes_ll)
        self.assertEqual(res, [
            "m3-1.grenoble.iot-lab.info", "m3-2.grenoble.iot-lab.info",
            "m3-1.strasbourg.iot-lab.info", "m3-2.strasbourg.iot-lab.info"
        ])
        self.assertFalse(g_nodes_list.called)

        res = common.list_nodes(api, 123, excl_nodes_ll=nodes_ll)
        self.assertEqual(
            res,
            ["m3-3.grenoble.iot-lab.info", "m3-3.strasbourg.iot-lab.info"])
        self.assertTrue(g_nodes_list.called)
Ejemplo n.º 3
0
 def test_exp_by_states(self):
     """ Run the 'exp_by_states' function """
     api = my_mock.api_mock({"items": [{'state': 'Waiting', 'id': 10134},
                                       {'state': 'Waiting', 'id': 10135},
                                       {'state': 'Running', 'id': 10130}]})
     states_d = helpers.exps_by_states_dict(api, helpers.ACTIVE_STATES)
     self.assertEqual(
         {'Waiting': [10134, 10135], 'Running': [10130]}, states_d)
     my_mock.api_mock_stop()
Ejemplo n.º 4
0
 def test_exp_by_states(self):
     """ Run the 'exp_by_states' function """
     api = my_mock.api_mock({"items": [{'state': 'Waiting', 'id': 10134},
                                       {'state': 'Waiting', 'id': 10135},
                                       {'state': 'Running', 'id': 10130}]})
     states_d = helpers.exps_by_states_dict(api, helpers.ACTIVE_STATES)
     self.assertEqual(
         {'Waiting': [10134, 10135], 'Running': [10130]}, states_d)
     my_mock.api_mock_stop()
Ejemplo n.º 5
0
    def test_robot_command(self):
        """ Test 'robot_command' """

        api = my_mock.api_mock()

        nodes_list = ["m3-1", "m3-2", "m3-3"]
        api.reset_mock()
        res = robot.robot_command(api, 'status', 123, nodes_list)
        self.assertEqual(my_mock.API_RET, res)

        api.robot_command.assert_called_with('status', 123, nodes_list)
Ejemplo n.º 6
0
 def test__get_experiment_nodes_list(self):
     """ Run get_experiment_nodes_list """
     api = api_mock(
         ret={
             "items": [
                 {"network_address": "m3-1.grenoble.iot-lab.info"},
                 {"network_address": "m3-2.grenoble.iot-lab.info"},
                 {"network_address": "m3-3.grenoble.iot-lab.info"},
             ]
         }
     )
     # pylint: disable=protected-access
     self.assertEqual(common._get_experiment_nodes_list(api, 3),
                      ["m3-1.grenoble.iot-lab.info",
                       "m3-2.grenoble.iot-lab.info",
                       "m3-3.grenoble.iot-lab.info"])
Ejemplo n.º 7
0
 def test__get_experiment_nodes_list(self):
     """ Run get_experiment_nodes_list """
     api = api_mock(
         ret={
             "items": [
                 {"network_address": "m3-1.grenoble.iot-lab.info"},
                 {"network_address": "m3-2.grenoble.iot-lab.info"},
                 {"network_address": "m3-3.grenoble.iot-lab.info"},
             ]
         }
     )
     # pylint: disable=protected-access
     self.assertEqual(common._get_experiment_nodes_list(api, 3),
                      ["m3-1.grenoble.iot-lab.info",
                       "m3-2.grenoble.iot-lab.info",
                       "m3-3.grenoble.iot-lab.info"])
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    def test_status_command(self):
        """ Test 'status_command' """

        api = my_mock.api_mock()

        api.reset_mock()
        res = status.status_command(api, 'sites')
        self.assertEqual(my_mock.API_RET, res)
        api.get_sites_details.assert_called()

        api.reset_mock()
        res = status.status_command(api, 'nodes')
        self.assertEqual(my_mock.API_RET, res)
        api.get_nodes.assert_called()

        api.reset_mock()
        res = status.status_command(api, 'nodes-ids', site='grenoble')
        self.assertEqual(my_mock.API_RET, res)
        api.get_nodes.assert_called_with(list_id=True, site='grenoble')

        api.reset_mock()
        res = status.status_command(api, 'experiments')
        self.assertEqual(my_mock.API_RET, res)
        api.get_running_experiments.assert_called()
Ejemplo n.º 10
0
 def setUp(self):
     self.api = my_mock.api_mock()
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
 def setUp(self):
     self.api = my_mock.api_mock()