This repository has been archived by the owner on Oct 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Changes to enable ST tests of golang calicoctl #163
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
901cbed
Code tidy up
lwr20 fca7c45
Add flag to calicoctl to choose python or Go calicoctl
lwr20 10341a9
Add assert_same function
lwr20 37fdc77
Updated docstring
lwr20 76ffb59
Change default calicoctl name to avoid breaking libnetwork-plugins tests
lwr20 c06e723
Logging and PEP8 improvements
lwr20 7a6e382
Add etcdctl to test container
lwr20 130589e
Move dictionary comparison to test_calicoctl.py
lwr20 450e36c
symlink etcdctl in same image layer as download
lwr20 a7a671a
Use calicoctl-go where possible
lwr20 c124d5f
Remove stray merge error
lwr20 69be47a
Remove mutable kwarg
lwr20 36b3d77
Add useful functions to test_base
lwr20 4eec3fa
Add method to write files onto hosts
lwr20 ef53a24
Load route reflector from a tgz file
lwr20 b99d401
Make tcp and udp checks work, add tests using them
lwr20 397108e
Changed hostname to node to match data model
lwr20 1b83a88
Write files out to debug logs
lwr20 0a94e29
New calicoctl supports running calico-node, no need for the old
lwr20 d0aa561
Review markups
lwr20 8e9cf44
Use golang calicoctl for everything
lwr20 4eb9cdc
Use tar images
lwr20 57961e0
Use tar images
lwr20 cfa0979
Always use golang calicoctl
lwr20 e5945c8
We now always use golang calicoctl
lwr20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
# running of the ST frameworks. Additionally, this allows for sharing of | ||
# common ST framework code (which calico-containers and libnetwork both use). | ||
# To run: | ||
# - volume mount the docker socket, allowing the STs to launch docker | ||
# - volume mount the docker socket, allowing the STs to launch docker | ||
# containers alongside itself. | ||
# - eliminate most isolation, (--uts=host --pid=host --net=host --privileged) | ||
# - volume mount your ST source code | ||
|
@@ -37,10 +37,10 @@ FROM docker | |
MAINTAINER Tom Denham <[email protected]> | ||
|
||
# Running STs in this containers require that it has all dependencies installed | ||
# for executing calicoctl. Install these dependencies (including glibc: | ||
# for executing calicoctl. Install these dependencies (including glibc: | ||
# https://github.com/jeanblanchard/docker-alpine-glibc/blob/master/Dockerfile) | ||
# We install glibc onto the official docker image (instead of adding docker to | ||
# the libc image) since glibc installs are more constant than the | ||
# We install glibc onto the official docker image (instead of adding docker to | ||
# the libc image) since glibc installs are more constant than the | ||
# docker-in-docker installation and configuration. | ||
RUN apk add --update python python-dev py-pip py-setuptools \ | ||
git musl-dev gcc \ | ||
|
@@ -62,6 +62,11 @@ RUN pip install -r /tmp/pycalico/calico_test/requirements.txt | |
# Add the testing framework | ||
ADD calico_test/tests tests | ||
|
||
# Install etcdctl | ||
RUN wget https://github.com/coreos/etcd/releases/download/v2.3.3/etcd-v2.3.3-linux-amd64.tar.gz && \ | ||
tar -xzf etcd-v2.3.3-linux-amd64.tar.gz && \ | ||
cd etcd-v2.3.3-linux-amd64 && \ | ||
ln -s etcdctl /usr/local/bin/ | ||
|
||
# The container is used by mounting the code-under-test to /code | ||
WORKDIR /code/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ monotime | |
ConcurrentLogHandler | ||
pyyaml | ||
simplejson | ||
deepdiff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,33 @@ | |
from functools import partial | ||
|
||
from utils import get_ip, log_and_run, retry_until_success, ETCD_SCHEME, \ | ||
ETCD_CA, ETCD_KEY, ETCD_CERT, ETCD_HOSTNAME_SSL | ||
ETCD_CA, ETCD_KEY, ETCD_CERT, ETCD_HOSTNAME_SSL | ||
from workload import Workload | ||
from network import DockerNetwork | ||
|
||
logger = logging.getLogger(__name__) | ||
CHECKOUT_DIR = os.getenv("HOST_CHECKOUT_DIR", os.getcwd()) | ||
# We want to default CHECKOUT_DIR if either the ENV var is unset | ||
# OR its set to an empty string. | ||
CHECKOUT_DIR = os.getenv("HOST_CHECKOUT_DIR", "") | ||
if CHECKOUT_DIR == "": | ||
CHECKOUT_DIR = os.getcwd() | ||
|
||
|
||
class DockerHost(object): | ||
""" | ||
A host container which will hold workload containers to be networked by | ||
Calico. | ||
|
||
:param calico_node_autodetect_ip: When set to True, the test framework | ||
will not perform IP detection, and will run `calicoctl node` without explicitly | ||
passing in a value for --ip. This means calico-node will be forced to do its IP detection. | ||
:param override_hostname: When set to True, the test framework will choose an alternate | ||
hostname for the host which it will pass to all calicoctl components as the HOSTNAME | ||
environment variable. If set to False, the HOSTNAME environment is not explicitly set. | ||
will not perform IP detection, and will run `calicoctl node` without | ||
explicitly passing in a value for --ip. This means calico-node will be | ||
forced to do its IP detection. | ||
:param override_hostname: When set to True, the test framework will | ||
choose an alternate hostname for the host which it will pass to all | ||
calicoctl components as the HOSTNAME environment variable. If set | ||
to False, the HOSTNAME environment is not explicitly set. | ||
""" | ||
|
||
def __init__(self, name, start_calico=True, dind=True, | ||
additional_docker_options="", | ||
post_docker_commands=["docker load -i /code/calico-node.tar", | ||
|
@@ -48,16 +56,18 @@ def __init__(self, name, start_calico=True, dind=True, | |
self.workloads = set() | ||
self.ip = None | ||
""" | ||
An IP address value to pass to calicoctl as `--ip`. If left as None, no value will be passed, | ||
forcing calicoctl to do auto-detection. | ||
An IP address value to pass to calicoctl as `--ip`. If left as None, | ||
no value will be passed, forcing calicoctl to do auto-detection. | ||
""" | ||
|
||
self.ip6 = None | ||
""" | ||
An IPv6 address value to pass to calicoctl as `--ipv6`. If left as None, no value will be passed. | ||
An IPv6 address value to pass to calicoctl as `--ipv6`. If left as | ||
None, no value will be passed. | ||
""" | ||
|
||
self.override_hostname = None if not override_hostname else uuid.uuid1().hex[:16] | ||
self.override_hostname = None if not override_hostname else \ | ||
uuid.uuid1().hex[:16] | ||
""" | ||
Create an arbitrary hostname if we want to override. | ||
""" | ||
|
@@ -78,16 +88,19 @@ def __init__(self, name, start_calico=True, dind=True, | |
log_and_run("docker rm -f %s || true" % self.name) | ||
# Pass the certs directory as a volume since the etcd SSL/TLS | ||
# environment variables use the full path on the host. | ||
# Set iptables=false to prevent iptables error when using dind libnetwork | ||
# Set iptables=false to prevent iptables error when using dind | ||
# libnetwork | ||
log_and_run("docker run %s " | ||
"calico/dind:latest " | ||
" --storage-driver=aufs " | ||
"--iptables=false " | ||
"%s" % | ||
(docker_args, additional_docker_options)) | ||
(docker_args, additional_docker_options)) | ||
|
||
self.ip = log_and_run("docker inspect --format " | ||
"'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" % self.name) | ||
self.ip = log_and_run( | ||
"docker inspect --format " | ||
"'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" % | ||
self.name) | ||
|
||
# Make sure docker is up | ||
docker_ps = partial(self.execute, "docker ps") | ||
|
@@ -96,7 +109,8 @@ def __init__(self, name, start_calico=True, dind=True, | |
for command in post_docker_commands: | ||
self.execute(command) | ||
elif not calico_node_autodetect_ip: | ||
# Find the IP so it can be specified as `--ip` when launching node later. | ||
# Find the IP so it can be specified as `--ip` when launching | ||
# node later. | ||
self.ip = get_ip(v6=False) | ||
self.ip6 = get_ip(v6=True) | ||
|
||
|
@@ -121,7 +135,6 @@ def execute(self, command): | |
|
||
return log_and_run(command) | ||
|
||
|
||
def calicoctl(self, command): | ||
""" | ||
Convenience function for abstracting away calling the calicoctl | ||
|
@@ -151,21 +164,20 @@ def calicoctl(self, command): | |
"export ETCD_KEY_FILE=%s; %s" % \ | ||
(etcd_auth, ETCD_SCHEME, ETCD_CA, ETCD_CERT, ETCD_KEY, | ||
calicoctl) | ||
# If the hostname is being overriden, then export the HOSTNAME environment. | ||
# If the hostname is being overriden, then export the HOSTNAME | ||
# environment. | ||
if self.override_hostname: | ||
calicoctl = "export HOSTNAME=%s; %s" % (self.override_hostname, calicoctl) | ||
calicoctl = "export HOSTNAME=%s; %s" % ( | ||
self.override_hostname, calicoctl) | ||
|
||
return self.execute(calicoctl + " " + command) | ||
|
||
def start_calico_node(self, options=""): | ||
""" | ||
Start calico in a container inside a host by calling through to the | ||
calicoctl node command. | ||
|
||
:param as_num: The AS Number for this node. A value of None uses the | ||
inherited default value. | ||
""" | ||
args = ['node'] | ||
args = ['node', 'run'] | ||
if self.ip: | ||
args.append('--ip=%s' % self.ip) | ||
if self.ip6: | ||
|
@@ -210,7 +222,6 @@ def start_calico_node_with_docker(self): | |
self.ip, | ||
etcd_auth, ETCD_SCHEME, ssl_args)) | ||
|
||
|
||
def remove_workloads(self): | ||
""" | ||
Remove all containers running on this host. | ||
|
@@ -354,7 +365,6 @@ def get_hostname(self): | |
Note, this function only works with a host with dind enabled. | ||
Raises an exception if dind is not enabled. | ||
|
||
:param host: DockerHost object | ||
:return: hostname of DockerHost | ||
""" | ||
# If overriding the hostname, return that one. | ||
|
@@ -363,3 +373,12 @@ def get_hostname(self): | |
|
||
command = "docker inspect --format {{.Config.Hostname}} %s" % self.name | ||
return log_and_run(command) | ||
|
||
def writefile(self, filename, data): | ||
""" | ||
Writes a file on a host (e.g. a yaml file for loading into calicoctl). | ||
:param filename: string, the filename to create | ||
:param data: string, the data to put inthe file | ||
:return: Return code of execute operation. | ||
""" | ||
return self.execute("cat << EOF > %s\n%s" % (filename, data)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need another EOF at the end of this string to terminate, yeah? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's weird, but it seems to work. Maybe docker adds the EOF or something. Since we're rushed I think it's fine as is. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick doc string here and below would be super