Ensure bootstrapped-osds count updated after add-disk

When we add/zap disks it may change the overall osd
count so need to ensure this is kept up-to-date.

Change-Id: Ib55547f88316e80a8948ce808ea992c1402458f5
Closes-Bug: #1861293
This commit is contained in:
Edward Hope-Morley 2020-01-31 12:12:08 +00:00
parent d4a6142a03
commit 871b057335
2 changed files with 73 additions and 2 deletions

View File

@ -24,12 +24,14 @@ sys.path.append('hooks')
import charmhelpers.contrib.storage.linux.ceph as ch_ceph
import charmhelpers.core.hookenv as hookenv
from charmhelpers.core.unitdata import kv
import ceph_hooks
import ceph.utils
def add_device(request, device_path, bucket=None):
ceph.utils.osdize(dev, hookenv.config('osd-format'),
ceph.utils.osdize(device_path, hookenv.config('osd-format'),
ceph_hooks.get_journal_devices(),
hookenv.config('ignore-device-errors'),
hookenv.config('osd-encrypt'),
@ -37,7 +39,7 @@ def add_device(request, device_path, bucket=None):
hookenv.config('osd-encrypt-keymanager'))
# Make it fast!
if hookenv.config('autotune'):
ceph.utils.tune_dev(dev)
ceph.utils.tune_dev(device_path)
mounts = filter(lambda disk: device_path
in disk.device, psutil.disk_partitions())
for osd in mounts:
@ -46,6 +48,18 @@ def add_device(request, device_path, bucket=None):
'op': 'move-osd-to-bucket',
'osd': "osd.{}".format(osd_id),
'bucket': bucket})
# Ensure mon's count of osds is accurate
db = kv()
bootstrapped_osds = len(db.get('osd-devices', []))
for r_id in hookenv.relation_ids('mon'):
hookenv.relation_set(
relation_id=r_id,
relation_settings={
'bootstrapped-osds': bootstrapped_osds,
}
)
return request

View File

@ -0,0 +1,57 @@
# Copyright 2020 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from actions import add_disk
from test_utils import CharmTestCase
class AddDiskActionTests(CharmTestCase):
def setUp(self):
super(AddDiskActionTests, self).setUp(
add_disk, ['hookenv', 'kv'])
self.kv.return_value = self.kv
@mock.patch.object(add_disk.ceph_hooks, 'get_journal_devices')
@mock.patch.object(add_disk.ceph.utils, 'osdize')
def test_add_device(self, mock_osdize, mock_get_journal_devices):
def fake_config(key):
return {
'ignore-device-errors': True,
'osd-encrypt': True,
'bluestore': True,
'osd-encrypt-keymanager': True,
'autotune': False,
}.get(key)
self.hookenv.config.side_effect = fake_config
mock_get_journal_devices.return_value = ''
self.hookenv.relation_ids.return_value = ['ceph:0']
db = mock.MagicMock()
self.kv.return_value = db
db.get.return_value = ['/dev/myosddev']
request = {'ops': []}
add_disk.add_device(request, '/dev/myosddev')
call = mock.call(relation_id='ceph:0',
relation_settings={'bootstrapped-osds': 1})
self.hookenv.relation_set.assert_has_calls([call])
mock_osdize.assert_has_calls([mock.call('/dev/myosddev',
None, '', True, True, True,
True)])