-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nose plugin to capture glance service logs
Adding custom nose plugin to capture entire glance service logs for failed tests. Disabled by default, enable by setting: $ NOSE_GLANCELOGCAPTURE=true ; ./run_tests.sh Change-Id: I8a3bd9529ec6adb8b98804e0ddc266a7ea8eca08
- Loading branch information
Eoghan Glynn
committed
Mar 16, 2012
1 parent
e1fae1d
commit 2145c24
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | |||
|
|||
# Copyright 2012 Red Hat, Inc | |||
# All Rights Reserved. | |||
# | |||
# 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. | |||
|
|||
""" | |||
Custom nose plugin to capture the entire glance service logs for failed tests. | |||
""" | |||
|
|||
from glance.tests import functional | |||
|
|||
from nose.plugins.base import Plugin | |||
from nose.util import ln, safe_str | |||
|
|||
|
|||
class GlanceLogCapture(Plugin): | |||
enabled = False | |||
env_opt = 'NOSE_GLANCELOGCAPTURE' | |||
name = 'glance-logcapture' | |||
|
|||
def options(self, parser, env): | |||
parser.add_option( | |||
"--glance-logcapture", | |||
action="store_true", | |||
default=env.get(self.env_opt), | |||
dest="glance_logcapture", | |||
help="Enable glance log capture plugin [NOSE_GLANCELOGCAPTURE]") | |||
|
|||
def configure(self, options, conf): | |||
self.enabled = options.glance_logcapture | |||
|
|||
def formatFailure(self, test, err): | |||
return self.formatError(test, err) | |||
|
|||
def formatError(self, test, err): | |||
if self.enabled: | |||
ec, ev, tb = err | |||
err = (ec, self._dump_logs(ev, test), tb) | |||
return err | |||
|
|||
def _dump_logs(self, ev, test): | |||
ret = ev | |||
if isinstance(test.test, functional.FunctionalTest): | |||
ret = '\n'.join([safe_str(ev), | |||
ln('>> begin captured glance logging <<')] + | |||
[test.test.dump_logs()] + | |||
[ln('>> end captured glance logging <<')]) | |||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters