Change in vdsm[ovirt-3.5]: profiling: move exceptions in a module
fromani at redhat.com
fromani at redhat.com
Tue Feb 16 10:40:36 UTC 2016
Hello Dan Kenigsberg,
I'd like you to do a code review. Please visit
https://gerrit.ovirt.org/47593
to review the following change.
Change subject: profiling: move exceptions in a module
......................................................................
profiling: move exceptions in a module
In order to make them (so far, 'it') reusable
across all the package, not only in the cpu module.
No code changes, just reorganization.
Change-Id: I1b12ea00b1613c028b0de2aeee9a9d3cc7a3b1e0
Signed-off-by: Francesco Romani <fromani at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/36013
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
---
M debian/vdsm-python.install
M lib/vdsm/profiling/Makefile.am
M lib/vdsm/profiling/cpu.py
A lib/vdsm/profiling/errors.py
M tests/cpuProfileTests.py
M vdsm.spec.in
6 files changed, 39 insertions(+), 8 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/47593/2
diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install
index 76ae6fb..030714d 100644
--- a/debian/vdsm-python.install
+++ b/debian/vdsm-python.install
@@ -16,6 +16,7 @@
./usr/lib/python2.7/dist-packages/vdsm/password.py
./usr/lib/python2.7/dist-packages/vdsm/profiling/__init__.py
./usr/lib/python2.7/dist-packages/vdsm/profiling/cpu.py
+./usr/lib/python2.7/dist-packages/vdsm/profiling/errors.py
./usr/lib/python2.7/dist-packages/vdsm/profiling/profile.py
./usr/lib/python2.7/dist-packages/vdsm/qemuimg.py
./usr/lib/python2.7/dist-packages/vdsm/sslutils.py
diff --git a/lib/vdsm/profiling/Makefile.am b/lib/vdsm/profiling/Makefile.am
index d6f547b..6bfd7d3 100644
--- a/lib/vdsm/profiling/Makefile.am
+++ b/lib/vdsm/profiling/Makefile.am
@@ -23,5 +23,6 @@
dist_vdsmprofiling_PYTHON = \
__init__.py \
cpu.py \
+ errors.py \
profile.py \
$(NULL)
diff --git a/lib/vdsm/profiling/cpu.py b/lib/vdsm/profiling/cpu.py
index e14ca95..ec52e94 100644
--- a/lib/vdsm/profiling/cpu.py
+++ b/lib/vdsm/profiling/cpu.py
@@ -30,6 +30,8 @@
from vdsm import constants
from vdsm.config import config
+from .errors import UsageError
+
# Import yappi lazily when profile is started
yappi = None
@@ -42,10 +44,6 @@
_THREADS = True
_lock = threading.Lock()
-
-
-class Error(Exception):
- """ Raised when profiler is used incorrectly """
def start():
@@ -100,7 +98,7 @@
# yappi is already started, happily having too different code paths
# that thinks they own the single process profiler.
if yappi.is_running():
- raise Error('CPU profiler is already running')
+ raise UsageError('CPU profiler is already running')
yappi.set_clock_type(clock)
yappi.start(builtins=builtins, profile_threads=threads)
diff --git a/lib/vdsm/profiling/errors.py b/lib/vdsm/profiling/errors.py
new file mode 100644
index 0000000..200438b
--- /dev/null
+++ b/lib/vdsm/profiling/errors.py
@@ -0,0 +1,27 @@
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+"""
+This module provides exceptions for the profiling package.
+"""
+
+
+class UsageError(Exception):
+ """ Raised when profiler is used incorrectly """
diff --git a/tests/cpuProfileTests.py b/tests/cpuProfileTests.py
index 373e67f..66fab2d 100644
--- a/tests/cpuProfileTests.py
+++ b/tests/cpuProfileTests.py
@@ -25,8 +25,9 @@
import time
import threading
-from vdsm.profiling import cpu
from vdsm import config
+from vdsm.profiling import cpu
+from vdsm.profiling.errors import UsageError
from monkeypatch import MonkeyPatch
from nose.plugins.skip import SkipTest
@@ -184,7 +185,8 @@
requires_yappi()
cpu.start()
try:
- self.assertRaises(cpu.Error, self.profiled_function)
+ self.assertRaises(UsageError,
+ self.profiled_function)
finally:
cpu.stop()
@@ -192,7 +194,8 @@
@MonkeyPatch(cpu, 'config', make_config(enable='false'))
def test_fail_recursive_profile(self):
requires_yappi()
- self.assertRaises(cpu.Error, self.recursive_profile)
+ self.assertRaises(UsageError,
+ self.recursive_profile)
@MonkeyPatch(cpu, 'config', make_config(enable='false'))
def test_ystat_format(self):
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 097f11a..bda574e 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1268,6 +1268,7 @@
%{python_sitelib}/%{vdsm_name}/password.py*
%{python_sitelib}/%{vdsm_name}/profiling/__init__.py*
%{python_sitelib}/%{vdsm_name}/profiling/cpu.py*
+%{python_sitelib}/%{vdsm_name}/profiling/errors.py*
%{python_sitelib}/%{vdsm_name}/profiling/profile.py*
%{python_sitelib}/%{vdsm_name}/qemuimg.py*
%{python_sitelib}/%{vdsm_name}/SecureXMLRPCServer.py*
--
To view, visit https://gerrit.ovirt.org/47593
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1b12ea00b1613c028b0de2aeee9a9d3cc7a3b1e0
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
More information about the vdsm-patches
mailing list