Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

[WIP] Add basic libvirt instance plugin #477

Merged
merged 4 commits into from Apr 25, 2017

Conversation

ijc
Copy link

@ijc ijc commented Apr 11, 2017

Supports basic VM creation but does not yet include storage or networking.
Hardcodes a bunch of things which should likely be exposed as properties, such
as the use of KVM and a serial console.

By default it targets qemu:///session which is a per-user session. To drive
the system instance run with --uri qemu:///system, this may require
authentication which is not yet supported (dependening on your desktop
environment it might result in a auth popup for each action).

The Label method is untested because I couldn't figure out how to cause it to
be called.

Signed-off-by: Ian Campbell ian.campbell@docker.com

@ijc
Copy link
Author

ijc commented Apr 11, 2017

Test failure is:

command cd $WORKDIR && make ci took more than 10 minutes since last output

which I guess is unrelated.

edit: it seems I'm able to kick retry myself, so I did.

@YujiOshima
Copy link
Contributor

@ijc25 Good Contribution! Please add some tests for libvirt instance!

@ijc
Copy link
Author

ijc commented Apr 11, 2017

@YujiOshima is there a good example of an existing plugin I can work from?

I looked at terraform and maas but they seem to operate against a dummy version of the service and/or stub out actually talking to the service. It looks like libvirtd has a mock driver so if it was allowable to install libvirtd in CI and use that I could likely put something together. I think we don't actually want to be starting real VMs in CI.

@rn
Copy link

rn commented Apr 11, 2017

https://github.com/docker/infrakit.gcp has a bunch of tests with mocks and the like. Maybe an inspiration?

@YujiOshima
Copy link
Contributor

I think that terraform or maas is good in the sense that they have many tests.

I think we don't actually want to be starting real VMs in CI.

I agree.
If you can use libvirtd's mock, I think it is a good choice, but since CircleCI's tests are run on a container it may be out of privileges.
In that case, what about using go mock(https://github.com/golang/mock)? I think that you can test by creating mock of libvirt / libvirt-go with go mock.

@YujiOshima
Copy link
Contributor

Ah @rneugeba looks referred same. infrakit.gcp is using gomock.

@chungers
Copy link
Contributor

The build inside Docker container failed... compiling libvirt:

go build -o build/infrakit-instance-libvirt -ldflags "-X github.com/docker/infrakit/pkg/cli.Version=6d612f0 -X github.com/docker/infrakit/pkg/cli.Revision=6d612f0fe4b82cdbf733d9a4da51b24e171f5cf8 -X github.com/docker/infrakit/pkg/util/docker.ClientVersion=1.24" github.com/docker/infrakit/cmd/instance/libvirt
# pkg-config --cflags libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt
Package libvirt was not found in the pkg-config search path.
Perhaps you should add the directory containing `libvirt.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found
Package 'libvirt', required by 'virtual:world', not found

@ijc
Copy link
Author

ijc commented Apr 12, 2017

@chungers I'll take a look, thanks (LOL @ pkg-config --cflags libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt libvirt, it really wants that package!)

@rneugeba / @YujiOshima it's not clear to me that mocking is all that useful here: the interesting thing to test is whether the XML given to the libvirt APIs (as a bare string) is well formed and semantically meaningful etc, which I don't think mock is capable of (I'd have to manually write the expected XML in the mock, but whose to say that matches what libvirt wants).

I'm going to try and use the test:// URI endpoint, perhaps with a locally spawned instance of the daemon, and test against that.

@codecov
Copy link

codecov bot commented Apr 12, 2017

Codecov Report

Merging #477 into master will increase coverage by 0.13%.
The diff coverage is 58.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
+ Coverage   56.65%   56.79%   +0.13%     
==========================================
  Files          53       54       +1     
  Lines        3401     3622     +221     
==========================================
+ Hits         1927     2057     +130     
- Misses       1241     1296      +55     
- Partials      233      269      +36
Impacted Files Coverage Δ
pkg/plugin/instance/libvirt/instance.go 58.82% <58.82%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8d3837...8bde7a3. Read the comment docs.

@ijc
Copy link
Author

ijc commented Apr 12, 2017

Fixed the container build and CI is nopw passing. I still want to add some tests. NB Friday and Monday are public holidays here and I'm on PTO on Thursday, so it might not be until next week.

@chungers chungers changed the title Add basic libvirt instance plugin [WIP] Add basic libvirt instance plugin Apr 12, 2017
Supports basic VM creation but does not yet include storage or networking.
Hardcodes a bunch of things which should likely be exposed as properties, such
as the use of KVM and a serial console.

By default it targets `qemu:///session` which is a per-user session. To drive
the system instance run with `--uri qemu:///system`, this may require
authentication which is not yet supported (dependening on your desktop
environment it might result in a auth popup for each action).

The `Label` method is untested because I couldn't figure out how to cause it to
be called.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
@ijc
Copy link
Author

ijc commented Apr 18, 2017

Forced update:

  • Added basic tests (basic lifecycle and labelling) using the libvirt test driver
  • Ramdisk is now optional
  • DomainType is now configurable (kvm vs ???)
  • Ignore unknown domains which do not have the expected metadata fields

@chungers my TestLabel and plugin.Label functions were cowritten with my own (perhaps^Wprobably flawed) interpretation of what the Label method is supposed to do...

@YujiOshima
Copy link
Contributor

YujiOshima commented Apr 18, 2017

@ijc25 Great!
Why did you put the libvirt plugin code under cmd/instance instead of putting it under /examples like other plugins?

@YujiOshima
Copy link
Contributor

@ijc25 I am sorry, I was misunderstanding, I edited my comment.


require.False(t, instanceExists(t, plugin, instance.ID(domname)), "domain was found in plugin instances before label")

labels := map[string]string{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Set not only emply but also some labels and check it.
Set some label when provisioning and add or edit labels with Label function.

Copy link
Author

Choose a reason for hiding this comment

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

Set some label when provisioning and add or edit labels with Label function.

I'll do that when someone points me to the documentation regarding the correct/expected semantics of the Label method. Otherwise I'm just guessing how it supposed to work and writing the answers to my guesses in both the implementation and the test.

@ijc
Copy link
Author

ijc commented Apr 19, 2017

@YujiOshima:

Why did you put the libvirt plugin code under cmd/instance instead of putting it under/examples like other plugins?

@chungers asked me to do it this way.

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "instance-libvirt" git@github.com:ijc25/infrakit.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354339792
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@chungers
Copy link
Contributor

@ijc25 can this work with virtualbox on MacOSX? I think we can merge this to get it in and iterate.

@ijc
Copy link
Author

ijc commented Apr 25, 2017

@chungers

can this work with virtualbox on MacOSX?

Does libvirt run on MacOSX and support VB there? If so then it ought to be possible to make it work. Note that libvirt doesn't abstract away all of the hypervisor specific bits and I've written/tested this with Qemu/KVM under Linux plus the test driver only so it is likely there will be a need to parameterise some more things to support other hypervisors and depending on the functionality available under those other hypervisors perhaps adding support for things like booting from ISO (e.g. if VB doesn't support direct kernel boot). Should all be pretty minor updates compared with the scaffolding added here though.

Looks like you have a policy of back merging master into the PR branches before merging, so I won't proactively rebase this PR now but if you would like me to do so just holler.

@chungers
Copy link
Contributor

@ijc25 - let's merge this and iterate. Thanks for starting this plugin!

@chungers chungers merged commit 09ae23d into docker-archive:master Apr 25, 2017
@ijc ijc deleted the instance-libvirt branch April 26, 2017 08:46
chungers pushed a commit to chungers/infrakit that referenced this pull request Sep 30, 2017
Updated Azure logs to match AWS format
chungers pushed a commit to chungers/infrakit that referenced this pull request Oct 1, 2017
Updated Azure logs to match AWS format
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants