Merge "Change copyright for dispatchers."
[yardstick.git] / yardstick / vTC / apexlake / tests / generates_template_test.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 unittest
16 import experimental_framework.heat_template_generation as heat_gen
17 import mock
18 import os
19 import experimental_framework.common as common
20
21 __author__ = 'gpetralx'
22
23
24 def reset_common():
25     common.LOG = None
26     common.CONF_FILE = None
27     common.DEPLOYMENT_UNIT = None
28     common.ITERATIONS = None
29     common.BASE_DIR = None
30     common.RESULT_DIR = None
31     common.TEMPLATE_DIR = None
32     common.TEMPLATE_NAME = None
33     common.TEMPLATE_FILE_EXTENSION = None
34     common.PKTGEN = None
35     common.PKTGEN_DIR = None
36     common.PKTGEN_DPDK_DIRECTORY = None
37     common.PKTGEN_PROGRAM = None
38     common.PKTGEN_COREMASK = None
39     common.PKTGEN_MEMCHANNEL = None
40     common.PKTGEN_BUS_SLOT_NIC_1 = None
41     common.PKTGEN_BUS_SLOT_NIC_2 = None
42     common.INFLUXDB_IP = None
43     common.INFLUXDB_PORT = None
44     common.INFLUXDB_DB_NAME = None
45
46
47 class TestGeneratesTemplate(unittest.TestCase):
48     def setUp(self):
49         self.deployment_configuration = {
50             'vnic_type': ['normal', 'direct'],
51             'ram': ['1024'],
52             'vcpus': ['2']
53         }
54         self.template_name = 'VTC_base_single_vm_wait.tmp'
55         # common.init()
56
57     def tearDown(self):
58         reset_common()
59
60     @mock.patch('experimental_framework.common.LOG')
61     @mock.patch('experimental_framework.common.get_template_dir')
62     def test_generates_template_for_success(self, mock_template_dir,
63                                             mock_log):
64         generated_templates_dir = 'tests/data/generated_templates/'
65         mock_template_dir.return_value = generated_templates_dir
66         test_templates = 'tests/data/test_templates/'
67         heat_gen.generates_templates(self.template_name,
68                                      self.deployment_configuration)
69         for dirname, dirnames, filenames in os.walk(test_templates):
70             for filename in filenames:
71                 with open(test_templates + filename) as test:
72                     with open(generated_templates_dir + filename) as generated:
73                         self.assertListEqual(test.readlines(),
74                                              generated.readlines())
75
76         t_name = '/tests/data/generated_templates/VTC_base_single_vm_wait.tmp'
77         self.template_name = "{}{}".format(os.getcwd(), t_name)
78         heat_gen.generates_templates(self.template_name,
79                                      self.deployment_configuration)
80         for dirname, dirnames, filenames in os.walk(test_templates):
81             for filename in filenames:
82                 with open(test_templates + filename) as test:
83                     with open(generated_templates_dir + filename) as generated:
84                         self.assertListEqual(test.readlines(),
85                                              generated.readlines())
86
87     @mock.patch('experimental_framework.common.get_template_dir')
88     def test_get_all_heat_templates_for_success(self, template_dir):
89         generated_templates = 'tests/data/generated_templates/'
90         template_dir.return_value = generated_templates
91         extension = '.yaml'
92         expected = ['experiment_1.yaml', 'experiment_2.yaml']
93         result = heat_gen.get_all_heat_templates(generated_templates,
94                                                  extension)
95         self.assertListEqual(expected, result)