Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The inventory command provides information about a nodes disk inventory. Existing logical volumes on a disk or one of its partitions are scanned and reported. The output can be formatted as plain text or json. Signed-off-by: Jan Fajerski <jfajerski@suse.com>
- Loading branch information
Jan Fajerski
committed
Nov 9, 2018
1 parent
22d78ad
commit 57adfc6
Showing
7 changed files
with
336 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .main import Inventory # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import argparse | ||
import pprint | ||
|
||
from ceph_volume.util.device import Devices, Device | ||
|
||
|
||
class Inventory(object): | ||
|
||
help = "Get this nodes available disk inventory" | ||
|
||
def __init__(self, argv): | ||
self.argv = argv | ||
|
||
def main(self): | ||
parser = argparse.ArgumentParser( | ||
prog='ceph-volume inventory', | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description=self.help, | ||
) | ||
parser.add_argument( | ||
'path', | ||
nargs='?', | ||
default=None, | ||
help=('Report on specific disk'), | ||
) | ||
parser.add_argument( | ||
'--format', | ||
choices=['plain', 'json', 'json-pretty'], | ||
default='plain', | ||
help='Output format', | ||
) | ||
self.args = parser.parse_args(self.argv) | ||
if self.args.path: | ||
self.format_report(Device(self.args.path)) | ||
else: | ||
self.format_report(Devices()) | ||
|
||
def format_report(self, inventory): | ||
if self.args.format == 'json': | ||
print(inventory.json_report()) | ||
elif self.args.format == 'json-pretty': | ||
pprint.pprint(inventory.json_report()) | ||
else: | ||
print(inventory.pretty_report()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
from ceph_volume.util.device import Devices | ||
from ceph_volume import sys_info | ||
|
||
@pytest.fixture | ||
def device_report_keys(): | ||
report = Devices().json_report()[0] | ||
return list(report.keys()) | ||
|
||
@pytest.fixture | ||
def device_sys_api_keys(): | ||
report = Devices().json_report()[0] | ||
return list(report['sys_api'].keys()) | ||
|
||
|
||
class TestInventory(object): | ||
|
||
# populate sys_info with something; creating a Device instance will use | ||
# this data | ||
sys_info.devices = { | ||
# example output of disk.get_devices() | ||
'/dev/sdb': {'human_readable_size': '1.82 TB', | ||
'locked': 0, | ||
'model': 'PERC H700', | ||
'nr_requests': '128', | ||
'partitions': {}, | ||
'path': '/dev/sdb', | ||
'removable': '0', | ||
'rev': '2.10', | ||
'ro': '0', | ||
'rotational': '1', | ||
'sas_address': '', | ||
'sas_device_handle': '', | ||
'scheduler_mode': 'cfq', | ||
'sectors': 0, | ||
'sectorsize': '512', | ||
'size': 1999844147200.0, | ||
'support_discard': '', | ||
'vendor': 'DELL'} | ||
} | ||
|
||
expected_keys = [ | ||
'path', | ||
'rejected_reasons', | ||
'sys_api', | ||
'valid', | ||
'lvs', | ||
] | ||
|
||
expected_sys_api_keys = [ | ||
'human_readable_size', | ||
'locked', | ||
'model', | ||
'nr_requests', | ||
'partitions', | ||
'path', | ||
'removable', | ||
'rev', | ||
'ro', | ||
'rotational', | ||
'sas_address', | ||
'sas_device_handle', | ||
'scheduler_mode', | ||
'sectors', | ||
'sectorsize', | ||
'size', | ||
'support_discard', | ||
'vendor', | ||
] | ||
|
||
def test_json_inventory_keys_unexpected(self, device_report_keys): | ||
for k in device_report_keys: | ||
assert k in self.expected_keys, "unexpected key {} in report".format(k) | ||
|
||
def test_json_inventory_keys_missing(self, device_report_keys): | ||
for k in self.expected_keys: | ||
assert k in device_report_keys, "expected key {} in report".format(k) | ||
|
||
def test_sys_api_keys_unexpected(self, device_sys_api_keys): | ||
for k in device_sys_api_keys: | ||
assert k in self.expected_sys_api_keys, "unexpected key {} in sys_api field".format(k) | ||
|
||
def test_sys_api_keys_missing(self, device_sys_api_keys): | ||
for k in self.expected_sys_api_keys: | ||
assert k in device_sys_api_keys, "expected key {} in sys_api field".format(k) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.