Skip to content

Commit

Permalink
Remove HostSeries
Browse files Browse the repository at this point in the history
Remove HostSeries everywhere it appears

In most places, it needs to be replaces with the new HostBase. However,
in a few places, it turns out it could just be dropped entirely
  • Loading branch information
jack-w-shaw committed Apr 22, 2024
1 parent c9649b5 commit 7aee297
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 74 deletions.
10 changes: 3 additions & 7 deletions api/agent/upgradeseries/upgradeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,14 @@ func (s *Client) StartUnitCompletion(reason string) error {
// completely finished, passing the current host OS series.
// We use the name "Finish" to distinguish this method from the various
// "Complete" phases.
func (s *Client) FinishUpgradeSeries(hostSeries string) error {
func (s *Client) FinishUpgradeSeries(hostBase corebase.Base) error {
var results params.ErrorResults
base, err := corebase.GetBaseFromSeries(hostSeries)
if err != nil {
return errors.Trace(err)
}
args := params.UpdateChannelArgs{Args: []params.UpdateChannelArg{{
Entity: params.Entity{Tag: s.authTag.String()},
Channel: base.Channel.Track,
Channel: hostBase.Channel.Track,
}}}

err = s.facade.FacadeCall("FinishUpgradeSeries", args, &results)
err := s.facade.FacadeCall("FinishUpgradeSeries", args, &results)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion api/agent/upgradeseries/upgradeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/juju/juju/api/agent/upgradeseries"
"github.com/juju/juju/api/base/mocks"
corebase "github.com/juju/juju/core/base"
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/status"
"github.com/juju/juju/rpc/params"
Expand Down Expand Up @@ -179,7 +180,7 @@ func (s *upgradeSeriesSuite) TestFinishUpgradeSeries(c *gc.C) {
fCaller.EXPECT().FacadeCall("FinishUpgradeSeries", args, gomock.Any()).SetArg(2, resultSource)

api := upgradeseries.NewStateFromCaller(fCaller, s.tag)
err := api.FinishUpgradeSeries("xenial")
err := api.FinishUpgradeSeries(corebase.MustParseBaseFromString("[email protected]"))
c.Assert(err, gc.IsNil)
}

Expand Down
2 changes: 1 addition & 1 deletion apiserver/common/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *getToolsSuite) TestOSTools(c *gc.C) {

current := coretesting.CurrentVersion()
currentCopy := current
currentCopy.Release = coretesting.HostSeries(c)
currentCopy.Release = "foo"
configAttrs := map[string]interface{}{
"name": "some-name",
"type": "some-type",
Expand Down
9 changes: 2 additions & 7 deletions container/kvm/initialisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"runtime"

"github.com/juju/errors"
"github.com/juju/os/v2/series"

"github.com/juju/juju/container"
"github.com/juju/juju/core/base"
coreos "github.com/juju/juju/core/os"
"github.com/juju/juju/core/paths"
"github.com/juju/juju/packaging"
"github.com/juju/juju/packaging/dependency"
Expand Down Expand Up @@ -45,11 +44,7 @@ func (ci *containerInitialiser) Initialise() error {
}

func ensureDependencies() error {
hostSeries, err := series.HostSeries()
if err != nil {
return errors.Trace(err)
}
hostBase, err := base.GetBaseFromSeries(hostSeries)
hostBase, err := coreos.HostBase()
if err != nil {
return errors.Trace(err)
}
Expand Down
5 changes: 3 additions & 2 deletions container/lxd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/juju/clock"

"github.com/juju/juju/container"
"github.com/juju/juju/core/base"
"github.com/juju/juju/core/network"
)

Expand Down Expand Up @@ -45,8 +46,8 @@ func PatchLXDViaSnap(patcher patcher, isSnap bool) {
patcher.PatchValue(&lxdViaSnap, func() bool { return isSnap })
}

func PatchHostSeries(patcher patcher, series string) {
patcher.PatchValue(&hostSeries, func() (string, error) { return series, nil })
func PatchHostBase(patcher patcher, b base.Base) {
patcher.PatchValue(&hostBase, func() (base.Base, error) { return b, nil })
}

func PatchGetSnapManager(patcher patcher, mgr SnapManager) {
Expand Down
10 changes: 3 additions & 7 deletions container/lxd/initialisation_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (
"time"

"github.com/juju/errors"
"github.com/juju/os/v2/series"
"github.com/juju/packaging/v3/manager"
"github.com/juju/proxy"

"github.com/juju/juju/container"
corebase "github.com/juju/juju/core/base"
coreos "github.com/juju/juju/core/os"
"github.com/juju/juju/packaging"
"github.com/juju/juju/packaging/dependency"
"github.com/juju/juju/service"
)

var hostSeries = series.HostSeries
var hostBase = coreos.HostBase

type containerInitialiser struct {
containerNetworkingMethod string
Expand Down Expand Up @@ -68,11 +68,7 @@ func NewContainerInitialiser(lxdSnapChannel, containerNetworkingMethod string) c

// Initialise is specified on the container.Initialiser interface.
func (ci *containerInitialiser) Initialise() (err error) {
localSeries, err := hostSeries()
if err != nil {
return errors.Trace(err)
}
localBase, err := corebase.GetBaseFromSeries(localSeries)
localBase, err := hostBase()
if err != nil {
return errors.Trace(err)
}
Expand Down
13 changes: 7 additions & 6 deletions container/lxd/initialisation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/juju/juju/container/lxd/mocks"
lxdtesting "github.com/juju/juju/container/lxd/testing"
"github.com/juju/juju/core/base"
coretesting "github.com/juju/juju/testing"
)

Expand Down Expand Up @@ -86,7 +87,7 @@ func (s *initialiserTestSuite) containerInitialiser(svr lxd.InstanceServer, lxdI

func (s *InitialiserSuite) TestSnapInstalled(c *gc.C) {
PatchLXDViaSnap(s, true)
PatchHostSeries(s, "jammy")
PatchHostBase(s, base.MustParseBaseFromString("[email protected]"))

ctrl := gomock.NewController(c)
defer ctrl.Finish()
Expand All @@ -103,7 +104,7 @@ func (s *InitialiserSuite) TestSnapInstalled(c *gc.C) {

func (s *InitialiserSuite) TestSnapChannelMismatch(c *gc.C) {
PatchLXDViaSnap(s, true)
PatchHostSeries(s, "focal")
PatchHostBase(s, base.MustParseBaseFromString("[email protected]"))

ctrl := gomock.NewController(c)
defer ctrl.Finish()
Expand All @@ -121,7 +122,7 @@ func (s *InitialiserSuite) TestSnapChannelMismatch(c *gc.C) {

func (s *InitialiserSuite) TestSnapChannelPrefixMatch(c *gc.C) {
PatchLXDViaSnap(s, true)
PatchHostSeries(s, "focal")
PatchHostBase(s, base.MustParseBaseFromString("[email protected]"))

ctrl := gomock.NewController(c)
defer ctrl.Finish()
Expand All @@ -143,7 +144,7 @@ func (s *InitialiserSuite) TestSnapChannelPrefixMatch(c *gc.C) {
func (s *InitialiserSuite) TestInstallViaSnap(c *gc.C) {
PatchLXDViaSnap(s, false)

PatchHostSeries(s, "focal")
PatchHostBase(s, base.MustParseBaseFromString("[email protected]"))

paccmder := commands.NewSnapPackageCommander()

Expand All @@ -157,7 +158,7 @@ func (s *InitialiserSuite) TestInstallViaSnap(c *gc.C) {

func (s *InitialiserSuite) TestLXDAlreadyInitialized(c *gc.C) {
s.patchDF100GB()
PatchHostSeries(s, "focal")
PatchHostBase(s, base.MustParseBaseFromString("[email protected]"))

ci := s.containerInitialiser(nil, true, "local")
ci.getExecCommand = s.PatchExecHelper.GetExecCommand(testing.PatchExecConfig{
Expand All @@ -171,7 +172,7 @@ func (s *InitialiserSuite) TestLXDAlreadyInitialized(c *gc.C) {
}

func (s *InitialiserSuite) TestInitializeSetsProxies(c *gc.C) {
PatchHostSeries(s, "jammy")
PatchHostBase(s, base.MustParseBaseFromString("[email protected]"))

ctrl := gomock.NewController(c)
defer ctrl.Finish()
Expand Down
4 changes: 2 additions & 2 deletions environs/testing/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ func RemoveFakeTools(c *gc.C, stor storage.Storage, toolsDir string) {
name := envtools.StorageName(toolsVersion, toolsDir)
err := stor.Remove(name)
c.Check(err, jc.ErrorIsNil)
defaultSeries := jujuversion.DefaultSupportedLTS()
if coretesting.HostSeries(c) != defaultSeries {
defaultBase := jujuversion.DefaultSupportedLTSBase()
if !defaultBase.IsCompatible(coretesting.HostBase(c)) {
toolsVersion.Release = "ubuntu"
name := envtools.StorageName(toolsVersion, toolsDir)
err := stor.Remove(name)
Expand Down
16 changes: 6 additions & 10 deletions mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"github.com/juju/errors"
"github.com/juju/loggo"
"github.com/juju/mgo/v3"
"github.com/juju/os/v2/series"
"github.com/juju/replicaset/v3"
"github.com/juju/retry"
"github.com/juju/utils/v3"

"github.com/juju/juju/core/base"
"github.com/juju/juju/core/network"
coreos "github.com/juju/juju/core/os"
"github.com/juju/juju/packaging"
"github.com/juju/juju/packaging/dependency"
"github.com/juju/juju/service/common"
Expand Down Expand Up @@ -225,15 +225,6 @@ func EnsureServerInstalled(ctx context.Context, args EnsureServerParams) error {
func ensureServer(ctx context.Context, args EnsureServerParams, mongoKernelTweaks map[string]string) (err error) {
tweakSysctlForMongo(mongoKernelTweaks)

hostSeries, err := series.HostSeries()
if err != nil {
return errors.Annotatef(err, "cannot get host series")
}
hostBase, err := base.GetBaseFromSeries(hostSeries)
if err != nil {
return errors.Annotatef(err, "host series %q not a vlaid base", hostSeries)
}

mongoDep := dependency.Mongo(args.JujuDBSnapChannel)
if args.DataDir == "" {
args.DataDir = dataPathForJujuDbSnap
Expand All @@ -257,6 +248,11 @@ func ensureServer(ctx context.Context, args EnsureServerParams, mongoKernelTweak
return errors.Annotatef(err, "cannot create mongo snap service")
}

hostBase, err := coreos.HostBase()
if err != nil {
return errors.Annotatef(err, "cannot get host base")
}

if err := installMongod(mongoDep, hostBase, svc); err != nil {
return errors.Annotatef(err, "cannot install mongod")
}
Expand Down
7 changes: 4 additions & 3 deletions testing/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
gc "gopkg.in/check.v1"

"github.com/juju/juju/core/arch"
"github.com/juju/juju/core/base"
"github.com/juju/juju/core/model"
coreos "github.com/juju/juju/core/os"
"github.com/juju/juju/core/os/ostype"
Expand Down Expand Up @@ -300,8 +301,8 @@ func CurrentVersion() version.Binary {
}

// HostSeries returns series.HostSeries(), asserting on error.
func HostSeries(c *gc.C) string {
hostSeries, err := series.HostSeries()
func HostBase(c *gc.C) base.Base {
hostBase, err := coreos.HostBase()
c.Assert(err, jc.ErrorIsNil)
return hostSeries
return hostBase
}
15 changes: 3 additions & 12 deletions worker/proxyupdater/proxyupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"

"github.com/juju/errors"
"github.com/juju/os/v2/series"
"github.com/juju/packaging/v3/commands"
"github.com/juju/packaging/v3/config"
"github.com/juju/proxy"
Expand Down Expand Up @@ -164,12 +163,8 @@ func (w *proxyWorker) handleProxyValues(legacyProxySettings, jujuProxySettings p

// getPackageCommander is a helper function which returns the
// package commands implementation for the current system.
func getPackageCommander() (commands.PackageCommander, error) {
hostSeries, err := series.HostSeries()
if err != nil {
return nil, errors.Trace(err)
}
return commands.NewPackageCommander(hostSeries)
func getPackageCommander() commands.PackageCommander {
return commands.NewAptPackageCommander()
}

func (w *proxyWorker) handleSnapProxyValues(proxy proxy.Settings, storeID, storeAssertions, storeProxyURL string) {
Expand Down Expand Up @@ -261,11 +256,7 @@ func (w *proxyWorker) handleAptProxyValues(aptSettings proxy.Settings, aptMirror
err error
)
if updateNeeded {
paccmder, err = getPackageCommander()
if err != nil {
w.config.Logger.Errorf("unable to process apt proxy changes: %v", err)
return
}
paccmder = getPackageCommander()
}

if aptSettings != w.aptProxy || w.first {
Expand Down
6 changes: 2 additions & 4 deletions worker/proxyupdater/proxyupdater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ func (s *ProxyUpdaterSuite) TestInitialStateLegacyProxy(c *gc.C) {
s.waitForFile(c, s.proxyEnvFile, proxySettings.AsScriptEnvironment())
s.waitForFile(c, s.proxySystemdFile, proxySettings.AsSystemdDefaultEnv())

paccmder, err := commands.NewPackageCommander(coretesting.HostSeries(c))
c.Assert(err, jc.ErrorIsNil)
paccmder := commands.NewAptPackageCommander()
s.waitForFile(c, pacconfig.AptProxyConfigFile, paccmder.ProxyConfigContents(aptProxySettings)+"\n")
}

Expand All @@ -249,8 +248,7 @@ func (s *ProxyUpdaterSuite) TestInitialStateJujuProxy(c *gc.C) {
s.waitForFile(c, s.proxyEnvFile, empty.AsScriptEnvironment())
s.waitForFile(c, s.proxySystemdFile, empty.AsSystemdDefaultEnv())

paccmder, err := commands.NewPackageCommander(coretesting.HostSeries(c))
c.Assert(err, jc.ErrorIsNil)
paccmder := commands.NewAptPackageCommander()
s.waitForFile(c, pacconfig.AptProxyConfigFile, paccmder.ProxyConfigContents(aptProxySettings)+"\n")
}

Expand Down
6 changes: 4 additions & 2 deletions worker/upgradeseries/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

package upgradeseries

import "github.com/juju/juju/core/base"

type patcher interface {
PatchValue(interface{}, interface{})
}

func PatchHostSeries(patcher patcher, series string) {
patcher.PatchValue(&hostSeries, func() (string, error) { return series, nil })
func PatchHostBase(patcher patcher, b base.Base) {
patcher.PatchValue(&hostBase, func() (base.Base, error) { return b, nil })
}
3 changes: 2 additions & 1 deletion worker/upgradeseries/mocks/package_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion worker/upgradeseries/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/juju/juju/api/agent/upgradeseries"
"github.com/juju/juju/api/base"
corebase "github.com/juju/juju/core/base"
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/watcher"
)
Expand All @@ -23,7 +24,7 @@ type Facade interface {
// Setters
StartUnitCompletion(reason string) error
SetMachineStatus(status model.UpgradeSeriesStatus, reason string) error
FinishUpgradeSeries(string) error
FinishUpgradeSeries(corebase.Base) error
PinMachineApplications() (map[string]error, error)
UnpinMachineApplications() (map[string]error, error)
SetInstanceStatus(model.UpgradeSeriesStatus, string) error
Expand Down
Loading

0 comments on commit 7aee297

Please sign in to comment.