Skip to content

Commit 92d1304

Browse files
committed
Move some shared files and errors etc from worker uniter to worker common
1 parent 558d7da commit 92d1304

File tree

133 files changed

+661
-1891
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+661
-1891
lines changed

cmd/juju/commands/debughooks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/juju/juju/apiserver/params"
1919
"github.com/juju/juju/cmd/modelcmd"
2020
"github.com/juju/juju/network/ssh"
21-
unitdebug "github.com/juju/juju/worker/uniter/runner/debug"
21+
unitdebug "github.com/juju/juju/worker/common/runner/debug"
2222
)
2323

2424
func newDebugHooksCommand(hostChecker ssh.ReachableChecker) cmd.Command {

cmd/juju/commands/helptool.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import (
1414

1515
"github.com/juju/juju/network"
1616
"github.com/juju/juju/storage"
17-
"github.com/juju/juju/worker/common/hookcommands"
1817
"github.com/juju/juju/worker/uniter/runner/jujuc"
1918
)
2019

2120
// dummyHookContext implements hooks.Context,
2221
// as expected by hooks.NewCommand.
23-
type dummyHookContext struct{ hookcommands.Context }
22+
type dummyHookContext struct{ jujuc.Context }
2423

2524
func (dummyHookContext) AddMetrics(_, _ string, _ time.Time) error {
2625
return nil
@@ -49,44 +48,44 @@ func (dummyHookContext) OpenedPorts() []network.PortRange {
4948
func (dummyHookContext) ConfigSettings() (charm.Settings, error) {
5049
return charm.NewConfig().DefaultSettings(), nil
5150
}
52-
func (dummyHookContext) HookRelation() (hookcommands.ContextRelation, error) {
51+
func (dummyHookContext) HookRelation() (jujuc.ContextRelation, error) {
5352
return nil, errors.NotFoundf("HookRelation")
5453
}
5554
func (dummyHookContext) RemoteUnitName() (string, error) {
5655
return "", errors.NotFoundf("RemoteUnitName")
5756
}
58-
func (dummyHookContext) Relation(id int) (hookcommands.ContextRelation, error) {
57+
func (dummyHookContext) Relation(id int) (jujuc.ContextRelation, error) {
5958
return nil, errors.NotFoundf("Relation")
6059
}
6160
func (dummyHookContext) RelationIds() ([]int, error) {
6261
return []int{}, errors.NotFoundf("RelationIds")
6362
}
6463

65-
func (dummyHookContext) RequestReboot(prio hookcommands.RebootPriority) error {
64+
func (dummyHookContext) RequestReboot(prio jujuc.RebootPriority) error {
6665
return nil
6766
}
6867

6968
func (dummyHookContext) HookStorageInstance() (*storage.StorageInstance, error) {
7069
return nil, errors.NotFoundf("HookStorageInstance")
7170
}
7271

73-
func (dummyHookContext) HookStorage() (hookcommands.ContextStorageAttachment, error) {
72+
func (dummyHookContext) HookStorage() (jujuc.ContextStorageAttachment, error) {
7473
return nil, errors.NotFoundf("HookStorage")
7574
}
7675

7776
func (dummyHookContext) StorageInstance(id string) (*storage.StorageInstance, error) {
7877
return nil, errors.NotFoundf("StorageInstance")
7978
}
8079

81-
func (dummyHookContext) UnitStatus() (*hookcommands.StatusInfo, error) {
82-
return &hookcommands.StatusInfo{}, nil
80+
func (dummyHookContext) UnitStatus() (*jujuc.StatusInfo, error) {
81+
return &jujuc.StatusInfo{}, nil
8382
}
8483

85-
func (dummyHookContext) SetStatus(hookcommands.StatusInfo) error {
84+
func (dummyHookContext) SetStatus(jujuc.StatusInfo) error {
8685
return nil
8786
}
8887

89-
func (dummyHookContext) Component(name string) (hookcommands.ContextComponent, error) {
88+
func (dummyHookContext) Component(name string) (jujuc.ContextComponent, error) {
9089
return nil, nil
9190
}
9291

component/all/payload.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
internalclient "github.com/juju/juju/payload/api/private/client"
1616
"github.com/juju/juju/payload/context"
1717
"github.com/juju/juju/payload/status"
18-
"github.com/juju/juju/worker/common/hookcommands"
1918
unitercontext "github.com/juju/juju/worker/uniter/runner/context"
2019
"github.com/juju/juju/worker/uniter/runner/jujuc"
2120
)
@@ -73,7 +72,7 @@ func (c payloads) registerHookContext() {
7372
}
7473

7574
unitercontext.RegisterComponentFunc(payload.ComponentName,
76-
func(config unitercontext.ComponentConfig) (hookcommands.ContextComponent, error) {
75+
func(config unitercontext.ComponentConfig) (jujuc.ContextComponent, error) {
7776
hctxClient := c.newUnitFacadeClient(config.APICaller)
7877
// TODO(ericsnow) Pass the unit's tag through to the component?
7978
component, err := context.NewContextAPI(hctxClient, config.DataDir)
@@ -88,7 +87,7 @@ func (c payloads) registerHookContext() {
8887
}
8988

9089
type payloadsHookContext struct {
91-
hookcommands.Context
90+
jujuc.Context
9291
}
9392

9493
// Component implements context.HookContext.
@@ -114,7 +113,7 @@ func (payloads) registerHookContextCommands() {
114113
return
115114
}
116115

117-
jujuc.RegisterCommand(context.RegisterCmdName, func(ctx hookcommands.Context) (cmd.Command, error) {
116+
jujuc.RegisterCommand(context.RegisterCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
118117
compCtx := payloadsHookContext{ctx}
119118
cmd, err := context.NewRegisterCmd(compCtx)
120119
if err != nil {
@@ -123,7 +122,7 @@ func (payloads) registerHookContextCommands() {
123122
return cmd, nil
124123
})
125124

126-
jujuc.RegisterCommand(context.StatusSetCmdName, func(ctx hookcommands.Context) (cmd.Command, error) {
125+
jujuc.RegisterCommand(context.StatusSetCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
127126
compCtx := payloadsHookContext{ctx}
128127
cmd, err := context.NewStatusSetCmd(compCtx)
129128
if err != nil {
@@ -132,7 +131,7 @@ func (payloads) registerHookContextCommands() {
132131
return cmd, nil
133132
})
134133

135-
jujuc.RegisterCommand(context.UnregisterCmdName, func(ctx hookcommands.Context) (cmd.Command, error) {
134+
jujuc.RegisterCommand(context.UnregisterCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
136135
compCtx := payloadsHookContext{ctx}
137136
cmd, err := context.NewUnregisterCmd(compCtx)
138137
if err != nil {

component/all/resource.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/juju/juju/resource/context"
1616
contextcmd "github.com/juju/juju/resource/context/cmd"
1717
"github.com/juju/juju/resource/resourceadapters"
18-
"github.com/juju/juju/worker/common/hookcommands"
1918
unitercontext "github.com/juju/juju/worker/uniter/runner/context"
2019
"github.com/juju/juju/worker/uniter/runner/jujuc"
2120
)
@@ -64,7 +63,7 @@ func (r resources) registerHookContext() {
6463

6564
unitercontext.RegisterComponentFunc(
6665
resource.ComponentName,
67-
func(config unitercontext.ComponentConfig) (hookcommands.ContextComponent, error) {
66+
func(config unitercontext.ComponentConfig) (jujuc.ContextComponent, error) {
6867
unitID := names.NewUnitTag(config.UnitName).String()
6968
hctxClient, err := r.newUnitFacadeClient(unitID, config.APICaller)
7069
if err != nil {
@@ -85,7 +84,7 @@ func (r resources) registerHookContextCommands() {
8584

8685
jujuc.RegisterCommand(
8786
contextcmd.GetCmdName,
88-
func(ctx hookcommands.Context) (jujucmd.Command, error) {
87+
func(ctx jujuc.Context) (jujucmd.Command, error) {
8988
compCtx, err := ctx.Component(resource.ComponentName)
9089
if err != nil {
9190
return nil, errors.Trace(err)

payload/context/base_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import (
1313

1414
"github.com/juju/juju/payload"
1515
"github.com/juju/juju/payload/context"
16-
"github.com/juju/juju/worker/common/hookcommands/hooktesting"
1716
)
1817

1918
type baseSuite struct {
20-
hooktesting.ContextSuite
19+
testing.ContextSuite
2120
payload payload.Payload
2221
}
2322

@@ -40,8 +39,8 @@ func (s *baseSuite) newPayload(name, ptype, id, status string) payload.Payload {
4039
return pl
4140
}
4241

43-
func (s *baseSuite) NewHookContext() (*stubHookContext, *hooktesting.ContextInfo) {
44-
ctx, info := s.ContextSuite.NewHookContextAndInfo()
42+
func (s *baseSuite) NewHookContext() (*stubHookContext, *testing.ContextInfo) {
43+
ctx, info := s.ContextSuite.NewHookContext()
4544
return &stubHookContext{ctx}, info
4645
}
4746

@@ -65,7 +64,7 @@ func checkPayloads(c *gc.C, payloads, expected []payload.Payload) {
6564
}
6665

6766
type stubHookContext struct {
68-
*hooktesting.Context
67+
*testing.Context
6968
}
7069

7170
func (c stubHookContext) Component(name string) (context.Component, error) {

payload/context/context_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/juju/juju/payload"
1414
"github.com/juju/juju/payload/context"
15-
"github.com/juju/juju/worker/common/hookcommands/hooktesting"
15+
"github.com/juju/juju/worker/uniter/runner/jujuc/jujuctesting"
1616
)
1717

1818
type contextSuite struct {
@@ -137,7 +137,7 @@ func (s *contextSuite) TestContextComponentMissing(c *gc.C) {
137137

138138
func (s *contextSuite) TestContextComponentWrong(c *gc.C) {
139139
hctx, info := s.NewHookContext()
140-
compCtx := &hooktesting.ContextComponent{}
140+
compCtx := &jujuctesting.ContextComponent{}
141141
info.SetComponent(payload.ComponentName, compCtx)
142142

143143
_, err := context.ContextComponent(hctx)

resource/context/cmd/get.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
"github.com/juju/cmd"
1010
"github.com/juju/errors"
1111

12-
"github.com/juju/juju/worker/common/hookcommands"
12+
"github.com/juju/juju/worker/uniter/runner/jujuc"
1313
)
1414

1515
// GetCmdName is the name of the resource-get command.
1616
const GetCmdName = "resource-get"
1717

1818
// NewGetCmd creates a new GetCmd for the given hook context.
19-
func NewGetCmd(c hookcommands.ContextComponent) (*GetCmd, error) {
19+
func NewGetCmd(c jujuc.ContextComponent) (*GetCmd, error) {
2020
return &GetCmd{
2121
compContext: c,
2222
}, nil
@@ -26,7 +26,7 @@ func NewGetCmd(c hookcommands.ContextComponent) (*GetCmd, error) {
2626
type GetCmd struct {
2727
cmd.CommandBase
2828

29-
compContext hookcommands.ContextComponent
29+
compContext jujuc.ContextComponent
3030
resourceName string
3131
}
3232

worker/caasoperator/commands/names.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ package commands
66
import (
77
"sort"
88

9-
"github.com/juju/juju/worker/common/hookcommands"
9+
"github.com/juju/cmd"
1010
)
1111

1212
// CmdSuffix is the filename suffix to use for executables.
1313
const cmdSuffix = ""
1414

15-
var registeredCommands = map[string]hookcommands.NewCommandFunc{}
15+
type creator func(interface{}) (cmd.Command, error)
16+
17+
var registeredCommands = map[string]creator{}
1618

1719
// baseCommands maps Command names to creators.
18-
var baseCommands = map[string]hookcommands.NewCommandFunc{
20+
var baseCommands = map[string]creator{
1921
"config-get" + cmdSuffix: nil,
2022
"juju-log" + cmdSuffix: nil,
21-
"status-get" + cmdSuffix: hookcommands.NewStatusGetCommand,
22-
"status-set" + cmdSuffix: hookcommands.NewStatusSetCommand,
23+
"status-get" + cmdSuffix: nil,
24+
"status-set" + cmdSuffix: nil,
2325
"application-version-set" + cmdSuffix: nil,
2426
"relation-ids" + cmdSuffix: nil,
2527
"relation-list" + cmdSuffix: nil,
@@ -28,9 +30,9 @@ var baseCommands = map[string]hookcommands.NewCommandFunc{
2830
"container-spec-set" + cmdSuffix: nil,
2931
}
3032

31-
func allEnabledCommands() map[string]hookcommands.NewCommandFunc {
32-
all := map[string]hookcommands.NewCommandFunc{}
33-
add := func(m map[string]hookcommands.NewCommandFunc) {
33+
func allEnabledCommands() map[string]creator {
34+
all := map[string]creator{}
35+
add := func(m map[string]creator) {
3436
for k, v := range m {
3537
all[k] = v
3638
}

worker/caasoperator/commands/server.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/juju/utils/exec"
2323

2424
"github.com/juju/juju/juju/sockets"
25-
"github.com/juju/juju/worker/common/hookcommands"
2625
)
2726

2827
var logger = loggo.GetLogger("worker.caasoperator.commands")
@@ -33,8 +32,16 @@ var ErrNoStdin = errors.New("hook tool requires stdin, none supplied")
3332

3433
// NewCommand returns an instance of the named Command, initialized to execute
3534
// against the supplied Context.
36-
func NewCommand(ctx hookcommands.Context, name string) (cmd.Command, error) {
37-
return hookcommands.NewCommand(ctx, name, allEnabledCommands)
35+
func NewCommand(ctx interface{}, name string) (cmd.Command, error) {
36+
f := allEnabledCommands()[name]
37+
if f == nil {
38+
return nil, errors.Errorf("unknown command: %s", name)
39+
}
40+
command, err := f(ctx)
41+
if err != nil {
42+
return nil, errors.Trace(err)
43+
}
44+
return command, nil
3845
}
3946

4047
// Request contains the information necessary to run a Command remotely.

worker/caasoperator/commands/server_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/juju/juju/juju/sockets"
2424
"github.com/juju/juju/testing"
2525
"github.com/juju/juju/worker/caasoperator/commands"
26-
"github.com/juju/juju/worker/common/hookcommands/hooktesting"
2726
)
2827

2928
type RpcCommand struct {
@@ -241,25 +240,23 @@ func (s *ServerSuite) TestBrokenCommand(c *gc.C) {
241240
c.Assert(string(resp.Stderr), gc.Equals, "ERROR blam\n")
242241
}
243242

244-
type NewCommandSuite struct {
245-
hooktesting.ContextSuite
246-
}
243+
type NewCommandSuite struct{}
247244

248245
var _ = gc.Suite(&NewCommandSuite{})
249246

250247
var newCommandTests = []struct {
251248
name string
252249
err string
253250
}{
254-
// TODO(caas) - add other commands as they get implemnted
255-
{"status-get", ""},
256-
{"status-set", ""},
251+
// TODO(caas) - add commands as they get implemnted
252+
//{"status-get", ""},
253+
//{"status-set", ""},
257254
// The error message contains .exe on Windows
258255
{"random", "unknown command: random(.exe)?"},
259256
}
260257

261258
func (s *NewCommandSuite) TestNewCommand(c *gc.C) {
262-
ctx := s.NewHookContext(c)
259+
var ctx interface{}
263260
for _, t := range newCommandTests {
264261
com, err := commands.NewCommand(ctx, t.name)
265262
if t.err == "" {

0 commit comments

Comments
 (0)