############################################################################## # 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 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 : 60 model name : Intel Core Processor (Haswell, no TSX) stepping : 1 microcode : 0x1 cpu MHz : 2294.684 cache size : 4096 KB physical id : 0 siblings : 5 core id : 2 cpu cores : 5 apicid : 2 initial apicid : 2 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat bugs : bogomips : 4589.36 clflush size : 64 cache_alignment : 64 address sizes : 46 bits physical, 48 bits virtual power management: processor : 3 vendor_id : GenuineIntel cpu family : 6 model
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd 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
##############################################################################
---
schema: "yardstick:task:0.1"
description: >
Yardstick TC005 config file;
Measure Storage IOPS, throughput and latency using fio.
{% set provider = provider or none %}
{% set physical_network = physical_network or 'physnet1' %}
{% set segmentation_id = segmentation_id or none %}
scenarios:
{% for rw in ['read', 'write', 'randwrite', 'randread', 'rw'] %}
{% for bs in ['4k', '64k', '1024k'] %}
-
type: Fio
options:
filename: /home/ubuntu/data.raw
bs: {{bs}}
rw: {{rw}}
ramp_time: 10
duration: 20
host: fio.yardstick-TC005
runner:
type: Iteration
iterations: 1
interval: 1
sla:
read_bw: 400
read_iops: 100
read_lat: 20000
write_bw: 400
write_iops: 100
write_lat: 20000
action: monitor
{% endfor %}
{% endfor %}
context:
name: yardstick-TC005
image: yardstick-image
flavor: yardstick-flavor
user: ubuntu
servers:
fio:
floating_ip: true
networks:
test:
cidr: '10.0.1.0/24'
{% if provider == "vlan" %}
provider: {{provider}}
physical_network: {{physical_network}}
{% if segmentation_id %}
segmentation_id: {{segmentation_id}}
{% endif %}
{% endif %}