Skip to content

Commit

Permalink
Remove rota and tran from resource graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemartinlogan committed Jan 12, 2024
1 parent 27666d2 commit cce8e81
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 63 deletions.
68 changes: 35 additions & 33 deletions jarvis_util/introspect/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
# pylint: disable=C0121


# Note, not using enum to avoid YAML serialization errors
# YAML expects simple types
class StorageDeviceType:
PMEM = 'pmem'
NVME = 'nvme'
SSD = 'ssd'
HDD = 'hdd'


class SystemInfo:
"""
This class queries information about the host machine, such as OS,
Expand Down Expand Up @@ -101,6 +110,7 @@ class Lsblk(Exec):
model: the exact model of the device
tran: the transport of the device (e.g., /dev/nvme)
rota: whether or not the device is rotational
dev_type: the category of the device
host: the host this record corresponds to
"""

Expand Down Expand Up @@ -135,6 +145,7 @@ def wait(self):
'tran': dev['tran'].lower(),
'mount': dev['mountpoint'],
'rota': dev['rota'],
'dev_type': self.GetDevType(dev),
'host': host
})
if 'children' not in dev:
Expand All @@ -150,11 +161,23 @@ def wait(self):
'tran': dev['tran'].lower(),
'mount': partition['mountpoint'],
'rota': dev['rota'],
'dev_type': self.GetDevType(dev),
'host': host
})
self.df = sdf.SmallDf(rows=total)
print(self.df)

def GetDevType(self, dev):
if dev['tran'] == 'sata':
if dev['rota']:
return str(StorageDeviceType.HDD)
else:
return str(StorageDeviceType.SSD)
elif dev['tran'] == 'nvme':
return str(StorageDeviceType.NVME)
elif dev['tran'] == 'dimm':
return str(StorageDeviceType.PMEM)


class PyLsblk(Exec):
"""
Expand Down Expand Up @@ -309,15 +332,6 @@ def wait(self):
self.df.drop_duplicates()


# Note, not using enum to avoid YAML serialization errors
# YAML expects simple types
class StorageDeviceType:
PMEM = 'pmem'
NVME = 'nvme'
SSD = 'ssd'
HDD = 'hdd'


class ResourceGraph:
"""
Stores helpful information about storage and networking info for machines.
Expand All @@ -326,12 +340,9 @@ class ResourceGraph:
fs:
parent: the parent device of the partition (e.g., /dev/sda or NaN)
device: the name of the device (e.g., /dev/sda1 or /dev/sda)
size: total size of the device (bytes)
mount: where the device is mounted (if anywhere)
model: the exact model of the device
rota: whether the device is rotational or not
tran: the transport of the device (e.g., /dev/nvme)
dev_type: type of device (derviced from rota + tran)
dev_type: type of device
fs_type: the type of filesystem (e.g., ext4)
uuid: filesystem-levle uuid from the FS metadata
avail: total number of bytes remaining
Expand All @@ -356,9 +367,9 @@ def __init__(self):
self.list_fs = None
self.fi_info = None
self.fs_columns = [
'parent', 'device', 'size', 'mount', 'model', 'rota',
'tran', 'fs_type', 'uuid',
'avail', 'shared', 'host'
'parent', 'device', 'mount', 'model', 'dev_type',
'fs_type', 'uuid',
'avail', 'shared', 'host',
]
self.net_columns = [
'provider', 'fabric', 'domain', 'host',
Expand Down Expand Up @@ -405,29 +416,26 @@ def walkthrough_prune(self, exec_info):
default='no')
new_devs = []
while x:
mount = self._ask_string('2.1.(1/7). Mount point')
mount = self._ask_string('2.1.(1/6). Mount point')
mount = mount.replace(r'\$', '$')
tran = self._ask_choices('2.1.(2/7). What transport?',
choices=['sata', 'nvme', 'dimm'])
rota = self._ask_yes_no('2.1.(3/7). Is this device rotational. '
'I.e., is it a hard drive?')
shared = self._ask_yes_no('2.1.(4/7). Is this device shared? '
dev_type = self._ask_choices('2.1.(2/6). What transport?',
choices=['hdd', 'ssd', 'nvme', 'pmem'])
shared = self._ask_yes_no('2.1.(3/6). Is this device shared? '
'I.e., a PFS?')
avail = self._ask_size('2.1.(5/7). How much capacity are you '
avail = self._ask_size('2.1.(4/6). How much capacity are you '
'willing to use?')
y = self._ask_yes_no('2.1.(6/7). Are you sure this is accurate?',
y = self._ask_yes_no('2.1.(5/6). Are you sure this is accurate?',
default='yes')
if not y:
continue
new_devs.append({
'mount': mount,
'tran': tran,
'rota': rota,
'dev_type': dev_type,
'shared': shared,
'avail': avail,
'size': avail,
})
x = self._ask_yes_no('2.1.(7/7). Are there any other '
x = self._ask_yes_no('2.1.(6/6). Are there any other '
'devices you would like to add?',
default='no')
if x is None:
Expand Down Expand Up @@ -637,12 +645,6 @@ def _derive_storage_cols(self):
df = self.fs
if df is None or len(df) == 0:
return
df[lambda r: (r['tran'] == 'sata') and (r['rota'] == True),
'dev_type'] = str(StorageDeviceType.HDD)
df[lambda r: (r['tran'] == 'sata') and (r['rota'] == False),
'dev_type'] = str(StorageDeviceType.SSD)
df[lambda r: (r['tran'] == 'nvme'),
'dev_type'] = str(StorageDeviceType.NVME)
df['mount'].fillna('')
df['shared'].fillna(True)
df['tran'].fillna('')
Expand Down
53 changes: 23 additions & 30 deletions test/unit/test_system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,43 @@ def test_custom_resource_graph(self):
{
'device': '/dev/sda1',
'mount': '/',
'tran': 'sata',
'rota': True,
'size': SizeConv.to_int('10g'),
'dev_type': 'hdd',
'size': '10g',
'shared': False
},
{
'device': '/dev/sda2',
'mount': '/mnt/hdd/$USER',
'tran': 'sata',
'rota': True,
'size': SizeConv.to_int('200g'),
'dev_type': 'hdd',
'size': '200g',
'shared': False
},
{
'device': '/dev/sdb1',
'mount': '/mnt/ssd/$USER',
'tran': 'sata',
'rota': False,
'size': SizeConv.to_int('50g'),
'dev_type': 'ssd',
'size': '50g',
'shared': False
},
{
'device': '/dev/sdb2',
'mount': '/mnt/ssd2/$USER',
'tran': 'sata',
'rota': False,
'size': SizeConv.to_int('50g'),
'dev_type': 'ssd',
'size': '50g',
'shared': False
},
{
'device': '/dev/nvme0n1',
'mount': '/mnt/nvme/$USER',
'tran': 'nvme',
'rota': False,
'size': SizeConv.to_int('100g'),
'dev_type': 'nvme',
'size': '100g',
'shared': False
},
{
'device': '/dev/nvme0n3',
'mount': '/mnt/nvme3/$USER',
'tran': 'nvme',
'rota': False,
'size': SizeConv.to_int('100g'),
'dev_type': 'nvme',
'size': '100g',
'shared': False
}
])
Expand All @@ -106,8 +100,7 @@ def test_custom_resource_graph(self):
{
'device': '/dev/nvme0n2',
'mount': '/mnt/nvme2/$USER',
'tran': 'nvme',
'rota': False,
'dev_type': 'nvme',
'size': SizeConv.to_int('10g'),
'shared': False
}
Expand All @@ -120,25 +113,26 @@ def test_custom_resource_graph(self):

# Find all mounted NVMes
df = rg.find_storage(dev_types=[StorageDeviceType.NVME])
self.assertEqual(7, len(df[lambda r: r['tran'] == 'nvme']))
self.assertEqual(0, len(df[lambda r: r['tran'] == 'sata']))
self.assertEqual(7, len(df[lambda r: r['dev_type'] == 'nvme']))
self.assertEqual(0, len(df[lambda r: r['dev_type'] == 'hdd']))
self.assertEqual(0, len(df[lambda r: r['dev_type'] == 'ssd']))
self.assertEqual(7, len(df))

# Find all mounted & common NVMes and SSDs
df = rg.find_storage([StorageDeviceType.NVME,
StorageDeviceType.SSD],
common=True)
self.assertEqual(6, len(df[lambda r: r['tran'] == 'nvme']))
self.assertEqual(6, len(df[lambda r: r['tran'] == 'sata']))
self.assertEqual(6, len(df[lambda r: r['dev_type'] == 'nvme']))
self.assertEqual(6, len(df[lambda r: r['dev_type'] == 'ssd']))
self.assertEqual(12, len(df))

# Select a single nvme and ssd per-node
df = rg.find_storage([StorageDeviceType.NVME,
StorageDeviceType.SSD],
common=True,
count_per_dev=1)
self.assertEqual(3, len(df[lambda r: r['tran'] == 'nvme']))
self.assertEqual(3, len(df[lambda r: r['tran'] == 'sata']))
self.assertEqual(3, len(df[lambda r: r['dev_type'] == 'nvme']))
self.assertEqual(3, len(df[lambda r: r['dev_type'] == 'ssd']))
self.assertEqual(6, len(df))

# Get condensed output
Expand All @@ -147,8 +141,8 @@ def test_custom_resource_graph(self):
common=True,
condense=True,
count_per_dev=1)
self.assertEqual(1, len(df[lambda r: str(r['tran']) == 'nvme']))
self.assertEqual(1, len(df[lambda r: str(r['tran']) == 'sata']))
self.assertEqual(1, len(df[lambda r: str(r['dev_type']) == 'nvme']))
self.assertEqual(1, len(df[lambda r: str(r['dev_type']) == 'ssd']))
self.assertEqual(2, len(df))
rg.print_df(df)

Expand Down Expand Up @@ -185,8 +179,7 @@ def test_add_suffix(self):
{
'device': '/dev/sda1',
'mount': '/',
'tran': 'sata',
'rota': True,
'dev_type': 'ssd',
'size': SizeConv.to_int('10g'),
'shared': False
}
Expand Down

0 comments on commit cce8e81

Please sign in to comment.