summaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/contexts/test_heat.py
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/unit/benchmark/contexts/test_heat.py
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/unit/benchmark/contexts/test_heat.py')
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py114
1 files changed, 114 insertions, 0 deletions
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')