Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Add test skip utils #1587

Merged
merged 2 commits into from
May 3, 2019

Conversation

jodh-intel
Copy link
Contributor

Enhance the katatestutils package to provide the ability to skip tests based on either user or distro the tests are running on.

Fixes #1586.

Signed-off-by: James O. D. Hunt [email protected]

@jodh-intel
Copy link
Contributor Author

This is kind of a PoC RFC. By providing a framework for skipping tests, we can make the skips clearer and provide more powerful abilities.

@devimc - you can use this to skip a test on RHEL say by doing something like:

var tc TestConstraint

func init() {
    tc := NewTestConstraint(false)
}

func TestFoo(t *testing.T) {
    if tc.NotValid(NeedDistroNotEquals("rhel")) {
        t.Skipf("skipping test: %+v", tc)
    }

    // Test code...
}

@devimc
Copy link

devimc commented Apr 25, 2019

/test
thanks @jodh-intel

@jodh-intel
Copy link
Contributor Author

/retest

@jodh-intel
Copy link
Contributor Author

18.04 initrd CI failed in spectacular Java fashion:

[4] Running command '/usr/bin/docker [docker run --cidfile /tmp/cid781234710/vSg5qeu44wKIsyvUaPdKk6SGajozR4 --runtime kata-runtime --name vSg5qeu44wKIsyvUaPdKk6SGajozR4 --rm --group-add cdrom --group-add games --group-add video --group-add audio -u root postgres id]'
FATAL: command execution failed
java.io.EOFException
	at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2681)
	at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3156)
	at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:862)
	at java.io.ObjectInputStream.<init>(ObjectInputStream.java:358)
	at hudson.remoting.ObjectInputStreamEx.<init>(ObjectInputStreamEx.java:49)
	at hudson.remoting.Command.readFrom(Command.java:140)
	at hudson.remoting.Command.readFrom(Command.java:126)
	at hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:36)
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:63)
Caused: java.io.IOException: Unexpected termination of the channel
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:77)
Caused: java.io.IOException: Backing channel 'ubuntu1804-azure901aa0' is disconnected.
	at hudson.remoting.RemoteInvocationHandler.channelOrFail(RemoteInvocationHandler.java:214)
	at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:283)
	at com.sun.proxy.$Proxy394.isAlive(Unknown Source)
	at hudson.Launcher$RemoteLauncher$ProcImpl.isAlive(Launcher.java:1144)
	at hudson.Launcher$RemoteLauncher$ProcImpl.join(Launcher.java:1136)
	at hudson.tasks.CommandInterpreter.join(CommandInterpreter.java:155)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
	at hudson.model.Build$BuildExecution.build(Build.java:206)
	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1816)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
FATAL: Unable to delete script file /tmp/jenkins1097468972697609172.sh
java.io.EOFException
	at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2681)
	at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3156)
	at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:862)
	at java.io.ObjectInputStream.<init>(ObjectInputStream.java:358)
	at hudson.remoting.ObjectInputStreamEx.<init>(ObjectInputStreamEx.java:49)
	at hudson.remoting.Command.readFrom(Command.java:140)
	at hudson.remoting.Command.readFrom(Command.java:126)
	at hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:36)
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:63)
Caused: java.io.IOException: Unexpected termination of the channel
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:77)
Caused: hudson.remoting.ChannelClosedException: Channel "unknown": Remote call on ubuntu1804-azure901aa0 failed. The channel is closing down or has closed down
	at hudson.remoting.Channel.call(Channel.java:950)
	at hudson.FilePath.act(FilePath.java:1069)
	at hudson.FilePath.act(FilePath.java:1058)
	at hudson.FilePath.delete(FilePath.java:1539)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:123)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
	at hudson.model.Build$BuildExecution.build(Build.java:206)
	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1816)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
Build step 'Execute shell' marked build as failure

Let's see if a rebuild resolves the spew...

@devimc
Copy link

devimc commented Apr 26, 2019

q35 CI is not happy

=== RUN   TestHostNetworkingRequested
--- FAIL: TestHostNetworkingRequested (0.01s)
    assertions.go:239: 
                          
	Error Trace:	network_test.go:99
        
	Error:      	Should be true

@jodh-intel
Copy link
Contributor Author

@devimc - I can recreate that, but I see the same result with the old code.

@lifupan - any thoughts on this as I think you wrote that test?

@jodh-intel
Copy link
Contributor Author

Whilst we wait, I'll add some unit tests for the code next week...

@jodh-intel
Copy link
Contributor Author

@devimc, @grahamwhaley - if you look at #1604, you'll see that the single failure is unrelated to this PR, so I think we can merge this one..?


osRelease = "/etc/os-release"

// Clear Linux has a different path (for stateless support)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - The use of /usr/lib/os-release is part of the os-release spec, so may not only be Clear specific :-)
https://www.freedesktop.org/software/systemd/man/os-release.html

@@ -0,0 +1,355 @@
// Copyright (c) 2019 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be some accompanying documentation with these additions - detailing what/how/where you can apply constraints to the test files?

@jodh-intel
Copy link
Contributor Author

I'm going to add some tests, a doc and kernel version handling for #1604, so let's mark as dnm for now...

@jodh-intel
Copy link
Contributor Author

Branch updated but not yet complete:

  • Need ability to skip based on distro version
  • Need ability to skip based on kernel version

@klynnrif and @grahamwhaley - ptal at the new doc on this PR (pkg/katatestutils/README.md).

Copy link

@klynnrif klynnrif left a comment

Choose a reason for hiding this comment

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

Completed a grammar/structure/flow review on pkg/katatestutils/README.md - a few suggested rewrites. Thanks!


## Test Constraints

This package provides helper functions to allow tests to be skipped based on a

Choose a reason for hiding this comment

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

Lines 14-15 suggested rewrite (unless I've changed the meaning - previous sentence is a bit ambiguous):
This package provides helper functions that accept user-specified constraints that allow you to skip tests.

### Usage

Create a `TestConstraint` object using the `NewTestConstraint()` constructor.
This takes a single boolean parameter which specifies if debug output should

Choose a reason for hiding this comment

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

Lines 20-21 suggested rewrite:
This takes a single Boolean parameter that specifies if debug output is generated.

This takes a single boolean parameter which specifies if debug output should
be generated.

In each test that needs to be skipped, call the `NotValid()` method on the

Choose a reason for hiding this comment

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

Lines 23-24: I'm not certain what the end of this sentence is trying relay - "passing one more constraint" or "passing on more constraints". I've removed the duplicate "more" but based on the intended meaning we might want to rewrite the end of the sentence as well.

In each test that is skipped, call the NotValid() method on the TestConstraint object, passing one more constraints that you want to be valid.


In each test that needs to be skipped, call the `NotValid()` method on the
`TestConstraint` object, passing one more more constraints that you want to be
valid. The `NotValid()` function will return `true` if any of the specified

Choose a reason for hiding this comment

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

Lines 25-27 suggested rewrite:
The NotValid() function returns true if any of the specified constraints are not available. This allows for a more natural way to code an arbitrarily complex test skip as shown in the following example:

constraints are not available. This allows for a natural way of coding an
arbitrarily complex test skip as shown below.

The main object can be created in the `init()` function to make it available to

Choose a reason for hiding this comment

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

Suggested rewrite:
The main object is created in the init() function to make it available for all tests:

@amshinde
Copy link
Member

@jodh-intel @lifupan This is similar to the rhel issue that we saw. See this:
#1517 (comment)

@lifupan
Copy link
Member

lifupan commented Apr 30, 2019

@jodh-intel @lifupan This is similar to the rhel issue that we saw. See this:
#1517 (comment)

@amshinde @jodh-intel Yes, the root cause is the absent of "nsfs" in kernel, maybe we can check is the "nsfs" feature supported on the host instead of checking the kernel version before we run the specific testcase.

@jodh-intel
Copy link
Contributor Author

@klynnrif et al - branch has now been updated!

/retest

@jodh-intel
Copy link
Contributor Author

/retest

@jodh-intel
Copy link
Contributor Author

/retest

@jodh-intel
Copy link
Contributor Author

All CI's are green apart from the known q35 issue (#1604).

Please review y'all!

Copy link

@klynnrif klynnrif left a comment

Choose a reason for hiding this comment

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

lgtm - thanks!

@jodh-intel
Copy link
Contributor Author

/retest

@jodh-intel
Copy link
Contributor Author

/retest

@jodh-intel
Copy link
Contributor Author

Restarted one of the travis jobs which had failed due to the new linter timing out:

ERRO [runner] 0/8 linters finished: deadline exceeded 
INFO File cache stats: 0 entries of total size 0B 
ERRO Deadline exceeded: try increase it by passing --deadline option 

/cc @ganeshmaharaj

@jodh-intel
Copy link
Contributor Author

Ubuntu nemu failed with:

14:43:25 Running command '/usr/bin/docker [docker run --cidfile /tmp/cid134291960/L1RkS6IZtDTtUT7xg7mpk6ingYlNc1 --runtime kata-runtime --rm --name L1RkS6IZtDTtUT7xg7mpk6ingYlNc1 --cpus 3 debian bash -c for c in $(seq 1 5); do if [ "$(nproc)" == "4" ]; then nproc; exit 0; fi; sleep 5; done; exit 1]'
14:44:06 command failed error 'exit status 1'
14:44:06 [docker run --cidfile /tmp/cid134291960/L1RkS6IZtDTtUT7xg7mpk6ingYlNc1 --runtime kata-runtime --rm --name L1RkS6IZtDTtUT7xg7mpk6ingYlNc1 --cpus 3 debian bash -c for c in $(seq 1 5); do if [ "$(nproc)" == "4" ]; then nproc; exit 0; fi; sleep 5; done; exit 1]
14:44:06 Timeout: 120 seconds
14:44:06 Exit Code: 1
14:44:06 Stdout: 
14:44:06 Stderr: 
14:44:06 Running command '/usr/bin/docker [docker ps -a -f name=L1RkS6IZtDTtUT7xg7mpk6ingYlNc1 --format {{.Status}}]'
14:44:06 [docker ps -a -f name=L1RkS6IZtDTtUT7xg7mpk6ingYlNc1 --format {{.Status}}]
14:44:06 Timeout: 120 seconds
14:44:06 Exit Code: 0
14:44:06 Stdout: 
14:44:06 Stderr: 
14:44:06 
14:44:06 • Failure [41.296 seconds]
14:44:06 [Serial Test] Hot plug CPUs
14:44:06 /tmp/jenkins/workspace/kata-containers-runtime-ubuntu-nemu/go/src/github.com/kata-containers/tests/integration/docker/cpu_test.go:54
14:44:06   container with CPU constraint
14:44:06   /tmp/jenkins/workspace/kata-containers-runtime-ubuntu-nemu/go/src/github.com/kata-containers/tests/vendor/github.com/onsi/ginkgo/extensions/table/table.go:92
14:44:06     should have 3 CPUs [It]
14:44:06     /tmp/jenkins/workspace/kata-containers-runtime-ubuntu-nemu/go/src/github.com/kata-containers/tests/vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go:46
14:44:06 
14:44:06     Expected
14:44:06         <int>: 1
14:44:06     to be zero-valued
14:44:06 
14:44:06     /tmp/jenkins/workspace/kata-containers-runtime-ubuntu-nemu/go/src/github.com/kata-containers/tests/integration/docker/cpu_test.go:107

sles 12:

not ok 22 ctr execsync std{out,err}
# (in test file ctr.bats, line 806)
#   `[ "$status" -eq 0 ]' failed

opensuse 15:

not ok 5 additional devices support
# (in test file ctr.bats, line 119)
#   `[ "$status" -eq 0 ]' failed

And centos with the usual #1604 🌰.

Restarted the failing ones (apart from centos).

Copy link
Contributor

@grahamwhaley grahamwhaley left a comment

Choose a reason for hiding this comment

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

One nit, one question.
Will lgtm, to ease merging...


#### Displaying the TestConstraint

Note that you could add the TestConstraint` object to the `Skip()` call as it
Copy link
Contributor

Choose a reason for hiding this comment

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

back tick code block messed up in this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


### Full details

The public API is shown in [`constraints_api.go`](constraints_api.go).
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance we can get that as a godoc, so we can see the go api in the same style one does for other go packages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to point at the godoc site.

Enhance the `katatestutils` package to provide the ability to skip
tests based on either user or distro the tests are running on.

Fixes kata-containers#1586.

Signed-off-by: James O. D. Hunt <[email protected]>
Updated the test code to use the new test constraints feature.

Signed-off-by: James O. D. Hunt <[email protected]>
@jodh-intel
Copy link
Contributor Author

It would be great to avoid re-running all those CI's for a doc change, but I'll leave it up to others to decide that since it's my PR ;)

@jodh-intel
Copy link
Contributor Author

meh...

/retest

@@ -0,0 +1,38 @@
# Gopkg.toml example
Copy link

Choose a reason for hiding this comment

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

woot! , is this correct? I thought that there should only be one vendor directory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem to be required, yes:

INFO: Running 'go test' as current user on package 'github.com/kata-containers/runtime/cli' with flags '-v -race -timeout 30s -outputdir "/tmp/tmp.RnuwUOlXss"'
# github.com/kata-containers/runtime/cli
package github.com/kata-containers/runtime/cli (test)
        imports github.com/kata-containers/runtime/pkg/katatestutils
        imports github.com/blang/semver: cannot find package "github.com/blang/semver" in any of:
        /home/james/go/src/github.com/kata-containers/runtime/vendor/github.com/blang/semver (vendor tree)
        /usr/local/go/src/github.com/blang/semver (from $GOROOT)
        /home/james/go/src/github.com/blang/semver (from $GOPATH)
FAIL    github.com/kata-containers/runtime/cli [setup failed]

... but:

$ dep ensure -add github.com/blang/semver
Fetching sources...

Failed to add the dependencies:

  ✗ github.com/blang/semver is already imported or required, so -add is only valid with a constraint

adding dependencies failed
$ grep -c semver Gopkg.*                
Gopkg.lock:0
Gopkg.toml:0
$

We do have other packages with their own vendoring, for example:

@jodh-intel
Copy link
Contributor Author

It would be good to get this landed before the sands shift once more... 😄

@grahamwhaley
Copy link
Contributor

Thanks for the updates. You have the acks, and we know the q35 is an anomaly right now... I think we can merge...

@grahamwhaley grahamwhaley merged commit b5b1c38 into kata-containers:master May 3, 2019
@jodh-intel
Copy link
Contributor Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

provide ability to skip tests based on user and distro
6 participants