Example #1
0
    def test_benchmark_init(self, in_relation_hook, relation_ids):

        in_relation_hook.return_value = True
        relation_ids.return_value = ['benchmark:0']
        actions = ['asdf', 'foobar']

        tempdir = mkdtemp(prefix=self.__class__.__name__)
        self.addCleanup(rmtree, tempdir)
        conf_path = join(tempdir, "benchmark.conf")
        with mock.patch.object(Benchmark, "BENCHMARK_CONF", conf_path):
            b = Benchmark(actions)

            self.assertIsInstance(b, Benchmark)

            self.assertTrue(self.relation_get.called)
            self.assertTrue(self.relation_set.called)

            relation_ids.assert_called_once_with('benchmark')

            self.relation_set.assert_called_once_with(
                relation_id='benchmark:0',
                relation_settings={'benchmarks': ",".join(actions)})

            conf_contents = open(conf_path).readlines()
            for key, val in iter(
                    FAKE_RELATION['benchmark:0']['benchmark/0'].items()):
                self.assertIn("%s=%s\n" % (key, val), conf_contents)
Example #2
0
    def test_benchmark_init(self, in_relation_hook, relation_ids, relation_set,
                            relation_get):

        in_relation_hook.return_value = True
        relation_ids.return_value = ['benchmark:0']
        actions = ['asdf', 'foobar']

        with patch_open() as (_open, _file):
            b = Benchmark(actions)

            self.assertIsInstance(b, Benchmark)

            self.assertTrue(relation_get.called)
            self.assertTrue(relation_set.called)

            relation_ids.assert_called_once_with('benchmark')

            for key in b.required_keys:
                relation_get.assert_any_call(key)

            relation_set.assert_called_once_with(
                relation_id='benchmark:0',
                relation_settings={'benchmarks': ",".join(actions)})

            _open.assert_called_with('/etc/benchmark.conf', 'w')
            for key, val in iter(
                    FAKE_RELATION['benchmark:0']['benchmark/0'].items()):
                _file.write.assert_any_called("%s=%s\n" % (key, val))
Example #3
0
 def test_benchmark_set_composite_score(self, action_set):
     self.assertTrue(Benchmark.set_composite_score(15.7, 'hits/sec',
                                                   'desc'))
     action_set.assert_called_once_with('meta.composite', {
         'value': 15.7,
         'units': 'hits/sec',
         'direction': 'desc'
     })
Example #4
0
    def test_benchmark_start(self, check_output, exists):

        exists.return_value = True
        check_output.return_value = "data"

        with patch_open() as (_open, _file):
            self.assertIsNone(Benchmark.start())
            # _open.assert_called_with('/etc/benchmark.conf', 'w')

        COLLECT_PROFILE_DATA = '/usr/local/bin/collect-profile-data'
        exists.assert_any_call(COLLECT_PROFILE_DATA)
        check_output.assert_any_call([COLLECT_PROFILE_DATA])
Example #5
0
 def test_benchmark_finish(self):
     with patch_open() as (_open, _file):
         self.assertIsNone(Benchmark.finish())
Example #6
0
def finish():
    Benchmark.finish()
Example #7
0
def start():
    Benchmark.start()