Skip to content

Commit 29e304e

Browse files
Raise error when role name > 32 chars
1 parent 77207f7 commit 29e304e

File tree

7 files changed

+25
-28
lines changed

7 files changed

+25
-28
lines changed

docs/reference/software-testing.md

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

4141
# Watch the counter is growing!
4242
```
4343
Expected results:
4444

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

4848
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
@@ -21,7 +21,7 @@
2121
)
2222

2323
# Copied these values from high_availability.application_charm.src.charm
24-
DATABASE_NAME = "continuous_writes_database"
24+
DATABASE_NAME = "continuous_writes"
2525
TABLE_NAME = "data"
2626

2727
CLUSTER_NAME = "test_cluster"

tests/integration/relations/test_relation_mysql_legacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
ENDPOINT = "mysql"
3030

3131
TEST_USER = "testuser"
32-
TEST_DATABASE = "continuous_writes_database"
32+
TEST_DATABASE = "continuous_writes"
3333
TIMEOUT = 15 * 60
3434

3535

tests/integration/roles/test_instance_dba_role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def test_build_and_deploy(ops_test: OpsTest, charm) -> None:
5050
async def test_charmed_dba_role(ops_test: OpsTest):
5151
"""Test the instance-level DBA role."""
5252
await ops_test.model.applications[INTEGRATOR_APP_NAME].set_config({
53-
"database-name": "charmed_dba_database",
53+
"database-name": "charmed_dba_db",
5454
"extra-user-roles": "charmed_dba",
5555
})
5656
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
@@ -64,7 +64,7 @@ async def test_build_and_deploy(ops_test: OpsTest, charm) -> None:
6464
async def test_charmed_read_role(ops_test: OpsTest):
6565
"""Test the instance-level charmed_read role."""
6666
await ops_test.model.applications[f"{INTEGRATOR_APP_NAME}1"].set_config({
67-
"database-name": "charmed_read_database",
67+
"database-name": "charmed_read_db",
6868
"extra-user-roles": "charmed_read",
6969
})
7070
await ops_test.model.add_relation(f"{INTEGRATOR_APP_NAME}1", DATABASE_APP_NAME)
@@ -83,8 +83,8 @@ async def test_charmed_read_role(ops_test: OpsTest):
8383
server_config_credentials["username"],
8484
server_config_credentials["password"],
8585
[
86-
"CREATE TABLE charmed_read_database.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
87-
"INSERT INTO charmed_read_database.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
86+
"CREATE TABLE charmed_read_db.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
87+
"INSERT INTO charmed_read_db.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
8888
],
8989
commit=True,
9090
)
@@ -98,14 +98,14 @@ async def test_charmed_read_role(ops_test: OpsTest):
9898
results["mysql"]["username"],
9999
results["mysql"]["password"],
100100
[
101-
"SELECT `data` FROM charmed_read_database.test_table",
101+
"SELECT `data` FROM charmed_read_db.test_table",
102102
],
103103
commit=True,
104104
)
105105
assert sorted(rows) == sorted([
106106
"test_data_1",
107107
"test_data_2",
108-
]), "Unexpected data in charmed_read_database with charmed_read role"
108+
]), "Unexpected data in charmed_read_db with charmed_read role"
109109

110110
logger.info("Checking that the charmed_read role cannot write into an existing table")
111111
with pytest.raises(ProgrammingError):
@@ -114,7 +114,7 @@ async def test_charmed_read_role(ops_test: OpsTest):
114114
results["mysql"]["username"],
115115
results["mysql"]["password"],
116116
[
117-
"INSERT INTO charmed_read_database.test_table (`data`) VALUES ('test_data_3')",
117+
"INSERT INTO charmed_read_db.test_table (`data`) VALUES ('test_data_3')",
118118
],
119119
commit=True,
120120
)
@@ -126,7 +126,7 @@ async def test_charmed_read_role(ops_test: OpsTest):
126126
results["mysql"]["username"],
127127
results["mysql"]["password"],
128128
[
129-
"CREATE TABLE charmed_read_database.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
129+
"CREATE TABLE charmed_read_db.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
130130
],
131131
commit=True,
132132
)
@@ -145,7 +145,7 @@ async def test_charmed_read_role(ops_test: OpsTest):
145145
async def test_charmed_dml_role(ops_test: OpsTest):
146146
"""Test the instance-level charmed_dml role."""
147147
await ops_test.model.applications[f"{INTEGRATOR_APP_NAME}1"].set_config({
148-
"database-name": "charmed_dml_database",
148+
"database-name": "charmed_dml_db",
149149
"extra-user-roles": "",
150150
})
151151
await ops_test.model.add_relation(f"{INTEGRATOR_APP_NAME}1", DATABASE_APP_NAME)
@@ -177,16 +177,16 @@ async def test_charmed_dml_role(ops_test: OpsTest):
177177
results["mysql"]["username"],
178178
results["mysql"]["password"],
179179
[
180-
"CREATE TABLE charmed_dml_database.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
181-
"INSERT INTO charmed_dml_database.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
182-
"SELECT `data` FROM charmed_dml_database.test_table",
180+
"CREATE TABLE charmed_dml_db.test_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
181+
"INSERT INTO charmed_dml_db.test_table (`data`) VALUES ('test_data_1'), ('test_data_2')",
182+
"SELECT `data` FROM charmed_dml_db.test_table",
183183
],
184184
commit=True,
185185
)
186186
assert sorted(rows) == sorted([
187187
"test_data_1",
188188
"test_data_2",
189-
]), "Unexpected data in charmed_dml_database with charmed_dml role"
189+
]), "Unexpected data in charmed_dml_db with charmed_dml role"
190190

191191
data_integrator_2_unit = ops_test.model.applications[f"{INTEGRATOR_APP_NAME}2"].units[0]
192192
results = await juju_.run_action(data_integrator_2_unit, "get-credentials")
@@ -197,22 +197,22 @@ async def test_charmed_dml_role(ops_test: OpsTest):
197197
results["mysql"]["username"],
198198
results["mysql"]["password"],
199199
[
200-
"SELECT `data` FROM charmed_dml_database.test_table",
200+
"SELECT `data` FROM charmed_dml_db.test_table",
201201
],
202202
commit=True,
203203
)
204204
assert sorted(rows) == sorted([
205205
"test_data_1",
206206
"test_data_2",
207-
]), "Unexpected data in charmed_dml_database with charmed_dml role"
207+
]), "Unexpected data in charmed_dml_db with charmed_dml role"
208208

209209
logger.info("Checking that the charmed_dml role can write into an existing table")
210210
await execute_queries_on_unit(
211211
primary_unit_address,
212212
results["mysql"]["username"],
213213
results["mysql"]["password"],
214214
[
215-
"INSERT INTO charmed_dml_database.test_table (`data`) VALUES ('test_data_3')",
215+
"INSERT INTO charmed_dml_db.test_table (`data`) VALUES ('test_data_3')",
216216
],
217217
commit=True,
218218
)
@@ -224,7 +224,7 @@ async def test_charmed_dml_role(ops_test: OpsTest):
224224
results["mysql"]["username"],
225225
results["mysql"]["password"],
226226
[
227-
"CREATE TABLE charmed_dml_database.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
227+
"CREATE TABLE charmed_dml_db.new_table (`id` SERIAL PRIMARY KEY, `data` TEXT)",
228228
],
229229
commit=True,
230230
)

tests/unit/test_mysql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,8 +2610,8 @@ def test_strip_off_password(self):
26102610
File "/var/lib/juju/agents/unit-mysql-k8s-edge-0/charm/venv/lib/python3.10/site-packages/ops/pebble.py", line 1771, in wait_output
26112611
raise ExecError[AnyStr](self._command, exit_code, out_value, err_value)
26122612
ops.pebble.ExecError: non-zero exit code 1 executing ['/usr/bin/mysqlsh', '--passwords-from-stdin', '--uri=serverconfig@mysql-k8s-edge-0.mysql-k8s-edge-endpoints.stg-alutay-datasql-juju361.svc.cluster.local:33062', '--python', '--verbose=0', '-c', 'shell.options.set(\'useWizards\', False)\nprint(\'###\')\nsh$
2613-
ll.connect_to_primary()\nsession.run_sql("CREATE DATABASE IF NOT EXISTS `continuous_writes_database`;")\nsession.run_sql("CREATE USER `relation-21_ff7306c7454f44`@`%` IDENTIFIED BY \'s1ffxPedAmX58aOdCRSzxEpm\' ATTRIBUTE \'{}\';")\nsession.run_sql("GRANT USAGE ON *.* TO `relation-21_ff7306c7454f44`@`%`;")\nses
2614-
sion.run_sql("GRANT ALL PRIVILEGES ON `continuous_writes_database`.* TO `relation-21_ff7306c7454f44`@`%`;")'], stdout="\x1b[1mPlease provide the password for 'serverconfig@mysql-k8s-edge-0.mysql-k8s-edge-endpoints.stg-alutay-datasql-juju361.svc.cluster.local:33062': \x1b[0m###\n", stderr='Cannot set LC_ALL to
2613+
ll.connect_to_primary()\nsession.run_sql("CREATE DATABASE IF NOT EXISTS `continuous_writes`;")\nsession.run_sql("CREATE USER `relation-21_ff7306c7454f44`@`%` IDENTIFIED BY \'s1ffxPedAmX58aOdCRSzxEpm\' ATTRIBUTE \'{}\';")\nsession.run_sql("GRANT USAGE ON *.* TO `relation-21_ff7306c7454f44`@`%`;")\nses
2614+
sion.run_sql("GRANT ALL PRIVILEGES ON `continuous_writes`.* TO `relation-21_ff7306c7454f44`@`%`;")'], stdout="\x1b[1mPlease provide the password for 'serverconfig@mysql-k8s-edge-0.mysql-k8s-edge-endpoints.stg-alutay-datasql-juju361.svc.cluster.local:33062': \x1b[0m###\n", stderr='Cannot set LC_ALL to
26152615
locale en_US.UTF-8: No such file or directory\n\x1b[36mNOTE: \x1b[0mAlready connected to a PRIMARY.\nTraceback (most recent call last):\n File "<string>", line 5, in <module>\nmysqlsh.DBError: MySQL Error (1396): ClassicSession.run_sql: Operation CREATE USER failed for \'relation-21_ff7306c7454f44\'@\'%\'\n
26162616
"""
26172617
output = self.mysql.strip_off_passwords(_input)

0 commit comments

Comments
 (0)