Skip to content

Commit d94eb7a

Browse files
committed
Merge branch 'auto-test-beta-run' into 'master'
fix automated test (#153): * environment variables * remove restarting containers * container labels See merge request postgres-ai/database-lab!163
2 parents 06cf9e1 + d9e8d5e commit d94eb7a

File tree

13 files changed

+34
-144
lines changed

13 files changed

+34
-144
lines changed

pkg/retrieval/engine/postgres/logical/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (d *DumpJob) getEnvironmentVariables(password string) []string {
353353

354354
func (d *DumpJob) buildContainerConfig(password string) *container.Config {
355355
return &container.Config{
356-
Labels: map[string]string{"label": tools.DBLabControlLabel},
356+
Labels: map[string]string{tools.DBLabControlLabel: tools.DBLabDumpLabel},
357357
Env: d.getEnvironmentVariables(password),
358358
Image: d.DockerImage,
359359
Healthcheck: health.GetConfig(),

pkg/retrieval/engine/postgres/logical/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (r *RestoreJob) Run(ctx context.Context) (err error) {
202202

203203
func (r *RestoreJob) buildContainerConfig(password string) *container.Config {
204204
return &container.Config{
205-
Labels: map[string]string{"label": tools.DBLabControlLabel},
205+
Labels: map[string]string{tools.DBLabControlLabel: tools.DBLabRestoreLabel},
206206
Env: append(os.Environ(), []string{
207207
"PGDATA=" + r.globalCfg.DataDir,
208208
"POSTGRES_PASSWORD=" + password,

pkg/retrieval/engine/postgres/physical/physical.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (r *RestoreJob) Run(ctx context.Context) (err error) {
144144
return nil
145145
}
146146

147-
contID, err := r.startContainer(ctx, r.restoreContainerName())
147+
contID, err := r.startContainer(ctx, r.restoreContainerName(), tools.DBLabRestoreLabel)
148148
if err != nil {
149149
return errors.Wrapf(err, "failed to create container: %s", r.restoreContainerName())
150150
}
@@ -232,7 +232,7 @@ func (r *RestoreJob) Run(ctx context.Context) (err error) {
232232
return nil
233233
}
234234

235-
func (r *RestoreJob) startContainer(ctx context.Context, containerName string) (string, error) {
235+
func (r *RestoreJob) startContainer(ctx context.Context, containerName, containerLabel string) (string, error) {
236236
hostConfig, err := r.buildHostConfig(ctx)
237237
if err != nil {
238238
return "", errors.Wrap(err, "failed to build container host config")
@@ -248,7 +248,7 @@ func (r *RestoreJob) startContainer(ctx context.Context, containerName string) (
248248
}
249249

250250
syncInstance, err := r.dockerClient.ContainerCreate(ctx,
251-
r.buildContainerConfig(pwd),
251+
r.buildContainerConfig(pwd, containerLabel),
252252
hostConfig,
253253
&network.NetworkingConfig{},
254254
containerName,
@@ -335,7 +335,7 @@ func (r *RestoreJob) runSyncInstance(ctx context.Context) error {
335335

336336
log.Msg("Starting sync instance: ", r.syncInstanceName())
337337

338-
syncInstanceID, err := r.startContainer(ctx, r.syncInstanceName())
338+
syncInstanceID, err := r.startContainer(ctx, r.syncInstanceName(), tools.DBLabSyncLabel)
339339
if err != nil {
340340
return err
341341
}
@@ -387,9 +387,9 @@ func (r *RestoreJob) getEnvironmentVariables(password string) []string {
387387
return envVariables
388388
}
389389

390-
func (r *RestoreJob) buildContainerConfig(password string) *container.Config {
390+
func (r *RestoreJob) buildContainerConfig(password, label string) *container.Config {
391391
return &container.Config{
392-
Labels: map[string]string{"label": tools.DBLabControlLabel},
392+
Labels: map[string]string{tools.DBLabControlLabel: label},
393393
Env: r.getEnvironmentVariables(password),
394394
Image: r.CopyOptions.DockerImage,
395395
}

pkg/retrieval/engine/postgres/snapshot/physical.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func (p *PhysicalInitial) adjustRecoveryConfiguration(pgVersion, clonePGDataDir
460460

461461
func (p *PhysicalInitial) buildContainerConfig(clonePath, promoteImage, password string) *container.Config {
462462
return &container.Config{
463-
Labels: map[string]string{"label": tools.DBLabControlLabel},
463+
Labels: map[string]string{tools.DBLabControlLabel: tools.DBLabPromoteLabel},
464464
Env: []string{
465465
"PGDATA=" + clonePath,
466466
"POSTGRES_PASSWORD=" + password,

pkg/retrieval/engine/postgres/tools/tools.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ const (
4747
// DBLabControlLabel defines a label to mark service containers.
4848
DBLabControlLabel = "dblab_control"
4949

50+
// DBLabSyncLabel defines a label value for sync containers.
51+
DBLabSyncLabel = "dblab_sync"
52+
// DBLabPromoteLabel defines a label value for promote containers.
53+
DBLabPromoteLabel = "dblab_promote"
54+
// DBLabDumpLabel defines a label value for dump containers.
55+
DBLabDumpLabel = "dblab_dump"
56+
// DBLabRestoreLabel defines a label value for restore containers.
57+
DBLabRestoreLabel = "dblab_restore"
58+
5059
// PasswordLength defines length for autogenerated passwords.
5160
PasswordLength = 16
5261
// PasswordMinDigits defines minimum digits for autogenerated passwords.

test/1.synthetic.sh

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euxo pipefail
33

44
DIR=${0%/*}
55
IMAGE2TEST="registry.gitlab.com/postgres-ai/database-lab/dblab-server:master"
6-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
6+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
77
### Step 1. Prepare a machine with two disks, Docker and ZFS.
88

99
source "${DIR}/_prerequisites.ubuntu.sh"
@@ -81,26 +81,8 @@ dblab clone reset testclone
8181
dblab clone status testclone
8282
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l'
8383

84-
### Step 9. Destroy clone
84+
### Step 7. Destroy clone
8585
dblab clone create --username testuser --password testuser --id testclone2
8686
dblab clone list
8787
dblab clone destroy testclone2
8888
dblab clone list
89-
90-
### Step 8. Restart containers.
91-
sudo docker ps -a --filter 'label=dblab_control' \
92-
| grep -v CONTAINER \
93-
| awk '{print $1}' \
94-
| sudo xargs --no-run-if-empty docker restart \
95-
|| true
96-
sudo docker ps -a --filter 'label=dblab-clone' \
97-
| grep -v CONTAINER \
98-
| awk '{print $1}' \
99-
| sudo xargs --no-run-if-empty docker restart \
100-
|| true
101-
102-
for i in {1..300}; do
103-
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l' 2>/dev/null && break || echo "cloned database is not ready yet"
104-
sleep 1
105-
done
106-

test/2.logical_generic.sh

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SOURCE_DBNAME="${SOURCE_DBNAME:-test}"
77
SOURCE_HOST="${SOURCE_HOST:-172.31.39.142}"
88
SOURCE_USERNAME="${SOURCE_USERNAME:-postgres}"
99
SOURCE_PASSWORD="${SOURCE_PASSWORD:-qwerty}"
10-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
10+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
1111

1212
### Step 1: Prepare a machine with two disks, Docker and ZFS
1313

@@ -42,6 +42,7 @@ sudo docker run \
4242
--publish 12345:12345 \
4343
--volume /var/run/docker.sock:/var/run/docker.sock \
4444
--volume /var/lib/dblab:/var/lib/dblab:rshared \
45+
--volume /var/lib/dblab/db.dump:/var/lib/dblab/db.dump \
4546
--volume ~/.dblab/server_test.yml:/home/dblab/configs/config.yml \
4647
"${IMAGE2TEST}"
4748

@@ -73,25 +74,8 @@ dblab clone reset testclone
7374
dblab clone status testclone
7475
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l'
7576

76-
### Step 9. Destroy clone
77+
### Step 7. Destroy clone
7778
dblab clone create --username testuser --password testuser --id testclone2
7879
dblab clone list
7980
dblab clone destroy testclone2
8081
dblab clone list
81-
82-
### Step ?. Restart containers
83-
sudo docker ps -a --filter 'label=dblab_control' \
84-
| grep -v CONTAINER \
85-
| awk '{print $1}' \
86-
| sudo xargs --no-run-if-empty docker restart \
87-
|| true
88-
sudo docker ps -a --filter 'label=dblab-clone' \
89-
| grep -v CONTAINER \
90-
| awk '{print $1}' \
91-
| sudo xargs --no-run-if-empty docker restart \
92-
|| true
93-
94-
for i in {1..300}; do
95-
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l' 2>/dev/null && break || echo "cloned database is not ready yet"
96-
sleep 1
97-
done

test/3.physical_walg.sh

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euxo pipefail
33

44
DIR=${0%/*}
55
IMAGE2TEST="registry.gitlab.com/postgres-ai/database-lab/dblab-server:master"
6-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
6+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
77
### Step 1: Prepare a machine with two disks, Docker and ZFS
88

99
source "${DIR}/_prerequisites.ubuntu.sh"
@@ -64,25 +64,8 @@ dblab clone reset testclone
6464
dblab clone status testclone
6565
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l'
6666

67-
### Step 9. Destroy clone
67+
### Step 7. Destroy clone
6868
dblab clone create --username testuser --password testuser --id testclone2
6969
dblab clone list
7070
dblab clone destroy testclone2
7171
dblab clone list
72-
73-
### Step ?. Restart containers
74-
sudo docker ps -a --filter 'label=dblab_control' \
75-
| grep -v CONTAINER \
76-
| awk '{print $1}' \
77-
| sudo xargs --no-run-if-empty docker restart \
78-
|| true
79-
sudo docker ps -a --filter 'label=dblab-clone' \
80-
| grep -v CONTAINER \
81-
| awk '{print $1}' \
82-
| sudo xargs --no-run-if-empty docker restart \
83-
|| true
84-
85-
for i in {1..300}; do
86-
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l' 2>/dev/null && break || echo "cloned database is not ready yet"
87-
sleep 1
88-
done

test/4.physical_basebackup.sh

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ IMAGE2TEST="registry.gitlab.com/postgres-ai/database-lab/dblab-server:master"
66
SOURCE_HOST="${SOURCE_HOST:-172.31.39.142}"
77
SOURCE_USERNAME="${SOURCE_USERNAME:-postgres}"
88
SOURCE_PASSWORD="${SOURCE_PASSWORD:-qwerty}"
9-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
9+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
1010

1111
### Step 1: Prepare a machine with two disks, Docker and ZFS
1212

@@ -67,25 +67,8 @@ dblab clone reset testclone
6767
dblab clone status testclone
6868
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l'
6969

70-
### Step 9. Destroy clone
70+
### Step 7. Destroy clone
7171
dblab clone create --username testuser --password testuser --id testclone2
7272
dblab clone list
7373
dblab clone destroy testclone2
7474
dblab clone list
75-
76-
### Step ?. Restart containers
77-
sudo docker ps -a --filter 'label=dblab_control' \
78-
| grep -v CONTAINER \
79-
| awk '{print $1}' \
80-
| sudo xargs --no-run-if-empty docker restart \
81-
|| true
82-
sudo docker ps -a --filter 'label=dblab-clone' \
83-
| grep -v CONTAINER \
84-
| awk '{print $1}' \
85-
| sudo xargs --no-run-if-empty docker restart \
86-
|| true
87-
88-
for i in {1..300}; do
89-
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l' 2>/dev/null && break || echo "cloned database is not ready yet"
90-
sleep 1
91-
done

test/5.logical_rds_iam.sh

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euxo pipefail
33

44
DIR=${0%/*}
55
IMAGE2TEST="registry.gitlab.com/postgres-ai/database-lab/dblab-server:master"
6-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
6+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
77
AWS_USER="${AWS_USER:-dmitry}"
88
RDS_DATABASENAME="${RDS_DATABASENAME:-database-df-test-2}"
99
IAM_POLICY="${IAM_POLICY:-rds-dblab-retrieval-test2}"
@@ -67,25 +67,8 @@ dblab clone reset testclone
6767
dblab clone status testclone
6868
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l'
6969

70-
### Step 9. Destroy clone
70+
### Step 7. Destroy clone
7171
dblab clone create --username testuser --password testuser --id testclone2
7272
dblab clone list
7373
dblab clone destroy testclone2
7474
dblab clone list
75-
76-
### Step ?. Restart containers
77-
sudo docker ps -a --filter 'label=dblab_control' \
78-
| grep -v CONTAINER \
79-
| awk '{print $1}' \
80-
| sudo xargs --no-run-if-empty docker restart \
81-
|| true
82-
sudo docker ps -a --filter 'label=dblab-clone' \
83-
| grep -v CONTAINER \
84-
| awk '{print $1}' \
85-
| sudo xargs --no-run-if-empty docker restart \
86-
|| true
87-
88-
for i in {1..300}; do
89-
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l' 2>/dev/null && break || echo "cloned database is not ready yet"
90-
sleep 1
91-
done

test/6.logical_rds_password.sh

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SOURCE_DBNAME="${SOURCE_DBNAME:-rds_test}"
77
SOURCE_HOST="${SOURCE_HOST:-database-df-test-2.cpawoeaiqdwq.us-east-2.rds.amazonaws.com}"
88
SOURCE_USERNAME="${SOURCE_USERNAME:-postgres1}"
99
SOURCE_PASSWORD="${SOURCE_PASSWORD:-welcome1}"
10-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
10+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
1111

1212
### Step 1: Prepare a machine with two disks, Docker and ZFS
1313

@@ -74,25 +74,8 @@ dblab clone reset testclone
7474
dblab clone status testclone
7575
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l'
7676

77-
### Step 9. Destroy clone
77+
### Step 7. Destroy clone
7878
dblab clone create --username testuser --password testuser --id testclone2
7979
dblab clone list
8080
dblab clone destroy testclone2
8181
dblab clone list
82-
83-
### Step ?. Restart containers
84-
sudo docker ps -a --filter 'label=dblab_control' \
85-
| grep -v CONTAINER \
86-
| awk '{print $1}' \
87-
| sudo xargs --no-run-if-empty docker restart \
88-
|| true
89-
sudo docker ps -a --filter 'label=dblab-clone' \
90-
| grep -v CONTAINER \
91-
| awk '{print $1}' \
92-
| sudo xargs --no-run-if-empty docker restart \
93-
|| true
94-
95-
for i in {1..300}; do
96-
psql "host=localhost port=6000 user=testuser dbname=rds_test" -c '\l' 2>/dev/null && break || echo "cloned database is not ready yet"
97-
sleep 1
98-
done

test/7.logical_aurora_password.sh

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SOURCE_DBNAME="${SOURCE_DBNAME:-rds_test}"
77
SOURCE_HOST="${SOURCE_HOST:-aurora-test2-instance-1.cpawoeaiqdwq.us-east-2.rds.amazonaws.com}"
88
SOURCE_USERNAME="${SOURCE_USERNAME:-postgres}"
99
SOURCE_PASSWORD="${SOURCE_PASSWORD:-welcome1}"
10-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
10+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
1111
### Step 1: Prepare a machine with two disks, Docker and ZFS
1212

1313
source "${DIR}/_prerequisites.ubuntu.sh"
@@ -73,25 +73,8 @@ dblab clone reset testclone
7373
dblab clone status testclone
7474
psql "host=localhost port=6000 user=testuser dbname=test" -c '\l'
7575

76-
### Step 9. Destroy clone
76+
### Step 7. Destroy clone
7777
dblab clone create --username testuser --password testuser --id testclone2
7878
dblab clone list
7979
dblab clone destroy testclone2
8080
dblab clone list
81-
82-
### Step ?. Restart containers
83-
sudo docker ps -a --filter 'label=dblab_control' \
84-
| grep -v CONTAINER \
85-
| awk '{print $1}' \
86-
| sudo xargs --no-run-if-empty docker restart \
87-
|| true
88-
sudo docker ps -a --filter 'label=dblab-clone' \
89-
| grep -v CONTAINER \
90-
| awk '{print $1}' \
91-
| sudo xargs --no-run-if-empty docker restart \
92-
|| true
93-
94-
for i in {1..300}; do
95-
psql "host=localhost port=6000 user=testuser dbname=rds_test" -c '\l' 2>/dev/null && break || echo "cloned database is not ready yet"
96-
sleep 1
97-
done

test/8.logical_aurora_iam.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euxo pipefail
33

44
DIR=${0%/*}
55
IMAGE2TEST="registry.gitlab.com/postgres-ai/database-lab/dblab-server:master"
6-
POSTGRES_VERSION="${SOURCE_PASSWORD:-10}"
6+
POSTGRES_VERSION="${POSTGRES_VERSION:-10}"
77
AWS_USER="${AWS_USER:-dmitry}"
88
RDS_DATABASENAME="${RDS_DATABASENAME:-aurora-test2-instance-1}"
99
IAM_POLICY="${IAM_POLICY:-rds-dblab-retrieval-test3}"

0 commit comments

Comments
 (0)