43fe83
From b0d1a7dcdb4a8a5a9dca85ce9f2e2b3204f07eb9 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <b0d1a7dcdb4a8a5a9dca85ce9f2e2b3204f07eb9.1377873641.git.jdenemar@redhat.com>
43fe83
From: John Ferlan <jferlan@redhat.com>
43fe83
Date: Thu, 22 Aug 2013 16:56:25 -0400
43fe83
Subject: [PATCH] Report secret usage error message similarly
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1000168
43fe83
43fe83
Each of the modules handled reporting error messages from the secret fetching
43fe83
slightly differently with respect to the error. Provide a similar message
43fe83
for each error case and provide as much data as possible.
43fe83
43fe83
(cherry picked from commit 1fa7946fbacedfa9f0caa83036816c46a617fb82)
43fe83
---
43fe83
 src/qemu/qemu_command.c             | 26 ++++++++++++++++++++------
43fe83
 src/storage/storage_backend_iscsi.c | 26 ++++++++++++++++++++------
43fe83
 src/storage/storage_backend_rbd.c   | 28 ++++++++++++++++++++++------
43fe83
 3 files changed, 62 insertions(+), 18 deletions(-)
43fe83
43fe83
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
43fe83
index b811e1d..43934f1 100644
43fe83
--- a/src/qemu/qemu_command.c
43fe83
+++ b/src/qemu/qemu_command.c
43fe83
@@ -3043,18 +3043,32 @@ qemuGetSecretString(virConnectPtr conn,
43fe83
     }
43fe83
 
43fe83
     if (!sec) {
43fe83
-        virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
-                       _("%s username '%s' specified but secret not found"),
43fe83
-                       scheme, username);
43fe83
+        if (diskSecretType == VIR_DOMAIN_DISK_SECRET_TYPE_UUID) {
43fe83
+            virReportError(VIR_ERR_NO_SECRET,
43fe83
+                           _("%s no secret matches uuid '%s'"),
43fe83
+                           scheme, uuid);
43fe83
+        } else {
43fe83
+            virReportError(VIR_ERR_NO_SECRET,
43fe83
+                           _("%s no secret matches usage value '%s'"),
43fe83
+                           scheme, usage);
43fe83
+        }
43fe83
         goto cleanup;
43fe83
     }
43fe83
 
43fe83
     secret = (char *)conn->secretDriver->secretGetValue(sec, &secret_size, 0,
43fe83
                                                         VIR_SECRET_GET_VALUE_INTERNAL_CALL);
43fe83
     if (!secret) {
43fe83
-        virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
-                       _("could not get value of the secret for username %s"),
43fe83
-                       username);
43fe83
+        if (diskSecretType == VIR_DOMAIN_DISK_SECRET_TYPE_UUID) {
43fe83
+            virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
+                           _("could not get value of the secret for "
43fe83
+                             "username '%s' using uuid '%s'"),
43fe83
+                           username, uuid);
43fe83
+        } else {
43fe83
+            virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
+                           _("could not get value of the secret for "
43fe83
+                             "username '%s' using usage value '%s'"),
43fe83
+                           username, usage);
43fe83
+        }
43fe83
         goto cleanup;
43fe83
     }
43fe83
 
43fe83
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
43fe83
index ee8dd2e..e71ea46 100644
43fe83
--- a/src/storage/storage_backend_iscsi.c
43fe83
+++ b/src/storage/storage_backend_iscsi.c
43fe83
@@ -732,15 +732,29 @@ virStorageBackendISCSISetAuth(const char *portal,
43fe83
             conn->secretDriver->secretGetValue(secret, &secret_size, 0,
43fe83
                                                VIR_SECRET_GET_VALUE_INTERNAL_CALL);
43fe83
         if (!secret_value) {
43fe83
-            virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
-                           _("could not get the value of the secret "
43fe83
-                             "for username %s"), chap.username);
43fe83
+            if (chap.secret.uuidUsable) {
43fe83
+                virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
+                               _("could not get the value of the secret "
43fe83
+                                 "for username %s using uuid '%s'"),
43fe83
+                                 chap.username, chap.secret.uuid);
43fe83
+            } else {
43fe83
+                virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
+                               _("could not get the value of the secret "
43fe83
+                                 "for username %s using usage value '%s'"),
43fe83
+                                 chap.username, chap.secret.usage);
43fe83
+            }
43fe83
             goto cleanup;
43fe83
         }
43fe83
     } else {
43fe83
-        virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
-                       _("username '%s' specified but secret not found"),
43fe83
-                       chap.username);
43fe83
+        if (chap.secret.uuidUsable) {
43fe83
+            virReportError(VIR_ERR_NO_SECRET,
43fe83
+                           _("no secret matches uuid '%s'"),
43fe83
+                           chap.secret.uuid);
43fe83
+        } else {
43fe83
+            virReportError(VIR_ERR_NO_SECRET,
43fe83
+                           _("no secret matches usage value '%s'"),
43fe83
+                           chap.secret.usage);
43fe83
+        }
43fe83
         goto cleanup;
43fe83
     }
43fe83
 
43fe83
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
43fe83
index e3340f6..d9e1789 100644
43fe83
--- a/src/storage/storage_backend_rbd.c
43fe83
+++ b/src/storage/storage_backend_rbd.c
43fe83
@@ -91,8 +91,15 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr *ptr,
43fe83
         }
43fe83
 
43fe83
         if (secret == NULL) {
43fe83
-            virReportError(VIR_ERR_NO_SECRET, "%s",
43fe83
-                           _("failed to find the secret"));
43fe83
+            if (pool->def->source.auth.cephx.secret.uuidUsable) {
43fe83
+                virReportError(VIR_ERR_NO_SECRET,
43fe83
+                               _("no secret matches uuid '%s'"),
43fe83
+                                 pool->def->source.auth.cephx.secret.uuid);
43fe83
+            } else {
43fe83
+                virReportError(VIR_ERR_NO_SECRET,
43fe83
+                               _("no secret matches usage value '%s'"),
43fe83
+                                 pool->def->source.auth.cephx.secret.usage);
43fe83
+            }
43fe83
             goto cleanup;
43fe83
         }
43fe83
 
43fe83
@@ -100,10 +107,19 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr *ptr,
43fe83
                                                           VIR_SECRET_GET_VALUE_INTERNAL_CALL);
43fe83
 
43fe83
         if (!secret_value) {
43fe83
-            virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
-                           _("could not get the value of the secret "
43fe83
-                             "for username %s"),
43fe83
-                           pool->def->source.auth.cephx.username);
43fe83
+            if (pool->def->source.auth.cephx.secret.uuidUsable) {
43fe83
+                virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
+                               _("could not get the value of the secret "
43fe83
+                                 "for username '%s' using uuid '%s'"),
43fe83
+                               pool->def->source.auth.cephx.username,
43fe83
+                               pool->def->source.auth.cephx.secret.uuid);
43fe83
+            } else {
43fe83
+                virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
+                               _("could not get the value of the secret "
43fe83
+                                 "for username '%s' using usage value '%s'"),
43fe83
+                               pool->def->source.auth.cephx.username,
43fe83
+                               pool->def->source.auth.cephx.secret.usage);
43fe83
+            }
43fe83
             goto cleanup;
43fe83
         }
43fe83
 
43fe83
-- 
43fe83
1.8.3.2
43fe83