3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # Unittest for yardstick.benchmark.contexts.standalone
20 from __future__ import absolute_import
24 from yardstick.benchmark.contexts import standalone
27 class StandaloneContextTestCase(unittest.TestCase):
29 NODES_SAMPLE = "standalone_sample.yaml"
30 NODES_DUPLICATE_SAMPLE = "standalone_duplicate_sample.yaml"
33 self.test_context = standalone.StandaloneContext()
35 def test_construct(self):
37 self.assertIsNone(self.test_context.name)
38 self.assertIsNone(self.test_context.file_path)
39 self.assertEqual(self.test_context.nodes, [])
40 self.assertEqual(self.test_context.nfvi_node, [])
42 def test_unsuccessful_init(self):
46 'file': self._get_file_abspath("error_file")
49 self.assertRaises(IOError, self.test_context.init, attrs)
51 def test_successful_init(self):
55 'file': self._get_file_abspath(self.NODES_SAMPLE)
58 self.test_context.init(attrs)
60 self.assertEqual(self.test_context.name, "foo")
61 self.assertEqual(len(self.test_context.nodes), 3)
62 self.assertEqual(len(self.test_context.nfvi_node), 1)
63 self.assertEqual(self.test_context.nfvi_node[0]["name"], "node2")
65 def test__get_server_with_dic_attr_name(self):
69 'file': self._get_file_abspath(self.NODES_SAMPLE)
72 self.test_context.init(attrs)
74 attr_name = {'name': 'foo.bar'}
75 result = self.test_context._get_server(attr_name)
77 self.assertEqual(result, None)
79 def test__get_server_not_found(self):
83 'file': self._get_file_abspath(self.NODES_SAMPLE)
86 self.test_context.init(attrs)
89 result = self.test_context._get_server(attr_name)
91 self.assertEqual(result, None)
93 def test__get_server_duplicate(self):
97 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
100 self.test_context.init(attrs)
102 attr_name = 'node2.foo'
104 self.assertRaises(ValueError, self.test_context._get_server, attr_name)
106 def test__get_server_found(self):
110 'file': self._get_file_abspath(self.NODES_SAMPLE)
113 self.test_context.init(attrs)
115 attr_name = 'node1.foo'
116 result = self.test_context._get_server(attr_name)
118 self.assertEqual(result['ip'], '1.1.1.1')
119 self.assertEqual(result['name'], 'node1.foo')
120 self.assertEqual(result['user'], 'root')
122 def test_deploy(self):
123 self.assertIsNone(self.test_context.deploy())
125 def test_undeploy(self):
126 self.assertIsNone(self.test_context.undeploy())
128 def _get_file_abspath(self, filename):
129 curr_path = os.path.dirname(os.path.abspath(__file__))
130 file_path = os.path.join(curr_path, filename)
133 def test__get_network(self):
137 'segmentation_id': 'seg54',
138 'network_type': 'type_a',
139 'physical_network': 'phys',
145 self.test_context.networks = {
151 self.assertIsNone(self.test_context._get_network(attr_name))
154 self.assertIsNone(self.test_context._get_network(attr_name))
156 attr_name = {'vld_id': 'vld777'}
157 self.assertIsNone(self.test_context._get_network(attr_name))
160 self.assertIsNone(self.test_context._get_network(attr_name))
162 attr_name = {'vld_id': 'vld999'}
166 "segmentation_id": None,
167 "network_type": None,
168 "physical_network": None,
170 result = self.test_context._get_network(attr_name)
171 self.assertDictEqual(result, expected)
175 result = self.test_context._get_network(attr_name)
176 self.assertDictEqual(result, expected)