Skip to content

Commit

Permalink
o/h/ctlcmd: rename kmod connection checker function
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy committed Jun 29, 2022
1 parent 7d308fb commit 01ac065
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions overlord/hookstate/ctlcmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ const (
var (
AttributesTask = attributesTask

KmodEnsureConnection = kmodEnsureConnection
KmodMatchConnection = kmodMatchConnection
KmodCheckConnection = kmodCheckConnection
KmodMatchConnection = kmodMatchConnection
)

type KmodCommand = kmodCommand

func MockKmodEnsureConnection(f func(*hookstate.Context, string, []string) error) (restore func()) {
r := testutil.Backup(&kmodEnsureConnection)
kmodEnsureConnection = f
func MockKmodCheckConnection(f func(*hookstate.Context, string, []string) error) (restore func()) {
r := testutil.Backup(&kmodCheckConnection)
kmodCheckConnection = f
return r
}

Expand Down
8 changes: 4 additions & 4 deletions overlord/hookstate/ctlcmd/kmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (k *KModInsertCmd) Execute([]string) error {
return err
}

if err := kmodEnsureConnection(context, k.Positional.Module, k.Positional.Options); err != nil {
if err := kmodCheckConnection(context, k.Positional.Module, k.Positional.Options); err != nil {
return fmt.Errorf("cannot load module %q: %v", k.Positional.Module, err)
}

Expand All @@ -98,7 +98,7 @@ func (k *KModRemoveCmd) Execute([]string) error {
return err
}

if err := kmodEnsureConnection(context, k.Positional.Module, []string{}); err != nil {
if err := kmodCheckConnection(context, k.Positional.Module, []string{}); err != nil {
return fmt.Errorf("cannot unload module %q: %v", k.Positional.Module, err)
}

Expand Down Expand Up @@ -133,10 +133,10 @@ func kmodMatchConnection(attributes map[string]interface{}, moduleName string, m
return true
}

// kmodFindConnections walks through the established connections to find one which
// kmodCheckConnection walks through the established connections to find one which
// is compatible with a kmod operation on the given moduleName and
// moduleOptions. Returns an error if not found.
var kmodEnsureConnection = func(context *hookstate.Context, moduleName string, moduleOptions []string) (err error) {
var kmodCheckConnection = func(context *hookstate.Context, moduleName string, moduleOptions []string) (err error) {
snapName := context.InstanceName()

st := context.State()
Expand Down
10 changes: 5 additions & 5 deletions overlord/hookstate/ctlcmd/kmod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (s *kmodSuite) TestFindConnectionBadConnection(c *C) {
ctx, err := hookstate.NewContext(task, state, setup, s.mockHandler, "")
c.Assert(err, IsNil)

err = ctlcmd.KmodEnsureConnection(ctx, "module1", []string{"one", "two"})
err = ctlcmd.KmodCheckConnection(ctx, "module1", []string{"one", "two"})
c.Assert(err, ErrorMatches, `.*internal error: cannot get connections: .*`)
}

Expand Down Expand Up @@ -176,14 +176,14 @@ func (s *kmodSuite) TestFindConnectionMissingProperPlug(c *C) {
s.state.Set("conns", connections)
s.state.Unlock()

err := ctlcmd.KmodEnsureConnection(s.mockContext, "module3", []string{"opt1=v1"})
err := ctlcmd.KmodCheckConnection(s.mockContext, "module3", []string{"opt1=v1"})
c.Check(err, ErrorMatches, "required interface not connected")
}

func (s *kmodSuite) TestFindConnectionHappy(c *C) {
s.injectSnapWithProperPlug(c)

err := ctlcmd.KmodEnsureConnection(s.mockContext, "module2", []string{"opt1=v1"})
err := ctlcmd.KmodCheckConnection(s.mockContext, "module2", []string{"opt1=v1"})
c.Check(err, IsNil)
}

Expand All @@ -193,7 +193,7 @@ func (s *kmodSuite) TestInsertFailure(c *C) {
var loadModuleError error
var ensureConnectionError error

r1 := ctlcmd.MockKmodEnsureConnection(func(ctx *hookstate.Context, moduleName string, moduleOptions []string) error {
r1 := ctlcmd.MockKmodCheckConnection(func(ctx *hookstate.Context, moduleName string, moduleOptions []string) error {
c.Check(moduleName, Equals, "moderr")
c.Check(moduleOptions, DeepEquals, []string{"o1=v1", "o2=v2"})
return ensureConnectionError
Expand Down Expand Up @@ -254,7 +254,7 @@ func (s *kmodSuite) TestRemoveFailure(c *C) {
var loadModuleError error
var ensureConnectionError error

r1 := ctlcmd.MockKmodEnsureConnection(func(ctx *hookstate.Context, moduleName string, moduleOptions []string) error {
r1 := ctlcmd.MockKmodCheckConnection(func(ctx *hookstate.Context, moduleName string, moduleOptions []string) error {
c.Check(moduleName, Equals, "moderr")
c.Check(moduleOptions, HasLen, 0)
return ensureConnectionError
Expand Down

0 comments on commit 01ac065

Please sign in to comment.