Esempio n. 1
0
    def test_experiment_load_min(self, read_file_mock):
        """ Try experiment_load """
        node_fmt = 'm3-%u.grenoble.iot-lab.info'
        self.expected = {
            "duration": 20,
            "nodes": [node_fmt % num for num in range(1, 6)],
            "type": "physical",
        }
        read_file_mock.side_effect = self._read_file_for_load

        experiment.load_experiment(self.api, experiment.EXP_FILENAME)

        # read_file_calls
        _files = {_call[0][0] for _call in read_file_mock.call_args_list}
        self.assertEqual(_files, set([experiment.EXP_FILENAME]))
Esempio n. 2
0
def load_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'load' command """

    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)
    files = helpers.flatten_list_list(opts.files)
    return experiment.load_experiment(api, opts.path_file, files)
Esempio n. 3
0
def load_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'load' command """

    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)
    files = helpers.flatten_list_list(opts.files)
    return experiment.load_experiment(api, opts.path_file, files)
Esempio n. 4
0
    def test_experiment_load(self, read_file_mock):
        """ Try experiment_load """
        node_fmt = 'm3-%u.grenoble.iot-lab.info'
        expected = {
            "name":
            None,
            "duration":
            20,
            "nodes": [node_fmt % num for num in range(1, 6)],
            "firmwareassociations": [{
                "firmwarename":
                "firmware.elf",
                "nodes": [node_fmt % num for num in range(1, 3)],
            }, {
                "firmwarename":
                "firmware_2.elf",
                "nodes": [node_fmt % num for num in range(3, 5)],
            }],
            "type":
            "physical",
            "profileassociations":
            None,
            "reservation":
            None,
        }

        def read_file(file_path, _=''):
            """ read_file mock """
            if file_path == experiment.EXP_FILENAME:
                return json.dumps(expected)
            else:
                return "elf32arm"

        read_file_mock.side_effect = read_file

        experiment.load_experiment(self.api, experiment.EXP_FILENAME,
                                   ['firmware.elf'])

        # read_file_calls
        _files = set([_call[0][0] for _call in read_file_mock.call_args_list])
        self.assertEqual(
            _files,
            set((experiment.EXP_FILENAME, 'firmware.elf', 'firmware_2.elf')))

        self.assertRaises(ValueError, experiment.load_experiment, self.api,
                          experiment.EXP_FILENAME,
                          ['firmware.elf', 'firmware_2.elf', 'firmware_3.elf'])
Esempio n. 5
0
    def test_experiment_load(self, read_file_mock):
        """ Try experiment_load """
        node_fmt = 'm3-%u.grenoble.iot-lab.info'
        expected = {
            "name": None,
            "duration": 20,
            "nodes": [node_fmt % num for num in range(1, 6)],
            "firmwareassociations": [
                {
                    "firmwarename": "firmware.elf",
                    "nodes": [node_fmt % num for num in range(1, 3)],
                },
                {
                    "firmwarename": "firmware_2.elf",
                    "nodes": [node_fmt % num for num in range(3, 5)],
                }
            ],
            "type": "physical",
            "profileassociations": None,
            "reservation": None,
        }

        def read_file(file_path, _=''):
            """ read_file mock """
            if file_path == experiment.EXP_FILENAME:
                return json.dumps(expected)
            else:
                return "elf32arm"
        read_file_mock.side_effect = read_file

        experiment.load_experiment(
            self.api, experiment.EXP_FILENAME, ['firmware.elf'])

        # read_file_calls
        _files = set([_call[0][0] for _call in read_file_mock.call_args_list])
        self.assertEqual(_files,
                         set((experiment.EXP_FILENAME,
                              'firmware.elf', 'firmware_2.elf')))

        self.assertRaises(
            ValueError,
            experiment.load_experiment,
            self.api, experiment.EXP_FILENAME,
            ['firmware.elf', 'firmware_2.elf', 'firmware_3.elf'])
Esempio n. 6
0
    def test_experiment_load_with_script(self, read_file_mock):
        """Try experiment_load with script."""
        self.expected = {
            "name":
            None,
            "duration":
            20,
            "nodes": ['m3-1.grenoble.iot-lab.info'],
            "firmwareassociations": [{
                "firmwarename": "firmware.elf",
                "nodes": ['m3-1.grenoble.iot-lab.info'],
            }],
            "type":
            "physical",
            "profileassociations":
            None,
            "reservation":
            None,
            "siteassociations": {
                'script': [{
                    "scriptname": "script.sh",
                    "sites": ['grenoble'],
                }],
                'scriptconfig': [{
                    "scriptconfigname": "scriptconfig",
                    "sites": ['grenoble'],
                }],
            },
            'profiles':
            None,
            'mobilities':
            None,
        }
        read_file_mock.side_effect = self._read_file_for_load

        experiment.load_experiment(self.api, experiment.EXP_FILENAME,
                                   ['script.sh'])

        # read_file_calls
        _files = {_call[0][0] for _call in read_file_mock.call_args_list}
        self.assertEqual(
            _files,
            set((experiment.EXP_FILENAME, 'firmware.elf', 'script.sh',
                 'scriptconfig')))
Esempio n. 7
0
    def test_experiment_load_full(self, read_file_mock):
        """ Try experiment_load """
        node_fmt = 'm3-%u.grenoble.iot-lab.info'
        self.expected = {
            "name":
            None,
            "duration":
            20,
            "nodes": [node_fmt % num for num in range(1, 6)],
            "firmwareassociations": [{
                "firmwarename":
                "firmware.elf",
                "nodes": [node_fmt % num for num in range(1, 3)],
            }, {
                "firmwarename":
                "firmware_2.elf",
                "nodes": [node_fmt % num for num in range(3, 5)],
            }],
            "type":
            "physical",
            "profileassociations":
            None,
            "reservation":
            None,
        }
        read_file_mock.side_effect = self._read_file_for_load

        experiment.load_experiment(self.api, experiment.EXP_FILENAME,
                                   ['firmware.elf'])

        # read_file_calls
        _files = {_call[0][0] for _call in read_file_mock.call_args_list}
        self.assertEqual(
            _files,
            set((experiment.EXP_FILENAME, 'firmware.elf', 'firmware_2.elf')))

        self.assertRaises(ValueError, experiment.load_experiment, self.api,
                          experiment.EXP_FILENAME,
                          ['firmware.elf', 'firmware_2.elf', 'firmware_3.elf'])

        self.assertRaises(ValueError, self._read_file_for_load,
                          'invalid/file/path')
Esempio n. 8
0
    def test_experiment_load(self, read_file_mock):
        """ Try experiment_load """
        node_fmt = 'm3-%u.grenoble.iot-lab.info'
        self.expected = {
            "name": None,
            "duration": 20,
            "nodes": [node_fmt % num for num in range(1, 6)],
            "firmwareassociations": [
                {
                    "firmwarename": "firmware.elf",
                    "nodes": [node_fmt % num for num in range(1, 3)],
                },
                {
                    "firmwarename": "firmware_2.elf",
                    "nodes": [node_fmt % num for num in range(3, 5)],
                }
            ],
            "type": "physical",
            "profileassociations": None,
            "reservation": None,
        }
        read_file_mock.side_effect = self._read_file_for_load

        experiment.load_experiment(
            self.api, experiment.EXP_FILENAME, ['firmware.elf'])

        # read_file_calls
        _files = {_call[0][0] for _call in read_file_mock.call_args_list}
        self.assertEqual(_files,
                         set((experiment.EXP_FILENAME,
                              'firmware.elf', 'firmware_2.elf')))

        self.assertRaises(
            ValueError,
            experiment.load_experiment,
            self.api, experiment.EXP_FILENAME,
            ['firmware.elf', 'firmware_2.elf', 'firmware_3.elf'])

        self.assertRaises(ValueError,
                          self._read_file_for_load, 'invalid/file/path')
Esempio n. 9
0
    def test_experiment_load_with_script(self, read_file_mock):
        """Try experiment_load with script."""
        self.expected = {
            "name": None,
            "duration": 20,
            "nodes": ['m3-1.grenoble.iot-lab.info'],
            "firmwareassociations": [{
                "firmwarename": "firmware.elf",
                "nodes": ['m3-1.grenoble.iot-lab.info'],
            }],
            "type": "physical",
            "profileassociations": None,
            "reservation": None,
            "siteassociations": {
                'script': [{
                    "scriptname": "script.sh",
                    "sites": ['grenoble'],
                }],
                'scriptconfig': [{
                    "scriptconfigname": "scriptconfig",
                    "sites": ['grenoble'],
                }],
            },
            'profiles': None,
            'mobilities': None,
        }
        read_file_mock.side_effect = self._read_file_for_load

        experiment.load_experiment(
            self.api, experiment.EXP_FILENAME, ['script.sh'])

        # read_file_calls
        _files = {_call[0][0] for _call in read_file_mock.call_args_list}
        self.assertEqual(_files,
                         set((experiment.EXP_FILENAME,
                              'firmware.elf', 'script.sh', 'scriptconfig')))