rgbkrk / libvirt-go

[DEPRECATED] Go bindings for libvirt
https://github.com/libvirt/libvirt-go
MIT License
166 stars 50 forks source link

Added Dockerfile to run the tests. #35

Closed cbosdo closed 8 years ago

cbosdo commented 10 years ago

Disclaimer: I am aware that this commit may be considered useless by vagrant fans, however, vagrant+virtualbox is a nogo on my dev machine running KVM.

Vagrant has the inconvenient to be depending on VirtualBox, while docker is just easy to setup. To run the tests, just run those two commands:

sudo docker build -t libvirt-go:master .
sudo docker run -ti --rm libvirt-go:master

This could be made even easier through a simple Makefile

cbosdo commented 10 years ago

huh... looks like drone.io doesn't like when I push from branches that don't exist in the forked repo... weird

alexzorin commented 10 years ago

The problem with drone is apparently fixed, I've tried updating the build server but had to wipe out old builds .. not sure. Might change CI.

cbosdo commented 10 years ago

I'll have a look at the integration tests.... didn't know about them until then. BTW testing libvirt-lxc wrapper against lxc sounds weird to me ;)

cbosdo commented 10 years ago

Integration tests are now running like a charm in the docker container:

To run the integration tests:

sudo docker run -ti --privileged --rm libvirt-go:master go test -tags integration
alexzorin commented 10 years ago

That's cool - probably means I can add the integration tests to CI as well (since that runs on Docker too).

I'll take a look at it all this weekend hopefully

cbosdo commented 10 years ago

Indeed, that would be a super good news :)

cbosdo commented 10 years ago

Now libvirtd and libvirt keep quiet, it's easier to see the actual tests run output in the log. Note that the last commit will need to be merged with the PR #34

alexzorin commented 10 years ago

Please remove ac9fabe from this PR, I've merged that commit on its own (also rebase on new master if you have the time).

Re: virtualbox, I'm thinking that I'll leave a vagrant script to run Docker inside virtualbox and then use docker as the primary testing env

cbosdo commented 10 years ago

Just removed that commit and rebased on master. Regarding vagrant, it's OK for me to keep it around... just that docker is way easier to setup here ;)

alexzorin commented 10 years ago

The integration-test task does not work for me (libvirtd does not seem to start).

If I enter via bash:

root@69788f296804:/libvirt-go# ./run-libvirt                                                                         
ln: failed to create symbolic link `/cgroup/systemd/name=systemd': Operation not permitted

then also

root@69788f296804:/libvirt-go# /usr/sbin/libvirtd 
/usr/sbin/libvirtd: error while loading shared libraries: libvirt-lxc.so.0: cannot open shared object file: Permission denied

This is doing a fresh docker build as per Makefile - can you reproduce a good result still?

cbosdo commented 10 years ago

On Fri, 2014-10-03 at 15:12 -0700, Alex Zorin wrote:

The integration-test task does not work for me.

If I enter via bash:

root@69788f296804:/libvirt-go# ./run-libvirt
ln: failed to create symbolic link `/cgroup/systemd/name=systemd': Operation not permitted

then also

root@69788f296804:/libvirt-go# /usr/sbin/libvirtd /usr/sbin/libvirtd: error while loading shared libraries: libvirt-lxc.so.0: cannot open shared object file: Permission denied

There is no need to run libvirtd when running a shell in the container: the entrypoint does that for you. These two commands are outputting the same errors here, but libvirtd is already up and running as shown by the ps command.

This is doing a fresh docker build as per Makefile - can you reproduce a good result still?

'sudo make test' runs nicely here

alexzorin commented 10 years ago

Well, the investigation in my previous comment is because of integration tests not working for me. I don't know if this is because of OS or docker version differences or whatever else, but there you go.

$ cat /etc/issue
Ubuntu 14.04.1 LTS \n \l
$ uname -a
Linux alexpc 3.13.0-35-generic #62-Ubuntu SMP Fri Aug 15 01:58:42 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ docker -v
Docker version 1.0.1, build 990021a
$ sudo make test
docker build -t libvirt-go:master .
Sending build context to Docker daemon 1.287 MB
Sending build context to Docker daemon 
Step 0 : FROM  debian:wheezy
 ---> c0c69167c0f8
Step 1 : MAINTAINER Cedric Bosdonnat <cbosdonnat@suse.com>
 ---> Using cache
 ---> 877e846b01ee
Step 2 : RUN echo 'deb http://http.debian.net/debian wheezy-backports main' >> /etc/apt/sources.list.d/backports.list
 ---> Using cache
 ---> 560ef5793fc9
Step 3 : RUN apt-get update &&    DEBCONF_FRONTEND=noninteractive DEBIAN_FRONTEND=noninteractive apt-get install -y    curl    gcc libvirt0=1.2.* libvirt-dev=1.2.* libvirt-bin=1.2.*
 ---> Using cache
 ---> a4e3db1af82c
Step 4 : RUN curl -sSL https://golang.org/dl/go1.3.1.src.tar.gz | tar -v -C /usr/local -xz
 ---> Using cache
 ---> 67c8c50c04b6
Step 5 : ENV GOROOT /usr/local/go
 ---> Using cache
 ---> defe9af1e067
Step 6 : ENV PATH    /go/bin:/usr/local/go/bin:$PATH
 ---> Using cache
 ---> 26d572adf0b2
Step 7 : ENV GOPATH  /go:/go/src/github.com/docker/docker/vendor
 ---> Using cache
 ---> 159db79d730b
Step 8 : RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1
 ---> Using cache
 ---> 153ffbf5b81e
Step 9 : RUN /bin/echo -e 'auto lo\niface lo inet loopback\nallow-hotplug eth0\niface eth0 inet dhcp\n'    >/etc/network/interfaces
 ---> Using cache
 ---> 8efad62a7168
Step 10 : WORKDIR /libvirt-go
 ---> Using cache
 ---> 3353732758cd
Step 11 : COPY . /libvirt-go
 ---> 778216647e65
Removing intermediate container 1e233de6f899
Step 12 : ENTRYPOINT ["./run-libvirt"]
 ---> Running in 182fe069d0d0
 ---> aeeb340bec15
Removing intermediate container 182fe069d0d0
Successfully built aeeb340bec15
docker run -ti --privileged --rm libvirt-go:master go test
PASS
ok      _/libvirt-go    0.053s
docker run -ti --privileged --rm libvirt-go:master go test -tags integration
--- FAIL: TestIntegrationGetMetadata (0.00 seconds)
    integration_test.go:42: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationSetMetadata (0.00 seconds)
    integration_test.go:76: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationGetSysinfo (0.00 seconds)
    integration_test.go:108: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntergrationDefineUndefineNWFilterXML (0.00 seconds)
    integration_test.go:138: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationNWFilterGetName (0.00 seconds)
    integration_test.go:161: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationNWFilterGetUUID (0.00 seconds)
    integration_test.go:182: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationNWFilterGetUUIDString (0.00 seconds)
    integration_test.go:203: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationNWFilterGetXMLDesc (0.00 seconds)
    integration_test.go:224: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationLookupNWFilterByName (0.00 seconds)
    integration_test.go:245: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationLookupNWFilterByUUIDString (0.00 seconds)
    integration_test.go:278: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationDomainAttachDetachDevice (0.00 seconds)
    integration_test.go:321: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestStorageVolResize (0.00 seconds)
    integration_test.go:353: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestStorageVolWipe (0.00 seconds)
    integration_test.go:397: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestStorageVolWipePattern (0.00 seconds)
    integration_test.go:440: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationSecretDefineUndefine (0.00 seconds)
    integration_test.go:497: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationSecretGetUUID (0.00 seconds)
    integration_test.go:515: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationSecretGetUUIDString (0.00 seconds)
    integration_test.go:536: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationSecretGetXMLDesc (0.00 seconds)
    integration_test.go:557: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationSecretGetUsageType (0.00 seconds)
    integration_test.go:578: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationSecretGetUsageID (0.00 seconds)
    integration_test.go:604: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationLookupSecretByUsage (0.00 seconds)
    integration_test.go:631: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationGetDomainCPUStats (0.00 seconds)
    integration_test.go:654: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationListAllInterfaces (0.00 seconds)
    integration_test.go:741: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntergrationListAllNWFilters (0.00 seconds)
    integration_test.go:769: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
--- FAIL: TestIntegrationDomainBlockStatsFlags (0.00 seconds)
    integration_test.go:806: [Code-38] [Domain-7] Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
FAIL
exit status 1
FAIL    _/libvirt-go    0.042s
make: *** [integration-test] Error 1
cbosdo commented 10 years ago

$ docker -v Docker version 1.0.1, build 990021a

I'ld bet the problem comes from docker version: I'm running

Docker version 1.2.0, build fa7b24f
alexzorin commented 10 years ago

I've updated to that version but the same problem occurs

alexzorin commented 10 years ago

Huh, on a whim I thought selinux might be messing with it, turns out AppArmor is:

Oct 10 07:45:52 alexpc kernel: [67863.823435] type=1400 audit(1412887552.218:172): apparmor="DENIED" operation="open" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/libvirtd" name="var/lib/docker/aufs/diff/08a9285805c663e5991d05e568cf6228456f99e2b31201d29bb2e13c2d7df86b/etc/ld.so.cache" pid=4601 comm="libvirtd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Oct 10 07:45:52 alexpc kernel: [67863.823490] type=1400 audit(1412887552.218:173): apparmor="DENIED" operation="getattr" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/libvirtd" name="var/lib/docker/aufs/diff/08a9285805c663e5991d05e568cf6228456f99e2b31201d29bb2e13c2d7df86b/lib/x86_64-linux-gnu" pid=4601 comm="libvirtd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Oct 10 07:45:52 alexpc kernel: [67863.823568] type=1400 audit(1412887552.218:174): apparmor="DENIED" operation="getattr" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/libvirtd" name="var/lib/docker/aufs/diff/08a9285805c663e5991d05e568cf6228456f99e2b31201d29bb2e13c2d7df86b/usr/lib/x86_64-linux-gnu" pid=4601 comm="libvirtd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Will need to have a think about whether this makes the testing environment too fragile

cbosdo commented 10 years ago
Oct 10 07:45:52 alexpc kernel: [67863.823568] type=1400 audit(1412887552.218:174): apparmor="DENIED" operation="getattr" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/libvirtd" name="var/lib/docker/aufs/diff/08a9285805c663e5991d05e568cf6228456f99e2b31201d29bb2e13c2d7df86b/usr/lib/x86_64-linux-gnu" pid=4601 comm="libvirtd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Will need to have a think about whether this makes the testing environment too fragile

Well... I guess this is a problem in the libvirtd apparmor profile shipped by the distro. To ensure the tests are running nicely, we could add some check in the makefile to warn about apparmor being enabled.

mraygalaxy commented 8 years ago

To throw another wrench into the pile, I have a test case for QEMU Monitor support which requires that libvirt have access to a cgroup to execute --------- so the only way to pass this test case is to run a "nested" cgroup, which seems problematic.

Ideas?

rgbkrk commented 8 years ago

I'm going to go ahead and close all PRs that have been open for more than 6 months, including this one. If it needs reopened feel free to do so or open a new PR.