Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Enable multiple non-IP interface to be connected via tc redirect #836

Merged
merged 28 commits into from
Jun 25, 2021
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0d7046e
First crack at multinet implementation
networkop May 10, 2021
0b3dfdb
fix the dhcp server bug
networkop May 10, 2021
9acef4f
Merge branch 'weaveworks:main' into multinet
networkop May 10, 2021
56ca546
Added wait for X number of interfaces to be connected
networkop May 10, 2021
52776a6
Merge branch 'weaveworks:main' into multinet
networkop May 10, 2021
e3baa91
Merge branch 'multinet' of github.com:networkop/ignite into multinet
networkop May 10, 2021
17765be
Fixed multiple bugs
networkop May 11, 2021
6e19436
Ensure maxIntfs is at least 1
networkop May 11, 2021
39d395e
Fixed formatting
networkop May 11, 2021
9a31fb9
Forgot to assign envVars
networkop May 11, 2021
20b4aa8
Updated docs
networkop May 11, 2021
35dc891
More updated docs
networkop May 11, 2021
e8bd47c
More docs updates
networkop May 11, 2021
b8ef5d3
Not using env vars anymore
networkop May 22, 2021
47c9140
Re-introducing env var support
networkop May 23, 2021
6f1f14a
Reverting the order to error checks
networkop May 24, 2021
90eaa58
Added multinet tests
networkop Jun 9, 2021
1020f90
Fixing dox
networkop Jun 9, 2021
053def5
Refactored StartVM with async spawn channel
networkop Jun 10, 2021
eb8997f
Refactored ignite-spawn's network setup
networkop Jun 10, 2021
051ad2b
Fixed the CNI plugin bug
networkop Jun 11, 2021
1c70e78
Tested with containerlab
networkop Jun 12, 2021
9957b70
Merging suggested changes
networkop Jun 21, 2021
3161ef4
Alternative e2e test
networkop Jun 22, 2021
f8d361d
Removed --wait flag and fixed up multinet tests
networkop Jun 22, 2021
668b5fe
Removing waitForSSH from exec
networkop Jun 24, 2021
71c801c
Removing leftover comment
networkop Jun 24, 2021
abddda2
Adding waitforSSH back
networkop Jun 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 89 additions & 51 deletions e2e/multinet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,105 @@ import (
"testing"

"github.com/weaveworks/ignite/e2e/util"
api "github.com/weaveworks/ignite/pkg/apis/ignite"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
igniteConstants "github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/dmlegacy"
"github.com/weaveworks/ignite/pkg/metadata"
"github.com/weaveworks/ignite/pkg/network"
"github.com/weaveworks/ignite/pkg/operations"
"github.com/weaveworks/ignite/pkg/providers"
igniteDocker "github.com/weaveworks/ignite/pkg/providers/docker"
"github.com/weaveworks/ignite/pkg/providers/ignite"
"github.com/weaveworks/ignite/pkg/runtime"
igniteUtil "github.com/weaveworks/ignite/pkg/util"
"gotest.tools/assert"
)

// TestMultipleInterface tests that a VM's can be configured with more than 1 interface
func TestOneExtraInterface(t *testing.T) {
var (
multinetVM = "e2e-test-vm-multinet"
sanboxImage = "weaveworks/ignite:dev"
kernelImage = "weaveworks/ignite-kernel:5.4.108"
vmImage = "weaveworks/ignite-ubuntu"
)

func startAsyncVM(t *testing.T, intfs []string) (*operations.VMChannels, string) {

assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")
igniteUtil.GenericCheckErr(providers.Populate(ignite.Preload))

vmName := "e2e-test-vm-multinet"
_ = igniteDocker.SetDockerRuntime()
_ = igniteDocker.SetDockerNetwork()
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a natural consequence of globals being side-effected here that these tests cannot be parallelized with other test runs that need different values.
This doesn't affect the existing test suites which make individual invocations of the ignite binary.
Also, we already run our e2e suite in serial anyway.

All of this is fine, but it's worth noting. 👍


igniteCmd := util.NewCommand(t, igniteBin)
dockerCmd := util.NewCommand(t, "docker")
providers.RuntimeName = runtime.RuntimeDocker
providers.NetworkPluginName = network.PluginDockerBridge
_ = providers.Populate(ignite.Providers)

// Clone this repo in a new dir.
tempDir, err := ioutil.TempDir("", "ignite-multinet")
vm := providers.Client.VMs().New()
vm.Status.Runtime.Name = runtime.RuntimeDocker
vm.Status.Network.Plugin = network.PluginDockerBridge

ociRef, err := meta.NewOCIImageRef(sanboxImage)
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
t.Fatalf("Failed to parse OCI image ref %s: %s", sanboxImage, err)
}
defer os.RemoveAll(tempDir)
vm.Spec.Sandbox.OCI = ociRef

// Write a VM config with annotations
ociRef, err = meta.NewOCIImageRef(kernelImage)
if err != nil {
t.Fatalf("Failed to parse OCI image ref %s: %s", kernelImage, err)
}
vm.Spec.Kernel.OCI = ociRef
k, _ := operations.FindOrImportKernel(providers.Client, ociRef)
vm.SetKernel(k)

vmConfig := []byte(`---
apiVersion: ignite.weave.works/v1alpha4
kind: VM
metadata:
name: e2e-test-vm-multinet
annotations:
"ignite.weave.works/interface/foo": "tc-redirect"
spec:
image:
oci: weaveworks/ignite-ubuntu
cpus: 1
diskSize: 3GB
memory: 800MB
ssh: true
`)
ociRef, err = meta.NewOCIImageRef(vmImage)
if err != nil {
t.Fatalf("Failed to parse OCI image ref %s: %s", vmImage, err)
}
img, err := operations.FindOrImportImage(providers.Client, ociRef)
if err != nil {
t.Fatalf("Failed to find OCI image ref %s: %s", ociRef, err)
}
vm.SetImage(img)

vmConfigPath := filepath.Join(tempDir, "my-vm.yaml")
assert.Check(t, ioutil.WriteFile(vmConfigPath, vmConfig, 0644), "failed to write VM config")
vm.Name = multinetVM
vm.Spec.SSH = &api.SSH{Generate: true}

// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", vmName).
Run()
_ = metadata.SetNameAndUID(vm, providers.Client)

// Run VM.
igniteCmd.New().
WithRuntime("docker").
WithNetwork("docker-bridge").
With("run").
With("--ssh").
With("--debug").
With("--wait=false").
With("--config=" + vmConfigPath).
Run()
for _, intf := range intfs {
vm.SetAnnotation(igniteConstants.IGNITE_INTERFACE_ANNOTATION+intf, "tc-redirect")
}

// Get the VM ID
idCmd := igniteCmd.New().
With("ps").
With("--filter").
With(fmt.Sprintf("{{.ObjectMeta.Name}}=%s", vmName)).
With("--template={{.ObjectMeta.UID}}")
_ = providers.Client.VMs().Set(vm)

idOut, idErr := idCmd.Cmd.CombinedOutput()
assert.Check(t, idErr, fmt.Sprintf("vm id not found: \n%q\n%s", idCmd.Cmd, idOut))
vmID := strings.TrimSuffix(string(idOut), "\n")
err = dmlegacy.AllocateAndPopulateOverlay(vm)
if err != nil {
t.Fatalf("Error AllocateAndPopulateOverlay: %s", err)
}

vmChans, err := operations.StartVMNonBlocking(vm, false)
if err != nil {
t.Fatalf("failed to start a VM: \n%q\n", err)
}

return vmChans, vm.GetUID().String()
}

// TestMultipleInterface tests that a VM's can be configured with more than 1 interface
func TestOneExtraInterface(t *testing.T) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")

igniteCmd := util.NewCommand(t, igniteBin)
dockerCmd := util.NewCommand(t, runtime.RuntimeDocker.String())

vmChans, vmID := startAsyncVM(t, []string{"foo"})

// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", multinetVM).
Run()

fooAddr := "aa:ca:e9:12:34:56"
dockerCmd.New().
Expand All @@ -87,8 +120,13 @@ spec:
With("ip", "link", "set", "foo", "address", fooAddr).
Run()

// check that the VM has started before trying exec
if err := <-vmChans.SpawnFinished; err != nil {
t.Fatalf("failed to start a VM: \n%q\n", err)
}
Comment on lines +120 to +123
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that these tests exercise the wait code that polls for the Firecracker Prometheus socket.


eth1Addr := igniteCmd.New().
With("exec", vmName).
With("exec", multinetVM).
With("cat", "/sys/class/net/eth1/address")

foundEth1Addr, _ := eth1Addr.Cmd.CombinedOutput()
Expand Down