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.
19 import experimental_framework.common as common
20 from experimental_framework.api import FrameworkApi
21 from experimental_framework.benchmarking_unit import BenchmarkingUnit
22 import experimental_framework.benchmarks.\
23 instantiation_validation_benchmark as iv
26 class DummyBenchmarkingUnit(BenchmarkingUnit):
29 BenchmarkingUnit.__init__(self)
32 def get_available_test_cases():
33 return ['BenchA', 'BenchB']
36 def get_required_benchmarks(required_benchmarks):
37 common.BASE_DIR = "base_dir/"
38 return [iv.InstantiationValidationBenchmark('benchmark', dict())]
41 class DummyBenchmarkingUnit2(BenchmarkingUnit):
47 def __init__(self, base_heat_template, credentials,
48 heat_template_parameters, iterations, test_cases):
49 DummyBenchmarkingUnit.counter_init = 0
50 DummyBenchmarkingUnit.counter_finalize = 0
51 DummyBenchmarkingUnit.counter_run = 0
54 DummyBenchmarkingUnit2.counter_init += 1
56 def run_benchmarks(self):
57 DummyBenchmarkingUnit2.counter_run += 1
60 DummyBenchmarkingUnit2.counter_finalize += 1
63 class TestGeneratesTemplate(unittest.TestCase):
70 @mock.patch('experimental_framework.common.init')
71 def test_init_for_success(self, mock_init):
73 mock_init.assert_called_once_with(api=True)
75 @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit.'
76 'get_available_test_cases',
77 side_effect=DummyBenchmarkingUnit.get_available_test_cases)
78 def test_get_available_test_cases_for_success(self, mock_bench):
79 expected = ['BenchA', 'BenchB']
80 output = FrameworkApi.get_available_test_cases()
81 self.assertEqual(expected, output)
83 @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit.'
84 'get_required_benchmarks',
85 side_effect=DummyBenchmarkingUnit.get_required_benchmarks)
86 def test_get_test_case_features_for_success(self, mock_get_req_bench):
89 expected['description'] = 'Instantiation Validation Benchmark'
90 expected['parameters'] = [
94 expected['allowed_values'] = dict()
95 expected['allowed_values'][iv.THROUGHPUT] = \
96 map(str, range(0, 100))
97 expected['allowed_values'][iv.VLAN_SENDER] = \
98 map(str, range(-1, 4096))
99 expected['allowed_values'][iv.VLAN_RECEIVER] = \
100 map(str, range(-1, 4096))
101 expected['default_values'] = dict()
102 expected['default_values'][iv.THROUGHPUT] = '1'
103 expected['default_values'][iv.VLAN_SENDER] = '-1'
104 expected['default_values'][iv.VLAN_RECEIVER] = '-1'
106 test_case = 'instantiation_validation_benchmark.' \
107 'InstantiationValidationBenchmark'
108 output = FrameworkApi.get_test_case_features(test_case)
109 self.assertEqual(expected, output)
111 def test____for_failure(self):
113 ValueError, FrameworkApi.get_test_case_features, 111)
115 @mock.patch('experimental_framework.common.LOG')
116 @mock.patch('experimental_framework.common.get_credentials')
117 @mock.patch('experimental_framework.heat_template_generation.'
118 'generates_templates')
119 @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit',
120 side_effect=DummyBenchmarkingUnit2)
121 def test_execute_framework_for_success(self, mock_b_unit, mock_heat,
122 mock_credentials, mock_log):
123 common.TEMPLATE_DIR = "{}/{}/".format(
124 os.getcwd(), 'tests/data/generated_templates'
129 heat_template = 'VTC_base_single_vm_wait.tmp'
130 heat_template_parameters = dict()
131 deployment_configuration = ''
132 openstack_credentials = dict()
133 openstack_credentials['ip_controller'] = ''
134 openstack_credentials['heat_url'] = ''
135 openstack_credentials['user'] = ''
136 openstack_credentials['password'] = ''
137 openstack_credentials['auth_uri'] = ''
138 openstack_credentials['project'] = ''
139 FrameworkApi.execute_framework(
140 test_cases, iterations, heat_template,
141 heat_template_parameters, deployment_configuration,
142 openstack_credentials)