diff --git a/ceph/ceph/files/mgr-restful-plugin.py b/ceph/ceph/files/mgr-restful-plugin.py index 98b5abe90..212dd7824 100644 --- a/ceph/ceph/files/mgr-restful-plugin.py +++ b/ceph/ceph/files/mgr-restful-plugin.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -# Copyright (c) 2019-2023 Wind River Systems, Inc. +# Copyright (c) 2019-2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -299,6 +299,15 @@ class ServiceMonitor(object): # REST API self signed certificate generated by restful plugin self.certificate = '' + # Get the ceph executable path + self.ceph_executable = self.get_ceph_executable() + + def get_ceph_executable(self): + cli_path = "/usr/local/bin/ceph" + if os.path.exists(cli_path): + return cli_path + return "/usr/bin/ceph" + def run(self): self.disable_certificate_check() with self.service_lock(), self.service_socket(), \ @@ -666,7 +675,7 @@ class ServiceMonitor(object): out=err.output) def ceph_fsid_get(self): - return self.run_with_timeout(['/usr/bin/ceph', 'fsid'], + return self.run_with_timeout([self.ceph_executable, 'fsid'], CONFIG.ceph_cli_timeout_sec) def ceph_mgr_has_auth(self): @@ -678,7 +687,7 @@ class ServiceMonitor(object): pass try: self.run_with_timeout( - ['/usr/bin/ceph', 'auth', 'get', + [self.ceph_executable, 'auth', 'get', 'mgr.{}'.format(CONFIG.ceph_mgr_identity), '-o', '{}/keyring'.format(path)], CONFIG.ceph_cli_timeout_sec) @@ -693,7 +702,7 @@ class ServiceMonitor(object): return LOG.info('Create ceph-mgr authentication') self.run_with_timeout( - ['/usr/bin/ceph', 'auth', 'get-or-create', + [self.ceph_executable, 'auth', 'get-or-create', 'mgr.{}'.format(CONFIG.ceph_mgr_identity), 'mon', 'allow *', 'osd', 'allow *'], CONFIG.ceph_cli_timeout_sec) @@ -748,7 +757,7 @@ class ServiceMonitor(object): try: with open(os.devnull, 'wb') as null: out = self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'get', + [self.ceph_executable, 'config-key', 'get', 'config/mgr/mgr/restful/server_port'], CONFIG.ceph_cli_timeout_sec, stderr=null) if out == str(CONFIG.restful_plugin_port): @@ -766,14 +775,14 @@ class ServiceMonitor(object): return LOG.info('Set restful plugin port=%d', CONFIG.restful_plugin_port) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'set', + [self.ceph_executable, 'config-key', 'set', 'config/mgr/mgr/restful/server_port', str(CONFIG.restful_plugin_port)], CONFIG.ceph_cli_timeout_sec) def restful_plugin_has_admin_key(self): try: self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'get', + [self.ceph_executable, 'config-key', 'get', 'mgr/restful/keys/admin'], CONFIG.ceph_cli_timeout_sec) return True @@ -786,26 +795,26 @@ class ServiceMonitor(object): return LOG.info('Create restful plugin admin key') self.run_with_timeout( - ['/usr/bin/ceph', 'restful', + [self.ceph_executable, 'restful', 'create-key', 'admin'], CONFIG.ceph_cli_timeout_sec) def restful_plugin_has_certificate(self): try: self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'get', + [self.ceph_executable, 'config-key', 'get', 'config/mgr/mgr/restful/{}/crt'.format(CONFIG.ceph_mgr_identity)], CONFIG.ceph_cli_timeout_sec) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'get', + [self.ceph_executable, 'config-key', 'get', 'mgr/restful/{}/crt'.format(CONFIG.ceph_mgr_identity)], CONFIG.ceph_cli_timeout_sec) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'get', + [self.ceph_executable, 'config-key', 'get', 'config/mgr/mgr/restful/{}/key'.format(CONFIG.ceph_mgr_identity)], CONFIG.ceph_cli_timeout_sec) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'get', + [self.ceph_executable, 'config-key', 'get', '/mgr/restful/{}/key'.format(CONFIG.ceph_mgr_identity)], CONFIG.ceph_cli_timeout_sec) return True @@ -847,22 +856,22 @@ class ServiceMonitor(object): reason='failed to generate self-signed certificate: {}'.format(str(err)), out=err.output) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'set', + [self.ceph_executable, 'config-key', 'set', 'config/mgr/mgr/restful/{}/crt'.format(CONFIG.ceph_mgr_identity), '-i', os.path.join(path, 'crt')], CONFIG.ceph_cli_timeout_sec) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'set', + [self.ceph_executable, 'config-key', 'set', 'mgr/restful/{}/crt'.format(CONFIG.ceph_mgr_identity), '-i', os.path.join(path, 'crt')], CONFIG.ceph_cli_timeout_sec) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'set', + [self.ceph_executable, 'config-key', 'set', 'config/mgr/mgr/restful/{}/key'.format(CONFIG.ceph_mgr_identity), '-i', os.path.join(path, 'key')], CONFIG.ceph_cli_timeout_sec) self.run_with_timeout( - ['/usr/bin/ceph', 'config-key', 'set', + [self.ceph_executable, 'config-key', 'set', 'mgr/restful/{}/key'.format(CONFIG.ceph_mgr_identity), '-i', os.path.join(path, 'key')], CONFIG.ceph_cli_timeout_sec) @@ -870,7 +879,7 @@ class ServiceMonitor(object): shutil.rmtree(path) def restful_plugin_is_enabled(self): - command = ['/usr/bin/ceph', 'mgr', 'module', 'ls', + command = [self.ceph_executable, 'mgr', 'module', 'ls', '--format', 'json'] with open(os.devnull, 'wb') as null: out = self.run_with_timeout( @@ -892,13 +901,13 @@ class ServiceMonitor(object): if not self.restful_plugin_is_enabled(): LOG.info('Enable restful plugin') self.run_with_timeout( - ['/usr/bin/ceph', 'mgr', + [self.ceph_executable, 'mgr', 'module', 'enable', 'restful'], CONFIG.ceph_cli_timeout_sec) time.sleep(CONFIG.restful_plugin_grace_period_sec) def restful_plugin_get_url(self): - command = ['/usr/bin/ceph', 'mgr', 'services', + command = [self.ceph_executable, 'mgr', 'services', '--format', 'json'] with open(os.devnull, 'wb') as null: out = self.run_with_timeout( @@ -914,7 +923,7 @@ class ServiceMonitor(object): self.request_update_plugin_url(self.restful_plugin_url) def restful_plugin_get_certificate(self): - command = ['/usr/bin/ceph', 'config-key', 'get', + command = [self.ceph_executable, 'config-key', 'get', 'config/mgr/mgr/restful/{}/crt'.format(CONFIG.ceph_mgr_identity)] with open(os.devnull, 'wb') as null: certificate = self.run_with_timeout(