Fix small things for integration of ApexLake with Yardstick
[yardstick.git] / yardstick / vTC / apexlake / experimental_framework / api.py
1 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import experimental_framework.benchmarking_unit as b_unit
16 from experimental_framework import heat_template_generation, common
17
18
19 class FrameworkApi(object):
20
21     @staticmethod
22     def init():
23         """
24         Initializes the Framework
25
26         :return: None
27         """
28         common.init(api=True)
29
30     @staticmethod
31     def get_available_test_cases():
32         """
33         Returns a list of available test cases.
34         This list include eventual modules developed by the user, if any.
35         Each test case is returned as a string that represents the full name
36         of the test case and that can be used to get more information
37         calling get_test_case_features(test_case_name)
38
39         :return: list of strings
40         """
41         return b_unit.BenchmarkingUnit.get_available_test_cases()
42
43     @staticmethod
44     def get_test_case_features(test_case):
45         """
46         Returns a list of features (description, requested parameters,
47         allowed values, etc.) for a specified test case.
48
49         :param test_case: name of the test case (string)
50                           The string represents the test case and can be
51                           obtained  calling  "get_available_test_cases()"
52                           method.
53
54         :return: dict() containing the features of the test case
55         """
56         if not isinstance(test_case, str):
57             raise ValueError('The provided test_case parameter has to be '
58                              'a string')
59         benchmark = b_unit.BenchmarkingUnit.get_required_benchmarks(
60             [test_case])[0]
61         return benchmark.get_features()
62
63     @staticmethod
64     def execute_framework(
65             test_cases,
66             iterations,
67             heat_template,
68             heat_template_parameters,
69             deployment_configuration,
70             openstack_credentials
71     ):
72         """
73         Executes the framework according the inputs
74
75         :param test_cases: Test cases to be ran on the workload
76                             (dict() of dict())
77
78                             Example:
79                             test_case = dict()
80                             test_case['name'] = 'module.Class'
81                             test_case['params'] = dict()
82                             test_case['params']['throughput'] = '1'
83                             test_case['params']['vlan_sender'] = '1007'
84                             test_case['params']['vlan_receiver'] = '1006'
85                             test_cases = [test_case]
86
87         :param iterations: Number of cycles to be executed (int)
88
89         :param heat_template: (string) File name of the heat template of the
90                             workload to be deployed. It contains the
91                             parameters to be evaluated in the form of
92                             #parameter_name. (See heat_templates/vTC.yaml as
93                             example).
94
95         :param heat_template_parameters: (dict) Parameters to be provided
96                             as input to the heat template.
97                             See http://docs.openstack.org/developer/heat/
98                             template_guide/hot_guide.html - section
99                             "Template input parameters" for further info.
100
101         :param deployment_configuration: ( dict[string] = list(strings) ) )
102                             Dictionary of parameters representing the
103                             deployment configuration of the workload
104                             The key is a string corresponding to the name of
105                             the parameter, the value is a list of strings
106                             representing the value to be assumed by a specific
107                             param.
108                             The parameters are user defined: they have to
109                             correspond to the place holders (#parameter_name)
110                             specified in the heat template.
111
112         :return: dict() Containing results
113         """
114         common.init(api=True)
115
116         # Input Validation
117         common.InputValidation.validate_os_credentials(openstack_credentials)
118         credentials = openstack_credentials
119
120         msg = 'The provided heat_template does not exist'
121         template = "{}{}".format(common.get_template_dir(), heat_template)
122         common.InputValidation.validate_file_exist(template, msg)
123
124         msg = 'The provided iterations variable must be an integer value'
125         common.InputValidation.validate_integer(iterations, msg)
126
127         msg = 'The provided heat_template_parameters variable must be a ' \
128               'dictionary'
129         common.InputValidation.validate_dictionary(heat_template_parameters,
130                                                    msg)
131         log_msg = "Generation of all the heat templates " \
132                   "required by the experiment"
133         common.LOG.info(log_msg)
134         heat_template_generation.generates_templates(heat_template,
135                                                      deployment_configuration)
136         benchmarking_unit = \
137             b_unit.BenchmarkingUnit(
138                 heat_template, credentials, heat_template_parameters,
139                 iterations, test_cases)
140         try:
141             common.LOG.info("Benchmarking Unit initialization")
142             benchmarking_unit.initialize()
143             common.LOG.info("Benchmarking Unit Running")
144             results = benchmarking_unit.run_benchmarks()
145         finally:
146             common.LOG.info("Benchmarking Unit Finalization")
147             benchmarking_unit.finalize()
148         return results