Skip to content

Commit

Permalink
Refactor series support to that juju itself can set its own supported…
Browse files Browse the repository at this point in the history
… series
  • Loading branch information
wallyworld committed Mar 11, 2021
1 parent b9be824 commit 9ff81fd
Show file tree
Hide file tree
Showing 145 changed files with 1,369 additions and 288 deletions.
2 changes: 1 addition & 1 deletion api/imagemetadatamanager/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"regexp"

"github.com/juju/errors"
"github.com/juju/os/series"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/api/base/testing"
"github.com/juju/juju/api/imagemetadatamanager"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/series"
coretesting "github.com/juju/juju/testing"
)

Expand Down
2 changes: 1 addition & 1 deletion apiserver/authentication/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/juju/juju/state"
)

// AgentIdentityProvider performs authentication for machine and unit agents.
// AgentAuthenticator performs authentication for machine and unit agents.
type AgentAuthenticator struct{}

var _ EntityAuthenticator = (*AgentAuthenticator)(nil)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/agent/provisioner/provisioninginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/juju/collections/set"
"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/juju/os/series"

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/common/storagecommon"
Expand All @@ -20,6 +19,7 @@ import (
"github.com/juju/juju/core/lxdprofile"
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/series"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/imagemetadata"
"github.com/juju/juju/environs/simplestreams"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os/series"
"gopkg.in/yaml.v2"

"github.com/juju/juju/apiserver/common"
Expand All @@ -29,6 +28,7 @@ import (
"github.com/juju/juju/core/devices"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/core/series"
"github.com/juju/juju/state"
"github.com/juju/juju/storage"
)
Expand Down
4 changes: 2 additions & 2 deletions apiserver/facades/client/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os"
"github.com/juju/os/series"
"github.com/juju/replicaset"
"github.com/juju/version"

Expand All @@ -28,7 +26,9 @@ import (
"github.com/juju/juju/core/life"
"github.com/juju/juju/core/multiwatcher"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/os"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/core/series"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/context"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os/series"
"github.com/juju/replicaset"
jtesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
Expand All @@ -39,6 +38,7 @@ import (
"github.com/juju/juju/core/multiwatcher"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/core/series"
"github.com/juju/juju/core/status"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
Expand Down
11 changes: 9 additions & 2 deletions apiserver/facades/client/machinemanager/machinemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ package machinemanager

import (
"fmt"
"strconv"
"time"

"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os"
"github.com/juju/os/series"

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/common/storagecommon"
"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/instance"
"github.com/juju/juju/core/os"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/core/series"
"github.com/juju/juju/core/status"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/context"
Expand Down Expand Up @@ -742,6 +743,12 @@ func isSeriesLessThan(series1, series2 string) (bool, error) {
if err != nil {
return false, err
}
// Versions may be numeric.
vers1Int, err1 := strconv.Atoi(version1)
vers2Int, err2 := strconv.Atoi(version2)
if err1 == nil && err2 == nil {
return vers2Int > vers1Int, nil
}
return version2 > version1, nil
}

Expand Down
51 changes: 47 additions & 4 deletions apiserver/facades/client/machinemanager/machinemanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ package machinemanager_test

import (
"sort"
"strconv"
"strings"
"time"

"github.com/golang/mock/gomock"
"github.com/juju/errors"
"github.com/juju/juju/core/os"
"github.com/juju/names/v4"
"github.com/juju/os/series"
jtesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
Expand All @@ -24,6 +25,7 @@ import (
apiservertesting "github.com/juju/juju/apiserver/testing"
"github.com/juju/juju/cloud"
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/series"
"github.com/juju/juju/core/status"
"github.com/juju/juju/environs/context"
"github.com/juju/juju/state"
Expand Down Expand Up @@ -873,16 +875,57 @@ func (s *MachineManagerSuite) TestIsSeriesLessThan(c *gc.C) {

ss := series.SupportedSeries()

// get the series versions
vs := make([]string, 0, len(ss))
// Group series by OS and check the list for
// each OS separately.
seriesByOS := make(map[os.OSType][]string)
for _, ser := range ss {
seriesOS, err := series.GetOSFromSeries(ser)
c.Assert(err, jc.ErrorIsNil)
seriesList := seriesByOS[seriesOS]
seriesList = append(seriesList, ser)
seriesByOS[seriesOS] = seriesList
}

for seriesOS, seriesList := range seriesByOS {
c.Logf("checking series for %v", seriesOS)
s.assertSeriesLessThan(c, seriesList)
}
}

type seriesVersion []string

func (s seriesVersion) Len() int {
return len(s)
}

func (s seriesVersion) Less(i, j int) bool {
v1 := s[i]
v2 := s[j]
v1Int, err1 := strconv.Atoi(v1)
v2Int, err2 := strconv.Atoi(v2)
if err1 == nil && err2 == nil {
return v1Int < v2Int
}
return v1 < v2
}

func (s seriesVersion) Swap(i, j int) {
sv := s[i]
s[i] = s[j]
s[j] = sv
}

func (s *MachineManagerSuite) assertSeriesLessThan(c *gc.C, seriesList []string) {
// get the series versions
vs := make(seriesVersion, 0, len(seriesList))
for _, ser := range seriesList {
ver, err := series.SeriesVersion(ser)
c.Assert(err, jc.ErrorIsNil)
vs = append(vs, ver)
}

// sort the values, so the lexicographical order is determined
sort.Strings(vs)
sort.Sort(vs)

// check that the IsSeriesLessThan works for all supported series
for i := range vs {
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/modelmanager/modelinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/juju/description/v2"
"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/juju/os/series"
gitjujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/juju/juju/core/life"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/core/series"
"github.com/juju/juju/core/status"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
Expand Down
4 changes: 2 additions & 2 deletions apiserver/facades/controller/metricsmanager/metricsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os"
"github.com/juju/os/series"
"github.com/juju/utils"

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/apiserver/facades/agent/metricsender"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/instance"
"github.com/juju/juju/core/os"
"github.com/juju/juju/core/series"
"github.com/juju/juju/state"
)

Expand Down
7 changes: 4 additions & 3 deletions cloudconfig/cloudinit/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.

// The cloudinit package implements a way of creating
// Package cloudinit implements a way of creating
// a cloud-init configuration file.
// See https://help.ubuntu.com/community/CloudInit.
package cloudinit
Expand All @@ -11,13 +11,14 @@ import (
"github.com/juju/errors"
corenetwork "github.com/juju/juju/core/network"
jujupackaging "github.com/juju/juju/packaging"
"github.com/juju/os"
"github.com/juju/os/series"
"github.com/juju/packaging"
"github.com/juju/packaging/commands"
"github.com/juju/packaging/config"
"github.com/juju/proxy"
"github.com/juju/utils/shell"

"github.com/juju/juju/core/os"
"github.com/juju/juju/core/series"
)

// CloudConfig is the interface of all cloud-init cloudconfig options.
Expand Down
7 changes: 4 additions & 3 deletions cloudconfig/machinecloudconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (

"github.com/juju/errors"
"github.com/juju/loggo"
utilsos "github.com/juju/os"
utilsseries "github.com/juju/os/series"
osseries "github.com/juju/os/series"
"github.com/juju/utils"
"gopkg.in/yaml.v2"

utilsos "github.com/juju/juju/core/os"
"github.com/juju/juju/core/paths"
utilsseries "github.com/juju/juju/core/series"
)

// InitReader describes methods for extracting machine provisioning config,
Expand Down Expand Up @@ -88,7 +89,7 @@ func (r *MachineInitReader) GetInitConfig() (map[string]interface{}, error) {
}
switch containerOS {
case utilsos.Ubuntu, utilsos.CentOS, utilsos.OpenSUSE:
hostSeries, err := utilsseries.HostSeries()
hostSeries, err := osseries.HostSeries()
if err != nil || series != hostSeries {
logger.Debugf("not attempting to get init config for %s, series of machine and container differ", series)
return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions cloudconfig/providerinit/providerinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.

// This package offers userdata in a gzipped format to be used by different
// Package providerinit offers userdata in a gzipped format to be used by different
// cloud providers
package providerinit

import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/os/series"

"github.com/juju/juju/cloudconfig"
"github.com/juju/juju/cloudconfig/cloudinit"
"github.com/juju/juju/cloudconfig/instancecfg"
"github.com/juju/juju/cloudconfig/providerinit/renderers"
"github.com/juju/juju/core/series"
)

var logger = loggo.GetLogger("juju.cloudconfig.providerinit")
Expand Down
5 changes: 2 additions & 3 deletions cloudconfig/providerinit/renderers/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.

// The renderers package implements a way to encode the userdata
// Package renderers implements a way to encode the userdata
// depending on the OS and the provider.
// It currently holds an interface and common functions, while
// the implementations live in the particular providers.
package renderers

import (
"github.com/juju/os"

"github.com/juju/juju/cloudconfig/cloudinit"
"github.com/juju/juju/core/os"
)

// ProviderRenderer defines a method to encode userdata depending on
Expand Down
4 changes: 2 additions & 2 deletions cloudconfig/userdatacfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/juju/os"
"github.com/juju/os/series"
"github.com/juju/proxy"
"github.com/juju/utils"

"github.com/juju/juju/agent"
"github.com/juju/juju/cloudconfig/cloudinit"
"github.com/juju/juju/cloudconfig/instancecfg"
"github.com/juju/juju/core/os"
"github.com/juju/juju/core/series"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cloudconfig/userdatacfg_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"github.com/juju/featureflag"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os"
"github.com/juju/proxy"
"github.com/juju/version"

"github.com/juju/juju/agent"
"github.com/juju/juju/cloudconfig/cloudinit"
"github.com/juju/juju/core/os"
"github.com/juju/juju/environs/simplestreams"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/service"
Expand Down
2 changes: 1 addition & 1 deletion cloudconfig/userdatacfg_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/juju/errors"
"github.com/juju/featureflag"
"github.com/juju/names/v4"
"github.com/juju/os/series"
"github.com/juju/utils/cert"

"github.com/juju/juju/core/paths"
"github.com/juju/juju/core/series"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/tools"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/application/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/juju/gnuflag"
"github.com/juju/loggo"
"github.com/juju/names/v4"
"github.com/juju/os/series"
jujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
Expand All @@ -50,6 +49,7 @@ import (
"github.com/juju/juju/core/devices"
"github.com/juju/juju/core/instance"
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/series"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/context"
Expand Down
Loading

0 comments on commit 9ff81fd

Please sign in to comment.