From 0cadbdeae290ebe54bcbcace407296e4befb3ec7 Mon Sep 17 00:00:00 2001 From: Rafael Leira Date: Wed, 22 Mar 2023 17:47:34 +0100 Subject: [PATCH] Added fixes and tests for issue Additional params in methods - create_vd Naudit/pystorcli2#2 --- pystorcli2/controller.py | 21 +- pystorcli2/version.py | 2 +- tests/baseTest.py | 15 +- ..._vd_raid0_drives=35_12-13_strip=512_J.json | 13 + .../create_vd_raid0_00/__c0_show_J.json | 304 ++++++++++++++++++ .../create_vd_raid0_00/__c0_v1_show_J.json | 29 ++ .../namedSet/create_vd_raid0_00/_show_J.json | 36 +++ .../namedSet/create_vd_raid0_00/device.json | 5 + ...ves=35_12-13_strip=512_PDperArray=2_J.json | 13 + .../create_vd_raid1_00/__c0_show_J.json | 304 ++++++++++++++++++ .../create_vd_raid1_00/__c0_v1_show_J.json | 29 ++ .../namedSet/create_vd_raid1_00/_show_J.json | 36 +++ .../namedSet/create_vd_raid1_00/device.json | 5 + .../namedSet/delete_vd_00/__c0_show_J.json | 304 ++++++++++++++++++ .../namedSet/delete_vd_00/__c0_v1_del_J.json | 13 + .../namedSet/delete_vd_00/__c0_v1_show_J.json | 29 ++ .../namedSet/delete_vd_00/_show_J.json | 36 +++ .../namedSet/delete_vd_00/device.json | 5 + tests/datatest/namedSet/readme.md | 1 + tests/test_operations.py | 73 +++++ tests/test_storcli.py | 2 +- 21 files changed, 1263 insertions(+), 12 deletions(-) create mode 100644 tests/datatest/namedSet/create_vd_raid0_00/__c0_add_vd_r0_name=create_vd_raid0_drives=35_12-13_strip=512_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid0_00/__c0_show_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid0_00/__c0_v1_show_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid0_00/_show_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid0_00/device.json create mode 100644 tests/datatest/namedSet/create_vd_raid1_00/__c0_add_vd_r1_name=create_vd_raid1_drives=35_12-13_strip=512_PDperArray=2_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid1_00/__c0_show_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid1_00/__c0_v1_show_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid1_00/_show_J.json create mode 100644 tests/datatest/namedSet/create_vd_raid1_00/device.json create mode 100644 tests/datatest/namedSet/delete_vd_00/__c0_show_J.json create mode 100644 tests/datatest/namedSet/delete_vd_00/__c0_v1_del_J.json create mode 100644 tests/datatest/namedSet/delete_vd_00/__c0_v1_show_J.json create mode 100644 tests/datatest/namedSet/delete_vd_00/_show_J.json create mode 100644 tests/datatest/namedSet/delete_vd_00/device.json create mode 100644 tests/datatest/namedSet/readme.md create mode 100644 tests/test_operations.py diff --git a/pystorcli2/controller.py b/pystorcli2/controller.py index ca464ab..34e9fc3 100644 --- a/pystorcli2/controller.py +++ b/pystorcli2/controller.py @@ -13,7 +13,7 @@ from . import virtualdrive from . import exc -from typing import List +from typing import List, Optional class ControllerMetrics(object): @@ -274,7 +274,7 @@ def encls(self): """ return enclosure.Enclosures(ctl_id=self._ctl_id, binary=self._binary) - def create_vd(self, name, raid, drives, strip='64'): + def create_vd(self, name: str, raid: str, drives: str, strip: str = '64', PDperArray: Optional[int] = None) -> Optional[virtualdrive.VirtualDrive]: """Create virtual drive (raid) managed by current controller Args: @@ -290,12 +290,19 @@ def create_vd(self, name, raid, drives, strip='64'): args = [ 'add', 'vd', - 'type={0}'.format(raid), + 'r{0}'.format(raid), 'name={0}'.format(name), 'drives={0}'.format(drives), 'strip={0}'.format(strip) ] + if raid == '1' or raid == '10': + if PDperArray is None: + PDperArray = 2 + + if PDperArray is not None: + args.append('PDperArray={0}'.format(PDperArray)) + self._run(args) for vd in self.vds: if name == vd.name: @@ -327,7 +334,7 @@ def __init__(self, binary='storcli64'): self._binary = binary self._storcli = StorCLI(binary) - @property + @ property def _ctl_ids(self) -> List[str]: out = self._storcli.run(['show']) response = common.response_data(out) @@ -337,7 +344,7 @@ def _ctl_ids(self) -> List[str]: else: return [ctl['Ctl'] for ctl in common.response_data(out)['System Overview']] - @property + @ property def _ctls(self): for ctl_id in self._ctl_ids: yield Controller(ctl_id=ctl_id, binary=self._binary) @@ -345,13 +352,13 @@ def _ctls(self): def __iter__(self): return self._ctls - @property + @ property def ids(self): """(list of str): controllers id """ return self._ctl_ids - def get_ctl(self, ctl_id): + def get_ctl(self, ctl_id: int) -> Optional[Controller]: """Get controller object by id Args: diff --git a/pystorcli2/version.py b/pystorcli2/version.py index c70758f..1e7e040 100644 --- a/pystorcli2/version.py +++ b/pystorcli2/version.py @@ -1 +1 @@ -__version__ = "0.5.0.6" +__version__ = "0.5.0.8" diff --git a/tests/baseTest.py b/tests/baseTest.py index e798ab2..9bd80b6 100644 --- a/tests/baseTest.py +++ b/tests/baseTest.py @@ -25,13 +25,22 @@ def get_cmdRunner(self, folder: str, options: List[str] = []): return StorcliCMDFile(folder, options) def setupEnv(self, folder: str): + # Check if storcli exists in self + if hasattr(self, 'storcli'): + return + # get cmdRunner cmdRunner = self.get_cmdRunner(folder) StorCLI.enable_singleton() - r = StorCLI(cmdrunner=cmdRunner) - r.clear_cache() + self.storcli = StorCLI(cmdrunner=cmdRunner) + self.storcli.clear_cache() # Conflirm cmdRunner is set properly - r.set_cmdrunner(cmdRunner) + self.storcli.set_cmdrunner(cmdRunner) return self.get_device_data(folder) + + def get_storcli(self, folder: str): + self.setupEnv(folder) + + return self.storcli diff --git a/tests/datatest/namedSet/create_vd_raid0_00/__c0_add_vd_r0_name=create_vd_raid0_drives=35_12-13_strip=512_J.json b/tests/datatest/namedSet/create_vd_raid0_00/__c0_add_vd_r0_name=create_vd_raid0_drives=35_12-13_strip=512_J.json new file mode 100644 index 0000000..8f99765 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid0_00/__c0_add_vd_r0_name=create_vd_raid0_drives=35_12-13_strip=512_J.json @@ -0,0 +1,13 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "Add VD Succeeded." + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid0_00/__c0_show_J.json b/tests/datatest/namedSet/create_vd_raid0_00/__c0_show_J.json new file mode 100644 index 0000000..6985191 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid0_00/__c0_show_J.json @@ -0,0 +1,304 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Product Name": "Intel(R) RAID Controller RS3DC080", + "Serial Number": "SK75074929", + "SAS Address": " 500605b00da13540", + "PCI Address": "00:3b:00:00", + "System Time": "03/22/2023 17:02:50", + "Mfg. Date": "12/19/17", + "Controller Time": "03/22/2023 16:02:27", + "FW Package Build": "24.15.0-0034", + "BIOS Version": "6.31.03.1_4.19.08.00_0x06140200", + "FW Version": "4.650.00-8128", + "Driver Name": "megaraid_sas", + "Driver Version": "07.717.02.00-rc1", + "Vendor Id": 4096, + "Device Id": 93, + "SubVendor Id": 32902, + "SubDevice Id": 37728, + "Host Interface": "PCI-E", + "Device Interface": "SAS-12G", + "Bus Number": 59, + "Device Number": 0, + "Function Number": 0, + "Domain ID": 0, + "Security Protocol": "None", + "Drive Groups": 2, + "TOPOLOGY": [ + { + "DG": 0, + "Arr": "-", + "Row": "-", + "EID:Slot": "-", + "DID": "-", + "Type": "RAID0", + "State": "Optl", + "BT": "N", + "Size": "43.655 TB", + "PDC": "enbl", + "PI": "N", + "SED": "N", + "DS3": "dflt", + "FSpace": "N", + "TR": "N" + }, + { + "DG": 0, + "Arr": 0, + "Row": "-", + "EID:Slot": "-", + "DID": "-", + "Type": "RAID0", + "State": "Optl", + "BT": "N", + "Size": "43.655 TB", + "PDC": "enbl", + "PI": "N", + "SED": "N", + "DS3": "dflt", + "FSpace": "N", + "TR": "N" + } + ], + "Virtual Drives": 1, + "VD LIST": [ + { + "DG/VD": "2/1", + "TYPE": "RAID0", + "State": "Optl", + "Access": "RW", + "Consist": "Yes", + "Cache": "RWTD", + "Cac": "-", + "sCC": "ON", + "Size": "43.655 TB", + "Name": "dummy" + } + ], + "Physical Drives": 12, + "PD LIST": [ + { + "EID:Slt": "35:12", + "DID": 21, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:13", + "DID": 47, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:14", + "DID": 14, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:15", + "DID": 15, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:16", + "DID": 23, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:17", + "DID": 45, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:18", + "DID": 9, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:19", + "DID": 28, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:20", + "DID": 11, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:21", + "DID": 22, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:22", + "DID": 25, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:23", + "DID": 30, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + } + ], + "Enclosures": 3, + "Enclosure LIST": [ + { + "EID": 35, + "State": "OK", + "Slots": 24, + "PD": 24, + "PS": 0, + "Fans": 0, + "TSs": 2, + "Alms": 0, + "SIM": 0, + "Port#": "Multipath", + "ProdID": "SC846P", + "VendorSpecific": "x40-66.12.31.1" + }, + { + "EID": 252, + "State": "OK", + "Slots": 8, + "PD": 0, + "PS": 0, + "Fans": 0, + "TSs": 0, + "Alms": 0, + "SIM": 1, + "Port#": "-", + "ProdID": "SGPIO", + "VendorSpecific": " " + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid0_00/__c0_v1_show_J.json b/tests/datatest/namedSet/create_vd_raid0_00/__c0_v1_show_J.json new file mode 100644 index 0000000..a1986b4 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid0_00/__c0_v1_show_J.json @@ -0,0 +1,29 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Virtual Drives": [ + { + "DG/VD": "2/1", + "TYPE": "RAID0", + "State": "Optl", + "Access": "RW", + "Consist": "Yes", + "Cache": "RWTD", + "Cac": "-", + "sCC": "ON", + "Size": "7.275 TB", + "Name": "create_vd_raid0" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid0_00/_show_J.json b/tests/datatest/namedSet/create_vd_raid0_00/_show_J.json new file mode 100644 index 0000000..12e396b --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid0_00/_show_J.json @@ -0,0 +1,36 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Status Code": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Number of Controllers": 1, + "Host Name": "sonda-naudit-dev-201800637", + "Operating System ": "Linux 5.15.0-58-generic", + "System Overview": [ + { + "Ctl": 0, + "Model": "Intel(R)RAIDControllerRS3DC080", + "Ports": 8, + "PDs": 36, + "DGs": 2, + "DNOpt": 0, + "VDs": 2, + "VNOpt": 0, + "BBU": "N/A", + "sPR": "Off", + "DS": "1&2", + "EHS": "N", + "ASOs": 3, + "Hlth": "Opt" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid0_00/device.json b/tests/datatest/namedSet/create_vd_raid0_00/device.json new file mode 100644 index 0000000..f648833 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid0_00/device.json @@ -0,0 +1,5 @@ +{ + "Controller_ids": [ + 0 + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid1_00/__c0_add_vd_r1_name=create_vd_raid1_drives=35_12-13_strip=512_PDperArray=2_J.json b/tests/datatest/namedSet/create_vd_raid1_00/__c0_add_vd_r1_name=create_vd_raid1_drives=35_12-13_strip=512_PDperArray=2_J.json new file mode 100644 index 0000000..8f99765 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid1_00/__c0_add_vd_r1_name=create_vd_raid1_drives=35_12-13_strip=512_PDperArray=2_J.json @@ -0,0 +1,13 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "Add VD Succeeded." + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid1_00/__c0_show_J.json b/tests/datatest/namedSet/create_vd_raid1_00/__c0_show_J.json new file mode 100644 index 0000000..6985191 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid1_00/__c0_show_J.json @@ -0,0 +1,304 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Product Name": "Intel(R) RAID Controller RS3DC080", + "Serial Number": "SK75074929", + "SAS Address": " 500605b00da13540", + "PCI Address": "00:3b:00:00", + "System Time": "03/22/2023 17:02:50", + "Mfg. Date": "12/19/17", + "Controller Time": "03/22/2023 16:02:27", + "FW Package Build": "24.15.0-0034", + "BIOS Version": "6.31.03.1_4.19.08.00_0x06140200", + "FW Version": "4.650.00-8128", + "Driver Name": "megaraid_sas", + "Driver Version": "07.717.02.00-rc1", + "Vendor Id": 4096, + "Device Id": 93, + "SubVendor Id": 32902, + "SubDevice Id": 37728, + "Host Interface": "PCI-E", + "Device Interface": "SAS-12G", + "Bus Number": 59, + "Device Number": 0, + "Function Number": 0, + "Domain ID": 0, + "Security Protocol": "None", + "Drive Groups": 2, + "TOPOLOGY": [ + { + "DG": 0, + "Arr": "-", + "Row": "-", + "EID:Slot": "-", + "DID": "-", + "Type": "RAID0", + "State": "Optl", + "BT": "N", + "Size": "43.655 TB", + "PDC": "enbl", + "PI": "N", + "SED": "N", + "DS3": "dflt", + "FSpace": "N", + "TR": "N" + }, + { + "DG": 0, + "Arr": 0, + "Row": "-", + "EID:Slot": "-", + "DID": "-", + "Type": "RAID0", + "State": "Optl", + "BT": "N", + "Size": "43.655 TB", + "PDC": "enbl", + "PI": "N", + "SED": "N", + "DS3": "dflt", + "FSpace": "N", + "TR": "N" + } + ], + "Virtual Drives": 1, + "VD LIST": [ + { + "DG/VD": "2/1", + "TYPE": "RAID0", + "State": "Optl", + "Access": "RW", + "Consist": "Yes", + "Cache": "RWTD", + "Cac": "-", + "sCC": "ON", + "Size": "43.655 TB", + "Name": "dummy" + } + ], + "Physical Drives": 12, + "PD LIST": [ + { + "EID:Slt": "35:12", + "DID": 21, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:13", + "DID": 47, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:14", + "DID": 14, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:15", + "DID": 15, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:16", + "DID": 23, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:17", + "DID": 45, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:18", + "DID": 9, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:19", + "DID": 28, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:20", + "DID": 11, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:21", + "DID": 22, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:22", + "DID": 25, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:23", + "DID": 30, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + } + ], + "Enclosures": 3, + "Enclosure LIST": [ + { + "EID": 35, + "State": "OK", + "Slots": 24, + "PD": 24, + "PS": 0, + "Fans": 0, + "TSs": 2, + "Alms": 0, + "SIM": 0, + "Port#": "Multipath", + "ProdID": "SC846P", + "VendorSpecific": "x40-66.12.31.1" + }, + { + "EID": 252, + "State": "OK", + "Slots": 8, + "PD": 0, + "PS": 0, + "Fans": 0, + "TSs": 0, + "Alms": 0, + "SIM": 1, + "Port#": "-", + "ProdID": "SGPIO", + "VendorSpecific": " " + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid1_00/__c0_v1_show_J.json b/tests/datatest/namedSet/create_vd_raid1_00/__c0_v1_show_J.json new file mode 100644 index 0000000..aec6505 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid1_00/__c0_v1_show_J.json @@ -0,0 +1,29 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Virtual Drives": [ + { + "DG/VD": "2/1", + "TYPE": "RAID0", + "State": "Optl", + "Access": "RW", + "Consist": "Yes", + "Cache": "RWTD", + "Cac": "-", + "sCC": "ON", + "Size": "7.275 TB", + "Name": "create_vd_raid1" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid1_00/_show_J.json b/tests/datatest/namedSet/create_vd_raid1_00/_show_J.json new file mode 100644 index 0000000..12e396b --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid1_00/_show_J.json @@ -0,0 +1,36 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Status Code": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Number of Controllers": 1, + "Host Name": "sonda-naudit-dev-201800637", + "Operating System ": "Linux 5.15.0-58-generic", + "System Overview": [ + { + "Ctl": 0, + "Model": "Intel(R)RAIDControllerRS3DC080", + "Ports": 8, + "PDs": 36, + "DGs": 2, + "DNOpt": 0, + "VDs": 2, + "VNOpt": 0, + "BBU": "N/A", + "sPR": "Off", + "DS": "1&2", + "EHS": "N", + "ASOs": 3, + "Hlth": "Opt" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/create_vd_raid1_00/device.json b/tests/datatest/namedSet/create_vd_raid1_00/device.json new file mode 100644 index 0000000..f648833 --- /dev/null +++ b/tests/datatest/namedSet/create_vd_raid1_00/device.json @@ -0,0 +1,5 @@ +{ + "Controller_ids": [ + 0 + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/delete_vd_00/__c0_show_J.json b/tests/datatest/namedSet/delete_vd_00/__c0_show_J.json new file mode 100644 index 0000000..6985191 --- /dev/null +++ b/tests/datatest/namedSet/delete_vd_00/__c0_show_J.json @@ -0,0 +1,304 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Product Name": "Intel(R) RAID Controller RS3DC080", + "Serial Number": "SK75074929", + "SAS Address": " 500605b00da13540", + "PCI Address": "00:3b:00:00", + "System Time": "03/22/2023 17:02:50", + "Mfg. Date": "12/19/17", + "Controller Time": "03/22/2023 16:02:27", + "FW Package Build": "24.15.0-0034", + "BIOS Version": "6.31.03.1_4.19.08.00_0x06140200", + "FW Version": "4.650.00-8128", + "Driver Name": "megaraid_sas", + "Driver Version": "07.717.02.00-rc1", + "Vendor Id": 4096, + "Device Id": 93, + "SubVendor Id": 32902, + "SubDevice Id": 37728, + "Host Interface": "PCI-E", + "Device Interface": "SAS-12G", + "Bus Number": 59, + "Device Number": 0, + "Function Number": 0, + "Domain ID": 0, + "Security Protocol": "None", + "Drive Groups": 2, + "TOPOLOGY": [ + { + "DG": 0, + "Arr": "-", + "Row": "-", + "EID:Slot": "-", + "DID": "-", + "Type": "RAID0", + "State": "Optl", + "BT": "N", + "Size": "43.655 TB", + "PDC": "enbl", + "PI": "N", + "SED": "N", + "DS3": "dflt", + "FSpace": "N", + "TR": "N" + }, + { + "DG": 0, + "Arr": 0, + "Row": "-", + "EID:Slot": "-", + "DID": "-", + "Type": "RAID0", + "State": "Optl", + "BT": "N", + "Size": "43.655 TB", + "PDC": "enbl", + "PI": "N", + "SED": "N", + "DS3": "dflt", + "FSpace": "N", + "TR": "N" + } + ], + "Virtual Drives": 1, + "VD LIST": [ + { + "DG/VD": "2/1", + "TYPE": "RAID0", + "State": "Optl", + "Access": "RW", + "Consist": "Yes", + "Cache": "RWTD", + "Cac": "-", + "sCC": "ON", + "Size": "43.655 TB", + "Name": "dummy" + } + ], + "Physical Drives": 12, + "PD LIST": [ + { + "EID:Slt": "35:12", + "DID": 21, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:13", + "DID": 47, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:14", + "DID": 14, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:15", + "DID": 15, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:16", + "DID": 23, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:17", + "DID": 45, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:18", + "DID": 9, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:19", + "DID": 28, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:20", + "DID": 11, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:21", + "DID": 22, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:22", + "DID": 25, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + }, + { + "EID:Slt": "35:23", + "DID": 30, + "State": "UGood", + "DG": "-", + "Size": "3.637 TB", + "Intf": "SAS", + "Med": "HDD", + "SED": "N", + "PI": "N", + "SeSz": "512B", + "Model": "HUS726040AL5210 ", + "Sp": "D", + "Type": "-" + } + ], + "Enclosures": 3, + "Enclosure LIST": [ + { + "EID": 35, + "State": "OK", + "Slots": 24, + "PD": 24, + "PS": 0, + "Fans": 0, + "TSs": 2, + "Alms": 0, + "SIM": 0, + "Port#": "Multipath", + "ProdID": "SC846P", + "VendorSpecific": "x40-66.12.31.1" + }, + { + "EID": 252, + "State": "OK", + "Slots": 8, + "PD": 0, + "PS": 0, + "Fans": 0, + "TSs": 0, + "Alms": 0, + "SIM": 1, + "Port#": "-", + "ProdID": "SGPIO", + "VendorSpecific": " " + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/delete_vd_00/__c0_v1_del_J.json b/tests/datatest/namedSet/delete_vd_00/__c0_v1_del_J.json new file mode 100644 index 0000000..5404c1a --- /dev/null +++ b/tests/datatest/namedSet/delete_vd_00/__c0_v1_del_J.json @@ -0,0 +1,13 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "Delete VD succeeded" + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/delete_vd_00/__c0_v1_show_J.json b/tests/datatest/namedSet/delete_vd_00/__c0_v1_show_J.json new file mode 100644 index 0000000..a1986b4 --- /dev/null +++ b/tests/datatest/namedSet/delete_vd_00/__c0_v1_show_J.json @@ -0,0 +1,29 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Controller": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Virtual Drives": [ + { + "DG/VD": "2/1", + "TYPE": "RAID0", + "State": "Optl", + "Access": "RW", + "Consist": "Yes", + "Cache": "RWTD", + "Cac": "-", + "sCC": "ON", + "Size": "7.275 TB", + "Name": "create_vd_raid0" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/delete_vd_00/_show_J.json b/tests/datatest/namedSet/delete_vd_00/_show_J.json new file mode 100644 index 0000000..12e396b --- /dev/null +++ b/tests/datatest/namedSet/delete_vd_00/_show_J.json @@ -0,0 +1,36 @@ +{ + "Controllers": [ + { + "Command Status": { + "CLI Version": "007.1704.0000.0000 Jan 16, 2021", + "Operating system": "Linux 5.15.0-58-generic", + "Status Code": 0, + "Status": "Success", + "Description": "None" + }, + "Response Data": { + "Number of Controllers": 1, + "Host Name": "sonda-naudit-dev-201800637", + "Operating System ": "Linux 5.15.0-58-generic", + "System Overview": [ + { + "Ctl": 0, + "Model": "Intel(R)RAIDControllerRS3DC080", + "Ports": 8, + "PDs": 36, + "DGs": 2, + "DNOpt": 0, + "VDs": 2, + "VNOpt": 0, + "BBU": "N/A", + "sPR": "Off", + "DS": "1&2", + "EHS": "N", + "ASOs": 3, + "Hlth": "Opt" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/delete_vd_00/device.json b/tests/datatest/namedSet/delete_vd_00/device.json new file mode 100644 index 0000000..f648833 --- /dev/null +++ b/tests/datatest/namedSet/delete_vd_00/device.json @@ -0,0 +1,5 @@ +{ + "Controller_ids": [ + 0 + ] +} \ No newline at end of file diff --git a/tests/datatest/namedSet/readme.md b/tests/datatest/namedSet/readme.md new file mode 100644 index 0000000..3acd7b5 --- /dev/null +++ b/tests/datatest/namedSet/readme.md @@ -0,0 +1 @@ +In this folder will be stored named datasets. Each folder will contain the data for a singletest/unittest. \ No newline at end of file diff --git a/tests/test_operations.py b/tests/test_operations.py new file mode 100644 index 0000000..77bf9ef --- /dev/null +++ b/tests/test_operations.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021 Rafael Leira, Naudit HPCN S.L. +# +# See LICENSE for details. +# +################################################################ + +import json +import os +import pytest +from typing import List + +from pystorcli2 import StorCLI, Controllers, Controller, VirtualDrives, VirtualDrive +from .baseTest import TestStorcliMainClass + + +# discover tests +dataset_main_path = './tests/datatest/namedSet/' + + +def getTests(base_name: str) -> List[str]: + """Gets the list of tests for a given base name + + Searchs in dataset_main_path for files with the given base name. + """ + return [dataset_main_path + p for p in os.listdir(dataset_main_path) if p.startswith(base_name)] + + +class TestStorcliOperations(TestStorcliMainClass): + + @pytest.mark.parametrize("folder", getTests('create_vd_raid0')) + def test_create_vd_raid0(self, folder): + # get storcli + s: StorCLI = self.get_storcli(folder) + + # get controller 0 + cs: Controllers = s.controllers + c = cs.get_ctl(0) + assert c is not None + + # create a new VD + vd = c.create_vd('create_vd_raid0', '0', '35:12-13', '512') + assert vd is not None + + @pytest.mark.parametrize("folder", getTests('delete_vd')) + def test_delete_vd(self, folder): + # get storcli + s: StorCLI = self.get_storcli(folder) + + # get controller 0 + cs: Controllers = s.controllers + c = cs.get_ctl(0) + assert c is not None + + # get the vd + vd = c.vds.get_vd('1') + assert vd is not None + + # delete the vd + assert vd.delete()['Status'] == 'Success' + + @pytest.mark.parametrize("folder", getTests('create_vd_raid1')) + def test_create_vd_raid1(self, folder): + # get storcli + s: StorCLI = self.get_storcli(folder) + # get controller 0 + cs: Controllers = s.controllers + c = cs.get_ctl(0) + assert c is not None + # create a new VD + vd = c.create_vd('create_vd_raid1', '1', '35:12-13', '512') + assert vd is not None diff --git a/tests/test_storcli.py b/tests/test_storcli.py index 5311b6c..d22e479 100644 --- a/tests/test_storcli.py +++ b/tests/test_storcli.py @@ -21,7 +21,7 @@ p for p in os.listdir(dataset_main_path)] -class TestStorcliMainClass(TestStorcliMainClass): +class TestStorcli(TestStorcliMainClass): @pytest.mark.parametrize("folder", folders) def test_init_disable_singleton(self, folder):