Skip to content

Commit

Permalink
Merge branch 'mimic' of github.com:ceph/ceph into mimic
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfredo Deza committed Jul 27, 2018
2 parents 5533ecd + 4d4408d commit 08941b5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 21 deletions.
11 changes: 9 additions & 2 deletions src/ceph-volume/ceph_volume/devices/lvm/listing.py
Expand Up @@ -49,8 +49,15 @@ def pretty_report(report):
value=value
)
)
output.append(
device_metadata_item_template.format(tag_name='devices', value=','.join(device['devices'])))
if not device.get('devices'):
continue
else:
output.append(
device_metadata_item_template.format(
tag_name='devices',
value=','.join(device['devices'])
)
)

print(''.join(output))

Expand Down
3 changes: 3 additions & 0 deletions src/ceph-volume/ceph_volume/devices/lvm/zap.py
Expand Up @@ -49,6 +49,9 @@ def __init__(self, argv):
@decorators.needs_root
def zap(self, args):
device = args.device
if disk.is_mapper_device(device):
terminal.error("Refusing to zap the mapper device: {}".format(device))
raise SystemExit(1)
lv = api.get_lv_from_argument(device)
if lv:
# we are zapping a logical volume
Expand Down
11 changes: 10 additions & 1 deletion src/ceph-volume/ceph_volume/tests/devices/test_zap.py
Expand Up @@ -14,4 +14,13 @@ def test_main_shows_full_help(self, capsys):
lvm.zap.Zap(argv=['--help']).main()
stdout, stderr = capsys.readouterr()
assert 'optional arguments' in stdout
assert 'positional arguments' in stdout

@pytest.mark.parametrize('device_name', [
'/dev/mapper/foo',
'/dev/dm-0',
])
def test_can_not_zap_mapper_device(self, capsys, is_root, device_name):
with pytest.raises(SystemExit):
lvm.zap.Zap(argv=[device_name]).main()
stdout, stderr = capsys.readouterr()
assert 'Refusing to zap' in stdout
4 changes: 2 additions & 2 deletions src/ceph-volume/ceph_volume/tests/functional/simple/tox.ini
Expand Up @@ -18,8 +18,8 @@ setenv=
VAGRANT_CWD = {changedir}
CEPH_VOLUME_DEBUG = 1
deps=
ansible==2.4.1
testinfra==1.7.1
ansible~=2.6,<2.7
testinfra
pytest-xdist
notario>=0.0.13
changedir=
Expand Down
27 changes: 18 additions & 9 deletions src/ceph-volume/ceph_volume/tests/util/test_prepare.py
Expand Up @@ -7,32 +7,32 @@
from ceph_volume.tests.conftest import Factory


class TestCheckID(object):
class TestOSDIDAvailable(object):

def test_false_if_id_is_none(self):
assert not prepare.check_id(None)
assert not prepare.osd_id_available(None)

def test_returncode_is_not_zero(self, monkeypatch):
monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: ('', '', 1))
with pytest.raises(RuntimeError):
prepare.check_id(1)
prepare.osd_id_available(1)

def test_id_does_exist(self, monkeypatch):
def test_id_does_exist_but_not_available(self, monkeypatch):
stdout = dict(nodes=[
dict(id=0),
dict(id=0, status="up"),
])
stdout = ['', json.dumps(stdout)]
monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: (stdout, '', 0))
result = prepare.check_id(0)
assert result
result = prepare.osd_id_available(0)
assert not result

def test_id_does_not_exist(self, monkeypatch):
stdout = dict(nodes=[
dict(id=0),
])
stdout = ['', json.dumps(stdout)]
monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: (stdout, '', 0))
result = prepare.check_id(1)
result = prepare.osd_id_available(1)
assert not result

def test_invalid_osd_id(self, monkeypatch):
Expand All @@ -41,9 +41,18 @@ def test_invalid_osd_id(self, monkeypatch):
])
stdout = ['', json.dumps(stdout)]
monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: (stdout, '', 0))
result = prepare.check_id("foo")
result = prepare.osd_id_available("foo")
assert not result

def test_returns_true_when_id_is_destroyed(self, monkeypatch):
stdout = dict(nodes=[
dict(id=0, status="destroyed"),
])
stdout = ['', json.dumps(stdout)]
monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: (stdout, '', 0))
result = prepare.osd_id_available(0)
assert result


class TestFormatDevice(object):

Expand Down
6 changes: 5 additions & 1 deletion src/ceph-volume/ceph_volume/util/disk.py
Expand Up @@ -356,6 +356,10 @@ def get_partitions_facts(sys_block_path):
return partition_metadata


def is_mapper_device(device_name):
return device_name.startswith(('/dev/mapper', '/dev/dm-'))


def get_devices(_sys_block_path='/sys/block', _dev_path='/dev', _mapper_path='/dev/mapper'):
"""
Captures all available devices from /sys/block/, including its partitions,
Expand Down Expand Up @@ -391,7 +395,7 @@ def get_devices(_sys_block_path='/sys/block', _dev_path='/dev', _mapper_path='/d
diskname = mapper_devs.get(block) or dev_devs.get(block)

# If the mapper device is a logical volume it gets excluded
if diskname.startswith(('/dev/mapper', '/dev/dm-')):
if is_mapper_device(diskname):
if lvm.is_lv(diskname):
continue

Expand Down
18 changes: 12 additions & 6 deletions src/ceph-volume/ceph_volume/util/prepare.py
Expand Up @@ -64,8 +64,11 @@ def create_id(fsid, json_secrets, osd_id=None):
'-i', '-',
'osd', 'new', fsid
]
if check_id(osd_id):
cmd.append(osd_id)
if osd_id is not None:
if osd_id_available(osd_id):
cmd.append(osd_id)
else:
raise RuntimeError("The osd ID {} is already in use or does not exist.".format(osd_id))
stdout, stderr, returncode = process.call(
cmd,
stdin=json_secrets,
Expand All @@ -76,10 +79,10 @@ def create_id(fsid, json_secrets, osd_id=None):
return ' '.join(stdout).strip()


def check_id(osd_id):
def osd_id_available(osd_id):
"""
Checks to see if an osd ID exists or not. Returns True
if it does exist, False if it doesn't.
Checks to see if an osd ID exists and if it's available for
reuse. Returns True if it is, False if it isn't.
:param osd_id: The osd ID to check
"""
Expand All @@ -103,7 +106,10 @@ def check_id(osd_id):

output = json.loads(''.join(stdout).strip())
osds = output['nodes']
return any([str(osd['id']) == str(osd_id) for osd in osds])
osd = [osd for osd in osds if str(osd['id']) == str(osd_id)]
if osd and osd[0].get('status') == "destroyed":
return True
return False


def mount_tmpfs(path):
Expand Down

0 comments on commit 08941b5

Please sign in to comment.