a00e17c3700597659f7702b85a7d09b7eae393e0
[functest.git] / functest / opnfv_tests / openstack / patrole / patrole.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2018 Orange and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # pylint: disable=missing-docstring
11
12 import logging
13 import os
14
15 from six.moves import configparser
16
17 from functest.opnfv_tests.openstack.tempest import tempest
18 from functest.utils import config
19
20
21 class Patrole(tempest.TempestCommon):
22
23     __logger = logging.getLogger(__name__)
24
25     def __init__(self, **kwargs):
26         if "case_name" not in kwargs:
27             kwargs["case_name"] = 'patrole'
28         super(Patrole, self).__init__(**kwargs)
29         self.res_dir = os.path.join(
30             getattr(config.CONF, 'dir_results'), 'patrole')
31         self.list = os.path.join(self.res_dir, 'tempest-list.txt')
32
33     def apply_tempest_blacklist(self):
34         pass
35
36     def configure(self, **kwargs):
37         super(Patrole, self).configure(**kwargs)
38         rconfig = configparser.RawConfigParser()
39         rconfig.read(self.conf_file)
40         rconfig.add_section('rbac')
41         rconfig.set('rbac', 'enable_rbac', True)
42         rconfig.set('rbac', 'rbac_test_role', kwargs.get('role', 'admin'))
43         with open(self.conf_file, 'wb') as config_file:
44             rconfig.write(config_file)
45         self.backup_tempest_config(self.conf_file, self.res_dir)
46
47     def run(self, **kwargs):
48         for exclude in kwargs.get('exclude', []):
49             self.mode = "{}(?!.*{})".format(self.mode, exclude)
50         self.mode = "'{}(?=patrole_tempest_plugin.tests.api.({}))'".format(
51             self.mode, '|'.join(kwargs.get('services', [])))
52         return super(Patrole, self).run(**kwargs)