Skip to content

Commit

Permalink
Merge branch 'master' into bug/1780712
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Young authored Sep 28, 2020
2 parents cdd9631 + 77f119a commit 02656fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
13 changes: 9 additions & 4 deletions charmhelpers/contrib/storage/linux/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,10 @@ def create_erasure_profile(service, profile_name,
erasure_plugin_technique=None):
"""Create a new erasure code profile if one does not already exist for it.
Updates the profile if it exists. Please refer to [0] for more details.
Profiles are considered immutable so will not be updated if the named
profile already exists.
Please refer to [0] for more details.
0: http://docs.ceph.com/docs/master/rados/operations/erasure-code-profile/
Expand Down Expand Up @@ -1122,6 +1125,11 @@ def create_erasure_profile(service, profile_name,
:type erasure_plugin_technique: str
:return: None. Can raise CalledProcessError, ValueError or AssertionError
"""
if erasure_profile_exists(service, profile_name):
log('EC profile {} exists, skipping update'.format(profile_name),
level=WARNING)
return

plugin_techniques = {
'jerasure': [
'reed_sol_van',
Expand Down Expand Up @@ -1221,9 +1229,6 @@ def create_erasure_profile(service, profile_name,
if scalar_mds:
cmd.append('scalar-mds={}'.format(scalar_mds))

if erasure_profile_exists(service, profile_name):
cmd.append('--force')

check_call(cmd)


Expand Down
23 changes: 15 additions & 8 deletions tests/contrib/storage/test_linux_ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def test_remove_pool_quota(self):

@patch.object(ceph_utils, 'erasure_profile_exists')
def test_create_erasure_profile(self, existing_profile):
existing_profile.return_value = True
existing_profile.return_value = False
self.test_config.set('customize-failure-domain', False)
self.cmp_pkgrevno.return_value = -1
ceph_utils.create_erasure_profile(
Expand All @@ -801,8 +801,7 @@ def test_create_erasure_profile(self, existing_profile):

cmd = ['ceph', '--id', 'admin', 'osd', 'erasure-code-profile', 'set', 'super-profile',
'plugin=' + 'jerasure', 'k=' + str(10), 'm=' + str(3),
'ruleset-failure-domain=' + 'rack',
'--force']
'ruleset-failure-domain=' + 'rack']
self.check_call.assert_has_calls([call(cmd)])

self.cmp_pkgrevno.return_value = 1
Expand All @@ -814,13 +813,22 @@ def test_create_erasure_profile(self, existing_profile):
cmd = ['ceph', '--id', 'admin', 'osd', 'erasure-code-profile', 'set', 'super-profile',
'plugin=' + 'jerasure', 'k=' + str(10), 'm=' + str(3),
'crush-failure-domain=' + 'rack',
'crush-device-class=ssd',
'--force']
'crush-device-class=ssd']
self.check_call.assert_has_calls([call(cmd)])

existing_profile.return_value = True
self.check_call.reset_mock()

ceph_utils.create_erasure_profile(
service='admin', profile_name='super-profile', erasure_plugin_name='jerasure',
failure_domain='rack', data_chunks=10, coding_chunks=3,
device_class='ssd')

self.check_call.assert_not_called()

@patch.object(ceph_utils, 'erasure_profile_exists')
def test_create_erasure_profile_failure_domain(self, existing_profile):
existing_profile.return_value = True
existing_profile.return_value = False
self.test_config.set('customize-failure-domain', True)
self.cmp_pkgrevno.return_value = -1
ceph_utils.create_erasure_profile(
Expand All @@ -830,8 +838,7 @@ def test_create_erasure_profile_failure_domain(self, existing_profile):

cmd = ['ceph', '--id', 'admin', 'osd', 'erasure-code-profile', 'set', 'super-profile',
'plugin=' + 'jerasure', 'k=' + str(10), 'm=' + str(3),
'ruleset-failure-domain=' + 'rack',
'--force']
'ruleset-failure-domain=' + 'rack']
self.config.assert_called_once_with('customize-failure-domain')
self.check_call.assert_has_calls([call(cmd)])

Expand Down

0 comments on commit 02656fa

Please sign in to comment.