summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQiLiang <liangqi1@huawei.com>2015-10-15 14:24:27 +0800
committerQiLiang <liangqi1@huawei.com>2015-10-20 11:35:26 +0800
commit1e3e9b5d7ff40eb6921e60dc1a3254e8c984a08c (patch)
tree92b1e8e81ddb0b2a0cf7e7f38688ebaf1d409f8f /tests
parent8069fee968b73833d314b41f004c8f1cb1ab6c28 (diff)
Heat context code refactor
Heat context code refactor to cater for the evolution of the Yardstick framework. At test_case.yaml context segment add "type" to indicate the context type, see samples/ping-heat-context.yaml for an example. And the default context type is Heat, so the existing yaml file do not need to change. JIRA: YARDSTICK-168 Change-Id: Ida0ce12c17cd9b88d7acfb4c9eb1ac6986394b38 Signed-off-by: QiLiang <liangqi1@huawei.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/benchmark/contexts/__init__.py (renamed from tests/unit/benchmark/context/__init__.py)0
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py114
-rw-r--r--tests/unit/benchmark/contexts/test_model.py (renamed from tests/unit/benchmark/context/test_model.py)135
3 files changed, 119 insertions, 130 deletions
diff --git a/tests/unit/benchmark/context/__init__.py b/tests/unit/benchmark/contexts/__init__.py
index e69de29bb..e69de29bb 100644
--- a/tests/unit/benchmark/context/__init__.py
+++ b/tests/unit/benchmark/contexts/__init__.py
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py
new file mode 100644
index 000000000..bf1174e27
--- /dev/null
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2015 Ericsson AB and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.benchmark.contexts.heat
+
+import mock
+import unittest
+
+from yardstick.benchmark.contexts import model
+from yardstick.benchmark.contexts import heat
+
+
+class HeatContextTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.test_context = heat.HeatContext()
+ self.mock_context = mock.Mock(spec=heat.HeatContext())
+
+ def test_construct(self):
+
+ self.assertIsNone(self.test_context.name)
+ self.assertIsNone(self.test_context.stack)
+ self.assertEqual(self.test_context.networks, [])
+ self.assertEqual(self.test_context.servers, [])
+ self.assertEqual(self.test_context.placement_groups, [])
+ self.assertIsNone(self.test_context.keypair_name)
+ self.assertIsNone(self.test_context.secgroup_name)
+ self.assertEqual(self.test_context._server_map, {})
+ self.assertIsNone(self.test_context._image)
+ self.assertIsNone(self.test_context._flavor)
+ self.assertIsNone(self.test_context._user)
+ self.assertIsNone(self.test_context.template_file)
+ self.assertIsNone(self.test_context.heat_parameters)
+
+ @mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup')
+ @mock.patch('yardstick.benchmark.contexts.heat.Network')
+ @mock.patch('yardstick.benchmark.contexts.heat.Server')
+ def test_init(self, mock_server, mock_network, mock_pg):
+
+ pgs = {'pgrp1': {'policy': 'availability'}}
+ networks = {'bar': {'cidr': '10.0.1.0/24'}}
+ servers = {'baz': {'floating_ip': True, 'placement': 'pgrp1'}}
+ attrs = {'name': 'foo',
+ 'placement_groups': pgs,
+ 'networks': networks,
+ 'servers': servers}
+
+ self.test_context.init(attrs)
+
+ self.assertEqual(self.test_context.keypair_name, "foo-key")
+ self.assertEqual(self.test_context.secgroup_name, "foo-secgroup")
+
+ mock_pg.assert_called_with('pgrp1', self.test_context,
+ pgs['pgrp1']['policy'])
+ self.assertTrue(len(self.test_context.placement_groups) == 1)
+
+ mock_network.assert_called_with(
+ 'bar', self.test_context, networks['bar'])
+ self.assertTrue(len(self.test_context.networks) == 1)
+
+ mock_server.assert_called_with('baz', self.test_context, servers['baz'])
+ self.assertTrue(len(self.test_context.servers) == 1)
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test__add_resources_to_template_no_servers(self, mock_template):
+
+ self.test_context.keypair_name = "foo-key"
+ self.test_context.secgroup_name = "foo-secgroup"
+
+ self.test_context._add_resources_to_template(mock_template)
+ mock_template.add_keypair.assert_called_with("foo-key")
+ mock_template.add_security_group.assert_called_with("foo-secgroup")
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test_deploy(self, mock_template):
+
+ self.test_context.name = 'foo'
+ self.test_context.template_file = '/bar/baz/some-heat-file'
+ self.test_context.heat_parameters = {'image': 'cirros'}
+ self.test_context.deploy()
+
+ mock_template.assert_called_with(self.test_context.name,
+ self.test_context.template_file,
+ self.test_context.heat_parameters)
+ self.assertIsNotNone(self.test_context.stack)
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test_undeploy(self, mock_template):
+
+ self.test_context.stack = mock_template
+ self.test_context.undeploy()
+
+ self.assertTrue(mock_template.delete.called)
+
+ def test__get_server(self):
+
+ self.mock_context.name = 'bar'
+ self.mock_context.stack.outputs = {'public_ip': '127.0.0.1',
+ 'private_ip': '10.0.0.1'}
+ attr_name = {'name': 'foo.bar',
+ 'public_ip_attr': 'public_ip',
+ 'private_ip_attr': 'private_ip'}
+ result = heat.HeatContext._get_server(self.mock_context, attr_name)
+
+ self.assertEqual(result.public_ip, '127.0.0.1')
+ self.assertEqual(result.private_ip, '10.0.0.1')
diff --git a/tests/unit/benchmark/context/test_model.py b/tests/unit/benchmark/contexts/test_model.py
index cf0a605f4..48584cf33 100644
--- a/tests/unit/benchmark/context/test_model.py
+++ b/tests/unit/benchmark/contexts/test_model.py
@@ -9,12 +9,12 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.context.model
+# Unittest for yardstick.benchmark.contexts.model
import mock
import unittest
-from yardstick.benchmark.context import model
+from yardstick.benchmark.contexts import model
class ObjectTestCase(unittest.TestCase):
@@ -141,7 +141,7 @@ class NetworkTestCase(unittest.TestCase):
self.assertFalse(test_network.has_route_to('ext_net'))
- @mock.patch('yardstick.benchmark.context.model.Network.has_route_to')
+ @mock.patch('yardstick.benchmark.contexts.model.Network.has_route_to')
def test_find_by_route_to(self, mock_has_route_to):
mock_network = mock.Mock()
@@ -183,7 +183,7 @@ class ServerTestCase(unittest.TestCase):
self.assertIsNone(test_server._flavor)
self.assertIn(test_server, model.Server.list)
- @mock.patch('yardstick.benchmark.context.model.PlacementGroup')
+ @mock.patch('yardstick.benchmark.contexts.model.PlacementGroup')
def test_construct_get_wrong_placement_group(self, mock_pg):
attrs = {'placement': 'baz'}
@@ -192,7 +192,7 @@ class ServerTestCase(unittest.TestCase):
self.assertRaises(ValueError, model.Server, 'foo',
self.mock_context, attrs)
- @mock.patch('yardstick.benchmark.context.model.HeatTemplate')
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test__add_instance(self, mock_template):
attrs = {'image': 'some-image', 'flavor': 'some-flavor'}
@@ -218,128 +218,3 @@ class ServerTestCase(unittest.TestCase):
key_name=self.mock_context.keypair_name,
scheduler_hints='hints')
-
-class ContextTestCase(unittest.TestCase):
-
- def setUp(self):
- self.test_context = model.Context()
- self.mock_context = mock.Mock()
-
- def tearDown(self):
- model.Context.list = []
-
- def test_construct(self):
-
- self.assertIsNone(self.test_context.name)
- self.assertIsNone(self.test_context.stack)
- self.assertEqual(self.test_context.networks, [])
- self.assertEqual(self.test_context.servers, [])
- self.assertEqual(self.test_context.placement_groups, [])
- self.assertIsNone(self.test_context.keypair_name)
- self.assertIsNone(self.test_context.secgroup_name)
- self.assertEqual(self.test_context._server_map, {})
- self.assertIsNone(self.test_context._image)
- self.assertIsNone(self.test_context._flavor)
- self.assertIsNone(self.test_context._user)
- self.assertIsNone(self.test_context.template_file)
- self.assertIsNone(self.test_context.heat_parameters)
- self.assertIn(self.test_context, model.Context.list)
-
- @mock.patch('yardstick.benchmark.context.model.PlacementGroup')
- @mock.patch('yardstick.benchmark.context.model.Network')
- @mock.patch('yardstick.benchmark.context.model.Server')
- def test_init(self, mock_server, mock_network, mock_pg):
-
- pgs = {'pgrp1': {'policy': 'availability'}}
- networks = {'bar': {'cidr': '10.0.1.0/24'}}
- servers = {'baz': {'floating_ip': True, 'placement': 'pgrp1'}}
- attrs = {'name': 'foo',
- 'placement_groups': pgs,
- 'networks': networks,
- 'servers': servers}
-
- self.test_context.init(attrs)
-
- self.assertEqual(self.test_context.keypair_name, "foo-key")
- self.assertEqual(self.test_context.secgroup_name, "foo-secgroup")
-
- mock_pg.assert_called_with('pgrp1', self.test_context,
- pgs['pgrp1']['policy'])
- self.assertTrue(len(self.test_context.placement_groups) == 1)
-
- mock_network.assert_called_with(
- 'bar', self.test_context, networks['bar'])
- self.assertTrue(len(self.test_context.networks) == 1)
-
- mock_server.assert_called_with('baz', self.test_context, servers['baz'])
- self.assertTrue(len(self.test_context.servers) == 1)
-
- @mock.patch('yardstick.benchmark.context.model.HeatTemplate')
- def test__add_resources_to_template_no_servers(self, mock_template):
-
- self.test_context.keypair_name = "foo-key"
- self.test_context.secgroup_name = "foo-secgroup"
-
- self.test_context._add_resources_to_template(mock_template)
- mock_template.add_keypair.assert_called_with("foo-key")
- mock_template.add_security_group.assert_called_with("foo-secgroup")
-
- @mock.patch('yardstick.benchmark.context.model.HeatTemplate')
- def test_deploy(self, mock_template):
-
- self.test_context.name = 'foo'
- self.test_context.template_file = '/bar/baz/some-heat-file'
- self.test_context.heat_parameters = {'image': 'cirros'}
- self.test_context.deploy()
-
- mock_template.assert_called_with(self.test_context.name,
- self.test_context.template_file,
- self.test_context.heat_parameters)
- self.assertIsNotNone(self.test_context.stack)
-
- @mock.patch('yardstick.benchmark.context.model.HeatTemplate')
- def test_undeploy(self, mock_template):
-
- self.test_context.stack = mock_template
- self.test_context.undeploy()
-
- self.assertTrue(mock_template.delete.called)
-
- def test_get_server_by_name(self):
-
- self.mock_context._server_map = {'foo.bar': True}
- model.Context.list = [self.mock_context]
-
- self.assertTrue(model.Context.get_server_by_name('foo.bar'))
-
- def test_get_server_by_wrong_name(self):
-
- self.assertRaises(ValueError, model.Context.get_server_by_name, 'foo')
-
- def test_get_context_by_name(self):
-
- self.mock_context.name = 'foo'
- model.Context.list = [self.mock_context]
-
- self.assertIs(model.Context.get_context_by_name('foo'),
- self.mock_context)
-
- def test_get_unknown_context_by_name(self):
-
- model.Context.list = []
- self.assertIsNone(model.Context.get_context_by_name('foo'))
-
- @mock.patch('yardstick.benchmark.context.model.Server')
- def test_get_server(self, mock_server):
-
- self.mock_context.name = 'bar'
- self.mock_context.stack.outputs = {'public_ip': '127.0.0.1',
- 'private_ip': '10.0.0.1'}
- model.Context.list = [self.mock_context]
- attr_name = {'name': 'foo.bar',
- 'public_ip_attr': 'public_ip',
- 'private_ip_attr': 'private_ip'}
- result = model.Context.get_server(attr_name)
-
- self.assertEqual(result.public_ip, '127.0.0.1')
- self.assertEqual(result.private_ip, '10.0.0.1')