Skip to content

Commit

Permalink
Adding bootstrap mysqlrouter action test to mysqlrouter
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrusia committed Aug 8, 2023
1 parent df6dd60 commit b2a5124
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions zaza/openstack/charm_tests/mysql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tempfile
import tenacity
import yaml
import time

import zaza.charm_lifecycle.utils as lifecycle_utils
import zaza.model
Expand Down Expand Up @@ -1145,3 +1146,64 @@ def test_910_restart_on_config_change(self):
{}, {},
self.services)
logging.info("Passed restart on changed test.")

def test_action_bootstrap_mysqlrouter(self):
"""Checking bootstrap-mysqlrouter action.
Run the bootstrap-mysqlrouter action
"""
logging.info("Starting bootstrap-mysqlrouter test")

# put empty string to conf_file and make it wrong
logging.info("Breaking configuration file")
zaza.model.run_on_leader(self.application,
"echo '[DEFAULT]\n \
[metadata_cache:[\\w$]+$] \
' > {}".format(
self.conf_file))

# update status to make the status error
logging.info("Run update-status")
self.run_update_status_hooks(['keystone-mysql-router/0'])

while True:
time.sleep(5)
# get current status
unit_status = (zaza.model.get_status()
.applications['keystone-mysql-router']['status'])
logging.info("Status:{}".format(unit_status))
if unit_status['status'] == "error":
break

# run bootstrap-mysqlrouter
logging.info("Running bootstrap-mysqlrouter action")
action = zaza.model.run_action_on_leader(
self.application,
"bootstrap-mysqlrouter",
action_params={})

while True:
logging.info("Running resolved unit")
zaza.model.resolve_units(self.application)
time.sleep(10)
# get current status
unit_status = (zaza.model.get_status()
.applications['keystone-mysql-router']['status'])
logging.info("Status:{}".format(unit_status))
if unit_status['status'] == "active":
break

logging.info("Getting configuration file")
recovered = zaza.model.run_on_leader(self.application,
"cat {}".format(
self.conf_file))['Stdout']

# Checking bootstrap action result
assert "Success" in action.data["results"]["outcome"], (
"Bootstrap mysqlrouter action failed.")
# Checking conf file length,
# if file is broken it is around 250
assert len(recovered) > 1000, (
"Bootstrap mysqlrouter action failed.")

logging.info("Passed bootstrap-mysqlrouter action test.")

0 comments on commit b2a5124

Please sign in to comment.