Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Mar 20, 2021
1 parent fabcd77 commit 3774d85
Show file tree
Hide file tree
Showing 36 changed files with 155 additions and 167 deletions.
4 changes: 2 additions & 2 deletions apiserver/common/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/juju/os/v2/series"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2/arch"
"github.com/juju/version/v2"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/juju/juju/apiserver/params"
apiservertesting "github.com/juju/juju/apiserver/testing"
"github.com/juju/juju/core/network"
coreos "github.com/juju/juju/core/os"
"github.com/juju/juju/environs"
"github.com/juju/juju/juju/testing"
"github.com/juju/juju/state"
Expand Down Expand Up @@ -247,7 +247,7 @@ func (s *toolsSuite) TestFindToolsExactInStorage(c *gc.C) {
}

s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
s.PatchValue(&series.HostSeries, func() (string, error) { return "ubuntu", nil })
s.PatchValue(&coreos.HostOS, func() coreos.OSType { return coreos.Ubuntu })
s.PatchValue(&jujuversion.Current, version.MustParseBinary("1.22-beta1-ubuntu-amd64").Number)
s.testFindToolsExact(c, mockToolsStorage, true, true)
s.PatchValue(&jujuversion.Current, version.MustParseBinary("1.22.0-ubuntu-amd64").Number)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/agent/upgrader/unitupgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s *unitUpgraderSuite) TestSetTools(c *gc.C) {
realTools, err := s.rawUnit.AgentTools()
c.Assert(err, jc.ErrorIsNil)
c.Check(realTools.Version.Arch, gc.Equals, cur.Arch)
c.Check(realTools.Version.OSType, gc.Equals, cur.OSType)
c.Check(realTools.Version.Release, gc.Equals, cur.Release)
c.Check(realTools.Version.Major, gc.Equals, cur.Major)
c.Check(realTools.Version.Minor, gc.Equals, cur.Minor)
c.Check(realTools.Version.Patch, gc.Equals, cur.Patch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ func (s *CAASProvisionerSuite) TestOperatorProvisioningInfo(c *gc.C) {

func (s *CAASProvisionerSuite) TestOperatorProvisioningInfoNoStorage(c *gc.C) {
s.st.operatorRepo = "somerepo"
minVers := version.MustParse("2.8.0")
s.st.app = &mockApplication{
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: version.MustParse("2.8.0")}},
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: jujuversion.ToVersion1(minVers)}},
}
result, err := s.api.OperatorProvisioningInfo(params.Entities{Entities: []params.Entity{{"application-gitlab"}}})
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -196,8 +197,9 @@ func (s *CAASProvisionerSuite) TestOperatorProvisioningInfoNoStorage(c *gc.C) {
func (s *CAASProvisionerSuite) TestOperatorProvisioningInfoNoStoragePool(c *gc.C) {
s.storagePoolManager.SetErrors(errors.NotFoundf("pool"))
s.st.operatorRepo = "somerepo"
minVers := version.MustParse("2.7.0")
s.st.app = &mockApplication{
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: version.MustParse("2.7.0")}},
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: jujuversion.ToVersion1(minVers)}},
}
result, err := s.api.OperatorProvisioningInfo(params.Entities{Entities: []params.Entity{{"application-gitlab"}}})
c.Assert(err, jc.ErrorIsNil)
Expand Down
8 changes: 4 additions & 4 deletions apiserver/facades/controller/migrationmaster/facade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *Suite) SetUpTest(c *gc.C) {
Type: "iaas",
Config: map[string]interface{}{"uuid": s.modelUUID},
Owner: names.NewUserTag("admin"),
LatestToolsVersion: jujuversion.Current,
LatestToolsVersion: jujuversion.ToVersion1(jujuversion.Current),
})

s.resources = common.NewResources()
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *Suite) TestExportCAAS(c *gc.C) {
Type: "caas",
Config: map[string]interface{}{"uuid": s.modelUUID},
Owner: names.NewUserTag("admin"),
LatestToolsVersion: jujuversion.Current,
LatestToolsVersion: jujuversion.ToVersion1(jujuversion.Current),
})
s.assertExport(c, "caas")
}
Expand All @@ -290,7 +290,7 @@ func (s *Suite) assertExport(c *gc.C, modelType string) {
const tools1 = "2.0.1-ubuntu-amd64"
m := s.model.AddMachine(description.MachineArgs{Id: names.NewMachineTag("9")})
m.SetTools(description.AgentToolsArgs{
Version: version.MustParseBinary(tools1),
Version: jujuversion.ToVersion1Binary(version.MustParseBinary(tools1)),
})

res := app.AddResource(description.ResourceArgs{Name: "bin"})
Expand Down Expand Up @@ -321,7 +321,7 @@ func (s *Suite) assertExport(c *gc.C, modelType string) {
Tag: names.NewUnitTag("foo/0"),
})
unit.SetTools(description.AgentToolsArgs{
Version: version.MustParseBinary(tools0),
Version: jujuversion.ToVersion1Binary(version.MustParseBinary(tools0)),
})
unitRes := unit.AddResource(description.UnitResourceArgs{
Name: "bin",
Expand Down
5 changes: 3 additions & 2 deletions apiserver/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (s *toolsSuite) TestUploadAllowsOtherModelUUIDPath(c *gc.C) {
s.assertUploadResponse(c, resp, expectedTools[0])
}

// TODO(juju3) - drop this test
func (s *toolsSuite) TestUploadSeriesExpanded(c *gc.C) {
// Make some fake tools.
expectedTools, v, toolsContent := s.setupToolsForUpload(c)
Expand All @@ -362,7 +363,7 @@ func (s *toolsSuite) TestUploadSeriesExpanded(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
defer storage.Close()
for _, series := range []string{"precise", "quantal"} {
v.OSType = series
v.Release = series
_, r, err := storage.Open(v.String())
c.Assert(err, jc.ErrorIsNil)
uploadedData, err := ioutil.ReadAll(r)
Expand All @@ -372,7 +373,7 @@ func (s *toolsSuite) TestUploadSeriesExpanded(c *gc.C) {
}

// ensure other series *aren't* there.
v.OSType = "trusty"
v.Release = "trusty"
_, err = storage.Metadata(v.String())
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
Expand Down
8 changes: 4 additions & 4 deletions cloudconfig/cloudinit/renderscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func init() {
environs.RegisterProvider("sshinit_test", &testProvider{})
}

func testConfig(c *gc.C, controller bool, vers version.Binary) *config.Config {
func testConfig(c *gc.C, series string, vers version.Binary) *config.Config {
testConfig, err := config.New(config.UseDefaults, coretesting.FakeConfig())
c.Assert(err, jc.ErrorIsNil)
testConfig, err = testConfig.Apply(map[string]interface{}{
"type": "sshinit_test",
"default-series": vers.OSType,
"default-series": series,
"agent-version": vers.Number.String(),
})
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -54,7 +54,7 @@ func testConfig(c *gc.C, controller bool, vers version.Binary) *config.Config {
func (s *configureSuite) getCloudConfig(c *gc.C, controller bool, vers version.Binary, series string) cloudinit.CloudConfig {
var icfg *instancecfg.InstanceConfig
var err error
modelConfig := testConfig(c, controller, vers)
modelConfig := testConfig(c, series, vers)
if controller {
icfg, err = instancecfg.NewBootstrapInstanceConfig(
coretesting.FakeControllerConfig(),
Expand Down Expand Up @@ -90,7 +90,7 @@ func (s *configureSuite) getCloudConfig(c *gc.C, controller bool, vers version.B
APIPort: 456,
}
} else {
icfg, err = instancecfg.NewInstanceConfig(coretesting.ControllerTag, "0", "ya", imagemetadata.ReleasedStream, vers.OSType, nil)
icfg, err = instancecfg.NewInstanceConfig(coretesting.ControllerTag, "0", "ya", imagemetadata.ReleasedStream, series, nil)
c.Assert(err, jc.ErrorIsNil)
icfg.Jobs = []model.MachineJob{model.JobHostUnits}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/backups/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const backupMetadataTemplate = `
backup ID: {{.BackupID}}
backup format version: {{.FormatVersion}}
juju version: {{.JujuVersion}}
series: {{.Release}}
series: {{.Series}}
controller UUID: {{.ControllerUUID}}{{if (gt .HANodes 1)}}
controllers in HA: {{.HANodes}}{{end}}
Expand Down
61 changes: 29 additions & 32 deletions cmd/juju/commands/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func (s *BootstrapSuite) SetUpTest(c *gc.C) {
// Set jujuversion.Current to a known value, for which we
// will make tools available. Individual tests may
// override this.
s.PatchValue(&jujuversion.Current, v100b64.Number)
s.PatchValue(&arch.HostArch, func() string { return v100b64.Arch })
s.PatchValue(&series.HostSeries, func() (string, error) { return v100b64.OSType, nil })
s.PatchValue(&jujuversion.Current, v100w64.Number)
s.PatchValue(&arch.HostArch, func() string { return v100w64.Arch })
s.PatchValue(&series.HostSeries, func() (string, error) { return "bionic", nil })
s.PatchValue(&jujuos.HostOS, func() jujuos.OSType { return jujuos.Ubuntu })
s.PatchValue(&jujuseries.UbuntuDistroInfo, "/path/notexists")

Expand Down Expand Up @@ -243,13 +243,12 @@ func (s *BootstrapSuite) run(c *gc.C, test bootstrapTest) testing.Restorer {
var restore testing.Restorer = func() {
s.store = jujuclienttesting.MinimalStore()
}
bootstrapVersion := v100b64
bootstrapVersion := v100w64
if test.version != "" {
useVersion := strings.Replace(test.version, "%LTS%", "bionic", 1)
bootstrapVersion = version.MustParseBinary(useVersion)
bootstrapVersion = version.MustParseBinary(test.version)
restore = restore.Add(testing.PatchValue(&jujuversion.Current, bootstrapVersion.Number))
restore = restore.Add(testing.PatchValue(&arch.HostArch, func() string { return bootstrapVersion.Arch }))
restore = restore.Add(testing.PatchValue(&series.HostSeries, func() (string, error) { return bootstrapVersion.OSType, nil }))
restore = restore.Add(testing.PatchValue(&series.HostSeries, func() (string, error) { return "ubuntu", nil }))
bootstrapVersion.Build = 1
if test.upload != "" {
uploadVers := version.MustParseBinary(test.upload)
Expand Down Expand Up @@ -370,7 +369,7 @@ var bootstrapTests = []bootstrapTest{{
logs: []jc.SimpleMessage{{loggo.ERROR, `ambiguous constraints: "instance-type" overlaps with "mem"`}},
}, {
info: "bad model",
version: "1.2.3-%LTS%-amd64",
version: "1.2.3-ubuntu-amd64",
args: []string{"--config", "broken=Bootstrap Destroy", "--auto-upgrade"},
silentErr: true,
logs: []jc.SimpleMessage{{loggo.ERROR, `failed to bootstrap model: dummy.Bootstrap is broken`}},
Expand All @@ -389,14 +388,14 @@ var bootstrapTests = []bootstrapTest{{
constraints: constraints.MustParse("mem=4G cores=4 cpu-power=10"),
}, {
info: "--build-agent uses arch from constraint if it matches current version",
version: "1.3.3-saucy-ppc64el",
version: "1.3.3-ubuntu-ppc64el",
hostArch: "ppc64el",
args: []string{"--build-agent", "--constraints", "arch=ppc64el"},
upload: "1.3.3.1-bionic-ppc64el", // from jujuversion.Current
upload: "1.3.3.1-ubuntu-ppc64el", // from jujuversion.Current
constraints: constraints.MustParse("arch=ppc64el"),
}, {
info: "--build-agent rejects mismatched arch",
version: "1.3.3-saucy-amd64",
version: "1.3.3-ubuntu-amd64",
hostArch: "amd64",
args: []string{"--build-agent", "--constraints", "arch=ppc64el"},
silentErr: true,
Expand All @@ -405,7 +404,7 @@ var bootstrapTests = []bootstrapTest{{
}},
}, {
info: "--build-agent rejects non-supported arch",
version: "1.3.3-saucy-mips64",
version: "1.3.3-ubuntu-mips64",
hostArch: "mips64",
args: []string{"--build-agent"},
silentErr: true,
Expand All @@ -414,10 +413,10 @@ var bootstrapTests = []bootstrapTest{{
}},
}, {
info: "--build-agent always bumps build number",
version: "1.2.3.4-xenial-amd64",
version: "1.2.3.4-ubuntu-amd64",
hostArch: "amd64",
args: []string{"--build-agent"},
upload: "1.2.3.5-bionic-amd64",
upload: "1.2.3.5-ubuntu-amd64",
}, {
info: "placement",
args: []string{"--to", "something"},
Expand All @@ -440,12 +439,12 @@ var bootstrapTests = []bootstrapTest{{
err: `invalid version "foo"`,
}, {
info: "agent-version doesn't match client version major",
version: "1.3.3-saucy-ppc64el",
version: "1.3.3-ubuntu-ppc64el",
args: []string{"--agent-version", "2.3.0"},
err: regexp.QuoteMeta(`this client can only bootstrap 1.3 agents`),
}, {
info: "agent-version doesn't match client version minor",
version: "1.3.3-saucy-ppc64el",
version: "1.3.3-ubuntu-ppc64el",
args: []string{"--agent-version", "1.4.0"},
err: regexp.QuoteMeta(`this client can only bootstrap 1.3 agents`),
}, {
Expand Down Expand Up @@ -1422,7 +1421,7 @@ func (s *BootstrapSuite) TestAutoUploadAfterFailedSync(c *gc.C) {
c.Check((<-opc).(dummy.OpBootstrap).Env, gc.Equals, bootstrap.ControllerModelName)
icfg := (<-opc).(dummy.OpFinalizeBootstrap).InstanceConfig
c.Assert(icfg, gc.NotNil)
c.Assert(icfg.AgentVersion().String(), gc.Equals, "1.7.3.1-xenial-"+arch.HostArch())
c.Assert(icfg.AgentVersion().String(), gc.Equals, "1.7.3.1-ubuntu-"+arch.HostArch())
}

func (s *BootstrapSuite) TestMissingToolsError(c *gc.C) {
Expand Down Expand Up @@ -2284,28 +2283,26 @@ func checkTools(c *gc.C, env environs.Environ, expected []version.Binary) {
}

var (
v100x64 = version.MustParseBinary("1.0.0-ubuntu-amd64")
v100b64 = version.MustParseBinary("1.0.0-windows-amd64")
v100g32 = version.MustParseBinary("1.0.0-ubuntu-i386")
v120x64 = version.MustParseBinary("1.2.0-ubuntu-amd64")
v120b64 = version.MustParseBinary("1.2.0-windows-amd64")
v120g32 = version.MustParseBinary("1.2.0-ubuntu-i386")
v120t32 = version.MustParseBinary("1.2.0-trusty-i386")
v120t64 = version.MustParseBinary("1.2.0-trusty-amd64")
v190b32 = version.MustParseBinary("1.9.0-bionic-i386")
v190g64 = version.MustParseBinary("1.9.0-groovy-amd64")
v200b64 = version.MustParseBinary("2.0.0-bionic-amd64")
v100u64 = version.MustParseBinary("1.0.0-ubuntu-amd64")
v100w64 = version.MustParseBinary("1.0.0-windows-amd64")
v100u32 = version.MustParseBinary("1.0.0-ubuntu-i386")
v120u64 = version.MustParseBinary("1.2.0-ubuntu-amd64")
v120w64 = version.MustParseBinary("1.2.0-windows-amd64")
v120u32 = version.MustParseBinary("1.2.0-ubuntu-i386")
v190u32 = version.MustParseBinary("1.9.0-ubuntu-i386")
v190w64 = version.MustParseBinary("1.9.0-windows-amd64")
v200u64 = version.MustParseBinary("2.0.0-ubuntu-amd64")
v100All = []version.Binary{
v100x64, v100b64, v100g64, v100g32,
v100u64, v100w64, v100u32,
}
v120All = []version.Binary{
v120x64, v120b64, v120g64, v120g32, v120t32, v120t64,
v120u64, v120w64, v120u32,
}
v190All = []version.Binary{
v190b32, v190g64,
v190u32, v190w64,
}
v200All = []version.Binary{
v200b64,
v200u64,
}
vAll = joinBinaryVersions(v100All, v120All, v190All, v200All)
)
Expand Down
24 changes: 12 additions & 12 deletions cmd/juju/commands/upgradecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,34 @@ var _ = gc.Suite(&UpgradeIAASControllerSuite{})

var upgradeIAASControllerPassthroughTests = []upgradeTest{{
about: "unwanted extra argument",
currentVersion: "1.0.0-groovy-amd64",
currentVersion: "1.0.0-ubuntu-amd64",
args: []string{"foo"},
expectInitErr: "unrecognized args:.*",
}, {
about: "invalid --agent-version value",
currentVersion: "1.0.0-groovy-amd64",
currentVersion: "1.0.0-ubuntu-amd64",
args: []string{"--agent-version", "invalid-version"},
expectInitErr: "invalid version .*",
}, {
about: "latest supported stable release",
available: []string{"2.1.0-groovy-amd64", "2.1.2-groovy-i386", "2.1.3-groovy-amd64", "2.1-dev1-groovy-amd64"},
currentVersion: "2.0.0-groovy-amd64",
available: []string{"2.1.0-ubuntu-amd64", "2.1.2-ubuntu-i386", "2.1.3-ubuntu-amd64", "2.1-dev1-ubuntu-amd64"},
currentVersion: "2.0.0-ubuntu-amd64",
agentVersion: "2.0.0",
expectVersion: "2.1.3",
}, {
about: "latest supported stable, when client is dev, explicit upload",
available: []string{"2.1-dev1-groovy-amd64", "2.1.0-groovy-amd64", "2.3-dev0-groovy-amd64", "3.0.1-groovy-amd64"},
currentVersion: "2.1-dev0-groovy-amd64",
available: []string{"2.1-dev1-ubuntu-amd64", "2.1.0-ubuntu-amd64", "2.3-dev0-ubuntu-amd64", "3.0.1-ubuntu-amd64"},
currentVersion: "2.1-dev0-ubuntu-amd64",
agentVersion: "2.0.0",
args: []string{"--build-agent"},
expectVersion: "2.1-dev0.1",
}, {
about: "upload with explicit version",
currentVersion: "2.2.0-groovy-amd64",
currentVersion: "2.2.0-ubuntu-amd64",
agentVersion: "2.0.0",
args: []string{"--build-agent", "--agent-version", "2.7.3"},
expectVersion: "2.7.3.1",
expectUploaded: []string{"2.7.3.1-groovy-amd64", "2.7.3.1-%LTS%-amd64", "2.7.3.1-xenial-amd64"},
expectUploaded: []string{"2.7.3.1-ubuntu-amd64"},
}}

func (s *UpgradeIAASControllerSuite) upgradeControllerCommand() cmd.Command {
Expand Down Expand Up @@ -133,16 +133,16 @@ func (s *UpgradeIAASControllerSuite) TestUpgradeCorrectController(c *gc.C) {
tests := []upgradeTest{
{
about: "latest supported stable release with specified controller",
available: []string{"2.1.0-groovy-amd64", "2.1.2-groovy-i386", "2.1.3-groovy-amd64", "2.1-dev1-groovy-amd64"},
currentVersion: "2.0.0-groovy-amd64",
available: []string{"2.1.0-ubuntu-amd64", "2.1.2-ubuntu-i386", "2.1.3-ubuntu-amd64", "2.1-dev1-ubuntu-amd64"},
currentVersion: "2.0.0-ubuntu-amd64",
agentVersion: "2.0.0",
expectVersion: "2.1.3",
args: []string{"--controller", "kontroll"},
},
{
about: "latest supported stable release without specified controller",
available: []string{"2.1.0-groovy-amd64", "2.1.2-groovy-i386", "2.1.3-groovy-amd64", "2.1-dev1-groovy-amd64"},
currentVersion: "2.0.0-groovy-amd64",
available: []string{"2.1.0-ubuntu-amd64", "2.1.2-ubuntu-i386", "2.1.3-ubuntu-amd64", "2.1-dev1-ubuntu-amd64"},
currentVersion: "2.0.0-ubuntu-amd64",
agentVersion: "2.0.0",
expectVersion: "2.1.3",
expectErr: badControllerSelected.Error(),
Expand Down
Loading

0 comments on commit 3774d85

Please sign in to comment.