Skip to content

Commit 82844ed

Browse files
Raise error when role name > 32 chars
1 parent 77207f7 commit 82844ed

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
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/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)