Role has to be listed in tempest.conf before calling testr.
It also saves the right config file.
Change-Id: Ifd122f31d0bfe3e9b3f93c6d62526acce96953d3
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
rconfig.set('rbac', 'rbac_test_role', kwargs.get('role', 'admin'))
with open(self.conf_file, 'wb') as config_file:
rconfig.write(config_file)
+ self.backup_tempest_config(self.conf_file, self.res_dir)
+
+ def generate_test_list(self):
+ self.backup_tempest_config(self.conf_file, '/etc')
+ super(Patrole, self).generate_test_list()
+ os.remove('/etc/tempest.conf')
def run(self, **kwargs):
for exclude in kwargs.get('exclude', []):
import logging
import fileinput
import os
-import shutil
import subprocess
import pkg_resources
'for-deployment-{}'.format(deployment_id))
-def backup_tempest_config(conf_file, res_dir):
- """
- Copy config file to tempest results directory
- """
- if not os.path.exists(res_dir):
- os.makedirs(res_dir)
- shutil.copyfile(conf_file,
- os.path.join(res_dir, 'tempest.conf'))
-
-
def update_tempest_conf_file(conf_file, rconfig):
"""Update defined paramters into tempest config file"""
with open(TEMPEST_CONF_YAML) as yfile:
rconfig.write(config_file)
-def configure_tempest_update_params(tempest_conf_file, res_dir,
+def configure_tempest_update_params(tempest_conf_file,
network_name=None, image_id=None,
flavor_id=None, compute_cnt=1):
# pylint: disable=too-many-branches, too-many-arguments
'into tempest.conf file')
update_tempest_conf_file(tempest_conf_file, rconfig)
- backup_tempest_config(tempest_conf_file, res_dir)
-
def configure_verifier(deployment_dir):
"""
result['num_failures'] = int(new_line[2])
return result
+ @staticmethod
+ def backup_tempest_config(conf_file, res_dir):
+ """
+ Copy config file to tempest results directory
+ """
+ if not os.path.exists(res_dir):
+ os.makedirs(res_dir)
+ shutil.copyfile(conf_file,
+ os.path.join(res_dir, 'tempest.conf'))
+
def generate_test_list(self):
"""Generate test list based on the test mode."""
LOGGER.debug("Generating test case list...")
self.resources.os_creds)
self.conf_file = conf_utils.configure_verifier(self.deployment_dir)
conf_utils.configure_tempest_update_params(
- self.conf_file, self.res_dir,
- network_name=resources.get("network_name"),
+ self.conf_file, network_name=resources.get("network_name"),
image_id=resources.get("image_id"),
flavor_id=resources.get("flavor_id"),
compute_cnt=compute_cnt)
+ self.backup_tempest_config(self.conf_file, self.res_dir)
def run(self, **kwargs):
self.start_time = time.time()
self.assertTrue(mock_get_vid.called)
self.assertTrue(mock_get_did.called)
- def test_backup_config_default(self):
- with mock.patch('functest.opnfv_tests.openstack.tempest.'
- 'conf_utils.os.path.exists',
- return_value=False), \
- mock.patch('functest.opnfv_tests.openstack.tempest.'
- 'conf_utils.os.makedirs') as mock_makedirs, \
- mock.patch('functest.opnfv_tests.openstack.tempest.'
- 'conf_utils.shutil.copyfile') as mock_copyfile:
- conf_utils.backup_tempest_config(
- 'test_conf_file', res_dir='test_dir')
- self.assertTrue(mock_makedirs.called)
- self.assertTrue(mock_copyfile.called)
-
- with mock.patch('functest.opnfv_tests.openstack.tempest.'
- 'conf_utils.os.path.exists',
- return_value=True), \
- mock.patch('functest.opnfv_tests.openstack.tempest.'
- 'conf_utils.shutil.copyfile') as mock_copyfile:
- conf_utils.backup_tempest_config(
- 'test_conf_file', res_dir='test_dir')
- self.assertTrue(mock_copyfile.called)
-
def _test_missing_param(self, params, image_id, flavor_id):
with mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.ConfigParser.RawConfigParser.'
'conf_utils.ConfigParser.RawConfigParser.'
'write') as mwrite, \
mock.patch('__builtin__.open', mock.mock_open()), \
- mock.patch('functest.opnfv_tests.openstack.tempest.'
- 'conf_utils.backup_tempest_config'), \
mock.patch('functest.utils.functest_utils.yaml.safe_load',
return_value={'validation': {'ssh_timeout': 300}}):
os.environ['OS_ENDPOINT_TYPE'] = ''
conf_utils.configure_tempest_update_params(
- 'test_conf_file', res_dir='test_dir', image_id=image_id,
+ 'test_conf_file', image_id=image_id,
flavor_id=flavor_id)
mset.assert_any_call(params[0], params[1], params[2])
self.assertTrue(mread.called)
class OSTempestTesting(unittest.TestCase):
+ # pylint: disable=too-many-public-methods
def setUp(self):
os_creds = OSCreds(
with self.assertRaises(Exception):
self.tempestcommon.parse_verifier_result()
+ def test_backup_config_default(self):
+ with mock.patch('os.path.exists', return_value=False), \
+ mock.patch('os.makedirs') as mock_makedirs, \
+ mock.patch('shutil.copyfile') as mock_copyfile:
+ self.tempestcommon.backup_tempest_config(
+ 'test_conf_file', res_dir='test_dir')
+ self.assertTrue(mock_makedirs.called)
+ self.assertTrue(mock_copyfile.called)
+
+ with mock.patch('os.path.exists', return_value=True), \
+ mock.patch('shutil.copyfile') as mock_copyfile:
+ self.tempestcommon.backup_tempest_config(
+ 'test_conf_file', res_dir='test_dir')
+ self.assertTrue(mock_copyfile.called)
+
@mock.patch("os.rename")
@mock.patch("os.remove")
@mock.patch("os.path.exists", return_value=True)