fence-agents: RHEL6 - fence_vmware_soap: Correct error message when user does not have privileges

Marek GrĂ¡c marx at fedoraproject.org
Wed Jun 18 16:38:44 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=f49052ae6f385e473e5acc062bee1c2c74159c99
Commit:        f49052ae6f385e473e5acc062bee1c2c74159c99
Parent:        b8cdfec7e67ca7ef816f0e138b849a0b32bab479
Author:        Marek 'marx' Grac <mgrac at redhat.com>
AuthorDate:    Wed Jun 18 14:22:51 2014 +0200
Committer:     Marek 'marx' Grac <mgrac at redhat.com>
CommitterDate: Wed Jun 18 14:22:51 2014 +0200

fence_vmware_soap: Correct error message when user does not have privileges

Previously, when an user does not have privileges to reboot a virtual machine, the
fence agent fails with python traceback. After applying this patch (by Shane Bradley),
the fence_vmware_soap fails with human readable error message.

Based on: be464e49a941f727812615107cbeeda119cf5669
Resolved: rhbz#1018263
---
 fence/agents/lib/fencing.py.py                |    4 +++-
 fence/agents/vmware_soap/fence_vmware_soap.py |   17 +++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 576140e..8c4a19b 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -26,6 +26,7 @@ EC_WAITING_OFF     = 7
 EC_STATUS          = 8
 EC_STATUS_HMC      = 9
 EC_PASSWORD_MISSING = 10
+EC_INVALID_PRIVILEGES = 11
 
 TELNET_PATH = "/usr/bin/telnet"
 SSH_PATH    = "/usr/bin/ssh"
@@ -451,7 +452,8 @@ def fail(error_code):
 		EC_WAITING_OFF : "Failed: Timed out waiting to power OFF",
 		EC_STATUS : "Failed: Unable to obtain correct plug status or plug is not available",
 		EC_STATUS_HMC : "Failed: Either unable to obtaion correct plug status, partition is not available or incorrect HMC version used",
-		EC_PASSWORD_MISSING : "Failed: You have to set login password"
+		EC_PASSWORD_MISSING : "Failed: You have to set login password",
+		EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action."
 	}[error_code] + "\n"
 	sys.stderr.write(message)
 	sys.exit(EC_GENERIC_ERROR)
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py
index e6e62ac..efdb8ff 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -161,10 +161,19 @@ def set_power_status(conn, options):
 	mo_machine = Property(vm.value)
 	mo_machine._type = "VirtualMachine"
 	
-	if options["-o"] == "on":
-		conn.service.PowerOnVM_Task(mo_machine)
-	else:
-		conn.service.PowerOffVM_Task(mo_machine)	
+	try:
+		if options["-o"] == "on":
+			conn.service.PowerOnVM_Task(mo_machine)
+		else:
+			conn.service.PowerOffVM_Task(mo_machine)
+	except WebFault, ex:
+		if ((str(ex).find("Permission to perform this operation was denied")) >= 0):
+			fail(EC_INVALID_PRIVILEGES)
+		else:
+			if options["-o"] == "on":
+				fail(EC_WAITING_ON)
+			else:
+				fail(EC_WAITING_OFF)
 
 def remove_tmp_dir(tmp_dir):
 	shutil.rmtree(tmp_dir)


More information about the cluster-commits mailing list