Skip to content
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
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ endef
# under the category of Juju agents, that are CGO. These targets are also the
# ones we are more then likely wanting to cross compile.
define BUILD_CGO_AGENT_TARGETS
$(call tool_platform_paths,jujuagentd,$(filter linux%,${AGENT_PACKAGE_PLATFORMS}))
$(call tool_platform_paths,jujuagentd,$(filter linux%,${AGENT_PACKAGE_PLATFORMS})) \
$(call tool_platform_paths,jujud,$(filter linux%,${AGENT_PACKAGE_PLATFORMS}))
endef

define BUILD_CGO_BENCH_TARGETS
Expand Down Expand Up @@ -165,6 +166,7 @@ endif
# We only add pebble to the list of install targets if we are building for linux
ifeq ($(GOOS), linux)
INSTALL_TARGETS += jujuagentd
INSTALL_TARGETS += jujud
INSTALL_TARGETS += pebble
endif

Expand Down Expand Up @@ -316,6 +318,13 @@ jujuagentd: musl-install-if-missing dqlite-install-if-missing
## jujuagentd: Install jujuagentd without updating dependencies
${run_cgo_install}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We'll know this works when this becomes the following:

Suggested change
${run_cgo_install}
${run_go_install}


.PHONY: jujud
jujud: PACKAGE = github.com/juju/juju/cmd/jujud
jujud: EXTRA_BUILD_TAGS += dqlite libsqlite3
jujud: musl-install-if-missing dqlite-install-if-missing
## jujud: Install jujud controller binary without updating dependencies
${run_cgo_install}

.PHONY: dqlite-repl
dqlite-repl: PACKAGE = github.com/juju/juju/scripts/dqlite/cmd
dqlite-repl: EXTRA_BUILD_TAGS += dqlite libsqlite3
Expand Down Expand Up @@ -371,6 +380,12 @@ ${BUILD_DIR}/%/bin/jujuagentd: phony_explicit musl-install-if-missing dqlite-ins
$(eval ARCH = $(word 2,$(subst _, ,$*)))
$(eval BBIN_DIR = ${BUILD_DIR}/${OS}_${ARCH}/bin)

${BUILD_DIR}/%/bin/jujud: PACKAGE = github.com/juju/juju/cmd/jujud
${BUILD_DIR}/%/bin/jujud: EXTRA_BUILD_TAGS += dqlite libsqlite3
${BUILD_DIR}/%/bin/jujud: phony_explicit musl-install-if-missing dqlite-install-if-missing
# build for jujud controller binary
$(run_cgo_build)

${BUILD_DIR}/%/bin/containeragent: PACKAGE = github.com/juju/juju/cmd/containeragent
${BUILD_DIR}/%/bin/containeragent: phony_explicit
# build for containeragent
Expand Down
2 changes: 1 addition & 1 deletion agent/tools/symlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func EnsureSymlinks(jujuDir, dir string, commands []string) (err error) {
jujucPath := filepath.Join(jujuDir, names.Jujuc)
targetPath := jujucPath
if _, err := os.Stat(jujucPath); os.IsNotExist(err) {
jujudPath := filepath.Join(jujuDir, names.Jujud)
jujudPath := filepath.Join(jujuDir, names.JujuAgentd)
logger.Debugf(context.TODO(), "jujuc not found at %s using jujud path %s", jujucPath, jujudPath)
targetPath = jujudPath
}
Expand Down
2 changes: 1 addition & 1 deletion agent/tools/symlinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *SymlinksSuite) TestEnsureSymlinksSymlinkedDir(c *tc.C) {
func (s *SymlinksSuite) testEnsureSymlinks(c *tc.C, dir string) {
// If we have both 'jujuc' and 'jujud' prefer 'jujuc'
jujucPath := filepath.Join(s.toolsDir, names.Jujuc)
jujudPath := filepath.Join(s.toolsDir, names.Jujud)
jujudPath := filepath.Join(s.toolsDir, names.JujuAgentd)
err := os.WriteFile(jujucPath, []byte("first pick"), 0755)
c.Assert(err, tc.ErrorIsNil)
err = os.WriteFile(jujudPath, []byte("assume sane"), 0755)
Expand Down
5 changes: 5 additions & 0 deletions cmd/containeragent/unit/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func (*importSuite) TestImports(c *tc.C) {
"cmd/jujuagentd/agent/config",
"cmd/jujuagentd/agent/engine",
"cmd/jujuagentd/agent/errors",
"cmd/jujud/agent/addons",
"cmd/jujud/agent/agentconf",
"cmd/jujud/agent/config",
"cmd/jujud/agent/engine",
"cmd/jujud/agent/errors",
"cmd/modelcmd",
"cmd/output",
"controller",
Expand Down
6 changes: 3 additions & 3 deletions cmd/jujuagentd/agent/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (defaultRunner) RunCommands(run exec.RunParams) (*exec.ExecResponse, error)
}

// MachineAgent is responsible for tying together all functionality
// needed to orchestrate a Jujud instance which controls a machine.
// needed to orchestrate a JujuAgentd instance which controls a machine.
type MachineAgent struct {
agentconfig.AgentConfigWriter

Expand Down Expand Up @@ -798,11 +798,11 @@ func (a *MachineAgent) Tag() names.Tag {
}

func (a *MachineAgent) createJujudSymlinks(dataDir string) error {
jujud := filepath.Join(tools.ToolsDir(dataDir, a.Tag().String()), jujunames.Jujud)
jujud := filepath.Join(tools.ToolsDir(dataDir, a.Tag().String()), jujunames.JujuAgentd)
symlinks := jujudSymlinks
if a.isCaasAgent {
// For IAAS, this is done in systemd for for caas we need to do it here.
caasJujud := filepath.Join(tools.ToolsDir(dataDir, ""), jujunames.Jujud)
caasJujud := filepath.Join(tools.ToolsDir(dataDir, ""), jujunames.JujuAgentd)
if err := a.createSymlink(caasJujud, jujud); err != nil {
return errors.Annotatef(err, "failed to create %s symlink", jujud)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/jujuagentd/agent/safemode.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func NewSafeModeMachineAgent(
}

// SafeModeMachineAgent is responsible for tying together all functionality
// needed to orchestrate a Jujud instance which controls a machine.
// needed to orchestrate a JujuAgentd instance which controls a machine.
type SafeModeMachineAgent struct {
agentconfig.AgentConfigWriter

Expand Down Expand Up @@ -352,7 +352,7 @@ func (a *SafeModeMachineAgent) executeRebootOrShutdown(action params.RebootActio
}

func ensuringJujudNotRunning(tag names.Tag) error {
cmd := exec.Command("systemctl", "check", fmt.Sprintf("%s-machine-%s.service", jujunames.Jujud, tag.Id()))
cmd := exec.Command("systemctl", "check", fmt.Sprintf("%s-machine-%s.service", jujunames.JujuAgentd, tag.Id()))
output, err := cmd.CombinedOutput()
if err != nil {
// Exit code of 3 is ESRCH, which means no such process.
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujuagentd/reboot/reboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *Reboot) stopDeployedUnits() error {
return err
}
for _, svcName := range services {
if strings.HasPrefix(svcName, jujunames.Jujud+"-unit-") {
if strings.HasPrefix(svcName, jujunames.JujuAgentd+"-unit-") {
svc, err := r.reboot.NewServiceReference(svcName)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujuagentd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func Main(args []string) int {
var code int
commandName := filepath.Base(args[0])
switch commandName {
case jujunames.Jujud:
case jujunames.JujuAgentd:
code, err = jujuDMain(args, ctx)
case jujunames.JujuExec:
lock, err := machinelock.New(machinelock.Config{
Expand Down
100 changes: 100 additions & 0 deletions cmd/jujud/agent/agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package agent

import (
"testing"

"github.com/juju/tc"

"github.com/juju/juju/agent"
"github.com/juju/juju/cmd/cmd"
"github.com/juju/juju/cmd/cmd/cmdtesting"
"github.com/juju/juju/cmd/internal/agent/agentconf"
corelogger "github.com/juju/juju/core/logger"
internallogger "github.com/juju/juju/internal/logger"
"github.com/juju/juju/internal/testhelpers"
)

type acCreator func() (cmd.Command, agentconf.AgentConf)

// CheckAgentCommand is a utility function for verifying that common agent
// options are handled by a Command; it returns an instance of that
// command pre-parsed, with any mandatory flags added.
func CheckAgentCommand(c *tc.C, dataDir string, create acCreator, args []string) cmd.Command {
_, conf := create()
c.Assert(conf.DataDir(), tc.Equals, dataDir)
badArgs := append(args, "--data-dir", "")
com, _ := create()
err := cmdtesting.InitCommand(com, badArgs)
c.Assert(err, tc.ErrorMatches, "--data-dir option must be set")
return com
}

// ParseAgentCommand is a utility function that inserts the always-required args
// before parsing an agent command and returning the result.
func ParseAgentCommand(ac cmd.Command, args []string) error {
common := []string{
"--data-dir", "jd",
}
return cmdtesting.InitCommand(ac, append(common, args...))
}

type agentLoggingSuite struct {
testhelpers.IsolationSuite
}

func TestAgentLoggingSuite(t *testing.T) {
tc.Run(t, &agentLoggingSuite{})
}

func (*agentLoggingSuite) TestNoLoggingConfig(c *tc.C) {
f := &fakeLoggingConfig{}
context := internallogger.LoggerContext(corelogger.WARNING)
initial := context.Config().String()

agentconf.SetupAgentLogging(context, f)

c.Assert(context.Config().String(), tc.Equals, initial)
}

func (*agentLoggingSuite) TestLoggingOverride(c *tc.C) {
f := &fakeLoggingConfig{
loggingOverride: "test=INFO",
}
context := internallogger.LoggerContext(corelogger.WARNING)

agentconf.SetupAgentLogging(context, f)

c.Assert(context.Config().String(), tc.Equals, "<root>=WARNING;test=INFO")
}

func (*agentLoggingSuite) TestLoggingConfig(c *tc.C) {
f := &fakeLoggingConfig{
loggingConfig: "test=INFO",
}
context := internallogger.LoggerContext(corelogger.WARNING)

agentconf.SetupAgentLogging(context, f)

c.Assert(context.Config().String(), tc.Equals, "<root>=WARNING;test=INFO")
}

type fakeLoggingConfig struct {
agent.Config

loggingConfig string
loggingOverride string
}

func (f *fakeLoggingConfig) LoggingConfig() string {
return f.loggingConfig
}

func (f *fakeLoggingConfig) Value(key string) string {
if key == agent.LoggingOverride {
return f.loggingOverride
}
return ""
}
Loading
Loading