Skip to content

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

Open
mdryaan wants to merge 1 commit 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 1 commit into
urunc-dev:mainfrom
mdryaan:fix/mewz-commandstring-no-network

Conversation

@mdryaan
Copy link
Copy Markdown

@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.

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 <alikhurshid4u@gmail.com>
Signed-off-by: mdryaan <alikhurshid842001@gmail.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 14, 2026

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 52439f6
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a051ca993225000087faaf5

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.

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.

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