Skip to content

Commit

Permalink
Support running uptimer against an isolation segment (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
geofffranks authored Jun 17, 2024
1 parent 7c0347b commit 6ef0d7c
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Here is an example config `json`:
"app_domain": "my-cf.com",
"admin_user": "admin",
"admin_password": "PASS",
"isolation_segment": name-of-my-isolation-segment",
"tcp_domain": "tcp.my-cf.com",
"use_single_app_instance": false,
"available_port": 1025
Expand Down Expand Up @@ -108,6 +109,9 @@ The `tcp_domain` and `available_port` values
are not required
_unless_ you elect to run the `app_syslog_availability` test.

The `isolation_segment` value is not required _unless_
you wish to run uptimer against apps pushed to an isolation segment.

Uptimer by default pushes two instances of an app
for its uptime measurements,
but it can be configured to push only a single instance
Expand Down
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 @@ -99,6 +101,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 @@ -219,6 +219,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
152 changes: 152 additions & 0 deletions cfCmdGenerator/cfCmdGeneratorfakes/fake_cf_cmd_generator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion cfWorkflow/cfWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,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 6ef0d7c

Please sign in to comment.