-__author__ = 'vmricco'
+# 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.
import unittest
import mock
import experimental_framework.common as common
import experimental_framework.constants.conf_file_sections as cf
+__author__ = 'vmricco'
+
def reset_common():
common.LOG = None
class DummyConfigurationFile(common.ConfigurationFile):
- def __init__(self, sections):
+ def __init__(self, sections, conf_file=''):
pass
def get_variable(self, section, variable_name):
if variable_name == cf.CFSG_TEMPLATE_NAME:
return 'vTC.yaml'
if variable_name == cf.CFSG_ITERATIONS:
- return 2
+ return '2'
if variable_name == cf.CFSG_DEBUG:
- return True
+ return 'True'
if variable_name == cf.CFSP_PACKET_GENERATOR:
if self.pktgen_counter == 1:
return 'non_supported'
expected = self.dir.split('experimental_framework/')[0]
self.assertEqual(common.BASE_DIR, expected)
- def test_init_general_vars_for_success(self):
+ @mock.patch('experimental_framework.common.InputValidation')
+ @mock.patch('os.path.exists')
+ @mock.patch('os.makedirs')
+ @mock.patch('experimental_framework.common.LOG')
+ def test_init_general_vars_for_success(self, mock_log, mock_makedirs,
+ mock_path_exists, mock_val_file):
common.BASE_DIR = "{}/".format(os.getcwd())
+ mock_path_exists.return_value = False
+ mock_val_file.return_value = True
common.init_general_vars()
self.assertEqual(common.TEMPLATE_FILE_EXTENSION, '.yaml')
- heat_dir = self.dir.split('experimental_framework/')[0]
- self.assertEqual(common.TEMPLATE_DIR,
- '{}{}'.format(heat_dir, 'heat_templates/'))
+ self.assertEqual(common.TEMPLATE_DIR, '/tmp/apexlake/heat_templates/')
self.assertEqual(common.TEMPLATE_NAME, 'vTC.yaml')
- self.assertEqual(common.RESULT_DIR,
- '{}{}'.format(heat_dir, 'results/'))
+ self.assertEqual(common.RESULT_DIR, '/tmp/apexlake/results/')
self.assertEqual(common.ITERATIONS, 1)
+ # mock_makedirs.assert_called_once_with('/tmp/apexlake/heat_templates/')
class TestCommonInit2(unittest.TestCase):
reset_common()
common.CONF_FILE = None
- def test_init_general_vars_2_for_success(self):
+ @mock.patch('experimental_framework.common.LOG')
+ def test_init_general_vars_2_for_success(self, mock_log):
common.BASE_DIR = "{}/".format(os.getcwd())
common.init_general_vars()
self.assertEqual(common.TEMPLATE_FILE_EXTENSION, '.yaml')
- heat_dir = self.dir.split('experimental_framework/')[0]
- self.assertEqual(common.TEMPLATE_DIR,
- '{}{}'.format(heat_dir, 'heat_templates/'))
+ self.assertEqual(common.TEMPLATE_DIR, '/tmp/apexlake/heat_templates/')
self.assertEqual(common.TEMPLATE_NAME, 'vTC.yaml')
- self.assertEqual(common.RESULT_DIR,
- '{}{}'.format(heat_dir, 'results/'))
+ self.assertEqual(common.RESULT_DIR, '/tmp/apexlake/results/')
self.assertEqual(common.ITERATIONS, 2)
def test_init_log_2_for_success(self):
'Deployment-parameters',
'Testcase-parameters'
]
- c_file = '/tests/data/common/conf.cfg'
+ c_file = './tests/data/common/conf.cfg'
common.BASE_DIR = os.getcwd()
self.conf_file = common.ConfigurationFile(self.sections, c_file)
sections = ['General', 'OpenStack', 'Experiment-VNF', 'PacketGen',
'Deployment-parameters', 'Testcase-parameters']
c = DummyConfigurationFile3(
- sections, config_file='/tests/data/common/conf.cfg')
+ sections, config_file='./tests/data/common/conf.cfg')
self.assertEqual(
DummyConfigurationFile3._config_section_map('', '', True),
6)
'Deployment-parameters',
'Testcase-parameters'
]
- config_file = '/tests/data/common/conf.cfg'
+ config_file = './tests/data/common/conf.cfg'
common.BASE_DIR = os.getcwd()
common.CONF_FILE = DummyConfigurationFile4(self.sections, config_file)
common.PKTGEN_MEMCHANNEL = 'var'
common.PKTGEN_BUS_SLOT_NIC_1 = 'var'
common.PKTGEN_BUS_SLOT_NIC_2 = 'var'
+ common.PKTGEN_NAME_NIC_1 = 'var'
+ common.PKTGEN_NAME_NIC_2 = 'var'
common.PKTGEN_DPDK_DIRECTORY = 'var'
expected = {
'bus_slot_nic_1': 'var',
'bus_slot_nic_2': 'var',
+ 'name_if_1': 'var',
+ 'name_if_2': 'var',
'coremask': 'var',
'dpdk_directory': 'var',
'memory_channels': 'var',