[PATCH v2 2/7] storage: Support "username" for "chap" type "auth"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To be consistent with "ceph" types for storage "auth" elements, allow
"username" to be used as an "auth" attribute name for "chap" types.
Continue to allow "login" for backwards compatibility when reading the XML,
but when writing the XML use "username".
---
 docs/schemas/storagepool.rng                       | 12 ++++++++---
 src/conf/storage_conf.c                            | 24 ++++++++++++++++++----
 .../storagepoolxml2xmlin/pool-iscsi-auth-login.xml | 17 +++++++++++++++
 .../pool-iscsi-auth-username.xml                   | 17 +++++++++++++++
 tests/storagepoolxml2xmlin/pool-iscsi-auth.xml     | 17 ---------------
 .../pool-iscsi-auth-login.xml                      | 20 ++++++++++++++++++
 .../pool-iscsi-auth-username.xml                   | 20 ++++++++++++++++++
 tests/storagepoolxml2xmlout/pool-iscsi-auth.xml    | 20 ------------------
 .../pool-iscsi-vendor-product.xml                  |  2 +-
 tests/storagepoolxml2xmltest.c                     |  3 ++-
 10 files changed, 106 insertions(+), 46 deletions(-)
 create mode 100644 tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml
 create mode 100644 tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml
 delete mode 100644 tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
 create mode 100644 tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml
 create mode 100644 tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml
 delete mode 100644 tests/storagepoolxml2xmlout/pool-iscsi-auth.xml

diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 2595e37..ba6c741 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -286,9 +286,15 @@
             <value>chap</value>
           </attribute>
           <interleave>
-            <attribute name='login'>
-              <text/>
-            </attribute>
+            <choice>
+              <!-- Legacy, but still supported to keep back-compat -->
+              <attribute name='login'>
+                <text/>
+              </attribute>
+              <attribute name='username'>
+                <text/>
+              </attribute>
+            </choice>
             <attribute name='passwd'>
               <text/>
             </attribute>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 2539c45..997df54 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -457,13 +457,29 @@ static int
 virStoragePoolDefParseAuthChap(xmlXPathContextPtr ctxt,
                                virStoragePoolAuthChapPtr auth)
 {
-    auth->login = virXPathString("string(./auth/@login)", ctxt);
-    if (auth->login == NULL) {
+    char *login = NULL;
+    char *username = NULL;
+
+    login = virXPathString("string(./auth/@login)", ctxt);
+    username = virXPathString("string(./auth/@username)", ctxt);
+
+    if (!login && !username) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing auth login attribute"));
+                       _("missing auth login or username attribute"));
         return -1;
     }
 
+    if (login && username) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("'login' is legacy name of 'username', both "
+                         "cannot be supplied"));
+        VIR_FREE(login);
+        VIR_FREE(username);
+        return -1;
+    }
+
+    auth->login = username ? username : login;
+
     auth->passwd = virXPathString("string(./auth/@passwd)", ctxt);
     if (auth->passwd == NULL) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -1123,7 +1139,7 @@ virStoragePoolSourceFormat(virBufferPtr buf,
     }
 
     if (src->authType == VIR_STORAGE_POOL_AUTH_CHAP)
-        virBufferAsprintf(buf,"    <auth type='chap' login='%s' passwd='%s'/>\n",
+        virBufferAsprintf(buf,"    <auth type='chap' username='%s' passwd='%s'/>\n",
                           src->auth.chap.login,
                           src->auth.chap.passwd);
 
diff --git a/tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml b/tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml
new file mode 100644
index 0000000..f7d4d52
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml
@@ -0,0 +1,17 @@
+<pool type='iscsi'>
+  <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <source>
+    <host name="iscsi.example.com"/>
+    <device path="demo-target"/>
+    <auth type='chap' login='foobar' passwd='frobbar'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml b/tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml
new file mode 100644
index 0000000..b8e4d37
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml
@@ -0,0 +1,17 @@
+<pool type='iscsi'>
+  <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <source>
+    <host name="iscsi.example.com"/>
+    <device path="demo-target"/>
+    <auth type='chap' username='foobar' passwd='frobbar'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml b/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
deleted file mode 100644
index f7d4d52..0000000
--- a/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<pool type='iscsi'>
-  <name>virtimages</name>
-  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
-  <source>
-    <host name="iscsi.example.com"/>
-    <device path="demo-target"/>
-    <auth type='chap' login='foobar' passwd='frobbar'/>
-  </source>
-  <target>
-    <path>/dev/disk/by-path</path>
-    <permissions>
-      <mode>0700</mode>
-      <owner>0</owner>
-      <group>0</group>
-    </permissions>
-  </target>
-</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml b/tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml
new file mode 100644
index 0000000..5e3e8a2
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml
@@ -0,0 +1,20 @@
+<pool type='iscsi'>
+  <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <available unit='bytes'>0</available>
+  <source>
+    <host name='iscsi.example.com'/>
+    <device path='demo-target'/>
+    <auth type='chap' username='foobar' passwd='frobbar'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml b/tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml
new file mode 100644
index 0000000..5e3e8a2
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml
@@ -0,0 +1,20 @@
+<pool type='iscsi'>
+  <name>virtimages</name>
+  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <available unit='bytes'>0</available>
+  <source>
+    <host name='iscsi.example.com'/>
+    <device path='demo-target'/>
+    <auth type='chap' username='foobar' passwd='frobbar'/>
+  </source>
+  <target>
+    <path>/dev/disk/by-path</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml b/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
deleted file mode 100644
index 4fa8f64..0000000
--- a/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<pool type='iscsi'>
-  <name>virtimages</name>
-  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
-  <capacity unit='bytes'>0</capacity>
-  <allocation unit='bytes'>0</allocation>
-  <available unit='bytes'>0</available>
-  <source>
-    <host name='iscsi.example.com'/>
-    <device path='demo-target'/>
-    <auth type='chap' login='foobar' passwd='frobbar'/>
-  </source>
-  <target>
-    <path>/dev/disk/by-path</path>
-    <permissions>
-      <mode>0700</mode>
-      <owner>0</owner>
-      <group>0</group>
-    </permissions>
-  </target>
-</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml b/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml
index 6ae1c39..9558e59 100644
--- a/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml
+++ b/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml
@@ -7,7 +7,7 @@
   <source>
     <host name='iscsi.example.com'/>
     <device path='demo-target'/>
-    <auth type='chap' login='foobar' passwd='frobbar'/>
+    <auth type='chap' username='foobar' passwd='frobbar'/>
     <vendor name='test-vendor'/>
     <product name='test-product'/>
   </source>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 0376e63..b8935ee 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -88,7 +88,8 @@ mymain(void)
     DO_TEST("pool-logical-create");
     DO_TEST("pool-disk");
     DO_TEST("pool-iscsi");
-    DO_TEST("pool-iscsi-auth");
+    DO_TEST("pool-iscsi-auth-login");
+    DO_TEST("pool-iscsi-auth-username");
     DO_TEST("pool-netfs");
     DO_TEST("pool-scsi");
     DO_TEST("pool-scsi-type-scsi-host");
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]