Skip to content

Configured Travis CI to run cookbooks via Test Kitchen#266

Closed
migurski wants to merge 6 commits intoopenstreetmap:masterfrom
migurski:migurski+jalessio/kitchen-separate-platform
Closed

Configured Travis CI to run cookbooks via Test Kitchen#266
migurski wants to merge 6 commits intoopenstreetmap:masterfrom
migurski:migurski+jalessio/kitchen-separate-platform

Conversation

@migurski
Copy link
Copy Markdown
Contributor

@migurski migurski commented Feb 9, 2020

In #259, we noted that observing Test Kitchen outputs required manual sharing of logs and some conversation about working Test Kitchen installations. This PR introduces the possibility of testing Chef cookbooks right in Travis CI, thanks to the use of Docker under Kitchen-Dokken which will successfully complete in a virtual environment such as Travis.

@jalessio and I have started with the small Apt cookbook suite as a proof of concept. Cookstyle and Kitchen tests now run in parallel with logs that can be shared and observed between editors in PRs to this repo. The end-user display in Travis is pretty nice:

Screen Shot 2020-02-09 at 12 08 11 PM

If accepted, future work would include adding each cookbook suite (Wiki, Website, etc.) in turn to the Travis config and ensuring that it passes tests. @gravitystorm has recommended that we break this work up over time and add remaining suites in followup PRs.

Notes:

  • We’ve defined the Kitchen-Dokken platform somewhat redundantly to leave the current Vagrant default untouched. A future version of .kitchen.yml could be simplified a lot by abandoning Vagrant entirely, but for now this change should be completely backwards-compatible with existing Vagrant setups.
  • Current Travis time limitation is 50 minutes per matrix build job. Optimistically this should cover all of our needs, but as we add Cookbook tests we may find that some of them run very slowly. We can try to increase our runtime ceiling with a paid Travis plan or use an alternate Test Kitchen driver such as EC2 if we encounter this problem in the future.
  • Any Kitchen command with the current Vagrant driver present requires that vagrant --version returns a valid version string. Since we can’t actually run Vagrant/Virtualbox on Travis, we cheat a little here by generating a one-line /usr/bin/vagrant to echo a fake version string. We could also apt-get install vagrant to be more correct, with some startup time cost.

jalessio and others added 4 commits February 9, 2020 18:44
With Kitchen-Dokken in place, Travis should now successfully run both
the Cookstyle script and individual Kitchen tests as separate matrix builds.
Matrix builds will run in parallel, and the global Travis 50min limit
should apply to each separately ensuring that all cookbooks get tested.

https://docs.travis-ci.com/user/build-matrix/
@tomhughes
Copy link
Copy Markdown
Member

This rather overlaps with the work I've been going to try and run the tests under docker but as expected my experience is that not all of them can be run under docker so unless you have a magic solution for that I'm not sure this is a feasible approach?

@tomhughes
Copy link
Copy Markdown
Member

Incidentally I've never heard of the "dokken" driver - what made you chose that over the standard docker driver?

@migurski
Copy link
Copy Markdown
Contributor Author

migurski commented Feb 9, 2020

Andy recommended the Dokken driver: it’s designed to emulate complete systems, has a functioning init, and is built specifically for Test Kitchen and Chef. @jalessio and I went some distance down the path of the plain Docker driver and found that we were duplicating existing work from Dokken.

@jalessio
Copy link
Copy Markdown
Contributor

jalessio commented Feb 9, 2020

my experience is that not all of them can be run under docker so unless you have a magic solution for that I'm not sure this is a feasible approach?

@tomhughes I can't definitively say yet that all of these will run under Docker, but one of the main issues I've encountered while testing Chef cookbooks via Docker is that you often need an init system running in order to test daemons such as MySQL. We got over this hurdle by utilizing the line pid_one_command: /bin/systemd (which also requires the addition of privileged: true). With this in place you can start multiple background processes (and make assertions against them). This unlocks a lot of testing possibilities with Docker + Chef + Test Kitchen.

I have a branch which uses this code to test the mysql cookbook from this repo, which demonstrates that the MySQL daemon starts successfully as part of the CI suite using Docker on Travis. It's part of this build (https://travis-ci.org/jalessio/openstreetmap-chef/builds/648127647) and sample MySQL logs are here (https://travis-ci.org/jalessio/openstreetmap-chef/jobs/648127652).

My kitchen-add-passing-cookbooks-to-ci branch currently has builds working on Travis for 6 of the 14 cookbooks in this repo. On that branch, I only added cookbooks which passed without any modification (as an easy starting point).
Screen Shot 2020-02-09 at 1 07 47 PM
(screenshot from https://travis-ci.org/jalessio/openstreetmap-chef/builds/648127647)

I haven't dug into each of the failing cookbooks yet, but I don't think the failures are necessarily related to using Docker since they are failing for reasons like missing test Data Bags (meaning they probably fail under Vagrant too).

As for utilizing Dokken, it does take care of some things we'd have to build anyway to make this work and my confidence was boosted when I saw it being used extensively in the check-cookbooks repo.

@tomhughes
Copy link
Copy Markdown
Member

Yes the init system is the main issue but I did actually have that running and still had some issues. Plus I was actually using podman and I wasn't sure real docker was up to running systemd as pid one.

I'll try and have a look at this at some point this week.

@tomhughes
Copy link
Copy Markdown
Member

Is there a reason why you have added kitchen-dokken as a separate platform rather than just switching to it?

I'd rather not have the complexity of supporting two different platforms for the tests if we can avoid it, and it we can make the tests run in a container environment then that would seem to be the better option from a performance point of view.

Personally I would have preferred it if this PR was split in two so that we could address the question of which driver to use separately from the question of running the tests in travis - aside from anything else I'm not sure it's actually practical to run the tests in travis once we have more testing just because of the length of time it would take.

I've had a brief look at kitchen-dokken and I can see how it speeds things up more - sadly it looks like it works via the docker API so requires real docker with a daemon which is less than ideal for me personally but that's not a deal breaker.

@migurski
Copy link
Copy Markdown
Contributor Author

Re: separate platform, Jamie and I had set up Docker as a complete Vagrant replacement originally and then looked for a way to make this change less invasive. This PR introduces Docker specifically for use in CI without upending any existing Vagrant setup you or anyone else from the OWG or sysadmins teams might have. A future version of .kitchen.yml could be simplified a lot by abandoning Vagrant entirely but it seemed very drastic for this proof of concept.

Re: split PR, I’m unsure it’s possible to split these two ideas. Only a Docker-based driver will work on hosted CI like our Travis integration. We previously tried to make this change work without a new driver but I think these two modifications have to go hand-in-hand. It’s possible to address the length of time by increasing our Travis parallelism with a paid plan: most of these test suites are quite speedy.

Glad to hear Docker is not a deal-breaker for you!

@tomhughes
Copy link
Copy Markdown
Member

The thing is that I'm reluctant to commit to a specific technology until we know it will work across the board, which is why I'd rather look at switching technology to something that will work in travis first.

Once I've reinstalled docker here I'll have a go with this and see how it goes across the whole range of test suites to get some idea of what the status is. I have my own notes from trying kitchen-docker as a baseline to compare to.

@tomhughes
Copy link
Copy Markdown
Member

Unfortunately it turns out that Fedora 31 can't run docker anymore, at least not without rebooting to go back to groupsv1, so I'm not going to be able to test this right now.

@tas50
Copy link
Copy Markdown
Contributor

tas50 commented Feb 10, 2020

Kitchen-dokken is our preferred method of testing chef cookbooks in CI systems. Kitchen-docker's PID 1 won't allow you to test most services. Kitchen-dokken will properly allow starting services. That coupled with the dokken images, which are "fat" containers allowing for full service testing, and you have fairly complete testing setup that can run in most CI environments.

@Firefishy Firefishy self-requested a review February 10, 2020 19:47
@tomhughes
Copy link
Copy Markdown
Member

I believe I've now fixed all the outstanding issues with the tests, and have a configuration at https://github.com/tomhughes/openstreetmap-chef/tree/dokken that can run them all in docker and in travis, as seen here:

https://travis-ci.org/tomhughes/openstreetmap-chef/builds/649655674

@migurski
Copy link
Copy Markdown
Contributor Author

Exciting! Do you plan to accept this compatible PR which includes comments in the config files explaining how things work, or would you like for us to close #266 out so you can use the version you’ve written?

@tomhughes
Copy link
Copy Markdown
Member

I took the commits from this PR and rearranged them slightly then added my work on top so that preserve as best as possible attribution for the work - that is all now pushed on master.

The only thing I haven't taken is the comments - many of them were either no longer relevant or were just documenting stuff that was boilerplate from the dokken instructions so I left them out.

Hopefully that all works for you, and thanks for your work on this, and for finding dokken!

@tomhughes tomhughes closed this Feb 13, 2020
@migurski
Copy link
Copy Markdown
Contributor Author

This works, and I’m excited to see new expanded test coverage on master!

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.

6 participants