[openlmi-scripts] fixed error handling and reporting in service scripts

Michal Minar miminar at fedoraproject.org
Wed Feb 26 13:43:54 UTC 2014


commit 5606be80f6654bfb9fa65560bb985ad62e81e8a4
Author: Michal Minar <miminar at redhat.com>
Date:   Wed Feb 26 12:43:42 2014 +0100

    fixed error handling and reporting in service scripts

 openlmi-scripts-0.2.7-service_error_handling.patch |   52 ++++++++++++++++++++
 openlmi-scripts.spec                               |    7 ++-
 2 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/openlmi-scripts-0.2.7-service_error_handling.patch b/openlmi-scripts-0.2.7-service_error_handling.patch
new file mode 100644
index 0000000..ee531c0
--- /dev/null
+++ b/openlmi-scripts-0.2.7-service_error_handling.patch
@@ -0,0 +1,52 @@
+diff --git a/commands/service/lmi/scripts/service/__init__.py b/commands/service/lmi/scripts/service/__init__.py
+index 1f7e3c6..18f8661 100644
+--- a/commands/service/lmi/scripts/service/__init__.py
++++ b/commands/service/lmi/scripts/service/__init__.py
+@@ -100,8 +100,9 @@ def list_services(ns, kind='enabled'):
+                 continue
+             yield service
+     except pywbem.CIMError as err:
+-        raise LmiFailed('Failed to get service "%s": %s'
+-                % (service, err.args[1]))
++        if err.args[0] == pywbem.CIM_ERR_NOT_SUPPORTED:
++            raise LmiFailed('Service provider is not installed or registered.')
++        raise LmiFailed('Failed to list services: %s' % err.args[1])
+ 
+ def start_service(ns, service):
+     """
+@@ -195,12 +196,17 @@ def get_service(ns, service):
+             inst = iname.to_instance()
+ 
+         elif isinstance(service, (LMIInstance, LMIInstanceName)):
+-            inst = service
+-            service = inst.Name
+-            if isinstance(inst, LMIInstanceName):
+-                inst = inst.to_instance()
++            try:
++                inst = service
++                service = inst.Name
++                if isinstance(inst, LMIInstanceName):
++                    inst = inst.to_instance()
++            except AttributeError:
++                raise ValueError('Invalid service instance name. It\'s missing'
++                        ' Name property.')
+ 
+-        return inst
++        else:
++            raise TypeError("service must be either string or ``LMIInstanceName``")
+ 
+     except pywbem.CIMError as err:
+         if err.args[0] == pywbem.CIM_ERR_NOT_FOUND:
+@@ -209,7 +215,11 @@ def get_service(ns, service):
+             raise LmiFailed('Failed to get service "%s": %s'
+                     % (service, err.args[1]))
+ 
+-    raise TypeError("service must be either string or ``LMIInstanceName``")
++    if inst is None:
++        raise LmiFailed('No such service "%s".' % service)
++
++    return inst
++
+ 
+ def get_status_string(ns, service):
+     """
diff --git a/openlmi-scripts.spec b/openlmi-scripts.spec
index 1c37cc9..f70035b 100644
--- a/openlmi-scripts.spec
+++ b/openlmi-scripts.spec
@@ -6,7 +6,7 @@
 
 Name:           openlmi-scripts
 Version:        %{openlmi_scripts_version}
-Release:        4%{?dist}
+Release:        5%{?dist}
 Summary:        Client-side python modules and command line utilities
 
 License:        BSD
@@ -29,6 +29,7 @@ Requires:       openlmi-tools >= 0.9
 
 Patch0:         openlmi-scripts-0.2.7-hardware_support_older_providers.patch
 Patch1:         openlmi-scripts-0.2.7-storage_mount_fix.patch
+Patch2:         openlmi-scripts-0.2.7-service_error_handling.patch
 
 %description
 Client-side python modules and command line utilities.
@@ -127,6 +128,7 @@ provider and command line wrapper.
 %setup -qn %{name}-%{commit}
 %patch0 -p1 -b .hardware_support_older_providers
 %patch1 -p1 -b .storage_mount_fix
+%patch2 -p1 -b .service_error_handling
 
 %build
 %{__python} setup.py build
@@ -239,6 +241,9 @@ install -m 644 README.md COPYING Changelog $RPM_BUILD_ROOT/%{_docdir}/%{name}
 %{python_sitelib}/openlmi_scripts_powermanagement-*
 
 %changelog
+* Wed Feb 26 2014 Michal Minar <miminar at redhat.com> 0.2.7-5
+- Fixed error handling in service scripts.
+
 * Tue Feb 25 2014 Michal Minar <miminar at redhat.com> 0.2.7-4
 - Removed unstable features from hardware scripts.
 


More information about the scm-commits mailing list