Fix bug in the inventory generator 98/67298/4
authorManuel Buil <mbuil@suse.com>
Tue, 19 Mar 2019 12:52:19 +0000 (13:52 +0100)
committerManuel Buil <mbuil@suse.com>
Mon, 25 Mar 2019 13:33:03 +0000 (13:33 +0000)
The dns keys should only appear in case the idf provides a dns entry for
the network. Otherwise, it should not exist at all. If it exists, even
if the value is empty, ansible will transform it in a variable and

"item.network.dns is defined"

will return true:

https://github.com/opnfv/releng-xci/blob/master/xci/playbooks/roles/bootstrap-host/templates/osa/debian.interface.j2#L35

A docstring is also added to explain what is the purpose of the class

Signed-off-by: Manuel Buil <mbuil@suse.com>
Change-Id: Ib8afa06cecb54f384083060073fa463c7f8d313f

xci/playbooks/dynamic_inventory.py

index 7831d19..0ea35ff 100755 (executable)
@@ -21,6 +21,12 @@ import json
 
 
 class XCIInventory(object):
+    """
+
+    Generates the ansible inventory based on the idf and pdf files provided
+    when executing the deployment script
+
+    """
     def __init__(self):
         super(XCIInventory, self).__init__()
         self.inventory = {}
@@ -130,11 +136,11 @@ class XCIInventory(object):
             for network, ndata in idf['idf']['net_config'].items():
                 network_interface_num = idf['idf']['net_config'][network]['interface']
                 host_networks[hostname][network] = {}
-                host_networks[hostname][network]['dns'] = []
                 host_networks[hostname][network]['address'] = pdf_host_info['interfaces'][int(network_interface_num)]['address'] + "/" + str(ndata['mask'])
                 if 'gateway' in ndata.keys():
                     host_networks[hostname][network]['gateway'] = str(ndata['gateway']) + "/" + str(ndata['mask'])
                 if 'dns' in ndata.keys():
+                    host_networks[hostname][network]['dns'] = []
                     for d in ndata['dns']:
                         host_networks[hostname][network]['dns'].append(str(d))