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.
16 import experimental_framework.heat_template_generation as heat_gen
19 import experimental_framework.common as common
24 common.CONF_FILE = None
25 common.DEPLOYMENT_UNIT = None
26 common.ITERATIONS = None
27 common.BASE_DIR = None
28 common.RESULT_DIR = None
29 common.TEMPLATE_DIR = None
30 common.TEMPLATE_NAME = None
31 common.TEMPLATE_FILE_EXTENSION = None
33 common.PKTGEN_DIR = None
34 common.PKTGEN_DPDK_DIRECTORY = None
35 common.PKTGEN_PROGRAM = None
36 common.PKTGEN_COREMASK = None
37 common.PKTGEN_MEMCHANNEL = None
38 common.PKTGEN_BUS_SLOT_NIC_1 = None
39 common.PKTGEN_BUS_SLOT_NIC_2 = None
40 common.INFLUXDB_IP = None
41 common.INFLUXDB_PORT = None
42 common.INFLUXDB_DB_NAME = None
45 class TestGeneratesTemplate(unittest.TestCase):
47 self.deployment_configuration = {
48 'vnic_type': ['normal', 'direct'],
52 self.template_name = 'VTC_base_single_vm_wait.tmp'
58 @mock.patch('experimental_framework.common.LOG')
59 @mock.patch('experimental_framework.common.get_template_dir')
60 def test_generates_template_for_success(self, mock_template_dir,
62 generated_templates_dir = 'tests/data/generated_templates/'
63 mock_template_dir.return_value = generated_templates_dir
64 test_templates = 'tests/data/test_templates/'
65 heat_gen.generates_templates(self.template_name,
66 self.deployment_configuration)
67 for dirname, dirnames, filenames in os.walk(test_templates):
68 for filename in filenames:
69 with open(test_templates + filename) as test:
70 with open(generated_templates_dir + filename) as generated:
71 self.assertListEqual(test.readlines(),
72 generated.readlines())
74 t_name = '/tests/data/generated_templates/VTC_base_single_vm_wait.tmp'
75 self.template_name = "{}{}".format(os.getcwd(), t_name)
76 heat_gen.generates_templates(self.template_name,
77 self.deployment_configuration)
78 for dirname, dirnames, filenames in os.walk(test_templates):
79 for filename in filenames:
80 with open(test_templates + filename) as test:
81 with open(generated_templates_dir + filename) as generated:
82 self.assertListEqual(test.readlines(),
83 generated.readlines())
85 @mock.patch('experimental_framework.common.get_template_dir')
86 def test_get_all_heat_templates_for_success(self, template_dir):
87 generated_templates = 'tests/data/generated_templates/'
88 template_dir.return_value = generated_templates
90 expected = ['experiment_1.yaml', 'experiment_2.yaml']
91 result = heat_gen.get_all_heat_templates(generated_templates,
93 self.assertListEqual(expected, result)