blob: 70e020d8fe316be57c75d1aa7cb75ff2de3f2deb [file] [log] [blame]
Avishek Dutadd808332018-09-20 13:27:10 -05001# Copyright 2017 AT&T Corporation.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import logging
17import os
18
19from oslo_concurrency import lockutils
20
21from tempest import config
22from tempest.test_discover import plugins
23
24from tungsten_tempest_plugin import config as project_config
25
26RBACLOG = logging.getLogger('rbac_reporting')
27
28
29class TungstenTempestPlugin(plugins.TempestPlugin):
30
31 def load_tests(self):
32 base_path = os.path.split(os.path.dirname(
33 os.path.abspath(__file__)))[0]
34 test_dir = "tungsten_tempest_plugin/tests/api"
35 full_test_dir = os.path.join(base_path, test_dir)
36 return full_test_dir, base_path
37
38 @lockutils.synchronized('_reset_log_file')
39 def _reset_log_file(self, logfile):
40 try:
41 os.remove(logfile)
42 except OSError:
43 pass
44
45 def _configure_per_test_logging(self, conf):
46 # Separate log handler for rbac reporting
47 RBACLOG.setLevel(level=logging.INFO)
48 # Set up proper directory handling
49 report_abs_path = os.path.abspath(conf.tungsten_log.report_log_path)
50 report_path = os.path.join(
51 report_abs_path, conf.tungsten_log.report_log_name)
52
53 # Remove the log file if it exists
54 self._reset_log_file(report_path)
55 # Delay=True so that we don't end up creating an empty file if we
56 # never log to it.
57 rbac_report_handler = logging.FileHandler(
58 filename=report_path, delay=True, mode='a')
59 rbac_report_handler.setFormatter(
60 fmt=logging.Formatter(fmt='%(message)s'))
61 RBACLOG.addHandler(rbac_report_handler)
62
63 def register_opts(self, conf):
64 config.register_opt_group(conf, project_config.service_available_group,
65 project_config.ServiceAvailableGroup)
66 config.register_opt_group(conf, project_config.sdn_group,
67 project_config.SDNGroup)
68 config.register_opt_group(conf, project_config.tungsten_log_group,
69 project_config.TungstenLogGroup)
70
71 if conf.tungsten_log.enable_reporting:
72 self._configure_per_test_logging(conf)
73
74 def get_opt_lists(self):
75 return [
76 (project_config.service_available_group.name,
77 project_config.ServiceAvailableGroup),
78 (project_config.sdn_group.name, project_config.SDNGroup),
79 (project_config.tungsten_log_group.name,
80 project_config.TungstenLogGroup),
81 ]