コード例 #1
0
ファイル: test_experimentd.py プロジェクト: edgerun/galileo
        def inject_experiment():
            exp = Experiment('experiment_id', creator='unittest')
            cfg = ExperimentConfiguration(
                2, 1,
                [WorkloadConfiguration('aservice', [3, 5], 2, 'constant')])

            queue = pymq.queue(ExperimentController.queue_key)
            queue.put(QueuedExperiment(exp, cfg))
            try:
                poll(
                    lambda: queue.qsize() == 0, timeout=2,
                    interval=0.1)  # wait for the daemon to take the experiment
            finally:
                daemon.close()
コード例 #2
0
    def test_queue(self):
        self.cctl.register_worker('host1')

        exp = Experiment(name='my-experiment', creator='unittest')
        config = ExperimentConfiguration(
            2, 1, [WorkloadConfiguration('aservice', [1, 2], 2, 'constant')])
        self.ectl.queue(config, exp)

        queue = pymq.queue(ExperimentController.queue_key)

        self.assertEqual(1, queue.qsize())
        self.assertEqual(1, self.ectl.experiment_queue.qsize())

        queued_experiment: QueuedExperiment = queue.get()
        self.assertEqual(config, queued_experiment.configuration)
        self.assertEqual('my-experiment', queued_experiment.experiment.name)
        self.assertEqual('unittest', queued_experiment.experiment.creator)
コード例 #3
0
ファイル: experimentd.py プロジェクト: edgerun/galileo
    def run(self) -> None:
        self.queue = pymq.queue(ExperimentController.queue_key)

        try:
            logger.info('listening for incoming experiment...')
            while not self.closed:
                item = self.queue.get()

                if item == self.POISON:
                    break

                exp = None
                try:
                    logger.debug('got queued experiment %s', item)
                    exp, cfg = self.load_experiment(item)
                except Exception as e:
                    if exp and exp.id:
                        exp = self.exp_service.find(exp.id)
                        if exp is not None:
                            exp.status = 'FAILED'
                            self.exp_service.save(exp)

                    logger.exception('error while loading experiment from queue')
                    continue

                status = exp.status
                try:
                    pymq.publish(StartTracingCommand())
                    self.run_experiment(exp, cfg)
                    status = 'FINISHED'
                except Exception as e:
                    logger.error('error while running experiment: %s', e)
                    status = 'FAILED'
                finally:
                    pymq.publish(PauseTracingCommand())
                    logger.info("finalizing experiment %s", exp.id)
                    self.exp_service.finalize_experiment(exp, status)

        except KeyboardInterrupt:
            logger.info("interrupted while listening")

        logger.info('exiting experiment daemon loop')
コード例 #4
0
    def test_post_experiment(self):
        payload = {
            'experiment': {
                'name': 'my_experiment',
                'creator': 'research star'
            },
            'configuration': {
                'duration':
                '10s',
                'interval':
                '2s',
                'workloads': [
                    {
                        'service': 'alexnet',
                        'ticks': [1, 2, 3, 1, 1],
                        'arrival_pattern': 'constant',
                        'clients_per_host': 2
                    },
                ]
            }
        }

        self.ctx.cctrl.register_worker('host1')

        result = self.simulate_post('/api/experiments', json=payload)
        self.assertIsNotNone(result.json, 'Response must not be none')

        all_exps = self.db_resource.db.find_all()
        self.assertEqual(len(all_exps), 1)
        exp = all_exps[0]
        self.assertEqual(exp.id, result.json)
        self.assertEqual(exp.status, 'QUEUED')
        self.assertIsNotNone(exp.created)

        load = pymq.queue(ExperimentController.queue_key).get(timeout=2)

        # TODO test workload translation?
        self.assertIsNotNone(load)
        self.assertEqual(exp.id, load.experiment.id)
コード例 #5
0
ファイル: test_pymq.py プロジェクト: thrau/pymq
 def test_queue_on_non_started_bus(self):
     with pytest.raises(ValueError):
         pymq.queue("foo")