93 Commits

Author SHA1 Message Date
Prateek Gogia
3c1d4581c4 pkg/ip: Return correct error if container name provided exists, and test cases
If interface name for a container provided by a user is already present,
Veth creation fails with incorrect error.
If os.IsExist error is returned by makeVethPair:
* Check for peer name, if exists generate another random peer name,
* else, IsExist error is due to container interface present, return error.

Fixes #155
2016-08-11 18:51:03 +00:00
Stefan Junker
22a0ddc906 pkg/utils/hwaddr tests: cover v4 in v6 addr 2016-08-01 16:50:40 -07:00
Stefan Junker
00f27577d5 pkg/ip link_test: ensure SetHWAddrByIP has an effect 2016-07-22 15:34:54 -07:00
Stefan Junker
c317888ac5 pkg/ip: use iface name in SetHWAddrByIP 2016-07-22 15:34:53 -07:00
Stefan Junker
1a04d9abba pkg/ip tests: cover SetupVeth and DelLinkByName* 2016-07-22 15:34:53 -07:00
Stefan Junker
b6137de993 plugins: set MAC addresses based on IP
This will give deterministic MAC addresses for all interfaces CNI
creates and manages the IP for:
* bridge: container veth and host bridge
* macvlan: container veth
* ptp: container veth and host veth
2016-07-22 15:34:53 -07:00
Stefan Junker
c3e8563e77 pkg/utils/hwaddr: migrate code from IPAM pkg 2016-07-22 15:18:38 -07:00
Stefan Junker
7ea07a6405 pkg/ipam{,test}: improve error handling and tests
* _suite.go and _test.go file should be in the same package, using the
  _test package for that, which requires some fields and methods to be
  exported
* Introduce error type for cleaner error handling
* test adaptions for error type checking
2016-07-22 15:17:22 -07:00
Minhan Xia
75f1fa2260 add tests for generateHardwardAddr 2016-07-22 15:01:57 -07:00
Minhan Xia
c19b82efc2 configure mac address based on assigned ip 2016-07-22 14:57:52 -07:00
Gabe Rosenhouse
6496749565 plugins: adds new no-op plugin that may be used as a test-double
Plugin can be configured to record all inputs and to respond with
arbitrary stdout or error message.  Will support upcoming integration
testing.
2016-07-15 12:48:02 -07:00
Gabe Rosenhouse
728071e7d1 misc: fix up copyright dates 2016-07-14 16:09:27 -07:00
Gabe Rosenhouse
eda79f7645 pkg/skel: improve error message for missing CNI_COMMAND env var
This makes the error message for missing CNI_COMMAND consistent with
that of other required environment variables.
2016-07-14 00:24:32 -04:00
Gabe Rosenhouse
f2b6ec0375 pkg/skel: missing env var log lines appear in stderr
Previously, the log lines appeared in stdout before the JSON encoding of
the error message.  That would break JSON parsing of stdout.  Instead, we use
stderr for these unstructured logs, consistent with the CNI spec.
2016-07-14 00:24:27 -04:00
Gabe Rosenhouse
3c43314926 pkg/skel: refactor to use dependency injection
Extract dependencies on os to enable more complete unit test coverage
2016-07-14 00:06:58 -04:00
Pengfei Ni
bd341ab5d1 pkg/ns: fix misspelling in comment 2016-06-14 09:52:58 -07:00
Stefan Junker
d48cb53715 pkg/types: cover string for unmarshal tests 2016-06-13 18:18:36 -07:00
Tom Denham
efc0f2987f pkg/types: Add UnmarshallableString type
Allow strings to be unmarshalled for CNI_ARGS

CNI_ARGS uses types.LoadArgs to populate a struct.
The fields in the struct must meet the TextUnmarshaler interface.

This code adds a UnmarshallableString type to assist with this.
2016-06-09 14:45:58 -07:00
Stefan Junker
3a4124d257 pkg/ns: introduce error types indicate NS verification 2016-05-27 13:50:16 +02:00
Stefan Junker
cfedcfd8f2 skel/test: add case for empty NETNS 2016-05-27 12:26:42 +02:00
Stefan Junker
5fe036b88a plugins: don't require CNI_NETNS for DEL command
This will allow to free up the IPAM allocations when the caller doesn't
have access to the network namespace anymore, e.g. due to a reboot.
2016-05-27 10:57:39 +02:00
Stefan Junker
d7de8d4f98 pkg/skel: allow arg requriements specified by CMD 2016-05-27 10:56:24 +02:00
Stefan Junker
2d47b0396d pkg/ns: consider PROCFS during NS verification
This is an attempt to bring compatibility with Kernel <3.19, where NSFS
where PROCFS was used for network namespaces.
2016-05-26 12:42:50 +02:00
Stefan Junker
ea073fc4c7 pkg/ns: test IsNSFS() 2016-05-24 22:30:49 +02:00
Stefan Junker
f64cfb84f8 pkg/ns: test case for rejecting a non-ns nspath 2016-05-24 22:30:49 +02:00
Stefan Junker
39eace3c38 pkg/ns: verify netns when initialized with GetNS 2016-05-24 22:30:49 +02:00
Stefan Junker
a8d1029294 pkg/ns: add tests cases for Close()'d NS 2016-05-24 21:15:51 +02:00
Stefan Junker
40440ec887 pkg/ns: don't allow operations after Close() 2016-05-24 20:52:00 +02:00
Dan Williams
fce81fbf78 testutils: add e2e testing helper code 2016-05-20 17:10:25 -05:00
Dan Williams
f2922c5c1f ns: add interface, use it, and fix thread-related namespace switch issues
Add a namespace object interface for somewhat cleaner code when
creating and switching between network namespaces.  All created
namespaces are now mounted in /var/run/netns to ensure they
have persistent inodes and paths that can be passed around
between plugin components without relying on the current namespace
being correct.

Also remove the thread-locking arguments from the ns package
per https://github.com/appc/cni/issues/183 by doing all the namespace
changes in a separate goroutine that locks/unlocks itself, instead of
the caller having to track OS thread locking.
2016-05-20 17:10:25 -05:00
Stefan Junker
c019ed25d2 Merge pull request #199 from dcbw/fix-bridge-tx-queue-length
bridge: leave TX queue length as kernel default, not 0
2016-05-19 23:05:08 +02:00
Michael Bridgen
3738692372 Merge pull request #200 from squaremo/simplify-readme
Simplify README preamble
2016-05-19 13:21:40 +01:00
Angus Lees
734bf1ba5b pkg/ns: evaluate syscall number at compile-time
Previously this code used a run-time map lookup keyed by
runtime.GOOS/GOARCH.  This version uses conditional compilation to make
this choice at compile time, giving immediate feedback for unsupported
platforms.
2016-05-19 12:06:37 +02:00
Angus Lees
5978cf8b88 pkg/ns: use correct syscall number on arm 2016-05-19 12:06:37 +02:00
Stefan Junker
fc229c5090 *: appc/cni -> containernetworking/cni
The project has been moved so internally we simply rename everything.
Consumers are recommended to update their vendored version of cni.
2016-05-19 12:06:36 +02:00
Piotr Skamruk
5cbd217cbe pkg/utils: add functions to work with sysctl 2016-05-19 12:06:16 +02:00
Gabe Rosenhouse
19850efc3a Document use of goroutine and lockosthread in test helpers 2016-05-19 12:06:16 +02:00
Dan Williams
5158edacef ns: fix reading net namespace in multi-threaded processes
/proc/self/ns/net gives the main thread's namespace, not necessarily
the namespace of the thread that's running the testcases.  This causes
sporadic failures of the tests.

For example, with a testcase reading inodes after switching netns:

/proc/27686/task/27689/ns/net 4026532565
/proc/self/ns/net 4026531969
/proc/27686/task/27689/ns/net 4026532565

See also:
008d17ae00

Running Suite: pkg/ns Suite
===========================
Random Seed: 1459953577
Will run 6 of 6 specs

• Failure [0.028 seconds]
Linux namespace operations
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:167
  WithNetNS
  /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:166
    executes the callback within the target network namespace [It]
    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:97

    Expected
        <uint64>: 4026531969
    to equal
        <uint64>: 4026532565

    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96
------------------------------
•••••

Summarizing 1 Failure:

[Fail] Linux namespace operations WithNetNS [It] executes the callback within the target network namespace
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96

Ran 6 of 6 Specs in 0.564 seconds
FAIL! -- 5 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestNs (0.56s)
FAIL
2016-05-19 12:06:16 +02:00
Gabe Rosenhouse
5260862f80 Fix issues with MakeNetworkNS test helper 2016-05-19 12:06:16 +02:00
Gabe Rosenhouse
c77f7431fb Add basic unit tests of testhelpers 2016-05-19 12:06:16 +02:00
Gabe Rosenhouse
bd7b83dd98 Extract inode inspection functions into testhelpers 2016-05-19 12:06:16 +02:00
Gabe Rosenhouse
3358f16dd6 Extract testhelpers from loopback test suite 2016-05-19 12:06:16 +02:00
Stefan Junker
9079565e0d *: appc/cni -> containernetworking/cni
The project has been moved so internally we simply rename everything.
Consumers are recommended to update their vendored version of cni.
2016-05-06 16:40:27 +02:00
Stefan Junker
c3a90e7682 Merge pull request #187 from appc/v0.3.0
merge unneeded branch v0.3.0 into master
2016-04-22 19:25:54 +02:00
Zach Gershman
f73261c431 Merge pull request #182 from rosenhouse/document-lockosthread
Document use of goroutine and LockOSThread in test helpers
2016-04-18 10:45:46 -07:00
Dan Williams
c272c49555 ns: fix reading net namespace in multi-threaded processes
/proc/self/ns/net gives the main thread's namespace, not necessarily
the namespace of the thread that's running the testcases.  This causes
sporadic failures of the tests.

For example, with a testcase reading inodes after switching netns:

/proc/27686/task/27689/ns/net 4026532565
/proc/self/ns/net 4026531969
/proc/27686/task/27689/ns/net 4026532565

See also:
008d17ae00

Running Suite: pkg/ns Suite
===========================
Random Seed: 1459953577
Will run 6 of 6 specs

• Failure [0.028 seconds]
Linux namespace operations
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:167
  WithNetNS
  /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:166
    executes the callback within the target network namespace [It]
    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:97

    Expected
        <uint64>: 4026531969
    to equal
        <uint64>: 4026532565

    /cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96
------------------------------
•••••

Summarizing 1 Failure:

[Fail] Linux namespace operations WithNetNS [It] executes the callback within the target network namespace
/cni/gopath/src/github.com/appc/cni/pkg/ns/ns_test.go:96

Ran 6 of 6 Specs in 0.564 seconds
FAIL! -- 5 Passed | 1 Failed | 0 Pending | 0 Skipped --- FAIL: TestNs (0.56s)
FAIL
2016-04-18 10:35:23 -05:00
Gabe Rosenhouse
d701ca6c82 Document use of goroutine and lockosthread in test helpers 2016-04-17 20:27:02 -07:00
Gabe Rosenhouse
c085ec98fd Fix issues with MakeNetworkNS test helper 2016-04-17 19:47:54 -07:00
Gabe Rosenhouse
82851a860e Add basic unit tests of testhelpers 2016-04-17 19:25:39 -07:00
Gabe Rosenhouse
5f757b6af7 Extract inode inspection functions into testhelpers 2016-04-17 18:35:49 -07:00