Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): Refactor lsblk -J to lsblk -P + LVM Validation Test Cases #18

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

lasith-kg
Copy link
Collaborator

@lasith-kg lasith-kg commented Jun 4, 2024

I was experimenting with ebs-bootstrap running on RHEL 7.9 and found that lsblk -J, a command that returns a JSON representation of a block device, is only supported on relatively modern operating systems.

After some digging, I found that lsblk -P returns a machine readable format response in the form of key-value pairs. Since this machine readable format is supported on older versions of lsblk, I refactored any invocations of lsblk -J to lsblk -P

# RHEL 9.2
$ lsblk -o NAME,LABEL,FSTYPE,MOUNTPOINT --nodeps -J /dev/nvme9n1
{
   "blockdevices": [
      {
         "name": "nvme9n1",
         "label": "ifmx-var",
         "fstype": "ext4",
         "mountpoint": null
      }
   ]
}

$ lsblk -o NAME,LABEL,FSTYPE,MOUNTPOINT --nodeps -P /dev/nvme9n1
NAME="nvme9n1" LABEL="ifmx-var" FSTYPE="ext4" MOUNTPOINT=""
# RHEL 7.9
$ lsblk -o NAME,LABEL,FSTYPE,MOUNTPOINT --nodeps -J /dev/nvme9n1
lsblk: invalid option -- 'J'
...

$ lsblk -o NAME,LABEL,FSTYPE,MOUNTPOINT --nodeps -P /dev/nvme9n1
NAME="nvme9n1" LABEL="ifmx-var" FSTYPE="ext4" MOUNTPOINT=""

Additionaly, I use this oppurtunity to improve the test cases around LVM validation and error handling. I introduce a performance optimisation for Regex logic by computing the expressions ahead of time and storing them in top-level variables

@lasith-kg lasith-kg changed the title (feat): Refactor lsblk -J to lsblk -P (feat): Refactor lsblk -J to lsblk -P + LVM Validation Test Cases Jun 4, 2024
@lasith-kg lasith-kg merged commit ed109b2 into main Jun 5, 2024
4 checks passed
@lasith-kg lasith-kg deleted the feature/lsblk-refactor branch June 5, 2024 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants