Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemtests now run completely in containers #46

Merged
merged 2 commits into from
Jan 6, 2017
Merged

systemtests now run completely in containers #46

merged 2 commits into from
Jan 6, 2017

Conversation

dseevr
Copy link
Contributor

@dseevr dseevr commented Dec 15, 2016

Copied from the top of systemtests.sh:

  1. builds a systemtests container
  2. creates a docker network (all containers are attached to it)
  3. starts an etcd container
  4. starts a consul container
  5. starts a systemtests container (does nothing by default)
  6. starts a ccn_proxy container on port 10000 linked to etcd
  7. starts a ccn_proxy container on port 10001 linked to consul
  8. executes ./scripts/systemtests_in_container.sh which runs all the systemtests against the etcd proxy and consul proxy
  9. stops etcd proxy container
  10. stops consul proxy container
  11. stops systemtests container
  12. stops etcd container
  13. stops consul container
  14. destroys the docker network

Fixes https://github.com/contiv/ccn/issues/84

@dseevr dseevr changed the title systemtests now launch etcd, consul, and ccn_proxy containers before running systemtests now run completely in containers Jan 6, 2017
@dseevr dseevr requested review from rhim and neelimamukiri January 6, 2017 00:20
@dseevr
Copy link
Contributor Author

dseevr commented Jan 6, 2017

As mentioned on Slack, CI will not pass until the firewall issue is resolved and the unit tests are also containerized (in progress)

Copy link
Contributor

@rhim rhim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions. Mostly looks good.

docker run --rm \
-p 10000:10000 \
-v $(pwd)/local_certs:/certs:ro \
ccn_proxy:devbuild \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is devbuild version hardcoded here?

Copy link
Contributor Author

@dseevr dseevr Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script can actually be deleted I guess. This was a convenience script for quickly testing the proxy during the early stages of development. There's now too many external components (datastore, netmaster, AD, etc.) to realistically have a universal "quick run" target.

-p 10000:10000 \
-v $(pwd)/local_certs:/local_certs:ro \
--network $NETWORK_NAME \
ccn_proxy:devbuild \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, why hardcode of version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default name when no BUILD_VERSION is given to the make build target.

Hmm... I was thinking about this in the context of a CI run (which invokes the make ci target which runs make build before tests run). I guess we can't make that assumption and need to always build the main proxy container before tests run (either systemtests or unit tests)

-p 10001:10001 \
-v $(pwd)/local_certs:/local_certs:ro \
--network $NETWORK_NAME \
ccn_proxy:devbuild \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same.

Copy link
Contributor Author

@dseevr dseevr Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be made into a variable. I missed it because originally there was only one proxy being spawned and I just copy-pasted and tweaked the --data-store-address and port

func Test(t *testing.T) {
if len(os.Getenv("DEBUG")) > 0 {
log.SetLevel(log.DebugLevel)
}

datastore := test.GetDatastore()
proxyHost = os.Getenv("PROXY_ADDRESS")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that systemtests assume that proxy is setup and running?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this will always be set before this container is invoked. Can you think of a use case for running systemtests in any other way than the make systemtests target?

I'll add a comment here that this is being set by systemtests_in_container.sh when the test suite is spun up



echo "Stopping etcd proxy container..."
docker stop $ETCD_PROXY_CONTAINER_ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker rm -f -v to do both in one shot? Same for all below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test this tomorrow and make sure it does The Right Thing™ when the container doesn't shut down in a timely manner. docker stop lets you specify a timeout (which I use when shutting down the systemtests container)

@dseevr
Copy link
Contributor Author

dseevr commented Jan 6, 2017

Removed scripts/run.sh, made the proxy image name a variable, replaced stop + rm -v with rm -f -v, and added a comment about where PROXY_ADDRESS is set

Also, cleaned up the systemtests.sh script a bit by moving some redundant IP stuff into a function and adding more comments

Copy link
Contributor

@neelimamukiri neelimamukiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Nice hack with the systemtest container start!

RUN apt-get update && apt-get -y upgrade && \
apt-get -y install curl build-essential docker.io

RUN curl -O https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will having this local save us some CI headaches?

Copy link
Contributor Author

@dseevr dseevr Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking that we put it into the repo itself? This will permanently increase the size of the repo by ~70mb for each version we upgrade to, and Github will start yelling at us and telling us to use their Large File Storage service 🙃

Also because we COPY the whole repo into our build container, it'll slow down almost every Docker-related operation we do here... 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points :) Ignore the suggestion. I wish we could build and push this to docker hub once and reuse it, though docker pull has its reliability issues too.

echo 1>&2 "${out}"
exit 1
# only build the base if necessary (saves a lot of time)
if [[ "$(docker images -q ccn_proxy_build_base 2>/dev/null)" == "" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when go version changes? Why is the image not being cached and how much additional time do you see this step taking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm going to remove the caching on this stuff and just change us to a more lightweight base image instead of using ubuntu:16.04

set -e
if [ "`echo \"${out}\" | sed '/^$/d' | wc -l`" -gt 0 ]
then
echo 1>&2 "gocycle errors in:"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gocycle -> gocyclo. Wouldn't it be simpler to move 10-60 to a function and call all the commands using it - something like run_check("gofmt", gofmt -s -l ${files}) ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script is originally from volplugin (https://github.com/contiv/volplugin/blob/0453e29b4d9916ae35ae492b9f3f302ff72bcc58/build/scripts/checks.sh) and we were using it verbatim. In this PR, I just removed the "fetch if not installed" lines because we're baking them in in the Dockerfile.checks

I'll fix this typo though :)

# 12. stops etcd container
# 13. stops consul container
# 14. destroys the docker network
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you use the mock server vs a real netmaster for the system tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a peek at any of the systemtests/*_test.go files and look for the runTest() function. Each systemtest has the MockServer injected into it and it can be programmed in a test-specific way.

Copy link
Contributor Author

@dseevr dseevr Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I misread the actual question being asked here. As mentioned on Slack, we don't support running the systemtests against a real netmaster for various logistical reasons. We use the mockserver to emulate the responses a real netmaster would send (@yuva29 did the heavy lifting on that) and validate that we process them properly.

docker exec $SYSTEMTESTS_CONTAINER_ID bash ./scripts/systemtests_in_container.sh $ETCD_PROXY_ADDRESS $CONSUL_PROXY_ADDRESS || true

# ---- CLEANUP ------------------------------------------------------------------

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the logs stored somewhere, in case things fail and we want to debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the test logs are written to stdout, and there's additional output if the DEBUG envvar is set. I actually need to pass -e DEBUG="$DEBUG" to the systemtests container docker run command...

I think having the tests clean up after themselves by default is a good idea, but I'm open to ideas around allowing state to hang around afterwards. Maybe a KEEP_CONTAINERS envvar you can set will result in the containers not being deleted? The downside there is that you would need to manually delete all the containers and then delete the Docker network before you could run the systemtests again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the CI gets them through stdout it is sufficient. For the rare cases where we need the containers themselves running (which is a pure proxy case should be very rare), we can change it then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run DEBUG=1 make systemtests, you'll now get log.Debug*() output on stdout/stderr as well 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Copy link
Contributor

@neelimamukiri neelimamukiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dseevr dseevr merged commit 55648a8 into contiv:master Jan 6, 2017
@dseevr dseevr deleted the make_testing_great_again branch January 6, 2017 23:34
dseevr pushed a commit to dseevr-dev/auth_proxy that referenced this pull request Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants