aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/vTC/apexlake/tests/api_test.py
blob: b6191ed8fbe5b8e8f3d791ed81b229c8c94b5374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from __future__ import absolute_import
import unittest
import mock
import os
import experimental_framework.common as common
from experimental_framework import APEX_LAKE_ROOT
from experimental_framework.api import FrameworkApi
from experimental_framework.benchmarking_unit import BenchmarkingUnit
import experimental_framework.benchmarks.\
    instantiation_validation_benchmark as iv
from six.moves import map
from six.moves import range


class DummyBenchmarkingUnit(BenchmarkingUnit):

    def __init__(self):
        BenchmarkingUnit.__init__(self)

    @staticmethod
    def get_available_test_cases():
        return ['BenchA', 'BenchB']

    @staticmethod
    def get_required_benchmarks(required_benchmarks):
        common.BASE_DIR = "base_dir/"
        return [iv.InstantiationValidationBenchmark('benchmark', dict())]


class DummyBenchmarkingUnit2(BenchmarkingUnit):

    counter_init = 0
    counter_finalize = 0
    counter_run = 0

    def __init__(self, base_heat_template, credentials,
                 heat_template_parameters, iterations, test_cases):
        DummyBenchmarkingUnit.counter_init = 0
        DummyBenchmarkingUnit.counter_finalize = 0
        DummyBenchmarkingUnit.counter_run = 0

    def initialize(self):
        DummyBenchmarkingUnit2.counter_init += 1

    def run_benchmarks(self):
        DummyBenchmarkingUnit2.counter_run += 1

    def finalize(self):
        DummyBenchmarkingUnit2.counter_finalize += 1


class TestGeneratesTemplate(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @mock.patch('experimental_framework.common.init')
    def test_init_for_success(self, mock_init):
        FrameworkApi.init()
        mock_init.assert_called_once_with(api=True)

    # @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit.'
    #             'get_available_test_cases',
    #             side_effect=DummyBenchmarkingUnit.get_available_test_cases)
    # def test_get_available_test_cases_for_success(self, mock_bench):
    #     expected = ['BenchA', 'BenchB']
    #     output = FrameworkApi.get_available_test_cases()
    #     self.assertEqual(expected, output)

    @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit.'
                'get_required_benchmarks',
                side_effect=DummyBenchmarkingUnit.get_required_benchmarks)
    def test_get_test_case_features_for_success(self, mock_get_req_bench):
        expected = dict()
        expected['description'] = 'Instantiation Validation Benchmark'
        expected['parameters'] = [
            iv.THROUGHPUT,
            iv.VLAN_SENDER,
            iv.VLAN_RECEIVER]
        expected['allowed_values'] = dict()
        expected['allowed_values'][iv.THROUGHPUT] = \
            list(map(str, list(range(0, 100))))
        expected['allowed_values'][iv.VLAN_SENDER] = \
            list(map(str, list(range(-1, 4096))))
        expected['allowed_values'][iv.VLAN_RECEIVER] = \
            list(map(str, list(range(-1, 4096))))
        expected['default_values'] = dict()
        expected['default_values'][iv.THROUGHPUT] = '1'
        expected['default_values'][iv.VLAN_SENDER] = '-1'
        expected['default_values'][iv.VLAN_RECEIVER] = '-1'

        test_case = 'instantiation_validation_benchmark.' \
                    'InstantiationValidationBenchmark'
        output = FrameworkApi.get_test_case_features(test_case)
        self.assertEqual(expected, output)

    def test__get_test_case_features__for_failure(self):
        self.assertRaises(
            ValueError, FrameworkApi.get_test_case_features, 111)

    @mock.patch('experimental_framework.common.init')
    @mock.patch('experimental_framework.common.LOG')
    @mock.patch('experimental_framework.common.get_credentials')
    @mock.patch('experimental_framework.heat_template_generation.'
                'generates_templates')
    @mock.patch('experimental_framework.benchmarking_unit.BenchmarkingUnit',
                side_effect=DummyBenchmarkingUnit2)
    def test_execute_framework_for_success(self, mock_b_unit, mock_heat,
                                           mock_credentials, mock_log,
                                           mock_common_init):
        common.TEMPLATE_DIR = os.path.join(APEX_LAKE_ROOT,
                                           'tests/data/generated_templates/')

        test_cases = dict()
        iterations = 1
        heat_template = 'VTC_base_single_vm_wait.tmp'
        heat_template_parameters = dict()
        deployment_configuration = ''
        openstack_credentials = dict()
        openstack_credentials['ip_controller'] = ''
        openstack_credentials['heat_url'] = ''
        openstack_credentials['user'] = ''
        openstack_credentials['password'] = ''
        openstack_credentials['auth_uri'] = ''
        openstack_credentials['project'] = ''
        FrameworkApi.execute_framework(
            test_cases, iterations, heat_template,
            heat_template_parameters, deployment_configuration,
            openstack_credentials)