Add extended parameter for cluster-status
Closes-Bug: #2051568 Change-Id: I53a6a1e4b54e3632ce90e4350a14bb45fba125c6
This commit is contained in:
parent
3150d34f19
commit
e355a51606
@ -25,6 +25,12 @@ cluster-status:
|
||||
description: |
|
||||
JSON dump of the cluster schema and status. This action can be used to
|
||||
determine the RW and RO instances.
|
||||
params:
|
||||
extended:
|
||||
type: integer
|
||||
default: 0
|
||||
description: |
|
||||
Level of information to report back, valid values between 0 and 3 inclusive
|
||||
reboot-cluster-from-complete-outage:
|
||||
description: |
|
||||
In the case of a complete outage, reboot the cluster from this instance's
|
||||
|
@ -130,7 +130,9 @@ def cluster_status(args):
|
||||
"""
|
||||
try:
|
||||
with charm.provide_charm_instance() as instance:
|
||||
_status = json.dumps(instance.get_cluster_status())
|
||||
_extended = ch_core.hookenv.action_get("extended")
|
||||
_status = json.dumps(
|
||||
instance.get_cluster_status(extended=_extended))
|
||||
ch_core.hookenv.action_set({"cluster-status": _status})
|
||||
except subprocess.CalledProcessError as e:
|
||||
ch_core.hookenv.action_set({
|
||||
@ -138,6 +140,13 @@ def cluster_status(args):
|
||||
"return-code": e.returncode,
|
||||
"traceback": traceback.format_exc()})
|
||||
ch_core.hookenv.action_fail("Cluster status failed")
|
||||
except ValueError as e:
|
||||
ch_core.hookenv.action_set({
|
||||
"error": str(e),
|
||||
"traceback": traceback.format_exc()
|
||||
})
|
||||
ch_core.hookenv.action_fail(
|
||||
"Cluster status failed, invalid values for extended parameter")
|
||||
|
||||
|
||||
def reboot_cluster_from_complete_outage(args):
|
||||
|
@ -1214,7 +1214,7 @@ class MySQLInnoDBClusterCharm(
|
||||
self.configure_instance(address)
|
||||
self.add_instance_to_cluster(address)
|
||||
|
||||
def get_cluster_status(self, nocache=False):
|
||||
def get_cluster_status(self, nocache=False, extended=0):
|
||||
"""Get cluster status
|
||||
|
||||
Return cluster.status() as a dictionary. If cached data exists and is
|
||||
@ -1223,6 +1223,8 @@ class MySQLInnoDBClusterCharm(
|
||||
|
||||
:param nocache: Do not return cached data
|
||||
:type nocache: Boolean
|
||||
:param extended: Extended output for cluster-status
|
||||
:type extended: integer
|
||||
:side effect: Calls self.check_mysql_connection
|
||||
:returns: Dictionary cluster status output
|
||||
:rtype: Union[None, dict]
|
||||
@ -1251,12 +1253,18 @@ class MySQLInnoDBClusterCharm(
|
||||
.format(self._error_str(e)), "ERROR")
|
||||
return
|
||||
|
||||
if extended < 0 or extended > 3:
|
||||
raise ValueError(
|
||||
'The value of extended parameter needs to be between '
|
||||
'0 and 3 inclusive')
|
||||
|
||||
_script = (
|
||||
"shell.connect('{}:{}@{}')\n"
|
||||
"cluster = dba.get_cluster('{}')\n"
|
||||
"print(cluster.status())"
|
||||
"print(cluster.status({{'extended': {}}}))"
|
||||
.format(self.cluster_user, self.cluster_password,
|
||||
self.cluster_address, self.cluster_name))
|
||||
self.cluster_address, self.cluster_name,
|
||||
extended))
|
||||
try:
|
||||
output = self.run_mysqlsh_script(_script)
|
||||
except subprocess.CalledProcessError as e:
|
||||
@ -1264,7 +1272,8 @@ class MySQLInnoDBClusterCharm(
|
||||
"Failed checking cluster status: {}"
|
||||
.format(self._error_str(e)), "ERROR")
|
||||
return
|
||||
self._cached_cluster_status = json.loads(output.decode("UTF-8"))
|
||||
output = ''.join(str(output.decode('UTF-8')).split('\n'))
|
||||
self._cached_cluster_status = json.loads(output)
|
||||
return self._cached_cluster_status
|
||||
|
||||
@staticmethod
|
||||
|
@ -1313,7 +1313,7 @@ class TestMySQLInnoDBClusterCharm(test_utils.PatchHelper):
|
||||
_script = (
|
||||
"shell.connect('{}:{}@{}')\n"
|
||||
"cluster = dba.get_cluster('{}')\n"
|
||||
"print(cluster.status())"
|
||||
"print(cluster.status({{'extended': 0}}))"
|
||||
.format(
|
||||
midbc.cluster_user, midbc.cluster_password,
|
||||
midbc.cluster_address, midbc.cluster_name))
|
||||
|
Loading…
Reference in New Issue
Block a user