summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py9
-rw-r--r--tests/unit/benchmark/contexts/test_model.py10
-rw-r--r--tests/unit/cmd/test_NSBperf.py3
-rw-r--r--tests/unit/common/test_openstack_utils.py28
4 files changed, 36 insertions, 14 deletions
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py
index f8f349205..8f4852ca8 100644
--- a/tests/unit/benchmark/contexts/test_heat.py
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -39,6 +39,7 @@ class HeatContextTestCase(unittest.TestCase):
self.assertEqual(self.test_context.networks, [])
self.assertEqual(self.test_context.servers, [])
self.assertEqual(self.test_context.placement_groups, [])
+ self.assertEqual(self.test_context.server_groups, [])
self.assertIsNone(self.test_context.keypair_name)
self.assertIsNone(self.test_context.secgroup_name)
self.assertEqual(self.test_context._server_map, {})
@@ -51,15 +52,18 @@ class HeatContextTestCase(unittest.TestCase):
self.assertIsNotNone(self.test_context.key_filename)
@mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup')
+ @mock.patch('yardstick.benchmark.contexts.heat.ServerGroup')
@mock.patch('yardstick.benchmark.contexts.heat.Network')
@mock.patch('yardstick.benchmark.contexts.heat.Server')
- def test_init(self, mock_server, mock_network, mock_pg):
+ def test_init(self, mock_server, mock_network, mock_sg, mock_pg):
pgs = {'pgrp1': {'policy': 'availability'}}
+ sgs = {'servergroup1': {'policy': 'affinity'}}
networks = {'bar': {'cidr': '10.0.1.0/24'}}
servers = {'baz': {'floating_ip': True, 'placement': 'pgrp1'}}
attrs = {'name': 'foo',
'placement_groups': pgs,
+ 'server_groups': sgs,
'networks': networks,
'servers': servers}
@@ -71,7 +75,10 @@ class HeatContextTestCase(unittest.TestCase):
mock_pg.assert_called_with('pgrp1', self.test_context,
pgs['pgrp1']['policy'])
+ mock_sg.assert_called_with('servergroup1', self.test_context,
+ sgs['servergroup1']['policy'])
self.assertTrue(len(self.test_context.placement_groups) == 1)
+ self.assertTrue(len(self.test_context.server_groups) == 1)
mock_network.assert_called_with(
'bar', self.test_context, networks['bar'])
diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py
index 537a8c008..a4b7d81ef 100644
--- a/tests/unit/benchmark/contexts/test_model.py
+++ b/tests/unit/benchmark/contexts/test_model.py
@@ -180,6 +180,7 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(test_server.keypair_name, 'some-keys')
self.assertEqual(test_server.secgroup_name, 'some-secgroup')
self.assertEqual(test_server.placement_groups, [])
+ self.assertIsNone(test_server.server_group)
self.assertEqual(test_server.instances, 1)
self.assertIsNone(test_server.floating_ip)
self.assertIsNone(test_server._image)
@@ -195,6 +196,15 @@ class ServerTestCase(unittest.TestCase):
self.assertRaises(ValueError, model.Server, 'foo',
self.mock_context, attrs)
+ @mock.patch('yardstick.benchmark.contexts.model.PlacementGroup')
+ def test_construct_get_wrong_server_group(self, mock_sg):
+
+ attrs = {'server_group': 'baz'}
+ mock_sg.get.return_value = None
+
+ self.assertRaises(ValueError, model.Server, 'foo',
+ self.mock_context, attrs)
+
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test__add_instance(self, mock_template):
diff --git a/tests/unit/cmd/test_NSBperf.py b/tests/unit/cmd/test_NSBperf.py
index a14c08464..5bd248a84 100644
--- a/tests/unit/cmd/test_NSBperf.py
+++ b/tests/unit/cmd/test_NSBperf.py
@@ -40,7 +40,8 @@ class TestYardstickNSCli(unittest.TestCase):
def test_generate_final_report(self):
yardstick_ns_cli = YardstickNSCli()
test_case = "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"
- subprocess.call(["touch", "/tmp/yardstick.out"])
+ if os.path.isfile("/tmp/yardstick.out"):
+ os.remove('/tmp/yardstick.out')
self.assertIsNone(yardstick_ns_cli.generate_final_report(test_case))
def test_generate_kpi_results(self):
diff --git a/tests/unit/common/test_openstack_utils.py b/tests/unit/common/test_openstack_utils.py
index d610e181c..b3dc2d9c4 100644
--- a/tests/unit/common/test_openstack_utils.py
+++ b/tests/unit/common/test_openstack_utils.py
@@ -22,21 +22,25 @@ class GetCredentialsTestCase(unittest.TestCase):
@mock.patch('yardstick.common.openstack_utils.os')
def test_get_credentials(self, mock_os):
- mock_os.getenv.return_value = ('2')
- openstack_utils.get_credentials()
+ with mock.patch.dict('os.environ', {'OS_IDENTITY_API_VERSION': '2'},
+ clear=True):
+ openstack_utils.get_credentials()
class GetHeatApiVersionTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.os')
- def test_get_heat_api_version(self, mock_os):
+ def test_get_heat_api_version_check_result(self):
API = 'HEAT_API_VERSION'
- openstack_utils.get_heat_api_version()
- mock_os.getenv.assert_called_with(API)
-
- @mock.patch('yardstick.common.openstack_utils.os')
- def test_get_heat_api_version(self, mock_os):
- mock_os.getenv.return_value = ('2')
expected_result = '2'
- api_version = openstack_utils.get_heat_api_version()
- self.assertEqual(api_version, expected_result)
+
+ with mock.patch.dict('os.environ', {API: '2'}, clear=True):
+ api_version = openstack_utils.get_heat_api_version()
+ self.assertEqual(api_version, expected_result)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()