def test_main_load_parser(self, load_exp):
     """ Run experiment_parser.main.load """
     load_exp.return_value = {}
     experiment_parser.main(['load', '-f', '../test_exp.json',
                             '-l', '~/firmware.elf,./firmware_2.elf'])
     load_exp.assert_called_with(self.api, '../test_exp.json',
                                 ['~/firmware.elf', './firmware_2.elf'])
 def test_main_load_parser(self, load_exp):
     """ Run experiment_parser.main.load """
     load_exp.return_value = {}
     experiment_parser.main(['load', '-f', '../test_exp.json',
                             '-l', '~/firmware.elf,./firmware_2.elf'])
     load_exp.assert_called_with(self.api, '../test_exp.json',
                                 ['~/firmware.elf', './firmware_2.elf'])
 def test_main_stop_parser(self, stop_exp):
     """ Run experiment_parser.main.stop """
     stop_exp.return_value = {}
     experiment_parser.main(['stop'])
     stop_exp.assert_called_with(self.api, 123)
     experiment_parser.main(['stop', '-i', '345'])
     stop_exp.assert_called_with(self.api, 345)
 def test_main_stop_parser(self, stop_exp):
     """ Run experiment_parser.main.stop """
     stop_exp.return_value = {}
     experiment_parser.main(['stop'])
     stop_exp.assert_called_with(self.api, 123)
     experiment_parser.main(['stop', '-i', '345'])
     stop_exp.assert_called_with(self.api, 345)
    def test_main_info_parser(self, info_exp):
        """ Run experiment_parser.main.info """
        info_exp.return_value = {}

        experiment_parser.main(['info', '--list'])
        info_exp.assert_called_with(self.api, False, None)
        experiment_parser.main(['info', '--list-id', '--site', 'grenoble'])
        info_exp.assert_called_with(self.api, True, 'grenoble')
    def test_main_info_parser(self, info_exp):
        """ Run experiment_parser.main.info """
        info_exp.return_value = {}

        experiment_parser.main(['info', '--list'])
        info_exp.assert_called_with(self.api, False, None)
        experiment_parser.main(['info', '--list-id', '--site', 'grenoble'])
        info_exp.assert_called_with(self.api, True, 'grenoble')
    def test_main_wait_parser(self, wait_exp):
        """ Run experiment_parser.main.info """
        wait_exp.return_value = {}

        experiment_parser.main(['wait'])
        wait_exp.assert_called_with(self.api, 234, 'Running', 5, float('+inf'))
        experiment_parser.main(['wait', '--id', '42',
                                '--state', 'Launching,Running', '--step', '1',
                                '--timeout', '60'])
        wait_exp.assert_called_with(self.api, 42, 'Launching,Running', 1, 60)
    def test_main_wait_parser(self, wait_exp):
        """ Run experiment_parser.main.info """
        wait_exp.return_value = {}

        experiment_parser.main(['wait'])
        wait_exp.assert_called_with(self.api, 234, 'Running', 5, float('+inf'))
        experiment_parser.main(['wait', '--id', '42',
                                '--state', 'Launching,Running', '--step', '1',
                                '--timeout', '60'])
        wait_exp.assert_called_with(self.api, 42, 'Launching,Running', 1, 60)
    def test_main_submit_parser_site_assocs(self, submit_exp):
        """Run experiment_parser.main.submit site associations."""
        script_sh = resource_file('script.sh')
        script_2_sh = resource_file('script_2.sh')
        scriptconfig = resource_file('scriptconfig')

        submit_exp.return_value = {}

        # Groupped assocs
        experiment_parser.main([
            'submit', '--name', 'exp_name', '--duration', '20',
            '--list', 'grenoble,m3,1',
            '--list', 'strasbourg,m3,1',
            '--site-association', 'grenoble,strasbourg,script=%s' % script_sh,
        ])

        sites_assocs = [
            experiment.site_association('grenoble.iot-lab.info',
                                        'strasbourg.iot-lab.info',
                                        script=script_sh),
        ]

        resources = [
            experiment.exp_resources(['m3-1.grenoble.iot-lab.info']),
            experiment.exp_resources(['m3-1.strasbourg.iot-lab.info']),
        ]
        submit_exp.assert_called_with(self.api, 'exp_name', 20, resources,
                                      None, False, sites_assocs)

        # Different assocs
        experiment_parser.main([
            'submit', '--name', 'exp_name', '--duration', '20',
            '--list', 'grenoble,m3,1',
            '--list', 'strasbourg,m3,1',
            '--site-association', 'grenoble,script=%s,ipv6=2001::' % script_sh,
            '--site-association', 'strasbourg,script=%s,scriptconfig=%s' % (
                script_2_sh, scriptconfig),
        ])

        sites_assocs = [
            experiment.site_association('grenoble.iot-lab.info',
                                        script=script_sh, ipv6='2001::'),
            experiment.site_association('strasbourg.iot-lab.info',
                                        script=script_2_sh,
                                        scriptconfig=scriptconfig),
        ]

        resources = [
            experiment.exp_resources(['m3-1.grenoble.iot-lab.info']),
            experiment.exp_resources(['m3-1.strasbourg.iot-lab.info']),
        ]
        submit_exp.assert_called_with(self.api, 'exp_name', 20, resources,
                                      None, False, sites_assocs)
    def test_main_reload_parser(self, reload_exp):
        """ Run experiment_parser.main.info """
        reload_exp.return_value = {}

        experiment_parser.main(['reload', '-i', '123'])
        reload_exp.assert_called_with(self.api, 123, None, None)
        experiment_parser.main(['reload',
                                '--id', '123',
                                '--duration', '120',
                                '--reservation', '314159'])
        reload_exp.assert_called_with(self.api, 123, 120, 314159)

        # Exp id is required
        self.assertRaises(SystemExit, experiment_parser.main, ['reload'])
    def test_get_experiments(self, get_active_experiments):
        """Run experiment_parser.main.get 'experiments'"""
        get_active_experiments.return_value = {
            "Running": [11667], "Waiting": [11668],
        }

        experiment_parser.main(['get', '-e'])
        self.assertEqual(1, get_active_experiments.call_count)
        get_active_experiments.assert_called_with(self.api, running_only=True)
        get_active_experiments.reset_mock()

        experiment_parser.main(['get', '--experiments', '--active'])
        self.assertEqual(1, get_active_experiments.call_count)
        get_active_experiments.assert_called_with(self.api, running_only=False)
        get_active_experiments.reset_mock()
    def test_main_load_parser(self, load_exp):
        """ Run experiment_parser.main.load """
        load_exp.return_value = {}

        experiment_parser.main(['load', '-f', '../test_exp.json',
                                '-l', '~/firmware.elf',
                                '-l', './firmware_2.elf'])
        load_exp.assert_called_with(self.api, '../test_exp.json',
                                    ['~/firmware.elf', './firmware_2.elf'])

        # Deprecated, not documented anymore but keep it working
        experiment_parser.main(['load', '-f', '../test_exp.json',
                                '-l', '~/firmware.elf,./firmware_2.elf'])
        load_exp.assert_called_with(self.api, '../test_exp.json',
                                    ['~/firmware.elf', './firmware_2.elf'])
    def test_main_submit_parser_assocs(self, submit_exp):
        """Run experiment_parser.main.submit mobility."""
        submit_exp.return_value = {}

        # Physical tests
        experiment_parser.main(
            ['submit', '--name', 'exp_name', '--duration', '20',
             '--list',
             ('grenoble,m3,1,'
              'mobility=controlled,kernel=linux,firmware=m3.elf')])

        assocs = {'mobility': 'controlled', 'kernel': 'linux'}
        resources = [
            experiment.exp_resources(['m3-1.grenoble.iot-lab.info'],
                                     'm3.elf', None, **assocs)
        ]
        submit_exp.assert_called_with(self.api, 'exp_name', 20, resources,
                                      None, False, None)
    def test_main_info_parser(self, info_exp):
        """ Run experiment_parser.main.info """
        info_exp.return_value = {}

        experiment_parser.main(['info', '--list'])
        info_exp.assert_called_with(self.api, False)
        experiment_parser.main(['info', '--list-id', '--site', 'grenoble'])
        info_exp.assert_called_with(self.api, True, site='grenoble')

        # Use other selections
        experiment_parser.main(['info', '--list', '--archi', 'm3',
                                '--state', 'Alive'])
        info_exp.assert_called_with(self.api, False, archi='m3', state='Alive')

        experiment_parser.main(['info', '--list-id', '--site', 'lille',
                                '--archi', 'm3'])
        info_exp.assert_called_with(self.api, True, site='lille', archi='m3')
示例#15
0
    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 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'])
        nodes_list = [
            experiment.exp_resources(
                ['m3-%u.grenoble.iot-lab.info' % i for i in range(1, 6)],
                None, None)
        ]
        submit_exp.assert_called_with(self.api, 'exp_name', 20, nodes_list,
                                      314159, False)

        # 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)

        # 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
        nodes_list = [
            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, nodes_list,
                                      None, False)
示例#17
0
    def test_main_wait_parser(self, wait_exp):
        """ Run experiment_parser.main.info """
        wait_exp.return_value = {}

        experiment_parser.main(['wait'])
        wait_exp.assert_called_with(self.api, 234, 'Running', 5,
                                    experiment.WAIT_TIMEOUT_DEFAULT, False)
        experiment_parser.main([
            'wait', '--id', '42', '--state', 'Launching,Running', '--step',
            '1', '--timeout', '60'
        ])
        wait_exp.assert_called_with(self.api, 42, 'Launching,Running', 1, 60,
                                    False)
        experiment_parser.main([
            'wait', '--id', '42', '--state', 'Launching,Running', '--step',
            '1', '--timeout', '60', '--cancel-on-timeout'
        ])
        wait_exp.assert_called_with(self.api, 42, 'Launching,Running', 1, 60,
                                    True)
    def test_main_get_parser(self, get_exp, get_exp_list):
        """ Run experiment_parser.main.get """
        get_exp.return_value = {}
        get_exp_list.return_value = {}

        get_exp.return_value = {'start_time': 1423131729}
        experiment_parser.main(['get', '--start-time'])
        get_exp.assert_called_with(self.api, 234, 'start')

        # No value is treated inside
        get_exp.return_value = {}

        experiment_parser.main(['get', '--id', '18', '--print'])
        get_exp.assert_called_with(self.api, 18, '')

        experiment_parser.main(['get', '--resources'])
        get_exp.assert_called_with(self.api, 123, 'resources')

        experiment_parser.main(['get', '--resources-id'])
        get_exp.assert_called_with(self.api, 123, 'id')

        experiment_parser.main(['get', '--exp-state'])
        get_exp.assert_called_with(self.api, 123, 'state')

        experiment_parser.main(['get', '--archive'])
        get_exp.assert_called_with(self.api, 123, 'data')

        experiment_parser.main(
            ['get', '--list', '--state=Running', '--limit=10', '--offset=50'])
        get_exp_list.assert_called_with(self.api, 'Running', 10, 50)

        experiment_parser.main(['get', '--list'])
        get_exp_list.assert_called_with(self.api, None, 0, 0)
示例#19
0
    def test_main_get_parser(self, get_exp, get_exp_list):
        """ Run experiment_parser.main.get """
        get_exp.return_value = {}
        get_exp_list.return_value = {}

        get_exp.return_value = {'start_date': "2018-01-19T14:54:15Z"}
        experiment_parser.main(['get', '--start-time'])
        get_exp.assert_called_with(self.api, 234, '')

        get_exp.return_value = {'state': "Running"}
        experiment_parser.main(['get', '--exp-state'])
        get_exp.assert_called_with(self.api, 234, '')

        # No value is treated inside
        get_exp.return_value = {}

        experiment_parser.main(['get', '--id', '18', '--print'])
        get_exp.assert_called_with(self.api, 18, '')

        experiment_parser.main(['get', '--nodes'])
        get_exp.assert_called_with(self.api, 123, 'nodes')

        experiment_parser.main(['get', '--nodes-id'])
        get_exp.assert_called_with(self.api, 123, 'nodes_ids')

        # add deprecated option
        experiment_parser.main(['get', '--resources'])
        get_exp.assert_called_with(self.api, 123, 'nodes')

        experiment_parser.main(['get', '--resources-id'])
        get_exp.assert_called_with(self.api, 123, 'nodes_ids')

        experiment_parser.main(['get', '--archive'])
        get_exp.assert_called_with(self.api, 123, 'data')

        experiment_parser.main(
            ['get', '--list', '--state=Running', '--limit=10', '--offset=50'])
        get_exp_list.assert_called_with(self.api, 'Running', 10, 50)

        experiment_parser.main(['get', '--list'])
        get_exp_list.assert_called_with(self.api, None, 0, 0)
    def test_main_get_parser(self, get_exp, get_exp_list):
        """ Run experiment_parser.main.get """
        get_exp.return_value = {}
        get_exp_list.return_value = {}

        experiment_parser.main(['get', '--id', '18', '--print'])
        get_exp.assert_called_with(self.api, 18, '')

        experiment_parser.main(['get', '--resources'])
        get_exp.assert_called_with(self.api, 123, 'resources')

        experiment_parser.main(['get', '--resources-id'])
        get_exp.assert_called_with(self.api, 123, 'id')

        experiment_parser.main(['get', '--exp-state'])
        get_exp.assert_called_with(self.api, 123, 'state')

        experiment_parser.main(['get', '--archive'])
        get_exp.assert_called_with(self.api, 123, 'data')

        experiment_parser.main(
            ['get', '--list', '--state=Running', '--limit=10', '--offset=50'])
        get_exp_list.assert_called_with(self.api, 'Running', 10, 50)

        experiment_parser.main(['get', '--list'])
        get_exp_list.assert_called_with(self.api, None, 0, 0)
    def test_main_script_parser(self, script):
        """ Run experiment_parser.main.run """
        # Run script
        script_sh = resource_file('script.sh')
        scriptconfig = resource_file('scriptconfig')

        script.return_value = {}
        experiment_parser.main(['script', '--run',
                                'grenoble,script=%s' % script_sh])
        script.assert_called_with(
            self.api, 123, 'run',
            experiment.site_association('grenoble.iot-lab.info',
                                        script=script_sh)
        )

        # Multiple sites
        experiment_parser.main(['script', '--run',
                                'grenoble,strasbourg,script=%s' % script_sh])
        script.assert_called_with(
            self.api, 123, 'run',
            experiment.site_association('grenoble.iot-lab.info',
                                        'strasbourg.iot-lab.info',
                                        script=script_sh)
        )

        # Multiple sites associations
        script.return_value = {}
        experiment_parser.main(['script', '--run',
                                'grenoble,script=%s,scriptconfig=%s' % (
                                    script_sh, scriptconfig),
                                'strasbourg,script=%s' % script_sh])
        script.assert_called_with(
            self.api, 123, 'run',
            experiment.site_association('grenoble.iot-lab.info',
                                        script=script_sh,
                                        scriptconfig=scriptconfig),
            experiment.site_association('strasbourg.iot-lab.info',
                                        script=script_sh)
        )

        # Error no arguments
        self.assertRaises(SystemExit, experiment_parser.main,
                          ['script', '--run'])
        # Unknown assoc
        self.assertRaises(SystemExit, experiment_parser.main,
                          ['script', '--run',
                           'grenoble,script=%s,assoc=new' % script_sh])
        # Error no script
        self.assertRaises(SystemExit, experiment_parser.main,
                          ['script', '--run', 'grenoble,assoc=test'])
        self.assertRaises(SystemExit, experiment_parser.main,
                          ['script', '--run', 'assoc=test'])

        # kill script
        experiment_parser.main(['script', '--kill'])
        script.assert_called_with(self.api, 123, 'kill')

        experiment_parser.main(['script', '--kill', 'grenoble'])
        script.assert_called_with(self.api, 123, 'kill',
                                  'grenoble.iot-lab.info')

        experiment_parser.main(['script', '--kill', 'grenoble', 'strasbourg'])
        script.assert_called_with(self.api, 123, 'kill',
                                  'grenoble.iot-lab.info',
                                  'strasbourg.iot-lab.info')

        # Status script
        experiment_parser.main(['script', '--status'])
        script.assert_called_with(self.api, 123, 'status')

        experiment_parser.main(['script', '--status', 'grenoble'])
        script.assert_called_with(self.api, 123, 'status',
                                  'grenoble.iot-lab.info')

        experiment_parser.main(['script', '--status',
                                'grenoble', 'strasbourg'])
        script.assert_called_with(self.api, 123, 'status',
                                  'grenoble.iot-lab.info',
                                  'strasbourg.iot-lab.info')