aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/contexts/test_heat.py
diff options
context:
space:
mode:
authorDeepak S <deepak.s@linux.intel.com>2017-06-20 14:31:19 -0700
committerRoss Brattain <ross.b.brattain@intel.com>2017-08-08 08:54:23 -0700
commit5ce3b6f8c8b3217091e51a6041455738603d90b8 (patch)
treeca34e15a85d69e2b23ce498fead47761624ae42c /tests/unit/benchmark/contexts/test_heat.py
parent72778951d6b8968f562fb8fefa02a57159ea1b83 (diff)
NSB update
Refactored main NSB VNF classes accroding to class diagram https://wiki.opnfv.org/display/yardstick/NSB+class+diagram All the SampleVNFs have been separated and placed under the SampleVNF class. Added AutoConnectSSH to automatically create SSH conneciton on demand. Added VnfdHelper class to wrap the VNFD dictionary in prepartion for class-based modeling. Extracted DpdkVnfSetupEnvHelper for DPDK based VNF setup. Extracted Stats and other client config to ResourceHelper Had to replace dict_key_flatten with deepgetitem due to Python 2.7 Jinja2 infinite recursion. Change-Id: Ia8840e9c44cdbdf39aab6b02e6d2176b31937dc9 Signed-off-by: Deepak S <deepak.s@linux.intel.com> Signed-off-by: Edward MacGillivray <edward.s.macgillivray@intel.com> Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit/benchmark/contexts/test_heat.py')
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py296
1 files changed, 275 insertions, 21 deletions
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py
index ae57402c0..658a8e580 100644
--- a/tests/unit/benchmark/contexts/test_heat.py
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -22,21 +22,24 @@ from collections import OrderedDict
import mock
+from itertools import count
from yardstick.benchmark.contexts import heat
from yardstick.benchmark.contexts import model
-
LOG = logging.getLogger(__name__)
class HeatContextTestCase(unittest.TestCase):
+ def __init__(self, *args, **kwargs):
+ super(HeatContextTestCase, self).__init__(*args, **kwargs)
+ self.name_iter = ('vnf{:03}'.format(x) for x in count(0, step=3))
+
def setUp(self):
self.test_context = heat.HeatContext()
self.mock_context = mock.Mock(spec=heat.HeatContext())
- def test_construct(self):
-
+ def test___init__(self):
self.assertIsNone(self.test_context.name)
self.assertIsNone(self.test_context.stack)
self.assertEqual(self.test_context.networks, OrderedDict())
@@ -121,18 +124,63 @@ class HeatContextTestCase(unittest.TestCase):
mock_template.add_router_interface.assert_called_with("bar-fool-network-router-if0", "bar-fool-network-router", "bar-fool-network-subnet")
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test_attrs_get(self, mock_template):
+ image, flavor, user = expected_tuple = 'foo1', 'foo2', 'foo3'
+ self.assertNotEqual(self.test_context.image, image)
+ self.assertNotEqual(self.test_context.flavor, flavor)
+ self.assertNotEqual(self.test_context.user, user)
+ self.test_context._image = image
+ self.test_context._flavor = flavor
+ self.test_context._user = user
+ attr_tuple = self.test_context.image, self.test_context.flavor, self.test_context.user
+ self.assertEqual(attr_tuple, expected_tuple)
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test_attrs_set_negative(self, mock_template):
+ with self.assertRaises(AttributeError):
+ self.test_context.image = 'foo'
+
+ with self.assertRaises(AttributeError):
+ self.test_context.flavor = 'foo'
+
+ with self.assertRaises(AttributeError):
+ self.test_context.user = 'foo'
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
@mock.patch('yardstick.benchmark.contexts.heat.get_neutron_client')
- def test_deploy(self, mock_neutron, mock_template):
+ def test_attrs_get(self, mock_neutron, mock_template):
+ image, flavor, user = expected_tuple = 'foo1', 'foo2', 'foo3'
+ self.assertNotEqual(self.test_context.image, image)
+ self.assertNotEqual(self.test_context.flavor, flavor)
+ self.assertNotEqual(self.test_context.user, user)
+ self.test_context._image = image
+ self.test_context._flavor = flavor
+ self.test_context._user = user
+ attr_tuple = self.test_context.image, self.test_context.flavor, self.test_context.user
+ self.assertEqual(attr_tuple, expected_tuple)
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test_attrs_set_negative(self, mock_template):
+ with self.assertRaises(AttributeError):
+ self.test_context.image = 'foo'
+
+ with self.assertRaises(AttributeError):
+ self.test_context.flavor = 'foo'
+
+ with self.assertRaises(AttributeError):
+ self.test_context.user = 'foo'
+ @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.heat_timeout = 5
+ self.test_context.get_neutron_info = mock.MagicMock()
self.test_context.deploy()
- mock_template.assert_called_with(self.test_context.name,
- self.test_context.template_file,
- self.test_context.heat_parameters)
+ mock_template.assert_called_with('foo',
+ '/bar/baz/some-heat-file',
+ {'image': 'cirros'})
self.assertIsNotNone(self.test_context.stack)
def test_add_server_port(self):
@@ -190,27 +238,233 @@ class HeatContextTestCase(unittest.TestCase):
@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'}
- self.mock_context.key_uuid = uuid.uuid4()
-
- 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)
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ @mock.patch('yardstick.benchmark.contexts.heat.os')
+ def test_undeploy_key_filename(self, mock_template, mock_os):
+ self.test_context.stack = mock_template
+ mock_os.path.exists.return_value = True
+ self.assertIsNone(self.test_context.undeploy())
+
+ def test__get_server_found_dict(self):
+ """
+ Use HeatContext._get_server to get a server that matches
+ based on a dictionary input.
+ """
+ foo2_server = mock.Mock()
+ foo2_server.key_filename = 'key_file'
+ foo2_server.private_ip = '10.0.0.2'
+ foo2_server.public_ip = '127.0.0.2'
+ foo2_server.context.user = 'oof'
+
+ baz3_server = mock.Mock()
+ baz3_server.key_filename = 'key_filename'
+ baz3_server.private_ip = '10.0.0.3'
+ baz3_server.public_ip = '127.0.0.3'
+ baz3_server.context.user = 'zab'
+
+ self.test_context.name = 'bar'
+ self.test_context._user = 'bot'
+ self.test_context.stack = mock.Mock()
+ self.test_context.stack.outputs = {
+ 'private_ip': '10.0.0.1',
+ 'public_ip': '127.0.0.1',
+ }
+ self.test_context.key_uuid = uuid.uuid4()
+ self.test_context._server_map = {
+ 'baz3': baz3_server,
+ 'foo2': foo2_server,
+ }
+ attr_name = {
+ 'name': 'foo.bar',
+ 'private_ip_attr': 'private_ip',
+ 'public_ip_attr': 'public_ip',
+ }
+ result = self.test_context._get_server(attr_name)
+ self.assertEqual(result['user'], 'bot')
+ self.assertIsNotNone(result['key_filename'])
self.assertEqual(result['ip'], '127.0.0.1')
self.assertEqual(result['private_ip'], '10.0.0.1')
+ def test__get_server_found_dict_no_attrs(self):
+ """
+ Use HeatContext._get_server to get a server that matches
+ based on a dictionary input.
+ """
+ foo2_server = mock.Mock()
+ foo2_server.private_ip = '10.0.0.2'
+ foo2_server.public_ip = '127.0.0.2'
+ foo2_server.context.user = 'oof'
+
+ baz3_server = mock.Mock()
+ baz3_server.private_ip = '10.0.0.3'
+ baz3_server.public_ip = '127.0.0.3'
+ baz3_server.context.user = 'zab'
+
+ self.test_context.name = 'bar'
+ self.test_context._user = 'bot'
+ self.test_context.stack = mock.Mock()
+ self.test_context.stack.outputs = {
+ 'private_ip': '10.0.0.1',
+ 'public_ip': '127.0.0.1',
+ }
+ self.test_context.key_uuid = uuid.uuid4()
+ self.test_context._server_map = {
+ 'baz3': baz3_server,
+ 'foo2': foo2_server,
+ }
+
+ attr_name = {
+ 'name': 'foo.bar',
+ }
+ result = self.test_context._get_server(attr_name)
+ self.assertEqual(result['user'], 'bot')
+ self.assertIsNotNone(result['key_filename'])
+ # no private ip attr mapping in the map results in None value in the result
+ self.assertIsNone(result['private_ip'])
+ # no public ip attr mapping in the map results in no value in the result
+ self.assertNotIn('ip', result)
+
+ def test__get_server_found_not_dict(self):
+ """
+ Use HeatContext._get_server to get a server that matches
+ based on a non-dictionary input
+ """
+ foo2_server = mock.Mock()
+ foo2_server.private_ip = '10.0.0.2'
+ foo2_server.public_ip = '127.0.0.2'
+ foo2_server.context.user = 'oof'
+
+ baz3_server = mock.Mock()
+ baz3_server.private_ip = '10.0.0.3'
+ baz3_server.public_ip = None
+ baz3_server.context.user = 'zab'
+
+ self.test_context.name = 'bar1'
+ self.test_context.stack = mock.Mock()
+ self.test_context.stack.outputs = {
+ 'private_ip': '10.0.0.1',
+ 'public_ip': '127.0.0.1',
+ }
+ self.test_context.key_uuid = uuid.uuid4()
+ self.test_context.generate_routing_table = mock.MagicMock(return_value=[])
+
+ self.test_context._server_map = {
+ 'baz3': baz3_server,
+ 'foo2': foo2_server,
+ }
+
+ attr_name = 'baz3'
+ result = self.test_context._get_server(attr_name)
+ self.assertEqual(result['user'], 'zab')
+ self.assertIsNotNone(result['key_filename'])
+ self.assertEqual(result['private_ip'], '10.0.0.3')
+ # no public_ip on the server results in no value in the result
+ self.assertNotIn('public_ip', result)
+
+ def test__get_server_none_found_not_dict(self):
+ """
+ Use HeatContext._get_server to not get a server due to
+ None value associated with the match to a non-dictionary
+ input
+ """
+ foo2_server = mock.Mock()
+ foo2_server.private_ip = '10.0.0.2'
+ foo2_server.public_ip = '127.0.0.2'
+ foo2_server.context.user = 'oof'
+
+ baz3_server = mock.Mock()
+ baz3_server.private_ip = '10.0.0.3'
+ baz3_server.public_ip = None
+ baz3_server.context.user = 'zab'
+
+ self.test_context.name = 'bar1'
+ self.test_context.stack = mock.Mock()
+ self.test_context.stack.outputs = {
+ 'private_ip': '10.0.0.1',
+ 'public_ip': '127.0.0.1',
+ }
+ self.test_context.key_uuid = uuid.uuid4()
+ self.test_context._server_map = {
+ 'baz3': baz3_server,
+ 'foo2': foo2_server,
+ 'wow4': None,
+ }
+
+ attr_name = 'wow4'
+ result = self.test_context._get_server(attr_name)
+ self.assertIsNone(result)
+
+ def test__get_server_not_found_dict(self):
+ """
+ Use HeatContext._get_server to not get a server for lack
+ of a match to a dictionary input
+ """
+ foo2_server = mock.Mock()
+ foo2_server.private_ip = '10.0.0.2'
+ foo2_server.public_ip = '127.0.0.2'
+ foo2_server.context.user = 'oof'
+
+ baz3_server = mock.Mock()
+ baz3_server.private_ip = '10.0.0.3'
+ baz3_server.public_ip = None
+ baz3_server.context.user = 'zab'
+
+ self.test_context.name = 'bar1'
+ self.test_context.stack = mock.Mock()
+ self.test_context.stack.outputs = {
+ 'private_ip': '10.0.0.1',
+ 'public_ip': '127.0.0.1',
+ }
+ self.test_context.key_uuid = uuid.uuid4()
+ self.test_context._server_map = {
+ 'baz3': baz3_server,
+ 'foo2': foo2_server,
+ }
+
+ attr_name = {
+ 'name': 'foo.wow4',
+ 'private_ip_attr': 'private_ip',
+ 'public_ip_attr': 'public_ip',
+ }
+ result = self.test_context._get_server(attr_name)
+ self.assertIsNone(result)
+
+ def test__get_server_not_found_not_dict(self):
+ """
+ Use HeatContext._get_server to not get a server for lack
+ of a match to a non-dictionary input
+ """
+ foo2_server = mock.Mock()
+ foo2_server.private_ip = '10.0.0.2'
+ foo2_server.public_ip = '127.0.0.2'
+ foo2_server.context.user = 'oof'
+
+ baz3_server = mock.Mock()
+ baz3_server.private_ip = '10.0.0.3'
+ baz3_server.public_ip = None
+ baz3_server.context.user = 'zab'
+
+ self.mock_context.name = 'bar1'
+ self.test_context.stack = mock.Mock()
+ self.mock_context.stack.outputs = {
+ 'private_ip': '10.0.0.1',
+ 'public_ip': '127.0.0.1',
+ }
+ self.mock_context.key_uuid = uuid.uuid4()
+ self.mock_context._server_map = {
+ 'baz3': baz3_server,
+ 'foo2': foo2_server,
+ }
+
+ attr_name = 'foo.wow4'
+ result = self.test_context._get_server(attr_name)
+ self.assertIsNone(result)
+
def test__get_network(self):
network1 = mock.MagicMock()
network1.name = 'net_1'