Merge "Document for Fraser test case results"
[yardstick.git] / yardstick / tests / unit / benchmark / contexts / test_base.py
1 # Copyright (c) 2018 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from yardstick.benchmark.contexts import base
16 from yardstick.tests.unit import base as ut_base
17
18
19 class DummyContextClass(base.Context):
20
21     def _get_network(self, *args):
22         pass
23
24     def _get_server(self, *args):
25         pass
26
27     def deploy(self):
28         pass
29
30     def undeploy(self):
31         pass
32
33
34 class FlagsTestCase(ut_base.BaseUnitTestCase):
35
36     def setUp(self):
37         self.flags = base.Flags()
38
39     def test___init__(self):
40         self.assertFalse(self.flags.no_setup)
41         self.assertFalse(self.flags.no_teardown)
42         self.assertEqual({'verify': False}, self.flags.os_cloud_config)
43
44     def test___init__with_flags(self):
45         flags = base.Flags(no_setup=True)
46         self.assertTrue(flags.no_setup)
47         self.assertFalse(flags.no_teardown)
48
49     def test_parse(self):
50         self.flags.parse(no_setup=True, no_teardown='False',
51                          os_cloud_config={'verify': True})
52
53         self.assertTrue(self.flags.no_setup)
54         self.assertEqual('False', self.flags.no_teardown)
55         self.assertEqual({'verify': True}, self.flags.os_cloud_config)
56
57     def test_parse_forbidden_flags(self):
58         self.flags.parse(foo=42)
59         with self.assertRaises(AttributeError):
60             _ = self.flags.foo
61
62
63 class ContextTestCase(ut_base.BaseUnitTestCase):
64
65     @staticmethod
66     def _remove_ctx(ctx_obj):
67         if ctx_obj in base.Context.list:
68             base.Context.list.remove(ctx_obj)
69
70     def test_split_host_name(self):
71         ctx_obj = DummyContextClass()
72         self.addCleanup(self._remove_ctx, ctx_obj)
73         config_name = 'host_name.ctx_name'
74         self.assertEqual(('host_name', 'ctx_name'),
75                          ctx_obj.split_host_name(config_name))
76
77     def test_split_host_name_wrong_separator(self):
78         ctx_obj = DummyContextClass()
79         self.addCleanup(self._remove_ctx, ctx_obj)
80         config_name = 'host_name-ctx_name'
81         self.assertEqual((None, None),
82                          ctx_obj.split_host_name(config_name))
83
84     def test_split_host_name_other_separator(self):
85         ctx_obj = DummyContextClass(host_name_separator='-')
86         self.addCleanup(self._remove_ctx, ctx_obj)
87         config_name = 'host_name-ctx_name'
88         self.assertEqual(('host_name', 'ctx_name'),
89                          ctx_obj.split_host_name(config_name))