1 # Copyright (c) 2018 Intel Corporation
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from yardstick.benchmark.contexts import base
16 from yardstick.tests.unit import base as ut_base
19 class DummyContextClass(base.Context):
21 def _get_network(self, *args):
24 def _get_server(self, *args):
34 class FlagsTestCase(ut_base.BaseUnitTestCase):
37 self.flags = base.Flags()
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)
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)
50 self.flags.parse(no_setup=True, no_teardown='False',
51 os_cloud_config={'verify': True})
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)
57 def test_parse_forbidden_flags(self):
58 self.flags.parse(foo=42)
59 with self.assertRaises(AttributeError):
63 class ContextTestCase(ut_base.BaseUnitTestCase):
66 def _remove_ctx(ctx_obj):
67 if ctx_obj in base.Context.list:
68 base.Context.list.remove(ctx_obj)
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))
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))
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))