Do not RESTART after configure_instance
After the mysql-shell update to 8.0.22 the shell.run_sql("RESTART") in configure_instance began exiting with non-zero and an error message stating the MySQL server has gone away. It seems the shell.run_sql("RESTART") is not necessary. This change removes this from the configure_instance method. It also adds a restart_instance method in case we need it in the future. Closes-Bug: #1901771 Change-Id: I5f5278a4097e75c1a37e1880b594a1e81691249b
This commit is contained in:
parent
827033dade
commit
14d69d2411
|
@ -571,8 +571,6 @@ class MySQLInnoDBClusterCharm(charms_openstack.charm.OpenStackCharm):
|
|||
.format(address), "INFO")
|
||||
_script = (
|
||||
"dba.configure_instance('{user}:{pw}@{addr}')\n"
|
||||
"myshell = shell.connect('{user}:{pw}@{addr}')\n"
|
||||
"myshell.run_sql('RESTART;')"
|
||||
.format(
|
||||
user=self.cluster_user,
|
||||
pw=self.cluster_password,
|
||||
|
@ -724,6 +722,47 @@ class MySQLInnoDBClusterCharm(charms_openstack.charm.OpenStackCharm):
|
|||
leadership.leader_set({"cluster-instance-clustered-{}"
|
||||
.format(address): True})
|
||||
|
||||
def restart_instance(self, address):
|
||||
"""Restart instance
|
||||
|
||||
:param self: Self
|
||||
:type self: MySQLInnoDBClusterCharm instance
|
||||
:param address: Address of the MySQL instance to be configured
|
||||
:type address: str
|
||||
:side effect: Calls self.run_mysqlsh_script
|
||||
:returns: This function is called for its side effect
|
||||
:rtype: None
|
||||
"""
|
||||
ch_core.hookenv.log("Restarting instance: {}.".format(address), "INFO")
|
||||
_server_gone_away_error = "MySQL Error (2006)"
|
||||
_script = (
|
||||
"myshell = shell.connect('{user}:{pw}@{addr}')\n"
|
||||
"myshell.run_sql('RESTART;')"
|
||||
.format(
|
||||
user=self.cluster_user,
|
||||
pw=self.cluster_password,
|
||||
addr=address))
|
||||
try:
|
||||
output = self.run_mysqlsh_script(_script)
|
||||
except subprocess.CalledProcessError as e:
|
||||
# If the shell reports the server went away we expect this
|
||||
# when giving the RESTART command
|
||||
if _server_gone_away_error not in e.stderr.decode("UTF-8"):
|
||||
ch_core.hookenv.log(
|
||||
"Failed restarting instance {}: {}"
|
||||
.format(address, e.stderr.decode("UTF-8")), "ERROR")
|
||||
raise e
|
||||
|
||||
# After configuration of the remote instance, the remote instance
|
||||
# restarts mysql. We need to pause here for that to complete.
|
||||
self.wait_until_connectable(username=self.cluster_user,
|
||||
password=self.cluster_password,
|
||||
address=address)
|
||||
|
||||
ch_core.hookenv.log("Instance restarted {}: {}"
|
||||
.format(address, output.decode("UTF-8")),
|
||||
level="DEBUG")
|
||||
|
||||
def reboot_cluster_from_complete_outage(self):
|
||||
"""Reboot cluster from complete outage.
|
||||
|
||||
|
|
|
@ -509,11 +509,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper):
|
|||
midbc.run_mysqlsh_script = mock.MagicMock()
|
||||
_script = (
|
||||
"dba.configure_instance('{}:{}@{}')\n"
|
||||
"myshell = shell.connect('{}:{}@{}')\n"
|
||||
"myshell.run_sql('RESTART;')"
|
||||
.format(
|
||||
midbc.cluster_user, midbc.cluster_password, _addr,
|
||||
midbc.cluster_user, midbc.cluster_password, _addr))
|
||||
.format(midbc.cluster_user, midbc.cluster_password, _addr))
|
||||
|
||||
midbc.configure_instance(_addr)
|
||||
self.is_flag_set.assert_called_once_with(
|
||||
|
@ -525,6 +521,28 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper):
|
|||
self.leader_set.assert_called_once_with(
|
||||
{"cluster-instance-configured-{}".format(_addr): True})
|
||||
|
||||
def test_restart_instance(self):
|
||||
_pass = "clusterpass"
|
||||
_addr = "10.10.30.30"
|
||||
self.data = {"cluster-password": _pass}
|
||||
self.is_flag_set.return_value = False
|
||||
|
||||
midbc = mysql_innodb_cluster.MySQLInnoDBClusterCharm()
|
||||
midbc._get_password = mock.MagicMock()
|
||||
midbc._get_password.side_effect = self._fake_data
|
||||
midbc.wait_until_connectable = mock.MagicMock()
|
||||
midbc.run_mysqlsh_script = mock.MagicMock()
|
||||
_script = (
|
||||
"myshell = shell.connect('{}:{}@{}')\n"
|
||||
"myshell.run_sql('RESTART;')"
|
||||
.format(midbc.cluster_user, midbc.cluster_password, _addr))
|
||||
|
||||
midbc.restart_instance(_addr)
|
||||
midbc.run_mysqlsh_script.assert_called_once_with(_script)
|
||||
midbc.wait_until_connectable.assert_called_once_with(
|
||||
address=_addr, username=midbc.cluster_user,
|
||||
password=midbc.cluster_password)
|
||||
|
||||
def test_create_cluster(self):
|
||||
_pass = "clusterpass"
|
||||
_addr = "10.10.40.40"
|
||||
|
|
Loading…
Reference in New Issue