aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2018-03-01 16:16:12 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-01 16:16:12 +0000
commitde8ce9889cfc9e9d62e26e53b5f27b2f4cd9ff06 (patch)
treeafdbac758b24c391979b9a24a4b5d02b6e7a2783 /yardstick/tests/unit
parent0b340735f2a37b9a05d3d86f79aa706b3e43bb5d (diff)
parent5c2824d8e184a3ff63a52e7c7cca7b4e6f0c0222 (diff)
Merge "Use context name instead of key_uuid"
Diffstat (limited to 'yardstick/tests/unit')
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_heat.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py
index 2f2d4643e..1e31abce8 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_heat.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py
@@ -12,8 +12,6 @@
from collections import OrderedDict
from itertools import count
import logging
-import os
-import uuid
import mock
import unittest
@@ -23,6 +21,7 @@ from yardstick.benchmark.contexts import heat
from yardstick.benchmark.contexts import model
from yardstick.common import exceptions as y_exc
from yardstick.orchestrator import heat as orch_heat
+from yardstick import ssh
LOG = logging.getLogger(__name__)
@@ -61,14 +60,14 @@ class HeatContextTestCase(unittest.TestCase):
self.assertIsNone(self.test_context._user)
self.assertIsNone(self.test_context.template_file)
self.assertIsNone(self.test_context.heat_parameters)
- self.assertIsNotNone(self.test_context.key_uuid)
- self.assertIsNotNone(self.test_context.key_filename)
+ self.assertIsNone(self.test_context.key_filename)
+ @mock.patch.object(ssh.SSH, 'gen_keys')
@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_sg, mock_pg):
+ def test_init(self, mock_server, mock_network, mock_sg, mock_pg, mock_ssh_gen_keys):
pgs = {'pgrp1': {'policy': 'availability'}}
sgs = {'servergroup1': {'policy': 'affinity'}}
@@ -106,13 +105,7 @@ class HeatContextTestCase(unittest.TestCase):
servers['baz'])
self.assertEqual(len(self.test_context.servers), 1)
- if os.path.exists(self.test_context.key_filename):
- try:
- os.remove(self.test_context.key_filename)
- os.remove(self.test_context.key_filename + ".pub")
- except OSError:
- LOG.exception("key_filename: %s",
- self.test_context.key_filename)
+ mock_ssh_gen_keys.assert_called()
def test_init_no_name_or_task_id(self):
attrs = {}
@@ -145,6 +138,7 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b"
netattrs = {'cidr': '10.0.0.0/24', 'provider': None,
'external_network': 'ext_net'}
+
self.test_context.networks = OrderedDict(
{"mynet": model.Network("mynet", self.test_context,
netattrs)})
@@ -152,7 +146,7 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context._add_resources_to_template(mock_template)
mock_template.add_keypair.assert_called_with(
"ctx-key",
- "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b")
+ "ctx-12345678")
mock_template.add_security_group.assert_called_with("ctx-secgroup")
mock_template.add_network.assert_called_with(
"ctx-12345678-mynet", 'physnet1', None, None, None, None)
@@ -294,13 +288,16 @@ class HeatContextTestCase(unittest.TestCase):
self.assertEqual(len(server.interfaces), 3)
self.assertDictEqual(server.interfaces['port_a'], expected)
+ @mock.patch('yardstick.benchmark.contexts.heat.os')
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
- def test_undeploy(self, mock_template):
+ def test_undeploy(self, mock_template, *args):
self.test_context.stack = mock_template
self.test_context._name = 'foo'
self.test_context._task_id = '1234567890'
self.test_context._name_task_id = '{}-{}'.format(
self.test_context._name, self.test_context._task_id[:8])
+ # mock_os.path.exists.return_value = True
+ self.test_context.key_filename = 'foo/bar/foobar'
self.test_context.undeploy()
self.assertTrue(mock_template.delete.called)
@@ -313,6 +310,7 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context._name_task_id = '{}-{}'.format(
self.test_context._name, self.test_context._task_id)
mock_os.path.exists.return_value = True
+ self.test_context.key_filename = 'foo/bar/foobar'
self.assertIsNone(self.test_context.undeploy())
@mock.patch("yardstick.benchmark.contexts.heat.pkg_resources")
@@ -343,7 +341,6 @@ class HeatContextTestCase(unittest.TestCase):
'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,
@@ -354,6 +351,7 @@ class HeatContextTestCase(unittest.TestCase):
'private_ip_attr': 'private_ip',
'public_ip_attr': 'public_ip',
}
+ self.test_context.key_uuid = 'foo-42'
result = self.test_context._get_server(attr_name)
self.assertEqual(result['user'], 'bot')
self.assertEqual(result['ip'], '127.0.0.1')
@@ -385,7 +383,6 @@ class HeatContextTestCase(unittest.TestCase):
'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,
@@ -394,6 +391,8 @@ class HeatContextTestCase(unittest.TestCase):
attr_name = {
'name': 'foo.bar-12345678',
}
+
+ self.test_context.key_uuid = 'foo-42'
result = self.test_context._get_server(attr_name)
self.assertEqual(result['user'], 'bot')
# no private ip attr mapping in the map results in None value in the result
@@ -418,12 +417,13 @@ class HeatContextTestCase(unittest.TestCase):
baz3_server.context.user = 'zab'
self.test_context._name = 'bar1'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = 'bar1-12345678'
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 = {
@@ -461,13 +461,13 @@ class HeatContextTestCase(unittest.TestCase):
'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,
}
+ self.test_context.key_uuid = 'foo-42'
attr_name = 'wow4'
result = self.test_context._get_server(attr_name)
self.assertIsNone(result)
@@ -497,12 +497,12 @@ class HeatContextTestCase(unittest.TestCase):
'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,
}
+ self.test_context.key_uuid = 'foo-42'
attr_name = {
'name': 'foo.wow4',
'private_ip_attr': 'private_ip',
@@ -533,12 +533,12 @@ class HeatContextTestCase(unittest.TestCase):
'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,
}
+ self.test_context.key_uuid = 'foo-42'
attr_name = 'foo.wow4'
result = self.test_context._get_server(attr_name)
self.assertIsNone(result)