diff options
author | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-06-28 16:17:17 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-06-28 16:17:17 +0000 |
commit | 931c7d87597fd61f9e300be2637a0bdd485001d9 (patch) | |
tree | 8a7593ff0e35edd8dc3bf91d436d602201ab1b12 | |
parent | 70ea01b882a5ff61a36f8927d64d1bf3b9446838 (diff) | |
parent | 8b7e3af001b997f34e6a19b510e9c86e8d8d39d5 (diff) |
Merge "Add "os_cloud_config" as a new context flag parameter" into stable/fraser
-rw-r--r-- | yardstick/benchmark/contexts/base.py | 7 | ||||
-rw-r--r-- | yardstick/benchmark/contexts/heat.py | 6 | ||||
-rw-r--r-- | yardstick/common/constants.py | 3 | ||||
-rw-r--r-- | yardstick/common/openstack_utils.py | 29 | ||||
-rw-r--r-- | yardstick/orchestrator/heat.py | 21 | ||||
-rw-r--r-- | yardstick/tests/unit/benchmark/contexts/test_base.py | 7 | ||||
-rw-r--r-- | yardstick/tests/unit/benchmark/contexts/test_heat.py | 9 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_openstack_utils.py | 27 | ||||
-rw-r--r-- | yardstick/tests/unit/orchestrator/test_heat.py | 19 |
9 files changed, 101 insertions, 27 deletions
diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py index 0707c1c5b..64cee8376 100644 --- a/yardstick/benchmark/contexts/base.py +++ b/yardstick/benchmark/contexts/base.py @@ -6,17 +6,20 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## + import abc import six -import yardstick.common.utils as utils +from yardstick.common import constants +from yardstick.common import utils class Flags(object): """Class to represent the status of the flags in a context""" _FLAGS = {'no_setup': False, - 'no_teardown': False} + 'no_teardown': False, + 'os_cloud_config': constants.OS_CLOUD_DEFAULT_CONFIG} def __init__(self, **kwargs): for name, value in self._FLAGS.items(): diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 3d8907bb5..cc87176d5 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -325,8 +325,10 @@ class HeatContext(Context): if not os.path.exists(self.key_filename): SSH.gen_keys(self.key_filename) - heat_template = HeatTemplate(self.name, self.template_file, - self.heat_parameters) + heat_template = HeatTemplate( + self.name, template_file=self.template_file, + heat_parameters=self.heat_parameters, + os_cloud_config=self._flags.os_cloud_config) if self.template_file is None: self._add_resources_to_template(heat_template) diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py index 3f5c37456..f6e4ab7e9 100644 --- a/yardstick/common/constants.py +++ b/yardstick/common/constants.py @@ -167,3 +167,6 @@ IS_PUBLIC = 'is_public' # general TESTCASE_PRE = 'opnfv_yardstick_' TESTSUITE_PRE = 'opnfv_' + +# OpenStack cloud default config parameters +OS_CLOUD_DEFAULT_CONFIG = {'verify': False} diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index 666404779..6ff6617a9 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -7,18 +7,20 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import os +import copy import logging +import os +from cinderclient import client as cinderclient +from novaclient import client as novaclient +from glanceclient import client as glanceclient from keystoneauth1 import loading from keystoneauth1 import session +from neutronclient.neutron import client as neutronclient import shade from shade import exc -from cinderclient import client as cinderclient -from novaclient import client as novaclient -from glanceclient import client as glanceclient -from neutronclient.neutron import client as neutronclient +from yardstick.common import constants log = logging.getLogger(__name__) @@ -154,8 +156,21 @@ def get_glance_client(): # pragma: no cover return glanceclient.Client(get_glance_client_version(), session=sess) -def get_shade_client(): - return shade.openstack_cloud() +def get_shade_client(**os_cloud_config): + """Get Shade OpenStack cloud client + + By default, the input parameters given to "shade.openstack_cloud" method + are stored in "constants.OS_CLOUD_DEFAULT_CONFIG". The input parameters + passed in this function, "os_cloud_config", will overwrite the default + ones. + + :param os_cloud_config: (kwargs) input arguments for + "shade.openstack_cloud" method. + :return: ``shade.OpenStackCloud`` object. + """ + params = copy.deepcopy(constants.OS_CLOUD_DEFAULT_CONFIG) + params.update(os_cloud_config) + return shade.openstack_cloud(**params) # ********************************************* diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py index 5afa4151e..bfc1f7061 100644 --- a/yardstick/orchestrator/heat.py +++ b/yardstick/orchestrator/heat.py @@ -22,13 +22,13 @@ import time from oslo_serialization import jsonutils from oslo_utils import encodeutils -import shade from shade._heat import event_utils -import yardstick.common.openstack_utils as op_utils +from yardstick.common import constants as consts from yardstick.common import exceptions from yardstick.common import template_format -from yardstick.common import constants as consts +from yardstick.common import openstack_utils as op_utils + log = logging.getLogger(__name__) @@ -41,10 +41,11 @@ _DEPLOYED_STACKS = {} class HeatStack(object): """Represents a Heat stack (deployed template) """ - def __init__(self, name): + def __init__(self, name, os_cloud_config=None): self.name = name self.outputs = {} - self._cloud = shade.openstack_cloud() + os_cloud_config = {} if not os_cloud_config else os_cloud_config + self._cloud = op_utils.get_shade_client(**os_cloud_config) self._stack = None def _update_stack_tracking(self): @@ -152,10 +153,12 @@ name (i.e. %s). # short hand for resources part of template self.resources = self._template['resources'] - def __init__(self, name, template_file=None, heat_parameters=None): + def __init__(self, name, template_file=None, heat_parameters=None, + os_cloud_config=None): self.name = name self.keystone_client = None self.heat_parameters = {} + self._os_cloud_config = {} if not os_cloud_config else os_cloud_config # heat_parameters is passed to heat in stack create, empty dict when # yardstick creates the template (no get_param in resources part) @@ -229,7 +232,11 @@ name (i.e. %s). name = "%s-%s" % (server_name, volume_name) + # TODO(elfoley): Fix this on master, it is a bug, and exposes untested + # code. Yardstick will crash when heat context uses volume. + # pylint: disable=no-value-for-parameter volume_id = op_utils.get_volume_id(volume_name) + # pylint: enable=no-value-for-parameter if not volume_id: volume_id = {'get_resource': volume_name} self.resources[name] = { @@ -622,7 +629,7 @@ name (i.e. %s). log.info("Creating stack '%s' START", self.name) start_time = time.time() - stack = HeatStack(self.name) + stack = HeatStack(self.name, os_cloud_config=self._os_cloud_config) stack.create(self._template, self.heat_parameters, block, timeout) if not block: diff --git a/yardstick/tests/unit/benchmark/contexts/test_base.py b/yardstick/tests/unit/benchmark/contexts/test_base.py index 1311317ac..81267cf98 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_base.py +++ b/yardstick/tests/unit/benchmark/contexts/test_base.py @@ -39,6 +39,7 @@ class FlagsTestCase(ut_base.BaseUnitTestCase): def test___init__(self): self.assertFalse(self.flags.no_setup) self.assertFalse(self.flags.no_teardown) + self.assertEqual({'verify': False}, self.flags.os_cloud_config) def test___init__with_flags(self): flags = base.Flags(no_setup=True) @@ -46,10 +47,12 @@ class FlagsTestCase(ut_base.BaseUnitTestCase): self.assertFalse(flags.no_teardown) def test_parse(self): - self.flags.parse(no_setup=True, no_teardown="False") + self.flags.parse(no_setup=True, no_teardown='False', + os_cloud_config={'verify': True}) self.assertTrue(self.flags.no_setup) - self.assertEqual(self.flags.no_teardown, "False") + self.assertEqual('False', self.flags.no_teardown) + self.assertEqual({'verify': True}, self.flags.os_cloud_config) def test_parse_forbidden_flags(self): self.flags.parse(foo=42) diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py index 749f731c0..bcc35902b 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_heat.py +++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py @@ -230,7 +230,7 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase): @mock.patch.object(os.path, 'exists', return_value=False) @mock.patch.object(ssh.SSH, 'gen_keys') - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') + @mock.patch.object(heat, 'HeatTemplate') def test_deploy(self, mock_template, mock_genkeys, mock_path_exists): self.test_context._name = 'foo' self.test_context._task_id = '1234567890' @@ -241,9 +241,10 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase): self.test_context.get_neutron_info = mock.MagicMock() self.test_context.deploy() - mock_template.assert_called_with('foo-12345678', - '/bar/baz/some-heat-file', - {'image': 'cirros'}) + mock_template.assert_called_with( + 'foo-12345678', template_file='/bar/baz/some-heat-file', + heat_parameters={'image': 'cirros'}, + os_cloud_config=self.test_context._flags.os_cloud_config) self.assertIsNotNone(self.test_context.stack) key_filename = ''.join( [consts.YARDSTICK_ROOT_PATH, diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py index c9f9129df..9361a97f2 100644 --- a/yardstick/tests/unit/common/test_openstack_utils.py +++ b/yardstick/tests/unit/common/test_openstack_utils.py @@ -10,8 +10,10 @@ from oslo_utils import uuidutils import unittest import mock - +import shade from shade import exc + +from yardstick.common import constants from yardstick.common import openstack_utils @@ -35,6 +37,29 @@ class GetHeatApiVersionTestCase(unittest.TestCase): self.assertEqual(api_version, expected_result) +class GetShadeClientTestCase(unittest.TestCase): + + @mock.patch.object(shade, 'openstack_cloud', return_value='os_client') + def test_get_shade_client(self, mock_openstack_cloud): + os_cloud_config = {'param1': True, 'param2': 'value2'} + self.assertEqual('os_client', + openstack_utils.get_shade_client(**os_cloud_config)) + os_cloud_config.update(constants.OS_CLOUD_DEFAULT_CONFIG) + mock_openstack_cloud.assert_called_once_with(**os_cloud_config) + + mock_openstack_cloud.reset_mock() + os_cloud_config = {'verify': True, 'param2': 'value2'} + self.assertEqual('os_client', + openstack_utils.get_shade_client(**os_cloud_config)) + mock_openstack_cloud.assert_called_once_with(**os_cloud_config) + + @mock.patch.object(shade, 'openstack_cloud', return_value='os_client') + def test_get_shade_client_no_parameters(self, mock_openstack_cloud): + self.assertEqual('os_client', openstack_utils.get_shade_client()) + mock_openstack_cloud.assert_called_once_with( + **constants.OS_CLOUD_DEFAULT_CONFIG) + + class DeleteNeutronNetTestCase(unittest.TestCase): def setUp(self): diff --git a/yardstick/tests/unit/orchestrator/test_heat.py b/yardstick/tests/unit/orchestrator/test_heat.py index 9598eeb04..3ec59a3c2 100644 --- a/yardstick/tests/unit/orchestrator/test_heat.py +++ b/yardstick/tests/unit/orchestrator/test_heat.py @@ -17,6 +17,7 @@ import shade import unittest from yardstick.benchmark.contexts import node +from yardstick.common import constants from yardstick.common import exceptions from yardstick.orchestrator import heat @@ -53,6 +54,14 @@ class HeatStackTestCase(unittest.TestCase): self._mock_stack_get.stop() heat._DEPLOYED_STACKS = {} + @mock.patch.object(shade, 'openstack_cloud') + def test__init(self, mock_openstack_cloud): + os_cloud_config = {'key': 'value'} + heatstack = heat.HeatStack('name', os_cloud_config=os_cloud_config) + self.assertEqual('name', heatstack.name) + os_cloud_config.update(constants.OS_CLOUD_DEFAULT_CONFIG) + mock_openstack_cloud.assert_called_once_with(**os_cloud_config) + def test_create(self): template = {'tkey': 'tval'} heat_parameters = {'pkey': 'pval'} @@ -192,7 +201,9 @@ class HeatStackTestCase(unittest.TestCase): class HeatTemplateTestCase(unittest.TestCase): def setUp(self): - self.template = heat.HeatTemplate('test') + self._os_cloud_config = {'key1': 'value1'} + self.template = heat.HeatTemplate( + 'test', os_cloud_config=self._os_cloud_config) def test_add_tenant_network(self): self.template.add_network('some-network') @@ -337,8 +348,12 @@ class HeatTemplateTestCase(unittest.TestCase): def test_create_not_block(self): heat_stack = mock.Mock() - with mock.patch.object(heat, 'HeatStack', return_value=heat_stack): + with mock.patch.object(heat, 'HeatStack', return_value=heat_stack) \ + as mock_heatstack: ret = self.template.create(block=False) + + mock_heatstack.assert_called_once_with( + self.template.name, os_cloud_config=self.template._os_cloud_config) heat_stack.create.assert_called_once_with( self.template._template, self.template.heat_parameters, False, 3600) |