Skip to content

Commit

Permalink
Merge branch '2.9' into merge-2.9-20221021
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Oct 21, 2022
2 parents 1353f4f + 8972fa8 commit 77c99ea
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
14 changes: 8 additions & 6 deletions apiserver/facades/client/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,16 @@ func (b *BundleAPI) bundleDataApplications(
return nil, nil, nil, errors.Errorf("missing charm origin data for %q", application)
}
var newApplication *charm.ApplicationSpec
p, err := corecharm.ParsePlatformNormalize(application.CharmOrigin().Platform())
platform, err := corecharm.ParsePlatform(application.CharmOrigin().Platform())
if err != nil {
return nil, nil, nil, errors.Trace(err)
return nil, nil, nil, fmt.Errorf("extracting charm origin from application description %w", err)
}
appSeries, err := series.GetSeriesFromChannel(p.OS, p.Channel)

appSeries, err := series.GetSeriesFromChannel(platform.OS, platform.Channel)
if err != nil {
return nil, nil, nil, errors.Trace(err)
return nil, nil, nil, fmt.Errorf("extracting series from application description %w", err)
}

usedSeries.Add(appSeries)

endpointsWithSpaceNames, err := b.endpointBindings(application.EndpointBindings(), allSpacesInfoLookup, printEndpointBindingSpaceNames)
Expand Down Expand Up @@ -646,11 +648,11 @@ func (b *BundleAPI) bundleDataMachines(machines []description.Machine, machineId
if !machineIds.Contains(machine.Tag().Id()) {
continue
}
macBase, err := state.ParseBase(machine.Base())
macBase, err := series.ParseBaseFromString(machine.Base())
if err != nil {
return nil, nil, errors.Trace(err)
}
macSeries, err := series.GetSeriesFromChannel(macBase.OS, macBase.Channel)
macSeries, err := series.GetSeriesFromBase(macBase)
if err != nil {
return nil, nil, errors.Trace(err)
}
Expand Down
16 changes: 15 additions & 1 deletion core/series/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ func ParseBase(os string, channel string) (Base, error) {
}
ch, err := ParseChannelNormalize(channel)
if err != nil {
return Base{}, errors.Annotatef(err, "parsing base %s:%s", os, channel)
return Base{}, errors.Annotatef(err, "parsing base %s@%s", os, channel)
}
return Base{OS: strings.ToLower(os), Channel: ch}, nil
}

// ParseBaseFromString takes a string containing os and channel separated
// by @ and returns a base.
func ParseBaseFromString(b string) (Base, error) {
parts := strings.Split(b, "@")
if len(parts) != 2 {
return Base{}, errors.New("expected base string to contain os and channel separated by '@'")
}
channel, err := ParseChannelNormalize(parts[1])
if err != nil {
return Base{}, errors.Trace(err)
}
return Base{OS: parts[0], Channel: channel}, nil
}

// MakeDefaultBase creates a base from an os and simple version string, eg "22.04".
func MakeDefaultBase(os string, channel string) Base {
return Base{OS: os, Channel: MakeDefaultChannel(channel)}
Expand Down
11 changes: 11 additions & 0 deletions core/series/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func (s *BaseSuite) TestGetSeriesFromBase(c *gc.C) {
c.Assert(series, gc.Equals, "jammy")
}

func (s *BaseSuite) TestParseBaseFromString(c *gc.C) {
base, err := ParseBaseFromString("[email protected]")
c.Assert(err, jc.ErrorIsNil)
c.Assert(base.String(), gc.Equals, "[email protected]/stable")
base, err = ParseBaseFromString("[email protected]/edge")
c.Assert(err, jc.ErrorIsNil)
c.Assert(base.String(), gc.Equals, "[email protected]/edge")
base, err = ParseBaseFromString("foo")
c.Assert(err, gc.ErrorMatches, `expected base string to contain os and channel separated by '@'`)
}

func (s *BaseSuite) TestDisplayString(c *gc.C) {
b := Base{OS: "ubuntu", Channel: Channel{Track: "18.04"}}
c.Check(b.DisplayString(), gc.Equals, "[email protected]")
Expand Down
6 changes: 0 additions & 6 deletions state/charm.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ func (b Base) String() string {
return fmt.Sprintf("%s@%s", b.OS, b.Channel)
}

// ParseBase parses a machine base string.
func ParseBase(b string) (Base, error) {
parts := strings.Split(b, "@")
return Base{OS: parts[0], Channel: parts[1]}, nil
}

// UbuntuBase is used in tests.
func UbuntuBase(channel string) Base {
return Base{OS: "ubuntu", Channel: channel + "/stable"}
Expand Down
6 changes: 4 additions & 2 deletions state/migration_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/payloads"
"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/state/cloudimagemetadata"
Expand Down Expand Up @@ -658,16 +659,17 @@ func (i *importer) makeMachineDoc(m description.Machine) (*machineDoc, error) {
}

machineTag := m.Tag()
base, err := ParseBase(m.Base())
base, err := series.ParseBaseFromString(m.Base())
if err != nil {
return nil, errors.Trace(err)
}
macBase := Base{OS: base.OS, Channel: base.Channel.String()}
return &machineDoc{
DocID: i.st.docID(id),
Id: id,
ModelUUID: i.st.ModelUUID(),
Nonce: m.Nonce(),
Base: base.Normalise(),
Base: macBase.Normalise(),
ContainerType: m.ContainerType(),
Principals: nil, // Set during unit import.
Life: Alive,
Expand Down
1 change: 1 addition & 0 deletions testing/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ func (factory *Factory) MakeApplicationReturningPassword(c *gc.C, params *Applic
base, err := coreseries.GetBaseFromSeries(chSeries)
c.Assert(err, jc.ErrorIsNil)
params.CharmOrigin = &state.CharmOrigin{Platform: &state.Platform{
Architecture: params.Charm.URL().Architecture,
OS: base.OS,
Channel: base.Channel.String(),
}}
Expand Down

0 comments on commit 77c99ea

Please sign in to comment.