Skip to content

Commit 19201d7

Browse files
committed
test: reduce the numbers of databases
boulder_sa_test and boulder_sa_integration are similar enough that we can simplify by collapsing them. Same for the incidents DB.
1 parent 0c321f7 commit 19201d7

23 files changed

Lines changed: 75 additions & 105 deletions

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ services:
156156
environment:
157157
# By specifying KEYSPACES vttestserver will create the corresponding
158158
# databases on startup.
159-
KEYSPACES: boulder_sa_test,boulder_sa_integration,incidents_sa_test,incidents_sa_integration
160-
NUM_SHARDS: 1,1,1,1
159+
KEYSPACES: boulder_sa,incidents_sa
160+
NUM_SHARDS: 1,1
161161
networks:
162162
bouldernet:
163163
aliases:

docs/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ New migrations should be added at `./sa/db-next`:
323323

324324
```shell
325325
$ cd sa/db
326-
$ sql-migrate new -env="boulder_sa_test" AddWizards
326+
$ sql-migrate new -env="boulder_sa" AddWizards
327327
Created migration boulder_sa/20220906165519-AddWizards.sql
328328
```
329329

sa/db/dbconfig.mariadb.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
# https://github.com/rubenv/sql-migrate#readme
2-
boulder_sa_test:
2+
boulder_sa:
33
dialect: mysql
4-
datasource: root@tcp(boulder-proxysql:6033)/boulder_sa_test?parseTime=true
4+
datasource: root@tcp(boulder-proxysql:6033)/boulder_sa?parseTime=true
55
dir: boulder_sa
66

7-
boulder_sa_integration:
7+
incidents_sa:
88
dialect: mysql
9-
datasource: root@tcp(boulder-proxysql:6033)/boulder_sa_integration?parseTime=true
10-
dir: boulder_sa
11-
12-
incidents_sa_test:
13-
dialect: mysql
14-
datasource: root@tcp(boulder-proxysql:6033)/incidents_sa_test?parseTime=true
15-
dir: incidents_sa
16-
17-
incidents_sa_integration:
18-
dialect: mysql
19-
datasource: root@tcp(boulder-proxysql:6033)/incidents_sa_integration?parseTime=true
9+
datasource: root@tcp(boulder-proxysql:6033)/incidents_sa?parseTime=true
2010
dir: incidents_sa

sa/db/dbconfig.mysql8.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
# https://github.com/rubenv/sql-migrate#readme
2-
boulder_sa_test:
2+
boulder_sa:
33
dialect: mysql
4-
datasource: root@tcp(boulder-vitess:33577)/boulder_sa_test?parseTime=true
4+
datasource: root@tcp(boulder-vitess:33577)/boulder_sa?parseTime=true
55
dir: boulder_sa
66

7-
boulder_sa_integration:
7+
incidents_sa:
88
dialect: mysql
9-
datasource: root@tcp(boulder-vitess:33577)/boulder_sa_integration?parseTime=true
10-
dir: boulder_sa
11-
12-
incidents_sa_test:
13-
dialect: mysql
14-
datasource: root@tcp(boulder-vitess:33577)/incidents_sa_test?parseTime=true
15-
dir: incidents_sa
16-
17-
incidents_sa_integration:
18-
dialect: mysql
19-
datasource: root@tcp(boulder-vitess:33577)/incidents_sa_integration?parseTime=true
9+
datasource: root@tcp(boulder-vitess:33577)/incidents_sa?parseTime=true
2010
dir: incidents_sa

test/create_db.sh

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ set -o errexit
33
cd $(dirname $0)/..
44

55

6-
# If you modify DBS or ENVS, you must also modify the corresponding keys in
6+
# If you modify DBS, you must also modify the corresponding keys in
77
# sa/db/dbconfig.yml, see: https://github.com/rubenv/sql-migrate#readme
88

99
DBS="boulder_sa
1010
incidents_sa"
1111

12-
ENVS="test
13-
integration"
14-
1512
# /path/to/boulder/repo
1613
root_dir=$(dirname $(dirname $(readlink -f "$0")))
1714

@@ -60,55 +57,53 @@ then
6057
fi
6158

6259
for db in $DBS; do
63-
for env in $ENVS; do
64-
dbname="${db}_${env}"
65-
print_heading "${dbname}"
66-
if [[ ${SKIP_CREATE} -eq 0 ]]
60+
dbname="${db}"
61+
print_heading "${dbname}"
62+
if [[ ${SKIP_CREATE} -eq 0 ]]
63+
then
64+
if mysql ${dbconn} -e 'show databases;' | grep -q "${dbname}"
6765
then
68-
if mysql ${dbconn} -e 'show databases;' | grep -q "${dbname}"
69-
then
70-
echo "Already exists - skipping create"
71-
else
72-
echo "Doesn't exist - creating"
73-
create_empty_db "${dbname}" "${dbconn}"
74-
fi
66+
echo "Already exists - skipping create"
7567
else
76-
echo "Skipping database create for ${dbname}"
68+
echo "Doesn't exist - creating"
69+
create_empty_db "${dbname}" "${dbconn}"
7770
fi
71+
else
72+
echo "Skipping database create for ${dbname}"
73+
fi
7874

79-
if [[ "${BOULDER_CONFIG_DIR}" == "test/config-next" ]]
80-
then
81-
dbpath="./sa/db-next"
82-
else
83-
dbpath="./sa/db"
84-
fi
75+
if [[ "${BOULDER_CONFIG_DIR}" == "test/config-next" ]]
76+
then
77+
dbpath="./sa/db-next"
78+
else
79+
dbpath="./sa/db"
80+
fi
8581

86-
# sql-migrate will default to ./dbconfig.yml and treat all configured dirs
87-
# as relative.
88-
cd "${dbpath}"
89-
r=`sql-migrate up -config="${DB_CONFIG_FILE}" -env="${dbname}" | xargs -0 echo`
90-
if [[ "${r}" == "Migration failed"* ]]
91-
then
92-
echo "sql-migrate: ${r}"
93-
echo "Try \`docker compose down --volumes\` and running again"
94-
exit 1
95-
else
96-
echo "sql-migrate: ${r}"
97-
fi
82+
# sql-migrate will default to ./dbconfig.yml and treat all configured dirs
83+
# as relative.
84+
cd "${dbpath}"
85+
r=`sql-migrate up -config="${DB_CONFIG_FILE}" -env="${dbname}" | xargs -0 echo`
86+
if [[ "${r}" == "Migration failed"* ]]
87+
then
88+
echo "sql-migrate: ${r}"
89+
echo "Try \`docker compose down --volumes\` and running again"
90+
exit 1
91+
else
92+
echo "sql-migrate: ${r}"
93+
fi
9894

99-
USERS_SQL="../db-users/${db}.sql"
100-
if [[ ${SKIP_USERS} -eq 1 ]]
101-
then
102-
echo "Skipping user grants for ${dbname}"
103-
else
104-
sed -e "s/'localhost'/'%'/g" < "${USERS_SQL}" | \
105-
mysql ${dbconn} -D "${dbname}" -f || exit_err "Unable to add users from ${USERS_SQL}"
106-
echo "Added users from ${USERS_SQL}"
107-
fi
95+
USERS_SQL="../db-users/${db}.sql"
96+
if [[ ${SKIP_USERS} -eq 1 ]]
97+
then
98+
echo "Skipping user grants for ${dbname}"
99+
else
100+
sed -e "s/'localhost'/'%'/g" < "${USERS_SQL}" | \
101+
mysql ${dbconn} -D "${dbname}" -f || exit_err "Unable to add users from ${USERS_SQL}"
102+
echo "Added users from ${USERS_SQL}"
103+
fi
108104

109-
# return to the root directory
110-
cd "${root_dir}"
111-
done
105+
# return to the root directory
106+
cd "${root_dir}"
112107
done
113108

114109
echo

test/db.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ type CleanUpDB interface {
2323
}
2424

2525
// ResetBoulderTestDatabase returns a cleanup function which deletes all rows in
26-
// all tables of the 'boulder_sa_test' database. Omits the 'gorp_migrations'
26+
// all tables of the 'boulder_sa' database. Omits the 'gorp_migrations'
2727
// table as this is used by sql-migrate (https://github.com/rubenv/sql-migrate)
2828
// to track migrations. If it encounters an error it fails the tests.
2929
func ResetBoulderTestDatabase(t testing.TB) func() {
3030
return resetTestDatabase(t, context.Background(), vars.DBConnSAFullPerms)
3131
}
3232

3333
// ResetIncidentsTestDatabase returns a cleanup function which deletes all rows
34-
// in all tables of the 'incidents_sa_test' database. Omits the
34+
// in all tables of the 'incidents_sa' database. Omits the
3535
// 'gorp_migrations' table as this is used by sql-migrate
3636
// (https://github.com/rubenv/sql-migrate) to track migrations. If it encounters
3737
// an error it fails the tests.

test/integration/cert_storage_failed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func getPrecertByName(db *sql.DB, reversedName string) (*x509.Certificate, error
7878
func TestIssuanceCertStorageFailed(t *testing.T) {
7979
os.Setenv("DIRECTORY", "http://boulder.service.consul:4001/directory")
8080

81-
db, err := sql.Open("mysql", vars.DBConnSAIntegrationFullPerms)
81+
db, err := sql.Open("mysql", vars.DBConnSAFullPerms)
8282
test.AssertNotError(t, err, "failed to open db connection")
8383

8484
if os.Getenv("USE_VITESS") == "false" {

test/integration/crl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func runUpdater(t *testing.T, configFile string) {
4848
// Reset the "leasedUntil" column so this can be done alongside other
4949
// updater runs without worrying about unclean state.
5050
fc := clock.NewFake()
51-
db, err := sql.Open("mysql", vars.DBConnSAIntegrationFullPerms)
51+
db, err := sql.Open("mysql", vars.DBConnSAFullPerms)
5252
test.AssertNotError(t, err, "opening database connection")
5353
_, err = db.Exec(`UPDATE crlShards SET leasedUntil = ?`, fc.Now().Add(-time.Minute))
5454
test.AssertNotError(t, err, "resetting leasedUntil column")
@@ -132,7 +132,7 @@ func TestCRLPipeline(t *testing.T) {
132132
configFile := path.Join(configDir, "crl-updater.json")
133133

134134
// Create a database connection so we can pretend to jump forward in time.
135-
db, err := sql.Open("mysql", vars.DBConnSAIntegrationFullPerms)
135+
db, err := sql.Open("mysql", vars.DBConnSAFullPerms)
136136
test.AssertNotError(t, err, "creating database connection")
137137

138138
// Issue a test certificate and save its serial number.

test/integration/validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func TestCAARechecking(t *testing.T) {
307307

308308
// Manipulate the database so that it looks like the authz was validated
309309
// more than 8 hours ago.
310-
db, err := sql.Open("mysql", vars.DBConnSAIntegrationFullPerms)
310+
db, err := sql.Open("mysql", vars.DBConnSAFullPerms)
311311
if err != nil {
312312
t.Fatalf("sql.Open: %s", err)
313313
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
badkeyrevoker@tcp(boulder-proxysql:6033)/boulder_sa_integration
1+
badkeyrevoker@tcp(boulder-proxysql:6033)/boulder_sa

0 commit comments

Comments
 (0)