Fix network property validation error
[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
22 class TestGeneratesTemplate(unittest.TestCase):
23     def setUp(self):
24         self.deployment_configuration = {
25             'vnic_type': ['normal', 'direct'],
26             'ram': ['1024'],
27             'vcpus': ['2']
28         }
29         self.template_name = 'VTC_base_single_vm_wait.tmp'
30         common.init()
31
32     def test_dummy(self):
33         self.assertTrue(True)
34
35     def tearDown(self):
36         pass
37
38     @mock.patch('experimental_framework.common.get_template_dir')
39     def test_generates_template_for_success(self, mock_template_dir):
40         generated_templates_dir = 'tests/data/generated_templates/'
41         mock_template_dir.return_value = generated_templates_dir
42         test_templates = 'tests/data/test_templates/'
43         heat_gen.generates_templates(self.template_name,
44                                      self.deployment_configuration)
45         for dirname, dirnames, filenames in os.walk(test_templates):
46             for filename in filenames:
47                 with open(test_templates + filename) as test:
48                     with open(generated_templates_dir + filename) as generated:
49                         self.assertListEqual(test.readlines(),
50                                              generated.readlines())
51
52         t_name = '/tests/data/generated_templates/VTC_base_single_vm_wait.tmp'
53         self.template_name = os.getcwd() + t_name
54         heat_gen.generates_templates(self.template_name,
55                                      self.deployment_configuration)
56         for dirname, dirnames, filenames in os.walk(test_templates):
57             for filename in filenames:
58                 with open(test_templates + filename) as test:
59                     with open(generated_templates_dir + filename) as generated:
60                         self.assertListEqual(test.readlines(),
61                                              generated.readlines())
62
63     @mock.patch('experimental_framework.common.get_template_dir')
64     def test_get_all_heat_templates_for_success(self, template_dir):
65         generated_templates = 'tests/data/generated_templates/'
66         template_dir.return_value = generated_templates
67         extension = '.yaml'
68         expected = ['experiment_1.yaml', 'experiment_2.yaml']
69         result = heat_gen.get_all_heat_templates(generated_templates,
70                                                  extension)
71         self.assertListEqual(expected, result)