Skip to content

Commit

Permalink
Replace systems with bases for metadata v2
Browse files Browse the repository at this point in the history
  • Loading branch information
hpidcock committed Mar 19, 2021
1 parent 68b7aaf commit 3b11467
Show file tree
Hide file tree
Showing 28 changed files with 202 additions and 328 deletions.
42 changes: 10 additions & 32 deletions api/common/charms/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func convertCharmMeta(meta *params.CharmMeta) (*charm.Meta, error) {
if err != nil {
return nil, errors.Trace(err)
}
systems, err := convertCharmSystems(meta.Systems)
bases, err := convertCharmBases(meta.Bases)
if err != nil {
return nil, errors.Trace(err)
}
Expand All @@ -103,10 +103,9 @@ func convertCharmMeta(meta *params.CharmMeta) (*charm.Meta, error) {
Resources: resources,
Terms: meta.Terms,
MinJujuVersion: minVersion,
Systems: systems,
Platforms: convertCharmPlatforms(meta.Platforms),
Architectures: convertCharmArchitectures(meta.Architectures),
Bases: bases,
Containers: containers,
Assumes: meta.Assumes,
}
return result, nil
}
Expand Down Expand Up @@ -359,9 +358,9 @@ func (c *charmImpl) Revision() int {
return c.info.Revision
}

func convertCharmSystems(input []params.CharmSystem) ([]systems.System, error) {
func convertCharmBases(input []params.CharmBase) ([]systems.Base, error) {
var err error
res := []systems.System(nil)
res := []systems.Base(nil)
for _, v := range input {
ch := channel.Channel{}
if v.Channel != "" {
Expand All @@ -370,41 +369,20 @@ func convertCharmSystems(input []params.CharmSystem) ([]systems.System, error) {
return nil, errors.Trace(err)
}
}
res = append(res, systems.System{
OS: v.OS,
Channel: ch,
Resource: v.Resource,
res = append(res, systems.Base{
Name: v.Name,
Channel: ch,
})
}
return res, nil
}

func convertCharmPlatforms(input []string) []charm.Platform {
platforms := []charm.Platform(nil)
for _, v := range input {
platforms = append(platforms, charm.Platform(v))
}
return platforms
}

func convertCharmArchitectures(input []string) []charm.Architecture {
architectures := []charm.Architecture(nil)
for _, v := range input {
architectures = append(architectures, charm.Architecture(v))
}
return architectures
}

func convertCharmContainers(input map[string]params.CharmContainer) (map[string]charm.Container, error) {
containers := map[string]charm.Container{}
for k, v := range input {
systems, err := convertCharmSystems(v.Systems)
if err != nil {
return nil, errors.Trace(err)
}
containers[k] = charm.Container{
Systems: systems,
Mounts: convertCharmMounts(v.Mounts),
Resource: v.Resource,
Mounts: convertCharmMounts(v.Mounts),
}
}
if len(containers) == 0 {
Expand Down
26 changes: 8 additions & 18 deletions api/common/charms/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,15 @@ func (s *charmsMockSuite) TestCharmInfo(c *gc.C) {
Description: "OCI image used for cockroachdb",
},
},
Systems: []params.CharmSystem{
Bases: []params.CharmBase{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: "20.04/stable",
},
},
Containers: map[string]params.CharmContainer{
"cockroachdb": {
Systems: []params.CharmSystem{
{
Resource: "cockroachdb-image",
},
},
Resource: "cockroachdb-image",
Mounts: []params.CharmMount{
{
Storage: "database",
Expand All @@ -84,13 +80,12 @@ func (s *charmsMockSuite) TestCharmInfo(c *gc.C) {
},
},
},
Platforms: []string{"kubernetes"},
Architectures: []string{"amd64"},
Storage: map[string]params.CharmStorage{
"database": {
Type: "filesystem",
},
},
Assumes: []string{"kubernetes"},
},
}

Expand Down Expand Up @@ -131,9 +126,9 @@ func (s *charmsMockSuite) TestCharmInfo(c *gc.C) {
Description: "OCI image used for cockroachdb",
},
},
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand All @@ -143,11 +138,7 @@ func (s *charmsMockSuite) TestCharmInfo(c *gc.C) {
},
Containers: map[string]charm.Container{
"cockroachdb": {
Systems: []systems.System{
{
Resource: "cockroachdb-image",
},
},
Resource: "cockroachdb-image",
Mounts: []charm.Mount{
{
Storage: "database",
Expand All @@ -156,13 +147,12 @@ func (s *charmsMockSuite) TestCharmInfo(c *gc.C) {
},
},
},
Platforms: []charm.Platform{"kubernetes"},
Architectures: []charm.Architecture{"amd64"},
Storage: map[string]charm.Storage{
"database": {
Type: "filesystem",
},
},
Assumes: []string{"kubernetes"},
},
}
c.Assert(got, gc.DeepEquals, want)
Expand Down
12 changes: 6 additions & 6 deletions apiserver/common/applicationwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (s *applicationWatcherSuite) TestEmbeddedFilter(c *gc.C) {
charm: mockAppWatcherCharm{
meta: &charm.Meta{
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down Expand Up @@ -77,9 +77,9 @@ func (s *applicationWatcherSuite) TestLegacyFilter(c *gc.C) {
charm: mockAppWatcherCharm{
meta: &charm.Meta{
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down Expand Up @@ -127,9 +127,9 @@ func (s *applicationWatcherSuite) TestNoFilter(c *gc.C) {
charm: mockAppWatcherCharm{
meta: &charm.Meta{
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down
36 changes: 9 additions & 27 deletions apiserver/common/charms/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ func convertCharmMeta(meta *charm.Meta) *params.CharmMeta {
Resources: convertCharmResourceMetaMap(meta.Resources),
Terms: meta.Terms,
MinJujuVersion: meta.MinJujuVersion.String(),
Systems: convertCharmSystems(meta.Systems),
Platforms: convertCharmPlatforms(meta.Platforms),
Architectures: convertCharmArchitectures(meta.Architectures),
Bases: convertCharmBases(meta.Bases),
Containers: convertCharmContainers(meta.Containers),
Assumes: meta.Assumes,
}
}

Expand Down Expand Up @@ -353,40 +352,23 @@ func convertCharmDevices(devices map[string]charm.Device) map[string]params.Char
return results
}

func convertCharmSystems(input []systems.System) []params.CharmSystem {
systems := []params.CharmSystem(nil)
func convertCharmBases(input []systems.Base) []params.CharmBase {
systems := []params.CharmBase(nil)
for _, v := range input {
systems = append(systems, params.CharmSystem{
OS: v.OS,
Channel: v.Channel.String(),
Resource: v.Resource,
systems = append(systems, params.CharmBase{
Name: v.Name,
Channel: v.Channel.String(),
})
}
return systems
}

func convertCharmPlatforms(input []charm.Platform) []string {
platforms := []string(nil)
for _, v := range input {
platforms = append(platforms, string(v))
}
return platforms
}

func convertCharmArchitectures(input []charm.Architecture) []string {
architectures := []string(nil)
for _, v := range input {
architectures = append(architectures, string(v))
}
return architectures
}

func convertCharmContainers(input map[string]charm.Container) map[string]params.CharmContainer {
containers := map[string]params.CharmContainer{}
for k, v := range input {
containers[k] = params.CharmContainer{
Systems: convertCharmSystems(v.Systems),
Mounts: convertCharmMounts(v.Mounts),
Resource: v.Resource,
Mounts: convertCharmMounts(v.Mounts),
}
}
if len(containers) == 0 {
Expand Down
18 changes: 6 additions & 12 deletions apiserver/common/charms/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,24 +245,18 @@ func (s *charmsSuite) TestClientCharmInfo(c *gc.C) {
URL: "local:focal/cockroachdb-0",
Config: map[string]params.CharmOption{},
Meta: &params.CharmMeta{
Name: "cockroachdb",
Summary: "cockroachdb",
Description: "cockroachdb",
Platforms: []string{"kubernetes"},
Architectures: []string{"amd64"},
Systems: []params.CharmSystem{
Name: "cockroachdb",
Summary: "cockroachdb",
Description: "cockroachdb",
Bases: []params.CharmBase{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: "20.04/stable",
},
},
Containers: map[string]params.CharmContainer{
"cockroachdb": {
Systems: []params.CharmSystem{
{
Resource: "cockroachdb-image",
},
},
Resource: "cockroachdb-image",
Mounts: []params.CharmMount{
{
Storage: "database",
Expand Down
4 changes: 2 additions & 2 deletions apiserver/facades/agent/caasapplication/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func newMockState() *mockState {
sha256: "fake-sha256",
meta: &charm.Meta{
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ func (s *CAASApplicationProvisionerSuite) TestGarbageCollectStateful(c *gc.C) {
DeploymentType: charm.DeploymentStateful,
},
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down Expand Up @@ -257,9 +257,9 @@ func (s *CAASApplicationProvisionerSuite) TestGarbageCollectDeployment(c *gc.C)
DeploymentType: charm.DeploymentStateless,
},
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down Expand Up @@ -330,9 +330,9 @@ func (s *CAASApplicationProvisionerSuite) TestGarbageCollectDaemon(c *gc.C) {
DeploymentType: charm.DeploymentDaemon,
},
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down Expand Up @@ -405,9 +405,9 @@ func (s *CAASApplicationProvisionerSuite) TestGarbageCollectForced(c *gc.C) {
DeploymentType: charm.DeploymentDaemon,
},
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down Expand Up @@ -552,9 +552,9 @@ func (s *CAASApplicationProvisionerSuite) TestUpdateApplicationsUnitsWithStorage
DeploymentType: charm.DeploymentStateful,
},
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down Expand Up @@ -735,9 +735,9 @@ func (s *CAASApplicationProvisionerSuite) TestUpdateApplicationsUnitsWithoutStor
DeploymentType: charm.DeploymentStateful,
},
// charm.FormatV2.
Systems: []systems.System{
Bases: []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (s *firewallerEmbeddedSuite) SetUpTest(c *gc.C) {
s.firewallerBaseSuite.SetUpTest(c)

// charm.FormatV2.
s.st.application.charm.meta.Systems = []systems.System{
s.st.application.charm.meta.Bases = []systems.Base{
{
OS: "ubuntu",
Name: "ubuntu",
Channel: channel.Channel{
Name: "20.04/stable",
Risk: "stable",
Expand Down
Loading

0 comments on commit 3b11467

Please sign in to comment.