You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2021/01/14 00:50:39 UTC

[cloudstack] branch 4.15 updated: kvm: Fix RBD primary storage host port null error (#4565)

This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.15
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.15 by this push:
     new c9a1d30  kvm: Fix RBD primary storage host port null error (#4565)
c9a1d30 is described below

commit c9a1d300cb16fa1d1cdddd61f7dc92f81115c6dc
Author: div8cn <35...@users.noreply.github.com>
AuthorDate: Thu Jan 14 08:50:16 2021 +0800

    kvm: Fix RBD primary storage host port null error (#4565)
    
    Add RBD main storage through UI, it will fail when there is no host port parameter;
    Because when we created the pool, we did not add the port target in the xml
---
 .../com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java  | 6 +++++-
 .../cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java
index 51ebdb3..bb3f713 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java
@@ -84,7 +84,11 @@ public class LibvirtDomainXMLParser {
                     String authUserName = getAttrValue("auth", "username", disk);
                     String poolUuid = getAttrValue("secret", "uuid", disk);
                     String host = getAttrValue("host", "name", disk);
-                    int port = Integer.parseInt(getAttrValue("host", "port", disk));
+                    int port = 0;
+                    String xmlPort = getAttrValue("host", "port", disk);
+                    if (StringUtils.isNotBlank(xmlPort)) {
+                        port = Integer.parseInt(xmlPort);
+                    }
                     String diskLabel = getAttrValue("target", "dev", disk);
                     String bus = getAttrValue("target", "bus", disk);
 
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java
index 239cc3d..7b70c37 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java
@@ -23,6 +23,7 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -55,7 +56,11 @@ public class LibvirtStoragePoolXMLParser {
             String format = getAttrValue("format", "type", source);
 
             if (type.equalsIgnoreCase("rbd")) {
-                int port = Integer.parseInt(getAttrValue("host", "port", source));
+                int port = 0;
+                String xmlPort = getAttrValue("host", "port", source);
+                if (StringUtils.isNotBlank(xmlPort)) {
+                    port = Integer.parseInt(xmlPort);
+                }
                 String pool = getTagValue("name", source);
 
                 Element auth = (Element)source.getElementsByTagName("auth").item(0);