Fix of centos bootstrap and dut_setup.sh
[csit.git] / resources / tools / virl / bin / start-testcase
index b46f5ad..151fce8 100755 (executable)
@@ -24,6 +24,7 @@ import tempfile
 import shutil
 import time
 import paramiko
+import netifaces
 
 #
 # Helper function to indent a text string
@@ -39,25 +40,31 @@ def indent(lines, amount, fillchar=' '):
 # functions.
 #
 def main():
+    #
+    # Get our default interface IP address. This will become the default
+    # value for the "NFS Server IP" option.
+    #
+    gws = netifaces.gateways()
+    addrs = netifaces.ifaddresses(gws['default'][netifaces.AF_INET][1])
+    default_addr = addrs[netifaces.AF_INET][0]['addr']
+
     #
     # Verify CLI parameters and try to download our VPP image into a temporary
     # file first
     #
     parser = argparse.ArgumentParser()
     parser.add_argument("topology", help="the base topology to be started")
-    parser.add_argument("packages", help="Path to the VPP .deb(s) that " +
-                        "is/are to be installed", nargs='+')
-    parser.add_argument("-c", "--copy", help="Copy the .deb packages, " +
+    parser.add_argument("packages", help="Path to the VPP .deb(s) or .rpm(s) " +
+                        "that is/are to be installed", nargs='+')
+    parser.add_argument("-c", "--copy", help="Copy the VPP packages, " +
                         "leaving the originals in place. Default is to " +
                         "move them.", action='store_true')
     parser.add_argument("-k", "--keep", help="Keep (do not delete) the " +
                         "simulation in case of error", action='store_true')
     parser.add_argument("-v", "--verbosity", action="count", default=0)
-    # FIXME: THe default value for the following line should not be a hardcoded
-    # address. We should determine it dynamically (e.g. IP address of first
-    # interface or whichever interface is tied to the flat network)
-    parser.add_argument("-nip", "--nfs-server-ip", help="NFS server (our) IP",
-                        default="10.30.51.28")
+    parser.add_argument("-nip", "--nfs-server-ip", help="NFS server (our) IP " +
+                        "default is derived from routing table: " +
+                        "{}".format(default_addr), default=default_addr)
     parser.add_argument("-ns", "--nfs-scratch-directory",
                         help="Server location for NFS scratch diretory",
                         default="/nfs/scratch")
@@ -66,7 +73,7 @@ def main():
                         "directory", default="/nfs/common")
     parser.add_argument("-wc", "--wait-count",
                         help="number of intervals to wait for simulation to " +
-                        "be ready", type=int, default=12)
+                        "be ready", type=int, default=24)
     parser.add_argument("-wt", "--wait-time",
                         help="length of a single interval to wait for " +
                         "simulation to be ready", type=int, default=5)
@@ -83,6 +90,9 @@ def main():
                         default="/home/jenkins-in/.ssh/id_rsa_virl")
     parser.add_argument("-spu", "--ssh-pubkey", help="SSH public keyfile",
                         default="/home/jenkins-in/.ssh/id_rsa_virl.pub")
+    parser.add_argument("-r", "--release", help="VM disk image/release " +
+                        "(ex. \"csit-ubuntu-16.04.1_2016-12-19_1.6\")",
+                        default="csit-ubuntu-16.04.1_2016-12-19_1.6")
     parser.add_argument("--topology-directory", help="Topology directory",
                         default="/home/jenkins-in/testcase-infra/topologies")
 
@@ -130,10 +140,11 @@ def main():
         open(topology_virl_filename, 'r') as old_file:
         for line in old_file:
             line = line.replace("  - VIRL-USER-SSH-PUBLIC-KEY", "  - "+pub_key)
-            line = line.replace("$$NFS_SERVER_SCRATCH$$", \
+            line = line.replace("$$NFS_SERVER_SCRATCH$$",
                 args.nfs_server_ip+":"+args.nfs_scratch_directory)
-            line = line.replace("$$NFS_SERVER_COMMON$$", \
+            line = line.replace("$$NFS_SERVER_COMMON$$",
                 args.nfs_server_ip+":"+args.nfs_common_directory)
+            line = line.replace("$$VM_IMAGE$$", "server-"+args.release)
             new_file.write(line)
     os.close(temp_handle)
 
@@ -332,8 +343,21 @@ def main():
                 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                 client.connect(ipaddr, username=args.ssh_user,
                                key_filename=args.ssh_privkey)
+                if 'centos' in args.topology:
+                    if args.verbosity >= 1:
+                        print "DEBUG: Installing RPM packages"
+                    vpp_install_command = 'sudo rpm -ivh /scratch/vpp/*.rpm'
+                elif 'trusty' in args.topology or 'xenial' in args.topology:
+                    if args.verbosity >= 1:
+                        print "DEBUG: Installing DEB packages"
+                    vpp_install_command = 'sudo dpkg -i --force-all ' \
+                                          '/scratch/vpp/*.deb'
+                else:
+                    print "ERROR: Unsupported OS requested: {}"\
+                        .format(args.topology)
+                    vpp_install_command = ''
                 stdin, stdout, stderr = \
-                    client.exec_command('sudo dpkg -i /scratch/vpp/*deb')
+                    client.exec_command(vpp_install_command)
                 c_stdout = stdout.read()
                 c_stderr = stderr.read()
                 if args.verbosity >= 2: