Check that ceph-mon service has started to get its version

Add an extra check to verify that ceph-mon service has started
before trying to retrieve its version.

An already existing function is being used, wait_for_daemon

Since we now guarantee that we are using systemctl, we can use
the is-active feature. If the service is running, the exit code
will be 0.

Also, change the command used to get the mon version. We can use
the ceph version command provided by the new cli instead of using
ceph daemon command which requires more privileges.

Change-Id: I2d4f23721107c4b5cb1c09719c55424eecd0c880
Closes-Bug: #1872855
This commit is contained in:
Victoria Martinez de la Cruz 2020-04-23 18:52:55 +00:00
parent e6591702d8
commit a97b1449cd
1 changed files with 12 additions and 4 deletions

View File

@ -226,15 +226,23 @@ function is_ceph_enabled_for_service {
# and healthy.
function _get_ceph_version {
local ceph_version_str
local mon_started
if [[ $1 == 'cli' ]]; then
# ceph --version show CLI version
ceph_version_str=$(sudo ceph --version | cut -d ' ' -f 3 | \
cut -d '.' -f 1,2)
elif [[ $1 == 'mon' ]]; then
# TODO(frickler): Find a better way to make sure that ceph-mon has started
sleep 5
ceph_version_str=$(sudo ceph daemon mon.$(hostname) version | \
cut -d '"' -f 4 | cut -f 1,2 -d '.')
# ceph version show mon daemon version
mon_started=$(wait_for_daemon "sudo systemctl is-active --quiet ceph-mon@$(hostname)")
if $mon_started; then
ceph_version_str=$(sudo ceph version | cut -d ' ' -f 3 | \
cut -f 1,2 -d '.')
else
die $LINENO "ceph-mon@${hostname} is not running and it's not possible to \
retrieve it's version"
fi
else
die $LINENO "Invalid argument. The get_ceph_version function needs \
an argument that can be 'cli' or 'mon'."