Skip to content

Commit

Permalink
Handle import/export of application expose parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleasa committed Sep 3, 2020
1 parent d28937e commit e56d091
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions state/migration_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ func (e *exporter) addApplication(ctx addApplicationContext) error {
CharmModifiedVersion: application.doc.CharmModifiedVersion,
ForceCharm: application.doc.ForceCharm,
Exposed: application.doc.Exposed,
ExposedEndpoints: application.doc.ExposedEndpoints,
ExposeToSpaceIDs: application.doc.ExposeToSpaceIDs,
ExposeToCIDRs: application.doc.ExposeToCIDRs,
PasswordHash: application.doc.PasswordHash,
Placement: application.doc.Placement,
HasResources: application.doc.HasResources,
Expand Down
25 changes: 25 additions & 0 deletions state/migration_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,31 @@ func (s *MigrationExportSuite) TestMultipleApplications(c *gc.C) {
c.Assert(applications, gc.HasLen, 3)
}

func (s *MigrationExportSuite) TestApplicationExposeParameters(c *gc.C) {
serverSpace, err := s.State.AddSpace("server", "", nil, true)
c.Assert(err, jc.ErrorIsNil)

app := s.AddTestingApplicationWithBindings(c, "mysql",
s.AddTestingCharm(c, "mysql"),
map[string]string{
"server": serverSpace.Id(),
},
)

err = app.SetExposed([]string{"server"}, []string{serverSpace.Id()}, []string{"13.37.0.0/16"})
c.Assert(err, jc.ErrorIsNil)

model, err := s.State.Export()
c.Assert(err, jc.ErrorIsNil)

applications := model.Applications()
c.Assert(applications, gc.HasLen, 1)

c.Assert(applications[0].ExposedEndpoints(), gc.DeepEquals, []string{"server"})
c.Assert(applications[0].ExposeToSpaceIDs(), gc.DeepEquals, []string{serverSpace.Id()})
c.Assert(applications[0].ExposeToCIDRs(), gc.DeepEquals, []string{"13.37.0.0/16"})
}

func (s *MigrationExportSuite) TestApplicationExposingOffers(c *gc.C) {
_ = s.Factory.MakeUser(c, &factory.UserParams{Name: "admin"})
fooUser := s.Factory.MakeUser(c, &factory.UserParams{Name: "foo"})
Expand Down
3 changes: 3 additions & 0 deletions state/migration_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,9 @@ func (i *importer) makeApplicationDoc(a description.Application) (*applicationDo
UnitCount: len(a.Units()),
RelationCount: i.relationCount(a.Name()),
Exposed: a.Exposed(),
ExposedEndpoints: a.ExposedEndpoints(),
ExposeToSpaceIDs: a.ExposeToSpaceIDs(),
ExposeToCIDRs: a.ExposeToCIDRs(),
MinUnits: a.MinUnits(),
Tools: i.makeTools(a.Tools()),
MetricCredentials: a.MetricsCredentials(),
Expand Down
11 changes: 10 additions & 1 deletion state/migration_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,16 @@ func (s *MigrationImportSuite) setupSourceApplications(
// Add a application with charm settings, app config, and leadership settings.
f := factory.NewFactory(st, s.StatePool)

serverSpace, err := s.State.AddSpace("server", "", nil, true)
c.Assert(err, jc.ErrorIsNil)
exposedSpaceIDs := []string{serverSpace.Id()}

testModel, err := st.Model()
c.Assert(err, jc.ErrorIsNil)
series := "quantal"
if testModel.Type() == state.ModelTypeCAAS {
series = "kubernetes"
exposedSpaceIDs = nil
}
// Add a application with charm settings, app config, and leadership settings.
testCharm := f.MakeCharm(c, &factory.CharmParams{
Expand Down Expand Up @@ -521,7 +526,8 @@ func (s *MigrationImportSuite) setupSourceApplications(
err = application.SetMetricCredentials([]byte("sekrit"))
c.Assert(err, jc.ErrorIsNil)
// Expose the application.
c.Assert(application.SetExposed(nil, nil, nil), jc.ErrorIsNil)
err = application.SetExposed([]string{"admin"}, exposedSpaceIDs, []string{"13.37.0.0/16"})
c.Assert(err, jc.ErrorIsNil)
err = testModel.SetAnnotations(application, testAnnotations)
c.Assert(err, jc.ErrorIsNil)
if testModel.Type() == state.ModelTypeCAAS {
Expand All @@ -545,6 +551,9 @@ func (s *MigrationImportSuite) assertImportedApplication(
c.Assert(imported.ApplicationTag(), gc.Equals, exported.ApplicationTag())
c.Assert(imported.Series(), gc.Equals, exported.Series())
c.Assert(imported.IsExposed(), gc.Equals, exported.IsExposed())
c.Assert(imported.ExposedEndpoints(), gc.DeepEquals, exported.ExposedEndpoints())
c.Assert(imported.ExposeToSpaceIDs(), gc.DeepEquals, exported.ExposeToSpaceIDs())
c.Assert(imported.ExposeToCIDRs(), gc.DeepEquals, exported.ExposeToCIDRs())
c.Assert(imported.MetricCredentials(), jc.DeepEquals, exported.MetricCredentials())
c.Assert(imported.PasswordValid(pwd), jc.IsTrue)
c.Assert(imported.CharmOrigin(), jc.DeepEquals, exported.CharmOrigin())
Expand Down
3 changes: 3 additions & 0 deletions state/migration_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ func (s *MigrationSuite) TestApplicationDocFields(c *gc.C) {
"CharmOrigin",
"ForceCharm",
"Exposed",
"ExposedEndpoints",
"ExposeToSpaceIDs",
"ExposeToCIDRs",
"MinUnits",
"MetricCredentials",
"PasswordHash",
Expand Down
3 changes: 3 additions & 0 deletions testcharms/charm-repo/bionic/starsay/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ maintainer: Nate Finch <nate.finch@gmail.com>
description: Doesn't do anything at all.
tags:
- application
provides:
admin:
interface: http
resources:
store-resource:
type: file
Expand Down
3 changes: 3 additions & 0 deletions testcharms/charm-repo/kubernetes/starsay/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ maintainer: Nate Finch <nate.finch@gmail.com>
description: Doesn't do anything at all.
tags:
- application
provides:
admin:
interface: http
resources:
store-resource:
type: file
Expand Down
3 changes: 3 additions & 0 deletions testcharms/charm-repo/quantal/starsay/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ maintainer: Nate Finch <nate.finch@gmail.com>
description: Doesn't do anything at all.
tags:
- application
provides:
admin:
interface: http
resources:
store-resource:
type: file
Expand Down

0 comments on commit e56d091

Please sign in to comment.