Fetch ips of interfaces with dhcp enabled

Change-Id: Ifa8bcae524307e7f62c599db32c2a766e2c899b1
diff --git a/TestON/drivers/common/cli/hostdriver.py b/TestON/drivers/common/cli/hostdriver.py
index 6175801..8f3037e 100644
--- a/TestON/drivers/common/cli/hostdriver.py
+++ b/TestON/drivers/common/cli/hostdriver.py
@@ -56,6 +56,7 @@
             self.interfaces.append( { 'ips': [ self.options[ 'ip' ] ],
                                       'isUp': True,
                                       'mac': self.options[ 'mac' ],
+                                      'dhcp': self.options[ 'dhcp' ],
                                       'name': self.options.get( 'interfaceName', None ) } )
 
             try:
@@ -80,6 +81,15 @@
                 port=None,
                 pwd=self.pwd )
 
+            # Update IP of interfaces if using dhcp
+            for intf in self.interfaces:
+                if intf[ 'dhcp' ].lower() == "true":
+                    ip = self.getIPAddress( iface=intf[ 'name' ] )
+                    if ip:
+                        intf['ips'] = [ ip ]
+                    else:
+                        main.log.warn( self.name + ": Could not find IP of %s" % intf[ 'name' ] )
+
             if self.handle:
                 main.log.info( "Connection successful to the " +
                                self.user_name +
@@ -208,6 +218,26 @@
             main.log.error( self.name + ":     " + self.handle.before )
             return main.FALSE
 
+    def getIPAddress( self, iface=None, proto='IPV4' ):
+        """
+        Returns IP address of the host
+        """
+        cmd = "ifconfig %s" % iface if iface else ""
+        response = self.command( cmd )
+        pattern = ''
+        if proto == 'IPV4':
+            pattern = "inet\s(\d+\.\d+\.\d+\.\d+)\s\snetmask"
+        else:
+            pattern = "inet6\s([\w,:]*)/\d+\s\sprefixlen"
+        ipAddressSearch = re.search( pattern, response )
+        if not ipAddressSearch:
+            return None
+        main.log.info(
+            self.name +
+            ": IP-Address is " +
+            ipAddressSearch.group( 1 ) )
+        return ipAddressSearch.group( 1 )
+
     def ping( self, dst, ipv6=False, interface=None, wait=3 ):
         """
         Description:
diff --git a/TestON/tests/USECASE/SegmentRouting/SRStaging/SRStaging.topo b/TestON/tests/USECASE/SegmentRouting/SRStaging/SRStaging.topo
index 7d7167e..f50b327 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRStaging/SRStaging.topo
+++ b/TestON/tests/USECASE/SegmentRouting/SRStaging/SRStaging.topo
@@ -108,6 +108,7 @@
             <COMPONENTS>
                 <mac></mac>
                 <inband>false</inband>
+                <dhcp>True</dhcp>
                 <ip>10.32.5.188</ip>
                 <shortName>h1</shortName>
                 <port1></port1>
@@ -135,6 +136,7 @@
             <COMPONENTS>
                 <mac></mac>
                 <inband>false</inband>
+                <dhcp>True</dhcp>
                 <ip>10.32.5.185</ip>
                 <shortName>h2</shortName>
                 <port1></port1>
@@ -162,6 +164,7 @@
             <COMPONENTS>
                 <mac></mac>
                 <inband>false</inband>
+                <dhcp>True</dhcp>
                 <ip>10.32.5.189</ip>
                 <shortName>h3</shortName>
                 <port1></port1>