Setup the cord-tester test container with openstack environment during startup/setup

Change-Id: I3849c0fbffd9099f2c26036ad653f22faa08538e
diff --git a/src/test/setup/cord-test.py b/src/test/setup/cord-test.py
index ab74ab2..d751124 100755
--- a/src/test/setup/cord-test.py
+++ b/src/test/setup/cord-test.py
@@ -449,6 +449,33 @@
 
     return ssh_key_file
 
+def openstack_setup(test_cnt_env):
+    admin_rc = os.path.join(os.getenv('HOME'), 'admin-openrc.sh')
+    if os.access(admin_rc, os.F_OK):
+        dest = os.path.join(CordTester.tester_base, 'admin-openrc.sh')
+        shutil.copy(admin_rc, dest)
+        with open(dest, 'r') as f:
+            cfg = {}
+            for data in f.read().splitlines():
+                try:
+                    k, v = data.split('=')
+                except:
+                    continue
+
+                k = k.split()[-1]
+                cfg[k] = v
+
+            if 'REQUESTS_CA_BUNDLE' in cfg:
+                #copy the certificate to setup directory
+                cert_src = cfg['REQUESTS_CA_BUNDLE']
+                shutil.copy(cert_src, CordTester.tester_base)
+                test_cert_loc = os.path.join(CordTester.sandbox_setup,
+                                             os.path.basename(cert_src))
+                cfg['REQUESTS_CA_BUNDLE'] = test_cert_loc
+
+            for key, value in cfg.iteritems():
+                test_cnt_env[key] = value
+
 def runTest(args):
     #Start the cord test tcp server
     test_manifest = TestManifest(args = args)
@@ -651,6 +678,8 @@
     if iterations is not None:
         test_cnt_env['ITERATIONS'] = iterations
 
+    openstack_setup(test_cnt_env)
+
     if args.num_containers > 1 and args.container:
         print('Cannot specify number of containers with container option')
         sys.exit(1)
@@ -911,6 +940,9 @@
         if use_manifest:
             test_cnt_env['MANIFEST'] = os.path.join(CordTester.sandbox_setup,
                                                     os.path.basename(args.manifest))
+
+        openstack_setup(test_cnt_env)
+
         test_cnt = CordTester((),
                               ctlr_ip = ctlr_addr,
                               image = nose_cnt['image'],