From 5c2824d8e184a3ff63a52e7c7cca7b4e6f0c0222 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Fri, 16 Feb 2018 15:22:12 +0000 Subject: Use context name instead of key_uuid context.key_uuid is only used as a suffix for the key files. There is already a unique ID associated with a the context; the context name includes a task ID, which is a UUID. This patch sets context.key_uuid to to context.name instead of generating a separate UUID As a result, get_short_key_uuid() is not needed. JIRA: YARDSTICK-1028 Change-Id: Id175061d6cfe23a068bb3d12ce176c1f176e8236 Signed-off-by: Emma Foley --- .../tests/unit/benchmark/contexts/test_heat.py | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'yardstick/tests/unit') 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) -- cgit 1.2.3-korg