Skip to content

fix(unikernels): skip network args in mewz commandstring when no network#674

Open
mdryaan wants to merge 2 commits into
urunc-dev:mainfrom
mdryaan:fix/mewz-commandstring-no-network
Open

fix(unikernels): skip network args in mewz commandstring when no network#674
mdryaan wants to merge 2 commits into
urunc-dev:mainfrom
mdryaan:fix/mewz-commandstring-no-network

Conversation

@mdryaan
Copy link
Copy Markdown
Contributor

@mdryaan mdryaan commented May 14, 2026

Description

Mewz.CommandString() unconditionally formatted ip=%s/%d gateway=%s even when no network was configured, producing "ip=/0 gateway= " as kernel boot parameters. Mewz does not handle this and panics at startup.

Guard the network args behind an m.Net.Address != "" check, matching the pattern already used by Hermit.CommandString(). Add unit tests covering both the no-network and with-network cases.

Related issues

How was this tested?

Added two unit tests in pkg/unikontainers/unikernels/mewz_test.go:

  • TestMewzCommandStringNoNetwork: asserts CommandString() returns "" when no network is configured.
  • TestMewzCommandStringWithNetwork: asserts CommandString() returns "ip=10.0.0.2/24 gateway=10.0.0.1" when network is configured.

Before fix (bug reproduced):
Screenshot 2026-05-14 064959

After fix:
Screenshot 2026-05-14 065053

LLM usage

N/A

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 14, 2026

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit d26e7f4
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a0b6cd515646f00089f1e70

Copy link
Copy Markdown
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Hello @mdryaan ,

thank you for the PR.

I have added some comments

Comment on lines +24 to +44
func TestMewzCommandStringNoNetwork(t *testing.T) {
t.Parallel()
m := &Mewz{}
result, err := m.CommandString()
require.NoError(t, err)
assert.Equal(t, "", result, "CommandString should return empty string when no network is configured")
}

func TestMewzCommandStringWithNetwork(t *testing.T) {
t.Parallel()
m := &Mewz{
Net: MewzNet{
Address: "10.0.0.2",
Mask: 24,
Gateway: "10.0.0.1",
},
}
result, err := m.CommandString()
require.NoError(t, err)
assert.Equal(t, "ip=10.0.0.2/24 gateway=10.0.0.1", result)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please mere these tests. They are unit tests for the same function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in d02e914

Comment thread pkg/unikontainers/unikernels/mewz.go Outdated
Comment on lines +39 to +44
var parts []string
if m.Net.Address != "" {
parts = append(parts, fmt.Sprintf("ip=%s/%d", m.Net.Address, m.Net.Mask))
parts = append(parts, fmt.Sprintf("gateway=%s", m.Net.Gateway))
}
return strings.Join(parts, " "), nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No reason to create a slice. It is a simple return of a specific string. So we can just wrap the previous Sprintf in an if statement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Merged into a single table-driven test with two subtests.

@mdryaan
Copy link
Copy Markdown
Contributor Author

mdryaan commented May 15, 2026

Thanks @cmainas for the review and feedback! PTAL

@cmainas
Copy link
Copy Markdown
Contributor

cmainas commented May 15, 2026

Hello @mdryaan , the PR looks good, but we need to coordinate adding yourself in https://github.com/urunc-dev/urunc/blob/main/.github/contributors.yaml This should be done in one of your open PRs and we should merge this first.

@mdryaan
Copy link
Copy Markdown
Contributor Author

mdryaan commented May 15, 2026

Hello @mdryaan , the PR looks good, but we need to coordinate adding yourself in https://github.com/urunc-dev/urunc/blob/main/.github/contributors.yaml This should be done in one of your open PRs and we should merge this first.

Hi @cmainas Already added myself in #676, you can merge that first and then this PR

@cmainas
Copy link
Copy Markdown
Contributor

cmainas commented May 18, 2026

Hello @mdryaan , unfortunately another rebase is necessary.

mdryaan added 2 commits May 18, 2026 19:47
Mewz.CommandString() unconditionally formatted ip=%s/%d and gateway=%s
even when no network was configured, producing "ip=/0 gateway= " as
kernel boot parameters. Mewz does not handle this case and panics.

Guard the network args behind an m.Net.Address != "" check, matching
the existing pattern in Hermit.CommandString(). Add unit tests covering
both the no-network and with-network cases.

Signed-off-by: mdryaan <[email protected]>
Signed-off-by: mdryaan <[email protected]>
@mdryaan mdryaan force-pushed the fix/mewz-commandstring-no-network branch from d02e914 to d26e7f4 Compare May 18, 2026 19:47
@mdryaan
Copy link
Copy Markdown
Contributor Author

mdryaan commented May 18, 2026

@cmainas Done, rebased over main.

@cmainas
Copy link
Copy Markdown
Contributor

cmainas commented May 19, 2026

Hello @mdryaan , this PR introduces a new unit test which can not be executed directly. You will need to add it here https://github.com/urunc-dev/urunc/blob/main/Makefile#L234 as the other unit tests for the unikontainers sub directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip network args in Mewz CommandString when network is not configured

2 participants