-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add preflight checks integration tests #3816
add preflight checks integration tests #3816
Conversation
@rhcarvalho The golang part of this is really just running playbooks (in parallel), checking for expected outcomes, and displaying the results nicely. It does seem like the sort of thing that could be done with pytest instead, and prettier. Re boilerplate, I think I've reduced the setup part about as much as possible. It is probably worth exploring a callback plugin for teardown rather than having the exception-handling block in every test. I don't know that we need to block this PR in order to finish that work though. Just a couple small things I'd like to do first:
|
The experiment to be done is to use pytest + pytest-xdist. And look out for flakiness. |
So, yeah... did those little things. |
The tests all pass if I run However with
I don't understand what the difference is between the two. |
Digging a little deeper, tox seems to be running its own ansible, which doesn't work quite the same as the system ansible I get from my path when I run ansible-playbook more directly. I get the same result if I run the vendored ansible. I bumped up debugging and had a closer look. The setup step runs a little differently, and afterward the facts seem to be wiped out. Not sure what's happening here:
|
Tests run if I modify requirements.txt to have |
requirements.txt
Outdated
@@ -1,4 +1,6 @@ | |||
ansible>=2.2 | |||
# ansible 2.2.2.0 inexplicably fails integration tests under tox; |
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.
I did get tests to run fine from a source checkout of ansible-2.2.2.0 but tox uses what pip gets so it seems there is still some difference.
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.
What's the error you saw?
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.
described at #3816 (comment)
I really don't want this in here so I'll keep fiddling with it as the CI work comes along.
@sdodson this adds integration tests to tox. However they're not running in travis and I assume they should be. How do we make that happen? How do we get them running in the jenkins test/merge also/instead? Also how do we ensure the local requirements of the tests (docker + golang) are available? |
Hey, we will probably not run them on Travis. Our usage of Travis within the As integration tests start taking time to run, we don't want to be affecting Travis builds across all projects. |
Right, makes sense. So I'm curious why travis isn't trying to run integration tests now? It's just another environment in tox.ini added in this PR. |
Can't see to find it... I have a vague memory that So to run an environment "foo" you have to explicitly select it: |
requirements.txt
Outdated
@@ -1,4 +1,6 @@ | |||
ansible>=2.2 | |||
# ansible 2.2.2.0 inexplicably fails integration tests under tox; |
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.
What's the error you saw?
test/integration/README.md
Outdated
or increase concurrency: | ||
|
||
``` | ||
go test ./test/integration/... -p 8 -run TestPackageUpdateDepMissing |
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.
-p
tells go test
how many packages to test in parallel... -parallel
operates within a single package.
Either way, I'd leave this discussion off the README and go with the defaults (based on number of CPU cores).
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.
did not know that, interesting. Actually the test script will provide this option, so I'll just leave it out of the README.
@@ -0,0 +1,2 @@ | |||
FROM centos/systemd | |||
RUN yum install -y iproute python-dbus PyYAML yum-utils |
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.
I think I never understood why openshift-ansible doesn't use ansible to install those... @sosiouxme do you happen to know?
checks: [ 'package_update' ] | ||
|
||
always: # destroy the container whether check passed or not | ||
- include: ../../teardown_container.yml |
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.
We need to isolate setup and teardown from the actual test, to avoid copy-pasting this snippet all the time.
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.
Agreed about teardown, I'm pretty sure that can go in a callback plugin.
For setup, you're always going to need some way to specify the various parameters for the host, which is most of what's copy-pasted. It could be a little cleaner if there were a setup action or something like that.
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.
We might have better luck using the test framework for that, not YAML.
import ( | ||
"testing" | ||
|
||
. ".." |
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.
FTR, this is something I wrote and I don't like it; but to use absolute imports we need to have the code checked out appropriately within a GOPATH.
The unit test failures (incl. Travis) were caused by the way we instantiate action plugins in tests, something that manifested itself only in Ansible 2.3 and fixed in #3919. |
docker-py is needed on the host. thinking of running this under tox after all... |
So now the integration tests actually run, and fail the same way they do locally for me. So it's not just something nuts about my setup. Progress! |
The test runner fails under ansible 2.2.2+ because it no longer sets facts on the test hosts the way it's supposed to. I do not think we want to drag the rest of the tests back to ansible 2.2.1 so I created a separate tox config under |
test/integration/run-tests.sh
Outdated
STARTTIME=$(date +%s) | ||
source_root=$(dirname "${0}") | ||
|
||
prefix="${PREFIX:-openshift-ansible-integration-}" |
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.
I noticed we're defaulting this value in multiple places -- 5 occurrences of openshift-ansible-integration-
in this PR. What's the case when we would actually use a different prefix?!
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.
That case is when we're building the images separately and pushing them to a shared registry to be used in tests running in later CI jobs. I wrote this originally expecting that's what we would do, then I learned the shared registry isn't ready yet. Assuming that becomes available, it should just require setting parameters in the Jenkins jobs.
test/integration/run-tests.sh
Outdated
go test ./${source_root#$PWD}/... ${gotest_options} \ | ||
|| retval=$? | ||
|
||
ENDTIME=$(date +%s); echo "$0 took $(($ENDTIME - $STARTTIME)) seconds" |
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.
I think this is a copy-paste from scripts in Origin... go test
already prints how long tests took, we could simplify the script and its output by removing this. WDYT?
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.
Would be fine with me; FWIW this also captures the time to set up the virtualenv. shrug
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.
ripped out
test/integration/tox.ini
Outdated
@@ -0,0 +1,14 @@ | |||
[tox] |
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.
I see we had a different requirement on the Ansible version because of the issue with delegate_to
, but we could probably still get away with a single tox.ini file in the repository. Earlier this year we've unified /tox.ini and /utils/tox.ini to avoid having to maintain two sets of configuration files.
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.
Would be happy to do that. I'm not an expert on tox config :) but it looked to me like that would mean specifying ansible version individually in tox.ini on each environment. Otherwise, if I left the ansible requirement in shared requirements.txt and tried to specify a different one just for integration, it complained about the mismatch. Is there a way to do it?
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.
It's good to keep ansible in requirements.txt
, because for a python developer that's the fist place she would look into and setup runtime requirements in a virtual env (unrelated to tox).
The mismatch is most likely related to how pip works so far... I remember seeing an open issue to allow it to resolve required versions when two sources ask for different versions. The workaround is to call pip twice.
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.
How do you get tox to call pip twice with different reqs? Or I suppose we could call it manually to update ansible after tox, though that seems odd to me...
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.
Have pip install ansible==2.2.1.0 be the integration test "command" :)
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.
Yes, that's the workaround. I think we've done that before. Odd, yes :)
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.
@rhcarvalho OK, done! Testing at https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible_tox/61/ but local tests went fine so I expect it to work. Travis already passed.
@sosiouxme do you know if there's any flag to make the output less verbose? The interesting line is buried in a ton of useless minutia:
More interesting than a GREEN test is to see how RED tests look like, and to make sure that when tests fail people can actually understand the output. |
On Tue, Apr 18, 2017 at 7:58 AM, Rodolfo Carvalho ***@***.***> wrote:
@sosiouxme <https://github.com/sosiouxme> do you know if there's any flag
to make the output less verbose?
Most of the console output is from the ansible run for setup/teardown,
which is from the Jenkins job. If the tests succeeded, it's pretty hard to
find the actual test output, but then, you hardly need to. If the tests
fail, you can generally find a link or some red text. I wish it could be
better sectioned out, perhaps indexed at the top by Jenkins stage.
More interesting than a GREEN test is to see how RED tests look like, and
to make sure that when tests fail people can actually understand the output.
Here's a test failure:
https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible_tox/58/
I think our output there is pretty good, but we may want to expand the
number of lines of output shown on a failing test.
|
aos-ci-test |
@sosiouxme this needs a rebase. I haven't had time to try out using pytest-xdist as a test runner. Instead of blocking on this for longer, I'm okay with getting what we have in and following up later. Please let's do our best to make sure our integration tests don't end up blocking the merge queue. |
also, there seems to be room for a |
To make room for integration tests.
Make the container setup and teardown more reusable. Remove example tests. Add basic package tests.
Add some scripts that can be run from Jenkins to build/push test images and to run the tests. Updated README to expand on running tests.
@rhcarvalho I rebased, and rearranged commits a bit. I think the ones left are the right level of granularity. Will make sure the tests pass, need an approved review to merge... |
# So for now, install separate ansible version for integration. | ||
# PR that fixes it: https://github.com/ansible/ansible/pull/23599 | ||
# Once that PR is available, drop this and use same ansible. | ||
integration: pip install ansible==2.2.1.0 |
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.
👍
@@ -12,6 +13,7 @@ deps = | |||
-rrequirements.txt | |||
-rtest-requirements.txt | |||
py35-flake8: flake8-bugbear==17.3.0 | |||
integration: docker-py==1.10.6 |
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.
👍
aos-ci-test |
[merge] at last |
[test]ing while waiting on the merge queue |
Evaluated for openshift ansible test up to e5f14b5 |
continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible/75/) (Base Commit: d5ec349) |
Flake openshift/origin#8571 |
Evaluated for openshift ansible merge up to e5f14b5 |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_openshift_ansible/293/) (Base Commit: 760bdbc) |
Adds some integration tests that can run preflight checks against inventory made up of throwaway docker containers, and test for expected results.