Skip to content

Commit 1c2c26f

Browse files
Raise error when role name > 32 chars
1 parent 6655767 commit 1c2c26f

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

docs/reference/software-testing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ juju run mysql-test-app/leader get-inserted-data
4141
# Start "continuous write" test:
4242
juju run mysql-test-app/leader start-continuous-writes
4343
export password=$(juju run mysql-k8s/leader get-password username=root | yq '.. | select(. | has("password")).password')
44-
watch -n1 -x juju ssh --container mysql mysql-k8s/leader "mysql -h 127.0.0.1 -uroot -p${password} -e \"select count(*) from continuous_writes_database.data\""
44+
watch -n1 -x juju ssh --container mysql mysql-k8s/leader "mysql -h 127.0.0.1 -uroot -p${password} -e \"select count(*) from continuous_writes.data\""
4545

4646
# Watch the counter is growing!
4747
```
4848
Expected results:
4949

50-
* mysql-test-app continuously inserts records in database `continuous_writes_database` table `data`.
50+
* mysql-test-app continuously inserts records in database `continuous_writes` table `data`.
5151
* the counters (amount of records in table) are growing on all cluster members
5252

5353
Hints:

lib/charms/mysql/v0/mysql.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,12 +1510,9 @@ def create_database(self, database: str) -> None:
15101510
"""Create an application database."""
15111511
role_name = f"charmed_dba_{database}"
15121512

1513-
if len(database) >= ROLE_MAX_LENGTH:
1514-
logger.error(f"Failed to create application database {database}")
1515-
raise MySQLCreateApplicationDatabaseError("Name longer than 32 characters")
15161513
if len(role_name) >= ROLE_MAX_LENGTH:
1517-
logger.warning(f"Pruning application database role name {role_name}")
1518-
role_name = role_name[:ROLE_MAX_LENGTH]
1514+
logger.error(f"Failed to create application database {database}")
1515+
raise MySQLCreateApplicationDatabaseError("Role name longer than 32 characters")
15191516

15201517
create_database_commands = (
15211518
"shell.connect_to_primary()",

tests/integration/high_availability/high_availability_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333

3434
# Copied these values from high_availability.application_charm.src.charm
35-
DATABASE_NAME = "continuous_writes_database"
35+
DATABASE_NAME = "continuous_writes"
3636
TABLE_NAME = "data"
3737

3838
CLUSTER_NAME = "test_cluster"

tests/integration/relations/test_mysql_root.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def test_build_and_deploy(ops_test: OpsTest, charm):
2929
config = {
3030
"profile": "testing",
3131
"mysql-root-interface-user": "test-user",
32-
"mysql-root-interface-database": "continuous_writes_database",
32+
"mysql-root-interface-database": "continuous_writes",
3333
}
3434
resources = {
3535
"mysql-image": DB_METADATA["resources"]["mysql-image"]["upstream-source"],

tests/integration/roles/test_instance_dba_role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def test_build_and_deploy(ops_test: OpsTest, charm) -> None:
5252
async def test_charmed_dba_role(ops_test: OpsTest):
5353
"""Test the DBA predefined role."""
5454
await ops_test.model.applications[INTEGRATOR_APP_NAME].set_config({
55-
"database-name": "charmed_dba_database",
55+
"database-name": "charmed_dba_db",
5656
"extra-user-roles": "charmed_dba",
5757
})
5858
await ops_test.model.add_relation(INTEGRATOR_APP_NAME, DATABASE_APP_NAME)

tests/integration/roles/test_instance_roles.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def test_build_and_deploy(ops_test: OpsTest, charm) -> None:
6868
async def test_charmed_read_role(ops_test: OpsTest):
6969
"""Test the charmed_read predefined role."""
7070
await ops_test.model.applications[f"{INTEGRATOR_APP_NAME}1"].set_config({
71-
"database-name": "charmed_read_database",
71+
"database-name": "charmed_read_db",
7272
"extra-user-roles": "charmed_read",
7373
})
7474
await ops_test.model.add_relation(f"{INTEGRATOR_APP_NAME}1", DATABASE_APP_NAME)
@@ -87,8 +87,8 @@ async def test_charmed_read_role(ops_test: OpsTest):
8787
server_config_credentials["username"],
8888
server_config_credentials["password"],
8989
[
90-
"CREATE TABLE charmed_read_database.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
91-
"INSERT INTO charmed_read_database.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
90+
"CREATE TABLE charmed_read_db.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
91+
"INSERT INTO charmed_read_db.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
9292
],
9393
commit=True,
9494
)
@@ -102,14 +102,14 @@ async def test_charmed_read_role(ops_test: OpsTest):
102102
results["mysql"]["username"],
103103
results["mysql"]["password"],
104104
[
105-
"SELECT `data` FROM charmed_read_database.test_table",
105+
"SELECT `data` FROM charmed_read_db.test_table",
106106
],
107107
commit=True,
108108
)
109109
assert sorted(rows) == sorted([
110110
"test_data_1",
111111
"test_data_2",
112-
]), "Unexpected data in charmed_read_database with charmed_read role"
112+
]), "Unexpected data in charmed_read_db with charmed_read role"
113113

114114
logger.info("Checking that the charmed_read role cannot write into an existing table")
115115
with pytest.raises(ProgrammingError):
@@ -118,7 +118,7 @@ async def test_charmed_read_role(ops_test: OpsTest):
118118
results["mysql"]["username"],
119119
results["mysql"]["password"],
120120
[
121-
"INSERT INTO charmed_read_database.test_table (`data`) VALUES ('test_data_3')",
121+
"INSERT INTO charmed_read_db.test_table (`data`) VALUES ('test_data_3')",
122122
],
123123
commit=True,
124124
)
@@ -130,7 +130,7 @@ async def test_charmed_read_role(ops_test: OpsTest):
130130
results["mysql"]["username"],
131131
results["mysql"]["password"],
132132
[
133-
"CREATE TABLE charmed_read_database.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
133+
"CREATE TABLE charmed_read_db.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
134134
],
135135
commit=True,
136136
)
@@ -149,7 +149,7 @@ async def test_charmed_read_role(ops_test: OpsTest):
149149
async def test_charmed_dml_role(ops_test: OpsTest):
150150
"""Test the charmed_dml role."""
151151
await ops_test.model.applications[f"{INTEGRATOR_APP_NAME}1"].set_config({
152-
"database-name": "charmed_dml_database",
152+
"database-name": "charmed_dml_db",
153153
"extra-user-roles": "",
154154
})
155155
await ops_test.model.add_relation(f"{INTEGRATOR_APP_NAME}1", DATABASE_APP_NAME)
@@ -181,16 +181,16 @@ async def test_charmed_dml_role(ops_test: OpsTest):
181181
results["mysql"]["username"],
182182
results["mysql"]["password"],
183183
[
184-
"CREATE TABLE charmed_dml_database.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
185-
"INSERT INTO charmed_dml_database.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
186-
"SELECT `data` FROM charmed_dml_database.test_table",
184+
"CREATE TABLE charmed_dml_db.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
185+
"INSERT INTO charmed_dml_db.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
186+
"SELECT `data` FROM charmed_dml_db.test_table",
187187
],
188188
commit=True,
189189
)
190190
assert sorted(rows) == sorted([
191191
"test_data_1",
192192
"test_data_2",
193-
]), "Unexpected data in charmed_dml_database with charmed_dml role"
193+
]), "Unexpected data in charmed_dml_db with charmed_dml role"
194194

195195
data_integrator_2_unit = ops_test.model.applications[f"{INTEGRATOR_APP_NAME}2"].units[0]
196196
results = await juju_.run_action(data_integrator_2_unit, "get-credentials")
@@ -201,22 +201,22 @@ async def test_charmed_dml_role(ops_test: OpsTest):
201201
results["mysql"]["username"],
202202
results["mysql"]["password"],
203203
[
204-
"SELECT `data` FROM charmed_dml_database.test_table",
204+
"SELECT `data` FROM charmed_dml_db.test_table",
205205
],
206206
commit=True,
207207
)
208208
assert sorted(rows) == sorted([
209209
"test_data_1",
210210
"test_data_2",
211-
]), "Unexpected data in charmed_dml_database with charmed_dml role"
211+
]), "Unexpected data in charmed_dml_db with charmed_dml role"
212212

213213
logger.info("Checking that the charmed_dml role can write into an existing table")
214214
execute_queries_on_unit(
215215
primary_unit_address,
216216
results["mysql"]["username"],
217217
results["mysql"]["password"],
218218
[
219-
"INSERT INTO charmed_dml_database.test_table (`data`) VALUES ('test_data_3')",
219+
"INSERT INTO charmed_dml_db.test_table (`data`) VALUES ('test_data_3')",
220220
],
221221
commit=True,
222222
)
@@ -228,7 +228,7 @@ async def test_charmed_dml_role(ops_test: OpsTest):
228228
results["mysql"]["username"],
229229
results["mysql"]["password"],
230230
[
231-
"CREATE TABLE charmed_dml_database.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
231+
"CREATE TABLE charmed_dml_db.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
232232
],
233233
commit=True,
234234
)

0 commit comments

Comments
 (0)