Skip to content

Commit

Permalink
Support running uptimer against an isolation segment
Browse files Browse the repository at this point in the history
  • Loading branch information
geofffranks committed May 12, 2023
1 parent ff53b65 commit 42c61da
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
17 changes: 17 additions & 0 deletions cfCmdGenerator/cfCmdGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type CfCmdGenerator interface {
SetQuota(org, quota string) cmdStartWaiter.CmdStartWaiter
CreateOrg(org string) cmdStartWaiter.CmdStartWaiter
CreateSpace(org, space string) cmdStartWaiter.CmdStartWaiter
EnableOrgIsolation(org, isolationSegment string) cmdStartWaiter.CmdStartWaiter
SetOrgDefaultIsolationSegment(org, isolationSegment string) cmdStartWaiter.CmdStartWaiter
Target(org, space string) cmdStartWaiter.CmdStartWaiter
Push(name, path string, instances int, noRoute bool) cmdStartWaiter.CmdStartWaiter
Delete(name string) cmdStartWaiter.CmdStartWaiter
Expand Down Expand Up @@ -98,6 +100,21 @@ func (c *cfCmdGenerator) CreateOrg(org string) cmdStartWaiter.CmdStartWaiter {
)
}

func (c *cfCmdGenerator) EnableOrgIsolation(org, isolationSegment string) cmdStartWaiter.CmdStartWaiter {
return c.setCfHome(
exec.Command(
"cf", "enable-org-isolation", org, isolationSegment,
),
)
}
func (c *cfCmdGenerator) SetOrgDefaultIsolationSegment(org, isolationSegment string) cmdStartWaiter.CmdStartWaiter {
return c.setCfHome(
exec.Command(
"cf", "set-org-default-isolation-segment", org, isolationSegment,
),
)
}

func (c *cfCmdGenerator) CreateSpace(org string, space string) cmdStartWaiter.CmdStartWaiter {
return c.setCfHome(
exec.Command(
Expand Down
16 changes: 16 additions & 0 deletions cfCmdGenerator/cfCmdGenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ var _ = Describe("CfCmdGenerator", func() {
expectCommandToBeEquivalent(cmd, expectedCmd, cfHomeEnvVar)
})
})

Describe("EnableOrgIsolation", func() {
It("Generates the correct command", func() {
expectedCmd := exec.Command("cf", "enable-org-isolation", "someOrg", "someIsoSeg")
cmd := generator.EnableOrgIsolation("someOrg", "someIsoSeg")
expectCommandToBeEquivalent(cmd, expectedCmd, cfHomeEnvVar)
})
})

Describe("SetOrgDefaultIsolationSegment", func() {
It("Generates the correct command", func() {
expectedCmd := exec.Command("cf", "set-org-default-isolation-segment", "someOrg", "someIsoSeg")
cmd := generator.SetOrgDefaultIsolationSegment("someOrg", "someIsoSeg")
expectCommandToBeEquivalent(cmd, expectedCmd, cfHomeEnvVar)
})
})
})

func expectCommandToBeEquivalent(cmd cmdStartWaiter.CmdStartWaiter, expectedCmd *exec.Cmd, envIncludes ...string) {
Expand Down
10 changes: 9 additions & 1 deletion cfWorkflow/cfWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ func (c *cfWorkflow) Setup(ccg cfCmdGenerator.CfCmdGenerator) []cmdStartWaiter.C
ccg.Api(c.cf.API),
ccg.Auth(c.cf.AdminUser, c.cf.AdminPassword),
ccg.CreateOrg(c.org),
ccg.CreateSpace(c.org, c.space),
}

if c.cf.IsolationSegment != "" {
ret = append(ret,
ccg.EnableOrgIsolation(c.org, c.cf.IsolationSegment),
ccg.SetOrgDefaultIsolationSegment(c.org, c.cf.IsolationSegment),
)
}
ret = append(ret, ccg.CreateSpace(c.org, c.space))

if c.quota != "" {
ret = append(ret, ccg.CreateQuota(c.quota), ccg.SetQuota(c.org, c.quota))
}
Expand Down
19 changes: 19 additions & 0 deletions cfWorkflow/cfWorkflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ var _ = Describe("CfWorkflow", func() {
))
})
})
When("Isolation Segments are provided", func() {
BeforeEach(func() { cfc.IsolationSegment = "someIsoSeg" })
It("returns a series of commands including setting up the isolation segment for the org/space", func() {
cmds := cw.Setup(ccg)

Expect(cmds).To(Equal(
[]cmdStartWaiter.CmdStartWaiter{
ccg.Api("jigglypuff.cf-app.com"),
ccg.Auth("pika", "chu"),
ccg.CreateOrg("someOrg"),
ccg.EnableOrgIsolation("someOrg", "someIsoSeg"),
ccg.SetOrgDefaultIsolationSegment("someOrg", "someIsoSeg"),
ccg.CreateSpace("someOrg", "someSpace"),
ccg.CreateQuota("someQuota"),
ccg.SetQuota("someOrg", "someQuota"),
},
))
})
})
})

Describe("TearDown", func() {
Expand Down
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type Command struct {
}

type Cf struct {
API string `json:"api"`
AppDomain string `json:"app_domain"`
AdminUser string `json:"admin_user"`
AdminPassword string `json:"admin_password"`
API string `json:"api"`
AppDomain string `json:"app_domain"`
AdminUser string `json:"admin_user"`
AdminPassword string `json:"admin_password"`
IsolationSegment string `json:"isolation_segment"`

TCPDomain string `json:"tcp_domain"`
TCPPort int `json:"tcp_port"`
Expand Down

0 comments on commit 42c61da

Please sign in to comment.