Add cli flag for virtual environment 22/44022/4
authorVictor Pickard <vpickard@redhat.com>
Mon, 15 Aug 2016 21:55:10 +0000 (17:55 -0400)
committerVictor Pickard <vpickard@redhat.com>
Wed, 17 Aug 2016 14:23:00 +0000 (10:23 -0400)
Docker-compose is installed in a virtual environment on Jenkins.

Add a cli flag to enable switching to a virtual environment, if needed.

Netvirt IT requires docker-compose, so the netvirt IT jenkins
script will set this flag: -DuseVenv=true

Change-Id: Ie66e274dd10f1cefcbe134d837faea7c52a55013
Signed-off-by: Victor Pickard <vpickard@redhat.com>
Signed-off-by: Sam Hague <shague@redhat.com>
Signed-off-by: Victor Pickard <vpickard@redhat.com>
utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/DockerOvs.java
utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/ItConstants.java

index 47f8475bc8b3747961c1f82a4d0b8ee6d8c282a0..8714e4128719143df5d22de65f91c64fe829e3e7 100644 (file)
@@ -115,6 +115,7 @@ public class DockerOvs implements AutoCloseable {
     private String[] upCmd = {"sudo", "docker-compose", "-f", null, "up", "-d", "--force-recreate"};
     private String[] downCmd = {"sudo", "docker-compose", "-f", null, "stop"};
     private String[] execCmd = {"sudo", "docker-compose", "-f", null, "exec", null};
+    private String[] venvCmd = {"source", "$WORKSPACE/venv/bin/activate"};
 
     private File tmpDockerComposeFile;
     boolean isRunning;
@@ -122,6 +123,7 @@ public class DockerOvs implements AutoCloseable {
     private String envServerPort;
     private String envDockerComposeFile;
     private boolean runDocker;
+    private boolean runVenv;
 
     class DockerComposeServiceInfo {
         public String name;
@@ -142,7 +144,8 @@ public class DockerOvs implements AutoCloseable {
                                             ItConstants.CONTROLLER_IPADDRESS,
                                             ItConstants.USERSPACE_ENABLED,
                                             ItConstants.DOCKER_COMPOSE_FILE_NAME,
-                                            ItConstants.DOCKER_RUN)
+                                            ItConstants.DOCKER_RUN,
+                                            ItConstants.DOCKER_USE_VENV)
         };
     }
 
@@ -196,12 +199,24 @@ public class DockerOvs implements AutoCloseable {
         String envRunDocker = env.getProperty(ItConstants.DOCKER_RUN);
         String connType = env.getProperty(ItConstants.CONNECTION_TYPE, ItConstants.CONNECTION_TYPE_ACTIVE);
         String dockerFile = env.getProperty(ItConstants.DOCKER_COMPOSE_FILE_NAME);
+        String useVenv = env.getProperty(ItConstants.DOCKER_USE_VENV);
         envDockerComposeFile = DOCKER_FILE_PATH + (null == dockerFile ? DEFAULT_DOCKER_FILE : dockerFile);
 
         //Are we running docker? If we specified docker.run, that's the answer. Otherwise, if there is a server
         //address we assume docker is already running
         runDocker = (envRunDocker != null) ? Boolean.parseBoolean(envRunDocker) : envServerAddress == null;
 
+        //Should we run in a virtual environment? Needed for jenkins and docker-compose
+        if (Boolean.parseBoolean(useVenv)) {
+            try{
+                LOG.info("DockerOvs.configured for virtual environment");
+                ProcUtils.tryProcess(60000, venvCmd);
+            }
+            catch(IOException | InterruptedException ex) {
+                LOG.info("DockerOvs failed to configure virtual environment", ex);
+            }
+        }
+
         if(runDocker) {
             return;
         }
index 7e9c700fc138a4d06be26a45a9581e1e7c1c0391..414f94bdac8b15ff90614c66741f9d235a4cfa1e 100644 (file)
@@ -38,4 +38,5 @@ public final class ItConstants {
     public static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
     public static final String DOCKER_COMPOSE_FILE_NAME="docker.compose.file";
     public static final String DOCKER_RUN="docker.run";
+    public static final String DOCKER_USE_VENV="docker.useVenv";
 }