Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,14 @@ func (vm *vm) relocateHyperCommand(hyper *api.Hyper) error {

for _, cmd := range cmds {
if hyper.HyperName == cmd.name {
if nTokens != 1 {
return fmt.Errorf("expected 1 token, got %d", nTokens)
if nTokens > 1 {
return fmt.Errorf("expected 0 or 1 token, got %d", nTokens)
}

// We don't need a token to start a process inside the VM, but we
// don't get a session in that case.
if nTokens == 0 {

Choose a reason for hiding this comment

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

Is it worth adding a log message here for this "special case"?

Copy link
Contributor Author

@dlespiau dlespiau Apr 13, 2017

Choose a reason for hiding this comment

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

Not really, it's business as usual.

It may be worth sprinkling more info messages in general, that's something I'll have a look at when improving the logging story in 3.0 (see #35, #36)

Choose a reason for hiding this comment

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

Right. wfm.

continue
}

token := hyper.Tokens[0]
Expand Down
37 changes: 26 additions & 11 deletions vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ func TestHyperRelocationNewcontainer(t *testing.T) {
assert.Equal(t, session.ioBase, cmdOut.Process.Stdio)
assert.Equal(t, session.ioBase+1, cmdOut.Process.Stderr)

// Giving other fewer or more tokens than 1 should result in an error
cmd = rig.createNewcontainer(vm, 0)
err = vm.relocateHyperCommand(cmd)
assert.NotNil(t, err)

cmd = rig.createNewcontainer(vm, 2)
// Giving more than 1 token should result in an error
cmd = rig.createExecmd(vm, 2)
err = vm.relocateHyperCommand(cmd)
assert.NotNil(t, err)

Expand All @@ -157,6 +153,29 @@ func TestHyperRelocationNewcontainer(t *testing.T) {
vm.Close()
}

// In some case, we want to create containers without caring about the session
// between the process inside the VM and the host. One of those cases is the
// pause container created as we create a pod in virtcontainers.
func TestHyperRelocationNewcontainerNoToken(t *testing.T) {
rig := newVMRig(t)
rig.Start()

vm := rig.CreateVM()

// Relocate an execcmd command, no token given!
cmd := rig.createNewcontainer(vm, 0)

// don't associate a dummy shim, we should wait for one when no token is
// given.

// relocate
err := vm.relocateHyperCommand(cmd)
assert.Nil(t, err)

rig.Stop()
vm.Close()
}

func (rig *vmRig) createExecmd(vm *vm, numTokens int) *api.Hyper {
process := rig.createBaseProcess()
cmd := hyperstart.ExecCommand{
Expand Down Expand Up @@ -194,11 +213,7 @@ func TestHyperRelocationExeccmd(t *testing.T) {
assert.Equal(t, session.ioBase, cmdOut.Process.Stdio)
assert.Equal(t, session.ioBase+1, cmdOut.Process.Stderr)

// Giving other fewer or more tokens than 1 should result in an error
cmd = rig.createExecmd(vm, 0)
err = vm.relocateHyperCommand(cmd)
assert.NotNil(t, err)

// Giving more than 1 token should result in an error
cmd = rig.createExecmd(vm, 2)
err = vm.relocateHyperCommand(cmd)
assert.NotNil(t, err)
Expand Down