1 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from __future__ import absolute_import
20 import experimental_framework.common as common
21 from experimental_framework import APEX_LAKE_ROOT
22 from experimental_framework.api import FrameworkApi
23 from experimental_framework.benchmarking_unit import BenchmarkingUnit
24 import experimental_framework.benchmarks.\
25 instantiation_validation_benchmark as iv
26 from six.moves import map
27 from six.moves import range
30 class DummyBenchmarkingUnit(BenchmarkingUnit):
33 BenchmarkingUnit.__init__(self)
36 def get_available_test_cases():
37 return ['BenchA', 'BenchB']
40 def get_required_benchmarks(required_benchmarks):
41 common.BASE_DIR = "base_dir/"
42 return [iv.InstantiationValidationBenchmark('benchmark', dict())]
45 class DummyBenchmarkingUnit2(BenchmarkingUnit):
51 def __init__(self, base_heat_template, credentials,
52 heat_template_parameters, iterations, test_cases):
53 DummyBenchmarkingUnit.counter_init = 0
54 DummyBenchmarkingUnit.counter_finalize = 0
55 DummyBenchmarkingUnit.counter_run = 0
58 DummyBenchmarkingUnit2.counter_init += 1
60 def run_benchmarks(self):
61 DummyBenchmarkingUnit2.counter_run += 1
64 DummyBenchmarkingUnit2.counter_finalize += 1
67 class TestGeneratesTemplate(unittest.TestCase):
75 @mock.patch('experimental_framework.common.init')
76 def test_init_for_success(self, mock_init):
78 mock_init.assert_called_once_with(api=True)
80 # @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit.'
81 # 'get_available_test_cases',
82 # side_effect=DummyBenchmarkingUnit.get_available_test_cases)
83 # def test_get_available_test_cases_for_success(self, mock_bench):
84 # expected = ['BenchA', 'BenchB']
85 # output = FrameworkApi.get_available_test_cases()
86 # self.assertEqual(expected, output)
88 @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit.'
89 'get_required_benchmarks',
90 side_effect=DummyBenchmarkingUnit.get_required_benchmarks)
91 def test_get_test_case_features_for_success(self, mock_get_req_bench):
93 expected['description'] = 'Instantiation Validation Benchmark'
94 expected['parameters'] = [
98 expected['allowed_values'] = dict()
99 expected['allowed_values'][iv.THROUGHPUT] = \
100 list(map(str, list(range(0, 100))))
101 expected['allowed_values'][iv.VLAN_SENDER] = \
102 list(map(str, list(range(-1, 4096))))
103 expected['allowed_values'][iv.VLAN_RECEIVER] = \
104 list(map(str, list(range(-1, 4096))))
105 expected['default_values'] = dict()
106 expected['default_values'][iv.THROUGHPUT] = '1'
107 expected['default_values'][iv.VLAN_SENDER] = '-1'
108 expected['default_values'][iv.VLAN_RECEIVER] = '-1'
110 test_case = 'instantiation_validation_benchmark.' \
111 'InstantiationValidationBenchmark'
112 output = FrameworkApi.get_test_case_features(test_case)
113 self.assertEqual(expected, output)
115 def test__get_test_case_features__for_failure(self):
117 ValueError, FrameworkApi.get_test_case_features, 111)
119 @mock.patch('experimental_framework.common.init')
120 @mock.patch('experimental_framework.common.LOG')
121 @mock.patch('experimental_framework.common.get_credentials')
122 @mock.patch('experimental_framework.heat_template_generation.'
123 'generates_templates')
124 @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit',
125 side_effect=DummyBenchmarkingUnit2)
126 def test_execute_framework_for_success(self, mock_b_unit, mock_heat,
127 mock_credentials, mock_log,
129 common.TEMPLATE_DIR = os.path.join(APEX_LAKE_ROOT,
130 'tests/data/generated_templates/')
134 heat_template = 'VTC_base_single_vm_wait.tmp'
135 heat_template_parameters = dict()
136 deployment_configuration = ''
137 openstack_credentials = dict()
138 openstack_credentials['ip_controller'] = ''
139 openstack_credentials['heat_url'] = ''
140 openstack_credentials['user'] = ''
141 openstack_credentials['password'] = ''
142 openstack_credentials['auth_uri'] = ''
143 openstack_credentials['project'] = ''
144 FrameworkApi.execute_framework(
145 test_cases, iterations, heat_template,
146 heat_template_parameters, deployment_configuration,
147 openstack_credentials)