-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature-e2e-regression
- Loading branch information
Showing
6 changed files
with
841 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# common | ||
CR_GROUP = "csi-baremetal.dell.com" | ||
CR_VERSION = "v1" | ||
|
||
# storage classes | ||
HDD_SC = "csi-baremetal-sc-hdd" | ||
SSD_SC = "csi-baremetal-sc-ssd" | ||
HDDLVG_SC = "csi-baremetal-sc-hddlvg" | ||
SSDLVG_SC = "csi-baremetal-sc-ssdlvg" | ||
SYSLVG_SC = "csi-baremetal-sc-syslvg" | ||
NVME_SC = "csi-baremetal-sc-nvme-raw-part" | ||
NVMELVG_SC = "csi-baremetal-sc-nvmelvg" | ||
|
||
# storage types | ||
STORAGE_TYPE_SSD = "SSD" | ||
STORAGE_TYPE_HDD = "HDD" | ||
STORAGE_TYPE_NVME = "NVME" | ||
STORAGE_TYPE_HDDLVG = "HDDLVG" | ||
STORAGE_TYPE_SSDLVG = "SSDLVG" | ||
STORAGE_TYPE_SYSLVG = "SYSLVG" | ||
STORAGE_TYPE_NVMELVG = "NVMELVG" | ||
|
||
# usages | ||
USAGE_IN_USE = "IN_USE" | ||
USAGE_RELEASING = "RELEASING" | ||
USAGE_RELEASED = "RELEASED" | ||
USAGE_REMOVING = "REMOVING" | ||
USAGE_REMOVED = "REMOVED" | ||
USAGE_RAILED = "FAILED" | ||
|
||
# statuses | ||
STATUS_ONLINE = "ONLINE" | ||
STATUS_OFFLINE = "OFFLINE" | ||
|
||
# health | ||
HEALTH_GOOD = "GOOD" | ||
HEALTH_BAD = "BAD" | ||
|
||
# fake attach | ||
FAKE_ATTACH_INVOLVED = "FakeAttachInvolved" | ||
FAKE_ATTACH_CLEARED = "FakeAttachCleared" | ||
|
||
# plurals | ||
DRIVES_PLURAL = "drives" | ||
AC_PLURAL = "availablecapacities" | ||
ACR_PLURAL = "availablecapacityreservations" | ||
LVG_PLURAL = "logicalvolumegroups" | ||
VOLUMES_PLURAL = "volumes" |
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,72 @@ | ||
import logging | ||
from typing import Any, List | ||
from framework.ssh import SSHCommandExecutor | ||
|
||
|
||
class DriveUtils: | ||
def __init__(self, executor: SSHCommandExecutor) -> None: | ||
self.executor = executor | ||
|
||
def get_scsi_id(self, device_name: str) -> str: | ||
""" | ||
Retrieves the SCSI ID for the given device name. | ||
Args: | ||
device_name (str): The name of the device. It can be either a path | ||
(starting with "/dev/") or a device name. | ||
Returns: | ||
str: The SCSI ID of the device. | ||
""" | ||
device_name = self._get_device_name(device_path_or_name=device_name) | ||
scsi_id, errors = self.executor.exec( | ||
f"sudo ls /sys/block/{device_name}/device/scsi_device/") | ||
self._handle_errors(errors) | ||
return scsi_id | ||
|
||
def remove(self, scsi_id: str) -> None: | ||
"""removes a device from the system using the SCSI ID or device name""" | ||
logging.info(f"removing drive SCSI ID: {scsi_id}") | ||
_, errors = self.executor.exec( | ||
f"echo 1 | sudo tee -a /sys/class/scsi_device/{scsi_id}/device/delete") | ||
self._handle_errors(errors) | ||
|
||
def restore(self, host_num: int) -> None: | ||
"""restores the drive for a specified host number""" | ||
logging.info(f"restoring drive for host: {host_num}") | ||
_, errors = self.executor.exec( | ||
f"echo '- - -' | sudo tee -a /sys/class/scsi_host/host{host_num}/scan") | ||
self._handle_errors(errors) | ||
|
||
def get_host_num(self, drive_path_or_name: str) -> int: | ||
""" | ||
Retrieves the host number associated with the specified drive path or name. | ||
Args: | ||
drive_path_or_name (str): The path or name of the drive. It can be either a path starting with "/dev/" or a device name. | ||
Returns: | ||
int: The host number associated with the drive. | ||
""" | ||
disk = self._get_device_name(drive_path_or_name) | ||
logging.info(f"getting host number for disk: {disk}") | ||
lsblk_output, errors = self.executor.exec("lsblk -S") | ||
lsblk_output = lsblk_output.split('\n') | ||
self._handle_errors(errors) | ||
|
||
entry = [e for e in lsblk_output if e.find(disk) >= 0] | ||
logging.debug(f"lsblk output for {disk}:\n{entry}") | ||
assert len(entry) == 1, f"Found {len(entry)} drives for requested disk {disk}" | ||
while entry[0].find(' ') >= 0: | ||
entry[0] = entry[0].replace(' ', ' ') | ||
|
||
logging.debug(f"final lsblk string: {entry[0]}") | ||
return entry[0].split(' ')[1].split(':')[0] | ||
|
||
def _get_device_name(self, device_path_or_name: str) -> str: | ||
return device_path_or_name[5:] if device_path_or_name.startswith("/dev/") else device_path_or_name | ||
|
||
def _handle_errors(self, errors: List[Any] | None) -> None: | ||
assert errors is None or len( | ||
errors) == 0, f"remote execution failed: {errors}" |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from typing import Any, List, Tuple | ||
import logging | ||
import paramiko | ||
|
||
|
||
|
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.