示例#1
0
    def test_get_active_experiments(self, exps_by_states_dict):
        """Test iotlabcli.experiment.get_active_experiments."""
        api = mock.Mock()

        # Running only no experiments
        exps_by_states_dict.return_value = {}
        ret = experiment.get_active_experiments(api)
        self.assertEqual(ret, {})
        exps_by_states_dict.assert_called_with(api, ['Running'])

        # Running only one experiment
        exps_by_states_dict.return_value = {'Running': [12345]}
        ret = experiment.get_active_experiments(api, running_only=True)
        self.assertEqual(ret, {'Running': [12345]})
        exps_by_states_dict.assert_called_with(api, ['Running'])

        # Active experiments
        exps_by_states_dict.return_value = {
            'Waiting': [10134, 10135],
            'Running': [10130]
        }
        ret = experiment.get_active_experiments(api, running_only=False)
        self.assertEqual(ret, {'Waiting': [10134, 10135], 'Running': [10130]})
        exps_by_states_dict.assert_called_with(
            api, ['Running', 'Launching', 'toLaunch', 'Waiting'])
示例#2
0
def get_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'get' command """

    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)

    # pylint:disable=no-else-return
    if opts.get_cmd == 'experiment_list':
        return experiment.get_experiments_list(api, opts.state, opts.limit,
                                               opts.offset)
    elif opts.get_cmd == 'start':
        exp_id = helpers.get_current_experiment(api, opts.experiment_id,
                                                running_only=False)
        ret = experiment.get_experiment(api, exp_id, opts.get_cmd)

        # Add a 'date' field
        timestamp = ret['start_time']
        ret['local_date'] = time.ctime(timestamp) if timestamp else 'Unknown'
        return ret
    elif opts.get_cmd == 'experiments':
        return experiment.get_active_experiments(api,
                                                 running_only=not opts.active)
    else:
        exp_id = helpers.get_current_experiment(api, opts.experiment_id)
        return experiment.get_experiment(api, exp_id, opts.get_cmd)
示例#3
0
def get_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'get' command """

    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)

    # pylint:disable=no-else-return
    if opts.get_cmd == 'experiment_list':
        return experiment.get_experiments_list(api, opts.state, opts.limit,
                                               opts.offset)
    elif opts.get_cmd == 'start':
        exp_id = helpers.get_current_experiment(api,
                                                opts.experiment_id,
                                                running_only=False)
        ret = experiment.get_experiment(api, exp_id, opts.get_cmd)

        # Add a 'date' field
        timestamp = ret['start_time']
        ret['local_date'] = time.ctime(timestamp) if timestamp else 'Unknown'
        return ret
    elif opts.get_cmd == 'experiments':
        return experiment.get_active_experiments(api,
                                                 running_only=not opts.active)
    else:
        exp_id = helpers.get_current_experiment(api, opts.experiment_id)
        return experiment.get_experiment(api, exp_id, opts.get_cmd)
示例#4
0
    def test_get_active_experiments(self, exps_by_states_dict):
        """Test iotlabcli.experiment.get_active_experiments."""
        api = mock.Mock()

        # Running only no experiments
        exps_by_states_dict.return_value = {}
        ret = experiment.get_active_experiments(api)
        self.assertEqual(ret, {})
        exps_by_states_dict.assert_called_with(api, ['Running'])

        # Running only one experiment
        exps_by_states_dict.return_value = {'Running': [12345]}
        ret = experiment.get_active_experiments(api, running_only=True)
        self.assertEqual(ret, {'Running': [12345]})
        exps_by_states_dict.assert_called_with(api, ['Running'])

        # Active experiments
        exps_by_states_dict.return_value = {'Waiting': [10134, 10135],
                                            'Running': [10130]}
        ret = experiment.get_active_experiments(api, running_only=False)
        self.assertEqual(ret, {'Waiting': [10134, 10135],
                               'Running': [10130]})
        exps_by_states_dict.assert_called_with(
            api, ['Running', 'Launching', 'toLaunch', 'Waiting'])
示例#5
0
def get_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'get' command """

    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)
    # pylint:disable=no-else-return
    if opts.get_cmd == 'experiment_list':
        return experiment.get_experiments_list(api, opts.state, opts.limit,
                                               opts.offset)
    elif opts.get_cmd in ('start_date', 'state'):
        return _get_experiment_attr(api, opts)
    elif opts.get_cmd == 'experiments':
        return experiment.get_active_experiments(api,
                                                 running_only=not opts.active)
    else:
        exp_id = helpers.get_current_experiment(api, opts.experiment_id)

        return experiment.get_experiment(api, exp_id,
                                         _deprecate_cmd(opts.get_cmd))