Files
charm-ceph-mon/actions/ceph_ops.py
Nobuto Murata c9389a8cd0 Revert "Create NRPE check to verify ceph daemons versions"
This reverts commit dfbda68e1a.

Reason for revert:

The Ceph version check seems to be missing a consideration of users to
execute the nrpe check. It actually fails to get keyrings to execute the
command as it's run by a non-root user.

$ juju run-action --wait nrpe/0 run-nrpe-check name=check-ceph-daemons-versions
unit-nrpe-0:
  UnitId: nrpe/0
  id: "20"
  results:
    Stderr: |
      2023-02-01T03:03:09.556+0000 7f4677361700 -1 auth: unable to find
      a keyring on
      /etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,/etc/ceph/keyring.bin:
      (2) No such file or directory
      2023-02-01T03:03:09.556+0000 7f4677361700 -1
      AuthRegistry(0x7f467005f540) no keyring found at
      /etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,/etc/ceph/keyring.bin,
      disabling cephx
      2023-02-01T03:03:09.556+0000 7f4677361700 -1 auth: unable to find
      a keyring on
      /etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,/etc/ceph/keyring.bin:
      (2) No such file or directory
      2023-02-01T03:03:09.556+0000 7f4677361700 -1
      AuthRegistry(0x7f4670064d88) no keyring found at
      /etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,/etc/ceph/keyring.bin,
      disabling cephx
      2023-02-01T03:03:09.560+0000 7f4677361700 -1 auth: unable to find
      a keyring on
      /etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,/etc/ceph/keyring.bin:
      (2) No such file or directory
      2023-02-01T03:03:09.560+0000 7f4677361700 -1
      AuthRegistry(0x7f4677360000) no keyring found at
      /etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,/etc/ceph/keyring.bin,
      disabling cephx
      [errno 2] RADOS object not found (error connecting to the cluster)
    check-output: 'UNKNOWN: could not determine OSDs versions, error: Command ''[''ceph'',
      ''versions'']'' returned non-zero exit status 1.'
  status: completed
  timing:
    completed: 2023-02-01 03:03:10 +0000 UTC
    enqueued: 2023-02-01 03:03:09 +0000 UTC
    started: 2023-02-01 03:03:09 +0000 UTC

Related-Bug: #1943628
Change-Id: I84b306e84661e6664e8a69fa93dfdb02fa4f1e7e
2023-02-01 12:31:16 +09:00

156 lines
4.7 KiB
Python
Executable File

# Copyright 2016 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from subprocess import CalledProcessError, check_output
from charmhelpers.core.hookenv import (
action_get,
action_fail,
)
from charmhelpers.contrib.storage.linux.ceph import pool_set, \
set_pool_quota, snapshot_pool, remove_pool_snapshot
def list_pools():
"""Return a list of all Ceph pools."""
try:
pool_list = check_output(['ceph', 'osd', 'pool', 'ls']).decode('UTF-8')
return pool_list
except CalledProcessError as e:
action_fail(str(e))
def pool_get():
"""
Returns a key from a pool using 'ceph osd pool get'.
The key is provided via the 'key' action parameter and the
pool provided by the 'pool_name' parameter. These are used when
running 'ceph osd pool get <pool_name> <key>', the result of
which is returned.
On failure, 'unknown' will be returned.
"""
key = action_get("key")
pool_name = action_get("pool_name")
try:
value = (check_output(['ceph', 'osd', 'pool', 'get', pool_name, key])
.decode('UTF-8'))
return value
except CalledProcessError as e:
action_fail(str(e))
return 'unknown'
def set_pool():
"""
Sets an arbitrary key key in a Ceph pool.
Sets the key specified by the action parameter 'key' to the value
specified in the action parameter 'value' for the pool specified
by the action parameter 'pool_name' using the charmhelpers
'pool_set' function.
"""
key = action_get("key")
value = action_get("value")
pool_name = action_get("pool_name")
pool_set(service='ceph', pool_name=pool_name, key=key, value=value)
def pool_stats():
"""
Returns statistics for a pool.
The pool name is provided by the action parameter 'name'.
"""
try:
pool_name = action_get("name")
stats = (
check_output(['ceph', 'osd', 'pool', 'stats', pool_name])
.decode('UTF-8')
)
return stats
except CalledProcessError as e:
action_fail(str(e))
def delete_pool_snapshot():
"""
Delete a pool snapshot.
Deletes a snapshot from the pool provided by the action
parameter 'name', with the snapshot name provided by
action parameter 'snapshot-name'
"""
pool_name = action_get("name")
snapshot_name = action_get("snapshot-name")
remove_pool_snapshot(service='ceph',
pool_name=pool_name,
snapshot_name=snapshot_name)
# Note only one or the other can be set
def set_pool_max_bytes():
"""
Sets the max bytes quota for a pool.
Sets the pool quota maximum bytes for the pool specified by
the action parameter 'name' to the value specified by
the action parameter 'max'
"""
pool_name = action_get("name")
max_bytes = action_get("max")
set_pool_quota(service='ceph',
pool_name=pool_name,
max_bytes=max_bytes)
def snapshot_ceph_pool():
"""
Snapshots a Ceph pool.
Snapshots the pool provided in action parameter 'name' and
uses the parameter provided in the action parameter 'snapshot-name'
as the name for the snapshot.
"""
pool_name = action_get("name")
snapshot_name = action_get("snapshot-name")
snapshot_pool(service='ceph',
pool_name=pool_name,
snapshot_name=snapshot_name)
def get_quorum_status(format_type="text"):
"""
Return the output of 'ceph quorum_status'.
On error, function_fail() is called with the exception info.
"""
ceph_output = check_output(['ceph', 'quorum_status'],
timeout=60).decode("utf-8")
ceph_output_json = json.loads(ceph_output)
if format_type == "json":
return {"message": json.dumps(ceph_output_json)}
else:
return {
"election-epoch": ceph_output_json.get("election_epoch"),
"quorum-age": ceph_output_json.get("quorum_age"),
"quorum-leader-name": ceph_output_json.get("quorum_leader_name",
"unknown"),
"quorum-names": ", ".join(ceph_output_json.get("quorum_names",
[])),
}