Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record official build number as separate variable #11071

Merged
merged 1 commit into from Jan 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
113 changes: 38 additions & 75 deletions agent/tools/tools_test.go
Expand Up @@ -208,90 +208,53 @@ func (t *ToolsSuite) TestReadGUIArchiveSuccess(c *gc.C) {
}

func (t *ToolsSuite) TestChangeAgentTools(c *gc.C) {
tests := []struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

All this is a revert back to old 2.7 behaviour

version1 version.Binary
version2 version.Binary
dir1 string
dir2 string
}{
{
version.MustParseBinary("1.2.3-quantal-amd64"),
version.MustParseBinary("1.2.4-quantal-amd64"),
"1.2.3-quantal-amd64", "1.2.4-quantal-amd64",
},
{
version.MustParseBinary("1.2-beta1.3-quantal-amd64"),
version.MustParseBinary("1.2.4-quantal-amd64"),
"1.2-beta1-quantal-amd64", "1.2.4-quantal-amd64",
},
{
version.MustParseBinary("1.2-beta1.3-quantal-amd64"),
version.MustParseBinary("1.2-beta2.4-quantal-amd64"),
"1.2-beta1-quantal-amd64", "1.2-beta2-quantal-amd64",
},
files := []*testing.TarFile{
testing.NewTarFile("jujuc", agenttools.DirPerm, "juju executable"),
testing.NewTarFile("jujud", agenttools.DirPerm, "jujuc executable"),
}
for k, v := range tests {
if k != 0 {
t.dataDir = c.MkDir()
}
files := []*testing.TarFile{
testing.NewTarFile("jujuc", agenttools.DirPerm, "juju executable"),
testing.NewTarFile("jujud", agenttools.DirPerm, "jujuc executable"),
}
data, checksum := testing.TarGz(files...)
testTools := &coretest.Tools{
URL: "http://foo/bar1",
Version: v.version1,
Size: int64(len(data)),
SHA256: checksum,
}
err := agenttools.UnpackTools(t.dataDir, testTools, bytes.NewReader(data))
c.Assert(err, jc.ErrorIsNil)
data, checksum := testing.TarGz(files...)
testTools := &coretest.Tools{
URL: "http://foo/bar1",
Version: version.MustParseBinary("1.2.3-quantal-amd64"),
Size: int64(len(data)),
SHA256: checksum,
}
err := agenttools.UnpackTools(t.dataDir, testTools, bytes.NewReader(data))
c.Assert(err, jc.ErrorIsNil)

gotTools, err := agenttools.ChangeAgentTools(t.dataDir, "testagent", testTools.Version)
c.Assert(err, jc.ErrorIsNil)
c.Assert(*gotTools, gc.Equals, *testTools)
gotTools, err := agenttools.ChangeAgentTools(t.dataDir, "testagent", testTools.Version)
c.Assert(err, jc.ErrorIsNil)
c.Assert(*gotTools, gc.Equals, *testTools)

assertDirNames(c, t.toolsDir(), []string{v.dir1, "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"jujuc", "jujud", agenttools.ToolsFile})
assertDirNames(c, t.toolsDir(), []string{"1.2.3-quantal-amd64", "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"jujuc", "jujud", agenttools.ToolsFile})

// Upgrade again to check that the link replacement logic works ok.
files2 := []*testing.TarFile{
testing.NewTarFile("quantal", agenttools.DirPerm, "foo content"),
testing.NewTarFile("amd64", agenttools.DirPerm, "bar content"),
}
data2, checksum2 := testing.TarGz(files2...)
tools2 := &coretest.Tools{
URL: "http://foo/bar2",
Version: v.version2,
Size: int64(len(data2)),
SHA256: checksum2,
}
err = agenttools.UnpackTools(t.dataDir, tools2, bytes.NewReader(data2))
c.Assert(err, jc.ErrorIsNil)
// Upgrade again to check that the link replacement logic works ok.
files2 := []*testing.TarFile{
testing.NewTarFile("quantal", agenttools.DirPerm, "foo content"),
testing.NewTarFile("amd64", agenttools.DirPerm, "bar content"),
}
data2, checksum2 := testing.TarGz(files2...)
tools2 := &coretest.Tools{
URL: "http://foo/bar2",
Version: version.MustParseBinary("1.2.4-quantal-amd64"),
Size: int64(len(data2)),
SHA256: checksum2,
}
err = agenttools.UnpackTools(t.dataDir, tools2, bytes.NewReader(data2))
c.Assert(err, jc.ErrorIsNil)

gotTools, err = agenttools.ChangeAgentTools(t.dataDir, "testagent", tools2.Version)
c.Assert(err, jc.ErrorIsNil)
c.Assert(*gotTools, gc.Equals, *tools2)
gotTools, err = agenttools.ChangeAgentTools(t.dataDir, "testagent", tools2.Version)
c.Assert(err, jc.ErrorIsNil)
c.Assert(*gotTools, gc.Equals, *tools2)

assertDirNames(c, t.toolsDir(), []string{v.dir1, v.dir2, "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"quantal", "amd64", agenttools.ToolsFile})
}
assertDirNames(c, t.toolsDir(), []string{"1.2.3-quantal-amd64", "1.2.4-quantal-amd64", "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"quantal", "amd64", agenttools.ToolsFile})
}

func (t *ToolsSuite) TestSharedToolsDir(c *gc.C) {
tests := []struct {
dataDir string
version version.Binary
out string
}{
{"/var/lib/juju", version.MustParseBinary("1.2.3-precise-amd64"), "/var/lib/juju/tools/1.2.3-precise-amd64"},
{"/var/lib/juju", version.MustParseBinary("1.2-beta1.3-precise-amd64"), "/var/lib/juju/tools/1.2-beta1-precise-amd64"},
}
for _, v := range tests {
dir := agenttools.SharedToolsDir(v.dataDir, v.version)
c.Assert(dir, gc.Equals, v.out)
}
dir := agenttools.SharedToolsDir("/var/lib/juju", version.MustParseBinary("1.2.3-precise-amd64"))
c.Assert(dir, gc.Equals, "/var/lib/juju/tools/1.2.3-precise-amd64")
}

func (t *ToolsSuite) TestSharedGUIDir(c *gc.C) {
Expand Down
1 change: 0 additions & 1 deletion agent/tools/toolsdir.go
Expand Up @@ -33,7 +33,6 @@ const (
// store binaries for the given version of the juju tools
// within the dataDir directory.
func SharedToolsDir(dataDir string, vers version.Binary) string {
vers.Number = vers.Number.ToPatch()
return path.Join(dataDir, "tools", vers.String())
}

Expand Down
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/juju/juju/state/watcher"
"github.com/juju/juju/storage"
"github.com/juju/juju/storage/poolmanager"
"github.com/juju/juju/version"
)

type API struct {
Expand Down Expand Up @@ -113,7 +114,7 @@ func (a *API) OperatorProvisioningInfo() (params.OperatorProvisioningInfo, error
)
}

imagePath := podcfg.GetJujuOCIImagePath(cfg, vers)
imagePath := podcfg.GetJujuOCIImagePath(cfg, vers.ToPatch(), version.OfficialBuild)
storageClassName, _ := modelConfig.AllAttrs()[provider.OperatorStorageKey].(string)
if storageClassName == "" {
return params.OperatorProvisioningInfo{}, errors.New("no operator storage class defined")
Expand Down
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/juju/juju/core/life"
"github.com/juju/juju/state"
coretesting "github.com/juju/juju/testing"
jujuversion "github.com/juju/juju/version"
)

var _ = gc.Suite(&CAASProvisionerSuite{})
Expand All @@ -44,6 +45,7 @@ func (s *CAASProvisionerSuite) SetUpTest(c *gc.C) {

s.resources = common.NewResources()
s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() })
s.PatchValue(&jujuversion.OfficialBuild, 666)

s.authorizer = &apiservertesting.FakeAuthorizer{
Tag: names.NewMachineTag("0"),
Expand Down Expand Up @@ -131,7 +133,7 @@ func (s *CAASProvisionerSuite) TestOperatorProvisioningInfoDefault(c *gc.C) {
result, err := s.api.OperatorProvisioningInfo()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, params.OperatorProvisioningInfo{
ImagePath: "jujusolutions/jujud-operator:2.6-beta3",
ImagePath: "jujusolutions/jujud-operator:2.6-beta3.666",
Version: version.MustParse("2.6-beta3"),
APIAddresses: []string{"10.0.0.1:1"},
Tags: map[string]string{
Expand All @@ -157,7 +159,7 @@ func (s *CAASProvisionerSuite) TestOperatorProvisioningInfo(c *gc.C) {
result, err := s.api.OperatorProvisioningInfo()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, params.OperatorProvisioningInfo{
ImagePath: s.st.operatorRepo + "/jujud-operator:" + "2.6-beta3",
ImagePath: s.st.operatorRepo + "/jujud-operator:" + "2.6-beta3.666",
Version: version.MustParse("2.6-beta3"),
APIAddresses: []string{"10.0.0.1:1"},
Tags: map[string]string{
Expand All @@ -184,7 +186,7 @@ func (s *CAASProvisionerSuite) TestOperatorProvisioningInfoNoStoragePool(c *gc.C
result, err := s.api.OperatorProvisioningInfo()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, params.OperatorProvisioningInfo{
ImagePath: s.st.operatorRepo + "/jujud-operator:" + "2.6-beta3",
ImagePath: s.st.operatorRepo + "/jujud-operator:" + "2.6-beta3.666",
Version: version.MustParse("2.6-beta3"),
APIAddresses: []string{"10.0.0.1:1"},
Tags: map[string]string{
Expand Down
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/juju/juju/state/watcher"
"github.com/juju/juju/storage"
"github.com/juju/juju/storage/poolmanager"
"github.com/juju/juju/version"
)

var logger = loggo.GetLogger("juju.apiserver.controller.caasunitprovisioner")
Expand Down Expand Up @@ -276,7 +277,7 @@ func (f *Facade) provisioningInfo(model Model, tagString string) (*params.Kubern
fmt.Sprintf("agent version is missing in model config %q", modelConfig.Name()),
)
}
operatorImagePath := podcfg.GetJujuOCIImagePath(controllerCfg, vers)
operatorImagePath := podcfg.GetJujuOCIImagePath(controllerCfg, vers.ToPatch(), version.OfficialBuild)

filesystemParams, err := f.applicationFilesystemParams(app, controllerCfg, modelConfig)
if err != nil {
Expand Down
Expand Up @@ -90,6 +90,7 @@ func (s *CAASProvisionerSuite) SetUpTest(c *gc.C) {
Controller: true,
}
s.clock = testclock.NewClock(time.Now())
s.PatchValue(&jujuversion.OfficialBuild, 666)

facade, err := caasunitprovisioner.NewFacade(
s.resources, s.authorizer, s.st, s.storage, s.devices, s.storagePoolManager, s.registry, s.clock)
Expand Down Expand Up @@ -201,7 +202,7 @@ func (s *CAASProvisionerSuite) TestProvisioningInfo(c *gc.C) {
DeploymentType: "stateful",
ServiceType: "loadbalancer",
},
OperatorImagePath: fmt.Sprintf("jujusolutions/jujud-operator:%s", jujuversion.Current.String()),
OperatorImagePath: fmt.Sprintf("jujusolutions/jujud-operator:%s", jujuversion.Current.String()+".666"),
Devices: []params.KubernetesDeviceParams{
{
Type: "nvidia.com/gpu",
Expand Down
3 changes: 2 additions & 1 deletion caas/kubernetes/provider/bootstrap_test.go
Expand Up @@ -65,6 +65,7 @@ func (s *bootstrapSuite) SetUpTest(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

pcfg.JujuVersion = jujuversion.Current
pcfg.OfficialBuild = 666
pcfg.APIInfo = &api.Info{
Password: "password",
CACert: testing.CACert,
Expand Down Expand Up @@ -559,7 +560,7 @@ func (s *bootstrapSuite) TestBootstrap(c *gc.C) {
{
Name: "api-server",
ImagePullPolicy: core.PullIfNotPresent,
Image: "jujusolutions/jujud-operator:" + jujuversion.Current.String(),
Image: "jujusolutions/jujud-operator:" + jujuversion.Current.String() + ".666",
Command: []string{
"/bin/sh",
},
Expand Down
5 changes: 3 additions & 2 deletions cloudconfig/podcfg/image.go
Expand Up @@ -20,7 +20,7 @@ const (

// GetControllerImagePath returns oci image path of jujud for a controller.
func (cfg *ControllerPodConfig) GetControllerImagePath() string {
return GetJujuOCIImagePath(cfg.Controller.Config, cfg.JujuVersion)
return GetJujuOCIImagePath(cfg.Controller.Config, cfg.JujuVersion, cfg.OfficialBuild)
}

// GetJujuDbOCIImagePath returns the juju-db oci image path.
Expand All @@ -39,8 +39,9 @@ func IsJujuOCIImage(imagePath string) bool {
}

// GetJujuOCIImagePath returns the jujud oci image path.
func GetJujuOCIImagePath(controllerCfg controller.Config, ver version.Number) string {
func GetJujuOCIImagePath(controllerCfg controller.Config, ver version.Number, build int) string {
// First check the deprecated "caas-operator-image-path" config.
ver.Build = build
imagePath := RebuildOldOperatorImagePath(
controllerCfg.CAASOperatorImagePath(), ver,
)
Expand Down
6 changes: 3 additions & 3 deletions cloudconfig/podcfg/image_test.go
Expand Up @@ -24,10 +24,10 @@ func (*imageSuite) TestGetJujuOCIImagePath(c *gc.C) {

cfg[controller.CAASImageRepo] = "testing-repo"
ver := version.MustParse("2.6-beta3")
path := podcfg.GetJujuOCIImagePath(cfg, ver)
c.Assert(path, jc.DeepEquals, "testing-repo/jujud-operator:2.6-beta3")
path := podcfg.GetJujuOCIImagePath(cfg, ver, 666)
c.Assert(path, jc.DeepEquals, "testing-repo/jujud-operator:2.6-beta3.666")

cfg[controller.CAASOperatorImagePath] = "testing-old-repo/jujud-old-operator:1.6"
path = podcfg.GetJujuOCIImagePath(cfg, ver)
path = podcfg.GetJujuOCIImagePath(cfg, ver, 0)
c.Assert(path, jc.DeepEquals, "testing-old-repo/jujud-old-operator:2.6-beta3")
}
3 changes: 3 additions & 0 deletions cloudconfig/podcfg/podcfg.go
Expand Up @@ -60,6 +60,9 @@ type ControllerPodConfig struct {
// JujuVersion is the juju version.
JujuVersion version.Number

// OfficialBuild is the build number to use when pulling the juju oci image.
OfficialBuild int

// DataDir holds the directory that juju state will be put in the new
// instance.
DataDir string
Expand Down
6 changes: 4 additions & 2 deletions cloudconfig/podcfg/podcfg_test.go
Expand Up @@ -65,7 +65,8 @@ func (*podcfgSuite) TestOperatorImagesDefaultRepo(c *gc.C) {
)
c.Assert(err, jc.ErrorIsNil)
podConfig.JujuVersion = version.MustParse("6.6.6")
c.Assert(podConfig.GetControllerImagePath(), gc.Equals, "jujusolutions/jujud-operator:6.6.6")
podConfig.OfficialBuild = 666
c.Assert(podConfig.GetControllerImagePath(), gc.Equals, "jujusolutions/jujud-operator:6.6.6.666")
c.Assert(podConfig.GetJujuDbOCIImagePath(), gc.Equals, "jujusolutions/juju-db:4.0")
}

Expand All @@ -80,7 +81,8 @@ func (*podcfgSuite) TestOperatorImagesCustomRepo(c *gc.C) {
)
c.Assert(err, jc.ErrorIsNil)
podConfig.JujuVersion = version.MustParse("6.6.6")
c.Assert(podConfig.GetControllerImagePath(), gc.Equals, "path/to/my/repo/jujud-operator:6.6.6")
podConfig.OfficialBuild = 666
c.Assert(podConfig.GetControllerImagePath(), gc.Equals, "path/to/my/repo/jujud-operator:6.6.6.666")
c.Assert(podConfig.GetJujuDbOCIImagePath(), gc.Equals, "path/to/my/repo/juju-db:4.0")
}

Expand Down
4 changes: 1 addition & 3 deletions cloudconfig/userdatacfg.go
Expand Up @@ -189,13 +189,11 @@ func (c *baseConfigure) toolsSymlinkCommand(toolsDir string) string {
c.icfg.AgentVersion(),
)
default:
ver := c.icfg.AgentVersion()
ver.Number = ver.ToPatch()
// TODO(dfc) ln -nfs, so it doesn't fail if for some reason that
// the target already exists.
return fmt.Sprintf(
"ln -s %v %s",
ver.String(),
c.icfg.AgentVersion(),
shquote(toolsDir),
)
}
Expand Down
6 changes: 3 additions & 3 deletions cloudconfig/userdatacfg_test.go
Expand Up @@ -392,7 +392,7 @@ mkdir -p /var/lib/juju/locks
\(id ubuntu &> /dev/null\) && chown ubuntu:ubuntu /var/lib/juju/locks
mkdir -p /var/log/juju
chown syslog:adm /var/log/juju
bin='/var/lib/juju/tools/1\.2\.3-precise-amd64'
bin='/var/lib/juju/tools/1\.2\.3\.123-precise-amd64'
mkdir -p \$bin
echo 'Fetching Juju agent version.*
curl .* '.*' --retry 10 -o \$bin/tools\.tar\.gz 'http://foo\.com/tools/released/juju1\.2\.3\.123-precise-amd64\.tgz'
Expand All @@ -406,10 +406,10 @@ chmod 0600 '/var/lib/juju/agents/machine-0/agent\.conf'
install -D -m 600 /dev/null '/var/lib/juju/bootstrap-params'
printf '%s\\n' '.*' > '/var/lib/juju/bootstrap-params'
echo 'Installing Juju machine agent'.*
/var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --timeout 10m0s --data-dir '/var/lib/juju' --debug '/var/lib/juju/bootstrap-params'
/var/lib/juju/tools/1\.2\.3\.123-precise-amd64/jujud bootstrap-state --timeout 10m0s --data-dir '/var/lib/juju' --debug '/var/lib/juju/bootstrap-params'
install -D -m 755 /dev/null '/sbin/remove-juju-services'
printf '%s\\n' '.*' > '/sbin/remove-juju-services'
ln -s 1\.2\.3-precise-amd64 '/var/lib/juju/tools/machine-0'
ln -s 1\.2\.3\.123-precise-amd64 '/var/lib/juju/tools/machine-0'
echo 'Starting Juju machine agent \(service jujud-machine-0\)'.*
cat > /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju agent for machine-0"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit .*\\n\\nscript\\n\\n\\n # Ensure log files are properly protected\\n touch /var/log/juju/machine-0\.log\\n chown syslog:adm /var/log/juju/machine-0\.log\\n chmod 0640 /var/log/juju/machine-0\.log\\n\\n exec '/var/lib/juju/tools/machine-0/jujud' machine --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nend script\\nEOF\\n
start jujud-machine-0
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/commands/upgradecontroller.go
Expand Up @@ -241,7 +241,7 @@ func initCAASVersions(
filterVersion.Major--
}
logger.Debugf("searching for agent images with major: %d", filterVersion.Major)
imagePath := podcfg.GetJujuOCIImagePath(controllerCfg, version.Zero)
imagePath := podcfg.GetJujuOCIImagePath(controllerCfg, version.Zero, 0)
availableTags, err := docker.ListOperatorImages(imagePath)
if err != nil {
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions cmd/supercommand.go
Expand Up @@ -42,8 +42,8 @@ type versionDetail struct {
GitTreeState string `json:"git-tree-state,omitempty" yaml:"git-tree-state,omitempty"`
// Compiler reported by runtime.Compiler
Compiler string `json:"compiler" yaml:"compiler"`
// Build is a monotonic integer set by Jenkins.
Build int `json:"build,omitempty" yaml:"build,omitempty"`
// OfficialBuild is a monotonic integer set by Jenkins.
OfficialBuild int `json:"official-build,omitempty" yaml:"official-build,omitempty"`
}

// NewSuperCommand is like cmd.NewSuperCommand but
Expand All @@ -62,11 +62,11 @@ func NewSuperCommand(p cmd.SuperCommandParams) *cmd.SuperCommand {
Series: series.MustHostSeries(),
}
detail := versionDetail{
Version: current.String(),
GitCommit: jujuversion.GitCommit,
GitTreeState: jujuversion.GitTreeState,
Compiler: jujuversion.Compiler,
Build: jujuversion.Build,
Version: current.String(),
GitCommit: jujuversion.GitCommit,
GitTreeState: jujuversion.GitTreeState,
Compiler: jujuversion.Compiler,
OfficialBuild: jujuversion.OfficialBuild,
}

// p.Version should be a version.Binary, but juju/cmd does not
Expand All @@ -80,7 +80,7 @@ func NewSuperCommand(p cmd.SuperCommandParams) *cmd.SuperCommand {
}

func runNotifier(name string) {
logger.Infof("running %s [%s %s %s %s]", name, jujuversion.Current, jujuversion.GitCommit, runtime.Compiler, runtime.Version())
logger.Infof("running %s [%s %d %s %s %s]", name, jujuversion.Current, jujuversion.OfficialBuild, jujuversion.GitCommit, runtime.Compiler, runtime.Version())
logger.Debugf(" args: %#v", os.Args)
}

Expand Down