Skip to content

Commit

Permalink
Fixes bug with series to platform upgrades.
Browse files Browse the repository at this point in the history
In the upgrade steps for applications we only upgraded applications from
series to platform with version greater then 7 and less then 9. This
logic is wrong and need to be all versions.
  • Loading branch information
tlm committed Oct 21, 2022
1 parent ecf06ac commit 281c268
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
19 changes: 12 additions & 7 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,18 @@ func importApplication(fields schema.Fields, defaults schema.Defaults, importVer
}

series, hasSeries := valid["series"].(string)
if importVersion <= 9 && importVersion >= 7 && hasSeries {
// If we have a series but no platform defined lets make a platform from the series
if result.CharmOrigin_ != nil && result.CharmOrigin_.Platform_ == "" {
platform, err := platformFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}
// If we have a series but no platform defined lets make a platform from the series
if hasSeries && (result.CharmOrigin_ == nil || result.CharmOrigin_.Platform_ == "") {
platform, err := platformFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}

if result.CharmOrigin_ == nil {
result.CharmOrigin_ = newCharmOrigin(CharmOriginArgs{
Platform: platform,
})
} else {
result.CharmOrigin_.Platform_ = platform
}
}
Expand Down
20 changes: 15 additions & 5 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ func (s *ApplicationSerializationSuite) TestV1ParsingReturnsLatest(c *gc.C) {
appLatest.Tools_ = nil
appLatest.OperatorStatus_ = nil
appLatest.Offers_ = nil
appLatest.CharmOrigin_ = nil
appLatest.CharmOrigin_ = newCharmOrigin(CharmOriginArgs{
Platform: "unknown/ubuntu/20.04",
})

appResult := s.exportImportVersion(c, appV1, 1)
appLatest.Series_ = ""
Expand All @@ -379,7 +381,9 @@ func (s *ApplicationSerializationSuite) TestV2ParsingReturnsLatest(c *gc.C) {
appLatest.Tools_ = nil
appLatest.OperatorStatus_ = nil
appLatest.Offers_ = nil
appLatest.CharmOrigin_ = nil
appLatest.CharmOrigin_ = newCharmOrigin(CharmOriginArgs{
Platform: "unknown/ubuntu/20.04",
})

appResult := s.exportImportVersion(c, appV1, 2)
appLatest.Series_ = ""
Expand All @@ -398,7 +402,9 @@ func (s *ApplicationSerializationSuite) TestV3ParsingReturnsLatest(c *gc.C) {
appLatest.DesiredScale_ = 0
appLatest.OperatorStatus_ = nil
appLatest.Offers_ = nil
appLatest.CharmOrigin_ = nil
appLatest.CharmOrigin_ = newCharmOrigin(CharmOriginArgs{
Platform: "unknown/ubuntu/20.04",
})

appResult := s.exportImportVersion(c, appV2, 3)
appLatest.Series_ = ""
Expand All @@ -413,7 +419,9 @@ func (s *ApplicationSerializationSuite) TestV5ParsingReturnsLatest(c *gc.C) {
// Make an app with fields not in v5 removed.
appLatest := appV5
appLatest.HasResources_ = false
appLatest.CharmOrigin_ = nil
appLatest.CharmOrigin_ = newCharmOrigin(CharmOriginArgs{
Platform: "unknown/ubuntu/20.04",
})

appResult := s.exportImportVersion(c, appV5, 5)
appLatest.Series_ = ""
Expand All @@ -427,7 +435,9 @@ func (s *ApplicationSerializationSuite) TestV6ParsingReturnsLatest(c *gc.C) {

// Make an app with fields not in v6 removed.
appLatest := appV6
appLatest.CharmOrigin_ = nil
appLatest.CharmOrigin_ = newCharmOrigin(CharmOriginArgs{
Platform: "unknown/ubuntu/20.04",
})

appResult := s.exportImportVersion(c, appV6, 6)
appLatest.Series_ = ""
Expand Down

0 comments on commit 281c268

Please sign in to comment.