Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying port and databases for bbr when not using bosh links #46

Merged
merged 4 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions jobs/bbr-postgres-db/spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ properties:
postgres.dbuser:
default: vcap
description: "Database user to run backup and restore"
postgres.port:
default: 5432
description: "The database port (not used when using links)"
postgres.databases:
default: []
description: "Databases to backup and restore (not used when using links)"
postgres.ssl_verify_hostname:
default: true
description: "If postgres is configured with a ca, setting this to 'true' changes sslmode to 'verify-full' rather than 'verify-ca'."
Expand Down
25 changes: 16 additions & 9 deletions jobs/bbr-postgres-db/templates/config.sh.erb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#!/bin/bash -eu
<%
dbhost = "localhost"
sslmode = "prefer"
port = p("postgres.port")
databases = p("postgres.databases")
if_link("database") do |data|
if p("postgres.dbuser") != "vcap"
dbhost = data.address
end
end
sslmode = "prefer"
if link("database").p("databases.tls.ca") != ''
if p("postgres.ssl_verify_hostname")
sslmode = "verify-full"
else
sslmode = "verify-ca"

if data.p("databases.tls.ca") != ''
if p("postgres.ssl_verify_hostname")
sslmode = "verify-full"
else
sslmode = "verify-ca"
end
end

port = data.p("databases.port")
databases = data.p("databases.databases")
end

%>
current_version="11.1"
JOB_DIR="/var/vcap/jobs/bbr-postgres-db"
PACKAGE_DIR="/var/vcap/packages/postgres-${current_version}"
PORT="<%= link("database").p("databases.port") %>"
DATABASES=(<%= link("database").p("databases.databases", []).map{|d| d["name"]}.join(' ')%>)
PORT="<%= port %>"
DATABASES=(<%= databases.map{|d| d["name"]}.join(' ')%>)
DBHOST=<%= dbhost %>

readonly PGSSLMODE="<%=sslmode%>"
Expand Down
30 changes: 20 additions & 10 deletions src/acceptance-tests/deploy/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,29 @@ var _ = Describe("Backup and restore a deployment", func() {
}

Context("BBR job is colocated", func() {
BeforeEach(func() {
deployHelper.SetOpDefs(helpers.Define_bbr_ops())
})
Context("When using BOSH links", func() {
BeforeEach(func() {
deployHelper.SetOpDefs(helpers.Define_bbr_ops())
})

It("Fails to restore the database", func() {
var err error
var cmd *exec.Cmd
cmd = exec.Command("bbr", "deployment", "--target", configParams.Bosh.Target, "--username", configParams.Bosh.Username, "--deployment", deployHelper.GetDeploymentName(), "restore", "--artifact-path", fmt.Sprintf("%s/doesnotexist", tempDir))
err = cmd.Run()
Expect(err).To(HaveOccurred())
It("Fails to restore the database", func() {
var err error
var cmd *exec.Cmd
cmd = exec.Command("bbr", "deployment", "--target", configParams.Bosh.Target, "--username", configParams.Bosh.Username, "--deployment", deployHelper.GetDeploymentName(), "restore", "--artifact-path", fmt.Sprintf("%s/doesnotexist", tempDir))
err = cmd.Run()
Expect(err).To(HaveOccurred())
})

It("Successfully backup and restore the database", AssertBackupRestoreSuccessful())
})

It("Successfully backup and restore the database", AssertBackupRestoreSuccessful())
Context("When not using BOSH links", func() {
BeforeEach(func() {
deployHelper.SetOpDefs(helpers.Define_bbr_no_link_ops())
})

It("Successfully backup and restore the database", AssertBackupRestoreSuccessful())
})
})

Context("BBR job is not colocated", func() {
Expand Down
23 changes: 23 additions & 0 deletions src/acceptance-tests/testing/helpers/op_defs_utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ func Define_bbr_ops() []OpDefinition {
return ops
}

func Define_bbr_no_link_ops() []OpDefinition {
var ops []OpDefinition
var value interface{}
var path string

path = "/instance_groups/name=postgres/jobs/-"
value = map[interface{}]interface{}{
"name": "bbr-postgres-db",
"release": "postgres",
"properties": map[interface{}]interface{}{
"release_level_backup": true,
"postgres": map[interface{}]interface{}{
"databases": []interface{}{
"sandbox",
"sandbox-2",
},
},
},
}
AddOpDefinition(&ops, "replace", path, value)
return ops
}

func Define_bbr_not_colocated_ops() []OpDefinition {
var ops []OpDefinition
var value interface{}
Expand Down