This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Enable multiple non-IP interface to be connected via tc redirect #836
Merged
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 0b3dfdb
fix the dhcp server bug
networkop 9acef4f
Merge branch 'weaveworks:main' into multinet
networkop 56ca546
Added wait for X number of interfaces to be connected
networkop 52776a6
Merge branch 'weaveworks:main' into multinet
networkop e3baa91
Merge branch 'multinet' of github.com:networkop/ignite into multinet
networkop 17765be
Fixed multiple bugs
networkop 6e19436
Ensure maxIntfs is at least 1
networkop 39d395e
Fixed formatting
networkop 9a31fb9
Forgot to assign envVars
networkop 20b4aa8
Updated docs
networkop 35dc891
More updated docs
networkop e8bd47c
More docs updates
networkop b8ef5d3
Not using env vars anymore
networkop 47c9140
Re-introducing env var support
networkop 6f1f14a
Reverting the order to error checks
networkop 90eaa58
Added multinet tests
networkop 1020f90
Fixing dox
networkop 053def5
Refactored StartVM with async spawn channel
networkop eb8997f
Refactored ignite-spawn's network setup
networkop 051ad2b
Fixed the CNI plugin bug
networkop 1c70e78
Tested with containerlab
networkop 9957b70
Merging suggested changes
networkop 3161ef4
Alternative e2e test
networkop f8d361d
Removed --wait flag and fixed up multinet tests
networkop 668b5fe
Removing waitForSSH from exec
networkop 71c801c
Removing leftover comment
networkop abddda2
Adding waitforSSH back
networkop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
||
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(). | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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. 👍