############################################################################## # 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.common.utils from __future__ import absolute_import import ipaddress import os import unittest from copy import deepcopy from itertools import product, chain import errno import mock from six.moves import configparser import yardstick from yardstick.common import utils from yardstick.common import constants class IterSubclassesTestCase(unittest.TestCase): # Disclaimer: this class is a modified copy from # rally/tests/unit/common/plugin/test_discover.py # Copyright 2015: Mirantis Inc. def test_itersubclasses(self): class A(object): pass class B(A): pass class C(A): pass class D(C): pass self.assertEqual([B, C, D], list(utils.itersubclasses(A))) class ImportModulesFromPackageTestCase(unittest.TestCase): @mock.patch('yardstick.common.utils.os.walk') def test_import_modules_from_package_no_mod(self, mock_walk): yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__)) mock_walk.return_value = ([ (os.path.join(yardstick_root, 'foo'), ['bar'], ['__init__.py']), (os.path.join(yardstick_root, 'foo', 'bar'), [], ['baz.txt', 'qux.rst']) ]) utils.import_modules_from_package('foo.bar') @mock.patch('yardstick.common.utils.os.walk') @mock.patch('yardstick.common.utils.importutils') def test_import_modules_from_package(self, mock_importutils, mock_walk): yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__)) mock_walk.return_value = ([ (os.path.join(yardstick_root, 'foo', os.pardir, 'bar'), [], ['baz.py']) ]) utils.import_modules_from_package('foo.bar') mock_importutils.import_module.assert_called_with('bar.baz') class GetParaFromYaml(unittest.TestCase): @mock.patch('yardstick.common.utils.os.environ.get') def test_get_param_para_not_found(self, get_env): file_path = 'config_sample.yaml' get_env.return_value = self._get_file_abspath(file_path) args = 'releng.file' default = 'hello' self.assertTrue(constants.get_param(args, default), default) @mock.patch('yardstick.common.utils.os.environ.get') def test_get_param_para_exists(self, get_env): file_path = 'config_sample.yaml' get_env.return_value = self._get_file_abspath(file_path) args = 'releng.dir' para = '/home/opnfv/repos/releng' self.assertEqual(para, constants.get_param(args)) def _get_file_abspath(self, filename): curr_path = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(curr_path, filename) return file_path class CommonUtilTestCase(unittest.TestCase): def setUp(self): self.data = { "benchmark": { "data": { "mpstat": { "cpu0": { "%sys": "0.00", "%idle": "99.00" }, "loadavg": [ "1.09", "0.29" ] }, "rtt": "1.03" } } } def test__dict_key_flatten(self): line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \ 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00' # need to sort for assert to work line = ",".join(sorted(line.split(','))) flattened_data = utils.flatten_dict_key( self.data['benchmark']['data']) result = ",".join( ("=".join(item) for item in sorted(flattened_data.items()))) self.assertEqual(result, line) class TestMacAddressToHex(unittest.TestCase): def test_mac_address_to_hex_list(self): self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"), ['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8']) class TranslateToStrTestCase(unittest.TestCase): def test_translate_to_str_unicode(self): input_str = u'hello' output_str = utils.translate_to_str(input_str) result = 'hello' self.assertEqual(result, output_str) def test_translate_to_str_dict_list_unicode(self): input_str = { u'hello': {u'hello': [u'world']} } output_str = utils.translate_to_str(input_str) result = { 'hello': {'hello': ['world']} } self.assertEqual(result, output_str) def test_translate_to_str_non_string(self): input_value = object() result = utils.translate_to_str(input_value) self.assertIs(input_value, result) class TestParseCpuInfo(unittest.TestCase): def test_single_socket_no_hyperthread(self): cpuinfo = """\ processor : 2 vendor_id : GenuineIntel cpu family : 6 model :
##############################################################################
# Copyright (c) 2017 Mirantis Inc., Enea 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
##############################################################################
---
classes:
- cluster.baremetal-mcp-pike-common-ha.openstack_init
parameters:
_param:
neutron_tenant_network_types: "flat,vxlan"
nova_cpu_pinning: "1,2,3,4,5,7,8,9,10,11"
compute_hugepages_size: 1G
compute_hugepages_count: 16
compute_hugepages_mount: /mnt/hugepages_1G
compute_kernel_isolcpu: ${_param:nova_cpu_pinning}