CephFS Helpers
Added a helper function to test if ceph fs new has already been called. If it has been than the ceph_broker will skip calling it again. Change-Id: Ib39542a55db5f03f08af72054c14bd6abb3d6a2a
This commit is contained in:
@@ -1244,6 +1244,37 @@ def get_running_osds():
|
||||
return []
|
||||
|
||||
|
||||
def get_cephfs(service):
|
||||
"""
|
||||
List the Ceph Filesystems that exist
|
||||
:rtype : list. Returns a list of the ceph filesystems
|
||||
:param service: The service name to run the ceph command under
|
||||
"""
|
||||
if get_version() < 0.86:
|
||||
# This command wasn't introduced until 0.86 ceph
|
||||
return []
|
||||
try:
|
||||
output = subprocess.check_output(["ceph",
|
||||
'--id', service,
|
||||
"fs", "ls"])
|
||||
if not output:
|
||||
return []
|
||||
"""
|
||||
Example subprocess output:
|
||||
'name: ip-172-31-23-165, metadata pool: ip-172-31-23-165_metadata,
|
||||
data pools: [ip-172-31-23-165_data ]\n'
|
||||
output: filesystems: ['ip-172-31-23-165']
|
||||
"""
|
||||
filesystems = []
|
||||
for line in output.splitlines():
|
||||
parts = line.split(',')
|
||||
for part in parts:
|
||||
if "name" in part:
|
||||
filesystems.append(part.split(' ')[1])
|
||||
except subprocess.CalledProcessError:
|
||||
return []
|
||||
|
||||
|
||||
def wait_for_all_monitors_to_upgrade(new_version, upgrade_key):
|
||||
"""
|
||||
Fairly self explanatory name. This function will wait
|
||||
|
||||
@@ -24,6 +24,7 @@ from charmhelpers.core.hookenv import (
|
||||
INFO,
|
||||
ERROR,
|
||||
)
|
||||
from ceph import get_cephfs
|
||||
from charmhelpers.contrib.storage.linux.ceph import (
|
||||
create_erasure_profile,
|
||||
delete_pool,
|
||||
@@ -418,7 +419,12 @@ def handle_create_cephfs(request, service):
|
||||
log(msg, level=ERROR)
|
||||
return {'exit-code': 1, 'stderr': msg}
|
||||
|
||||
# Finally create CephFS
|
||||
if get_cephfs(service=service):
|
||||
# CephFS new has already been called
|
||||
log("CephFS already created")
|
||||
return
|
||||
|
||||
# Finally create CephFS
|
||||
try:
|
||||
check_output(["ceph",
|
||||
'--id', service,
|
||||
@@ -426,8 +432,12 @@ def handle_create_cephfs(request, service):
|
||||
metadata_pool,
|
||||
data_pool])
|
||||
except CalledProcessError as err:
|
||||
log(err.output, level=ERROR)
|
||||
return {'exit-code': 1, 'stderr': err.output}
|
||||
if err.returncode == 22:
|
||||
log("CephFS already created")
|
||||
return
|
||||
else:
|
||||
log(err.output, level=ERROR)
|
||||
return {'exit-code': 1, 'stderr': err.output}
|
||||
|
||||
|
||||
def handle_rgw_region_set(request, service):
|
||||
|
||||
@@ -112,13 +112,16 @@ class CephBrokerTestCase(unittest.TestCase):
|
||||
self.assertEqual(json.loads(rc)['exit-code'], 0)
|
||||
self.assertEqual(json.loads(rc)['request-id'], '1ef5aede')
|
||||
|
||||
@mock.patch('ceph_broker.get_cephfs')
|
||||
@mock.patch('ceph_broker.check_output')
|
||||
@mock.patch('ceph_broker.pool_exists')
|
||||
@mock.patch('ceph_broker.log')
|
||||
def test_process_requests_create_cephfs(self,
|
||||
mock_log,
|
||||
mock_pool_exists,
|
||||
check_output):
|
||||
check_output,
|
||||
get_cephfs):
|
||||
get_cephfs.return_value = []
|
||||
mock_pool_exists.return_value = True
|
||||
reqs = json.dumps({'api-version': 1,
|
||||
'request-id': '1ef5aede',
|
||||
|
||||
Reference in New Issue
Block a user