Skip to content

Commit

Permalink
ceph-volume: adjust tests for empty PARTLABEL fields
Browse files Browse the repository at this point in the history
It seems like ceph-disk sometimes creates OSDs where the wal and db
partitions have no PARTLABEL set. This commit alters tests so that the
empty string is considered a valid label.

Signed-off-by: Jan Fajerski <jfajerski@suse.com>
(cherry picked from commit bb29110)
  • Loading branch information
Jan Fajerski committed Aug 2, 2019
1 parent eac6767 commit 833ca7c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 30 deletions.
32 changes: 22 additions & 10 deletions src/ceph-volume/ceph_volume/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pytest
from ceph_volume.util import disk
from ceph_volume.util.constants import ceph_disk_guids
from ceph_volume.api import lvm as lvm_api
from ceph_volume import conf, configuration

Expand Down Expand Up @@ -192,13 +193,6 @@ def generate_file(name='file', contents='', directory=None):
return generate_file


@pytest.fixture(params=[
'ceph data', 'ceph journal', 'ceph block',
'ceph block.wal', 'ceph block.db', 'ceph lockbox'])
def ceph_partlabel(request):
return request.param


@pytest.fixture
def disable_kernel_queries(monkeypatch):
'''
Expand All @@ -217,16 +211,34 @@ def disable_lvm_queries(monkeypatch):
monkeypatch.setattr("ceph_volume.util.device.lvm.get_lv", lambda vg_name, lv_uuid: None)


@pytest.fixture(params=[
'', 'ceph data', 'ceph journal', 'ceph block',
'ceph block.wal', 'ceph block.db', 'ceph lockbox'])
def ceph_partlabel(request):
return request.param


@pytest.fixture(params=list(ceph_disk_guids.keys()))
def ceph_parttype(request):
return request.param


@pytest.fixture
def lsblk_ceph_disk_member(monkeypatch, request, ceph_partlabel):
def lsblk_ceph_disk_member(monkeypatch, request, ceph_partlabel, ceph_parttype):
monkeypatch.setattr("ceph_volume.util.device.disk.lsblk",
lambda path: {'PARTLABEL': ceph_partlabel})
# setting blkid here too in order to be able to fall back to PARTTYPE based
# membership
monkeypatch.setattr("ceph_volume.util.device.disk.blkid",
lambda path: {'PARTLABEL': '',
'PARTTYPE': ceph_parttype})


@pytest.fixture
def blkid_ceph_disk_member(monkeypatch, request, ceph_partlabel):
def blkid_ceph_disk_member(monkeypatch, request, ceph_partlabel, ceph_parttype):
monkeypatch.setattr("ceph_volume.util.device.disk.blkid",
lambda path: {'PARTLABEL': ceph_partlabel})
lambda path: {'PARTLABEL': ceph_partlabel,
'PARTTYPE': ceph_parttype})


@pytest.fixture(params=[
Expand Down
36 changes: 18 additions & 18 deletions src/ceph-volume/ceph_volume/tests/util/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ def test_is_not_mapper_device(self, device_info):
"disable_kernel_queries",
"disable_lvm_queries")
def test_is_ceph_disk_lsblk(self, monkeypatch):
monkeypatch.setattr("ceph_volume.util.device.disk.blkid",
lambda path: {'PARTLABEL': ""})
disk = device.Device("/dev/sda")
assert disk.is_ceph_disk_member

Expand All @@ -158,8 +156,6 @@ def test_is_ceph_disk_blkid(self, monkeypatch):
"disable_kernel_queries",
"disable_lvm_queries")
def test_is_ceph_disk_member_not_available_lsblk(self, monkeypatch):
monkeypatch.setattr("ceph_volume.util.device.disk.blkid",
lambda path: {'PARTLABEL': ""})
disk = device.Device("/dev/sda")
assert disk.is_ceph_disk_member
assert not disk.available
Expand Down Expand Up @@ -422,9 +418,10 @@ def test_accept_non_readonly_device(self, device_info):
disk = device.Device("/dev/sda")
assert disk.available

def test_is_member_lsblk(self, device_info, ceph_partlabel):
lsblk = {"PARTLABEL": ceph_partlabel}
device_info(lsblk=lsblk)
@pytest.mark.usefixtures("lsblk_ceph_disk_member",
"disable_kernel_queries",
"disable_lvm_queries")
def test_is_member_lsblk(self):
disk = device.CephDiskDevice(device.Device("/dev/sda"))

assert disk.is_member is True
Expand All @@ -436,20 +433,23 @@ def test_unknown_type(self, device_info):

assert disk.type == 'unknown'

def test_type_blkid(self, device_info, ceph_partlabel):
expected = ceph_partlabel.split()[-1].split('.')[-1]
lsblk = {"PARTLABEL": ""}
blkid = {"PARTLABEL": ceph_partlabel}
device_info(lsblk=lsblk, blkid=blkid)
ceph_types = ['data', 'wal', 'db', 'lockbox', 'journal', 'block']

@pytest.mark.usefixtures("blkid_ceph_disk_member",
"disable_kernel_queries",
"disable_lvm_queries")
def test_type_blkid(self, monkeypatch, device_info, ceph_partlabel):
monkeypatch.setattr("ceph_volume.util.device.disk.lsblk",
lambda path: {'PARTLABEL': ''})
disk = device.CephDiskDevice(device.Device("/dev/sda"))

assert disk.type == expected
assert disk.type in self.ceph_types

@pytest.mark.usefixtures("blkid_ceph_disk_member",
"lsblk_ceph_disk_member",
"disable_kernel_queries",
"disable_lvm_queries")
def test_type_lsblk(self, device_info, ceph_partlabel):
expected = ceph_partlabel.split()[-1].split('.')[-1]
lsblk = {"PARTLABEL": ceph_partlabel}
blkid = {"PARTLABEL": ''}
device_info(lsblk=lsblk, blkid=blkid)
disk = device.CephDiskDevice(device.Device("/dev/sda"))

assert disk.type == expected
assert disk.type in self.ceph_types
17 changes: 15 additions & 2 deletions src/ceph-volume/ceph_volume/util/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,24 @@
'cafecafe-9b03-4f30-b4c6-35865ceff106': {'type': 'block', 'encrypted': True, 'encryption_type': 'luks'},
'166418da-c469-4022-adf4-b30afd37f176': {'type': 'block.db', 'encrypted': True, 'encryption_type': 'luks'},
'86a32090-3647-40b9-bbbd-38d8c573aa86': {'type': 'block.wal', 'encrypted': True, 'encryption_type': 'luks'},
'4fbd7e29-9d25-41b8-afd0-35865ceff05d': {'type': 'osd', 'encrypted': True, 'encryption_type': 'luks'},
'4fbd7e29-9d25-41b8-afd0-35865ceff05d': {'type': 'data', 'encrypted': True, 'encryption_type': 'luks'},
# plain
'45b0969e-9b03-4f30-b4c6-5ec00ceff106': {'type': 'journal', 'encrypted': True, 'encryption_type': 'plain'},
'cafecafe-9b03-4f30-b4c6-5ec00ceff106': {'type': 'block', 'encrypted': True, 'encryption_type': 'plain'},
'93b0052d-02d9-4d8a-a43b-33a3ee4dfbc3': {'type': 'block.db', 'encrypted': True, 'encryption_type': 'plain'},
'306e8683-4fe2-4330-b7c0-00a917c16966': {'type': 'block.wal', 'encrypted': True, 'encryption_type': 'plain'},
'4fbd7e29-9d25-41b8-afd0-5ec00ceff05d': {'type': 'osd', 'encrypted': True, 'encryption_type': 'plain'},
'4fbd7e29-9d25-41b8-afd0-5ec00ceff05d': {'type': 'data', 'encrypted': True, 'encryption_type': 'plain'},
# regular guids that differ from plain
'fb3aabf9-d25f-47cc-bf5e-721d1816496b': {'type': 'lockbox', 'encrypted': False, 'encryption_type': None},
'30cd0809-c2b2-499c-8879-2d6b78529876': {'type': 'block.db', 'encrypted': False, 'encryption_type': None},
'5ce17fce-4087-4169-b7ff-056cc58473f9': {'type': 'block.wal', 'encrypted': False, 'encryption_type': None},
'4fbd7e29-9d25-41b8-afd0-062c0ceff05d': {'type': 'data', 'encrypted': False, 'encryption_type': None},
'cafecafe-9b03-4f30-b4c6-b4b80ceff106': {'type': 'block', 'encrypted': False, 'encryption_type': None},
# multipath
'01b41e1b-002a-453c-9f17-88793989ff8f': {'type': 'block.wal', 'encrypted': False, 'encryption_type': None},
'ec6d6385-e346-45dc-be91-da2a7c8b3261': {'type': 'block.wal', 'encrypted': False, 'encryption_type': None},
'45b0969e-8ae0-4982-bf9d-5a8d867af560': {'type': 'journal', 'encrypted': False, 'encryption_type': None},
'4fbd7e29-8ae0-4982-bf9d-5a8d867af560': {'type': 'data', 'encrypted': False, 'encryption_type': None},
'7f4a666a-16f3-47a2-8445-152ef4d03f6c': {'type': 'lockbox', 'encrypted': False, 'encryption_type': None},
'cafecafe-8ae0-4982-bf9d-5a8d867af560': {'type': 'block', 'encrypted': False, 'encryption_type': None},
}

0 comments on commit 833ca7c

Please sign in to comment.