@@ -722,6 +722,9 @@ func (s *RefreshSuite) TestForcedSeriesUpgrade(c *gc.C) {
722722 c .Fatal (errors .Annotate (err , "cannot write to metadata.yaml" ))
723723 }
724724
725+ // TODO (jam) 2024-11-15: this test is kept for backward compatibility,
726+ // in 3.x the --force-series argument exists, though it is being
727+ // replaced by --force-base
725728 _ , err = s .runRefresh (c , "multi-series" , "--path" , s .archivePath (c , repoPath ), "--force-series" )
726729 c .Assert (err , jc .ErrorIsNil )
727730
@@ -744,6 +747,94 @@ func (s *RefreshSuite) TestForcedSeriesUpgrade(c *gc.C) {
744747 })
745748}
746749
750+ // func (s *RefreshSuite) TestForcedBaseUpgrade(c *gc.C) {
751+ // repoPath := testcharms.RepoWithSeries("jammy").ClonedDirPath(c.MkDir(), "multi-base")
752+ // err := runDeploy(c, repoPath, "multi-base", "--base", "[email protected] ") 753+ // c.Assert(err, jc.ErrorIsNil)
754+ // app, err := s.State.Application("multi-base")
755+ // c.Assert(err, jc.ErrorIsNil)
756+ // ch, _, err := app.Charm()
757+ // c.Assert(err, jc.ErrorIsNil)
758+ // c.Assert(ch.Revision(), gc.Equals, 1)
759+
760+ // units, err := app.AllUnits()
761+ // c.Assert(err, jc.ErrorIsNil)
762+ // c.Assert(units, gc.HasLen, 1)
763+ // unit := units[0]
764+ // tags := []names.UnitTag{unit.UnitTag()}
765+ // errs, err := unitassigner.New(s.APIState).AssignUnits(tags)
766+ // c.Assert(err, jc.ErrorIsNil)
767+ // c.Assert(errs, gc.DeepEquals, make([]error, len(units)))
768+
769+ // // Overwrite the manifest.yaml to change the supported series.
770+ // manifestPath := filepath.Join(repoPath, "manifest.yaml")
771+ // file, err := os.OpenFile(manifestPath, os.O_TRUNC|os.O_RDWR, 0666)
772+ // if err != nil {
773+ // c.Fatal(errors.Annotate(err, "cannot open manifest.yaml for overwriting"))
774+ // }
775+ // defer func() { _ = file.Close() }()
776+
777+ // // We deployed a version of the charm that supported jammy (22.04), but
778+ // // now we declare that this charm only supports focal, but with a
779+ // // --force-base we are allowed to target it anyway.
780+ // manifest := strings.Join(
781+ // []string{
782+ // `bases:`,
783+ // `- architectures:`,
784+ // ` - amd64`,
785+ // // Now only supports focal
786+ // ` channel: '20.04'`,
787+ // ` name: ubuntu`,
788+ // },
789+ // "\n",
790+ // )
791+ // if _, err := file.WriteString(manifest); err != nil {
792+ // c.Fatal(errors.Annotate(err, "cannot write to manifest.yaml"))
793+ // }
794+
795+ // s.charmClient.charmInfo = &apicommoncharms.CharmInfo{
796+ // URL: ch.URL(),
797+ // Meta: ch.Meta(),
798+ // Revision: ch.Revision(),
799+ // }
800+ // // First confirm that normal refresh would be refused
801+ // _, err = s.runRefresh(c, s.cmd, "multi-base", "--path", repoPath)
802+ // c.Check(err, gc.NotNil)
803+ // c.Check(err, gc.ErrorMatches, `.*base "[email protected] " not supported by charm, the charm supported bases are: [email protected] `) 804+ // // jam (2024-11-15): The structure of this test suite is that you can only run
805+ // // Refresh one time without reinitializing it. Since we are doing it 2x to test
806+ // // that it fails properly before succeeding, we have to reset the internal structure
807+ // // commands report back errors about "no model selected"
808+ // s.cmd = NewRefreshCommandForStateTest(
809+ // newCharmAdder,
810+ // func(conn base.APICallCloser) utils.CharmClient {
811+ // return &s.charmClient
812+ // },
813+ // deployer.DeployResources,
814+ // nil,
815+ // )
816+
817+ // err = app.Refresh()
818+ // c.Assert(err, jc.ErrorIsNil)
819+ // ch, _, err = app.Charm()
820+ // c.Assert(err, jc.ErrorIsNil)
821+ // // The charm should not have changed
822+ // c.Check(ch.Revision(), gc.Equals, 1)
823+
824+ // // But with --force-base we are happy
825+ // _, err = s.runRefresh(c, s.cmd, "multi-base", "--path", repoPath, "--force-base")
826+ // c.Assert(err, jc.ErrorIsNil)
827+
828+ // err = app.Refresh()
829+ // c.Assert(err, jc.ErrorIsNil)
830+
831+ // ch, force, err := app.Charm()
832+ // c.Assert(err, jc.ErrorIsNil)
833+ // // Check charm is at revision 3 because the local charm is uploaded twice more.
834+ // c.Check(ch.Revision(), gc.Equals, 3)
835+ // c.Check(force, gc.Equals, false)
836+ // }
837+
747838func (s * RefreshSuite ) TestForcedUnitsUpgrade (c * gc.C ) {
748839 s .
BaseRefreshSuite .
setup (
c ,
corebase .
MustParseBaseFromString (
"[email protected] " ),
charm .
MustParseURL (
"ch:riak" ),
charm .
MustParseURL (
"ch:riak" ))
749840 s .
charmAPIClient .
charmOrigin = commoncharm.
Origin {
Base :
corebase .
MustParseBaseFromString (
"[email protected] " )}
0 commit comments