From a97b1449cde413277b896854104645786d290a89 Mon Sep 17 00:00:00 2001 From: Victoria Martinez de la Cruz Date: Thu, 23 Apr 2020 18:52:55 +0000 Subject: [PATCH] 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 --- devstack/lib/ceph | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/devstack/lib/ceph b/devstack/lib/ceph index 74e54423..6b8683d7 100755 --- a/devstack/lib/ceph +++ b/devstack/lib/ceph @@ -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'."