Class DockerOvs
java.lang.Object
org.opendaylight.ovsdb.utils.ovsdb.it.utils.DockerOvs
- All Implemented Interfaces:
AutoCloseable
Run OVS(s) using docker-compose for use in integration tests.
For example,
try(DockerOvs ovs = new DockerOvs()) { ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo( ovs.getOvsdbAddress(0), ovs.getOvsdbPort(0)); ... nodeInfo.disconnect(); } catch (Exception e) { ...Nota bene, DockerOvs will check whether or not docker-compose command requires "sudo" to run. However, if it does require sudo, it must be configured to not prompt for a password ("NOPASSWD: ALL" is the sudoers file). DockerOvs loads its docker-compose yaml files from inside the ovsdb-it-utils bundle at the path META-INF/docker-compose-files/. Currently, a single yaml file is used, "docker-ovs-2.5.1.yml." DockerOvs does support docker-compose files that launch more than one docker image, more on this later. DockerOvs will wait for OVS to accept OVSDB connections. Any docker-compose file must have a port mapping.
The following explains how system properties are used to configure DockerOvs
private static String ENV_USAGE = "-Ddocker.run - explicitly configure whether or not DockerOvs should run docker-compose\n" + "-Dovsdbserver.ipaddress - specify IP address of ovsdb server - implies -Ddocker.run=false\n" + "-Dovsdbserver.port - specify the port of the ovsdb server - required with -Dovsdbserver.ipaddress\n" + "-Ddocker.compose.file - docker compose file in META-INF/docker-compose-files/. If not specified, default file is used\n" + "-Dovsdb.userspace.enabled - true when Ovs is running in user space (usually the case with docker)\n" + "-Dovsdb.controller.address - IP address of the controller (usually the docker0 interface with docker)\n" + "To auto-run Ovs and connect actively:\n" + " -Dovsdb.controller.address=x.x.x.x -Dovsdb.userspace.enabled=yes [-Ddocker.compose.file=ffff]\n" + "To auto-run Ovs and connect passively:\n" + " -Dovsdbserver.connection=passive -Dovsdb.controller.address=x.x.x.x -Dovsdb.userspace.enabled=yes [-Ddocker.compose.file=ffff]\n" + "To actively connect to a running Ovs:\n" + " -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=6641 -Dovsdb.controller.address=y.y.y.y\n" + "To passively connect to a running Ovs:\n" + " -Dovsdbserver.connection=passive -Ddocker.run=false\n";Note: Ommiting the environment variable ovsdb.controller.address will cause DockerOvs to use a predefined docker network called "odl". This network's subnet must be 172.99.0.0/16 and its gateway must be defined as 172.99.0.254. If the "odl" network is not present, DockerOvs will create it for you. When DockerOvs does not run docker-compose getOvsdbAddress and getOvsdbPort return the address and port specified in the system properties.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Shut everything down.String[]
getExecCmdPrefix
(int numOvs) int
How many OVS nodes are there.getOvsdbAddress
(int ovsNumber) Get the IP address of the n'th OVS.getOvsdbPort
(int ovsNumber) Get the port of the n'th OVS.getOvsdbPort
(String ovsName) static org.ops4j.pax.exam.Option[]
Get the array of system properties as pax exam Option objects for use in pax exam unit tests with Configuration annotation.void
Useful for debugging.int
runInContainer
(int reserved, int waitFor, int numOvs, String... cmdWords) void
runInContainer
(int waitFor, int numOvs, String... cmdWords) int
runInContainer
(int reserved, int waitFor, StringBuilder capturedStdout, int numOvs, String... cmdWords) void
tryInContainer
(String logText, int waitFor, int numOvs, String... cmdWords) boolean
Are we using some other OVS, not a docker we spin up?.
-
Constructor Details
-
DockerOvs
Bring up all docker images in the default docker-compose file.- Throws:
IOException
- if something goes wrong on the IO endInterruptedException
- If this thread is interrupted
-
DockerOvs
Bring up all docker images in the provided docker-compose file under "META-INF/docker-compose-files/".- Parameters:
yamlFileName
- Just the file name- Throws:
IOException
- if something goes wrong on the IO endInterruptedException
- If this thread is interrupted
-
-
Method Details
-
getSysPropOptions
public static org.ops4j.pax.exam.Option[] getSysPropOptions()Get the array of system properties as pax exam Option objects for use in pax exam unit tests with Configuration annotation.- Returns:
- List of Option objects
-
usingExternalDocker
public boolean usingExternalDocker()Are we using some other OVS, not a docker we spin up?.- Returns:
- true if we are *not* running a docker image to test against
-
getOvsdbAddress
Get the IP address of the n'th OVS.- Parameters:
ovsNumber
- which OVS?- Returns:
- IP string
-
getOvsdbPort
Get the port of the n'th OVS.- Parameters:
ovsNumber
- which OVS?- Returns:
- Port as a string
-
getOvsdbPort
-
getNumOvsNodes
public int getNumOvsNodes()How many OVS nodes are there.- Returns:
- number of running OVS nodes
-
getExecCmdPrefix
-
runInContainer
public void runInContainer(int waitFor, int numOvs, String... cmdWords) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
runInContainer
public int runInContainer(int reserved, int waitFor, int numOvs, String... cmdWords) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
runInContainer
public int runInContainer(int reserved, int waitFor, StringBuilder capturedStdout, int numOvs, String... cmdWords) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
tryInContainer
public void tryInContainer(String logText, int waitFor, int numOvs, String... cmdWords) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
close
Shut everything down.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
InterruptedException
-
logState
Useful for debugging. Dump some interesting config- Throws:
IOException
- If something goes wrong with reading the process outputInterruptedException
- because there's some sleeping in here
-