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):
88 expected['description'] = 'Instantiation Validation Benchmark'
89 expected['parameters'] = [
93 expected['allowed_values'] = dict()
94 expected['allowed_values'][iv.THROUGHPUT] = \
95 map(str, range(0, 100))
96 expected['allowed_values'][iv.VLAN_SENDER] = \
97 map(str, range(-1, 4096))
98 expected['allowed_values'][iv.VLAN_RECEIVER] = \
99 map(str, range(-1, 4096))
100 expected['default_values'] = dict()
101 expected['default_values'][iv.THROUGHPUT] = '1'
102 expected['default_values'][iv.VLAN_SENDER] = '-1'
103 expected['default_values'][iv.VLAN_RECEIVER] = '-1'
105 test_case = 'instantiation_validation_benchmark.' \
106 'InstantiationValidationBenchmark'
107 output = FrameworkApi.get_test_case_features(test_case)
108 self.assertEqual(expected, output)
110 def test__get_test_case_features__for_failure(self):
112 ValueError, FrameworkApi.get_test_case_features, 111)
114 @mock.patch('experimental_framework.common.init')
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,
124 common.TEMPLATE_DIR = "{}/{}/".format(
125 os.getcwd(), 'tests/data/generated_templates'
130 heat_template = 'VTC_base_single_vm_wait.tmp'
131 heat_template_parameters = dict()
132 deployment_configuration = ''
133 openstack_credentials = dict()
134 openstack_credentials['ip_controller'] = ''
135 openstack_credentials['heat_url'] = ''
136 openstack_credentials['user'] = ''
137 openstack_credentials['password'] = ''
138 openstack_credentials['auth_uri'] = ''
139 openstack_credentials['project'] = ''
140 FrameworkApi.execute_framework(
141 test_cases, iterations, heat_template,
142 heat_template_parameters, deployment_configuration,
143 openstack_credentials)