Blob Blame History Raw
From 77760bdeb1642e30f109ba88a98fff8b1faba206 Mon Sep 17 00:00:00 2001
From: Ivan Devat <idevat@redhat.com>
Date: Tue, 19 Mar 2019 10:05:40 +0100
Subject: [PATCH] squash bz1690290 GUI cannot create a cluster if k

fix missing addrs field in cluster setup in webUi

fix transport options in cluster setup in webui
---
 pcsd/public/js/api.js           | 41 ++++++++++++++++++++++++---------
 pcsd/public/js/cluster-setup.js |  8 +++----
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/pcsd/public/js/api.js b/pcsd/public/js/api.js
index 6c433b54..b9c94720 100644
--- a/pcsd/public/js/api.js
+++ b/pcsd/public/js/api.js
@@ -209,10 +209,39 @@ api.checkAuthAgainstNodes = function(nodesNames){
 
 api.clusterSetup = function(submitData, processOptions){
   var setupData = submitData.setupData;
+  var transportOptions = {};
+  if (setupData.transportType === "knet") {
+    transportOptions = {
+      ip_version: setupData.transportOptions.ip_version,
+      knet_pmtud_interval: setupData.transportOptions.knet_pmtud_interval,
+      link_mode: setupData.transportOptions.link_mode,
+    };
+  } else if(setupData.transportType !== undefined) {
+    transportOptions = {
+        ip_version: setupData.transportOptions.ip_version,
+        netmtu: setupData.transportOptions.netmtu,
+    };
+  }
   var data = {
     cluster_name: setupData.clusterName,
     nodes: setupData.nodeList.map(function(node){
       apiNode = { name: node.name };
+      // The backend defaults addresses. But for the defaulting addresses there
+      // must be no key "addrs".
+      // There can be following (valid) scenarios:
+      // 1 User uses no link. We omit key "addrs" for every node. The backend
+      //   defaults addresses.
+      // 2 User uses 1 link and keep all addresses fields empty. We omit key
+      //   "addrs" for every node. The backend defaults addresses.
+      // 3 User uses 1 link and keep some addresses fields empty. We omit key
+      //   "addrs" for respective nodes. The backend then refuses it because
+      //   nodes addreses are inconsistent.
+      // 4 User uses more links. We omit key "addrs" when no address for node is
+      //   filled. The backend then refuses it because nodes addresses count
+      //   is inconsistent with links count.
+      // Because we need to support scenario 2 and the backend defaults
+      // addresses only when key "addrs" is not specified we cannot simply
+      // sent empty addresses or empty address list (i.e. key "addrs").
       var addrs = node.addrs.filter(function(addr){return addr.length > 0});
       if (addrs.length > 0) {
         apiNode["addrs"] = addrs;
@@ -220,17 +249,7 @@ api.clusterSetup = function(submitData, processOptions){
       return apiNode;
     }),
     transport_type: setupData.transportType,
-    transport_options: setupData.transportType == "knet"
-      ? {
-        ip_version: setupData.transportOptions.ip_version,
-        knet_pmtud_interval: setupData.transportOptions.knet_pmtud_interval,
-        link_mode: setupData.transportOptions.link_mode,
-      }
-      : {
-        ip_version: setupData.transportOptions.ip_version,
-        netmtu: setupData.transportOptions.netmtu,
-      }
-    ,
+    transport_options: transportOptions,
     link_list: setupData.linkList.map(function(link){
       return setupData.transportType == "knet"
         ? {
diff --git a/pcsd/public/js/cluster-setup.js b/pcsd/public/js/cluster-setup.js
index 2b7b0a4e..be0a22d5 100644
--- a/pcsd/public/js/cluster-setup.js
+++ b/pcsd/public/js/cluster-setup.js
@@ -322,11 +322,9 @@ clusterSetup.data.validateNameAndNodes = function(formData){
 
 clusterSetup.data.nodes = function(nodesNames, getAddrs){
   return nodesNames.map(function(nodeName){
-    addrs = getAddrs ? getAddrs(nodeName) : [];
-    return addrs.length > 0
-      ? { name: nodeName, addrs: addrs }
-      : { name: nodeName }
-    ;
+    // The field addrs is here always. The details of backend is solved within
+    // api.js module.
+    return { name: nodeName, addrs: getAddrs ? getAddrs(nodeName) : [] };
   });
 };
 
-- 
2.20.1