Merge "Remove absolute path of ceph binary from commands"

This commit is contained in:
Zuul 2024-08-01 20:13:48 +00:00 committed by Gerrit Code Review
commit dfef542445

View File

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