Skip to content

Commit 1b267f2

Browse files
RevanthRajashekarAndrzejJakowski
authored andcommitted
sedcli: sedcli test enhancement
This patch adds the following enhancements to the existing test: 1. Read/RW/Lock lock the Disk 2. Test if these locks function properly by reading/writing from/to the disk 3. Change the Admin1 password 4. Check if the Admin1 password was successfully changed and the old password never works 5. Revert TPer with SID & PSID authority Also, this patch ensures if the user provides device path & device PSID Signed-off-by: Revanth Rajashekar <[email protected]> Signed-off-by: Andrzej Jakowski <[email protected]>
1 parent 43a8c08 commit 1b267f2

File tree

1 file changed

+103
-9
lines changed

1 file changed

+103
-9
lines changed

test/test_sedcli_basic.py

+103-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
Tests end-user scenarios for sedcli binary.
77
This suite needs to be run against Python 3.x and the sedcli binary must be
88
in your $PATH.
9+
The user must provide:
10+
1. Device Path
11+
2. Device PSID
912
"""
1013

1114
import os
@@ -27,42 +30,133 @@ def gen_rand_key(key_len):
2730
letters = string.ascii_lowercase
2831
return ''.join(random.choice(letters) for i in range(key_len)).encode('ascii')
2932

33+
def read_opal_drive(device_path):
34+
# Read from the disk
35+
pipe = subprocess.Popen(["dd", "if=" + device_path, "of=/dev/null", "bs=4k", "count=100", "iflag=direct"], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.PIPE)
36+
err = pipe.communicate()
37+
return pipe.returncode
38+
39+
def write_opal_drive(device_path):
40+
# Write to the disk
41+
pipe = subprocess.Popen(["dd", "if=/dev/zero", "of=" + device_path, "bs=4k", "count=100", "oflag=direct"], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.PIPE)
42+
err = pipe.communicate()
43+
return pipe.returncode
44+
45+
nvme_sid_key = gen_rand_key(32)
46+
print("\nKey used to initial provision drive:" + str(nvme_sid_key) + "\n")
47+
f = open("random_pswd.txt", "w+")
48+
f.write("Randomly Generated SID password to initially provision drive: " + str(nvme_sid_key) + "\n")
49+
3050
class TestSedcliBasic(unittest.TestCase):
3151

3252
NVME_DEV_PATH = '/dev/nvme0n1'
3353

3454
def __init__(self, *args, **kwargs):
3555
super(TestSedcliBasic, self).__init__(*args, **kwargs)
3656

37-
self.nvme_sid_key = gen_rand_key(32)
38-
3957
def test_initial_setup(self):
4058
"""
4159
Tests for: sedcli intial provision of drive (that is take ownerhisp,
4260
activate Locking SP and setup global locking range)
4361
"""
44-
print("Key used to initial provision drive:" + str(self.nvme_sid_key))
45-
4662
# Test taking ownership (test is assuming that drive is in Manufactured-inactive state)
47-
outs, errs = run_cmd(["sedcli", "--ownership", "--device", self.NVME_DEV_PATH], self.nvme_sid_key + b'\n' + self.nvme_sid_key + b'\n')
63+
outs, errs = run_cmd(["sedcli", "--ownership", "--device", self.NVME_DEV_PATH], nvme_sid_key + b'\n' + nvme_sid_key + b'\n')
4864

4965
self.assertEqual(pipe.returncode, 0, "sedcli returned error while taking ownership of the drive:\n" + str(errs))
5066
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
5167

5268
# Activate Locking SP
53-
outs, errs = run_cmd(["sedcli", "--activate-lsp", "--device", self.NVME_DEV_PATH], self.nvme_sid_key + b'\n')
69+
outs, errs = run_cmd(["sedcli", "--activate-lsp", "--device", self.NVME_DEV_PATH], nvme_sid_key + b'\n')
5470

5571
self.assertEqual(pipe.returncode, 0, "sedcli returned error while activating Locking SP:\n" + str(errs))
5672
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
5773

5874
# Set RLE and WLE on global locking range
59-
outs, errs = run_cmd(["sedcli", "--setup-global-range", "--device", self.NVME_DEV_PATH], self.nvme_sid_key + b'\n')
75+
outs, errs = run_cmd(["sedcli", "--setup-global-range", "--device", self.NVME_DEV_PATH], nvme_sid_key + b'\n')
6076

6177
self.assertEqual(pipe.returncode, 0, "sedcli returned error while setting RLE and WLE on global range:\n" + str(errs))
6278
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
6379

80+
def test_locking_range_test(self):
81+
# Read Lock Disk
82+
outs, errs = run_cmd(["sedcli", "--lock-unlock", "--device", self.NVME_DEV_PATH, "--accesstype", "RO"], nvme_sid_key + b'\n')
83+
84+
self.assertEqual(pipe.returncode, 0, "sedcli returned error while Read-Only locking the disk:\n" + str(errs))
85+
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
86+
87+
read = read_opal_drive(TestSedcliBasic.NVME_DEV_PATH)
88+
self.assertEqual(read, 0, "Unable to read data from the disk when the user is supposed to: " + str(errs))
89+
90+
write = write_opal_drive(TestSedcliBasic.NVME_DEV_PATH)
91+
self.assertEqual(write, 1, "Able to write data to the disk when the user is NOT supposed to: " + str(errs))
92+
93+
# ReadWrite Lock Disk
94+
outs, errs = run_cmd(["sedcli", "--lock-unlock", "--device", self.NVME_DEV_PATH, "--accesstype", "RW"], nvme_sid_key + b'\n')
95+
96+
self.assertEqual(pipe.returncode, 0, "sedcli returned error while Read-Write locking the disk:\n" + str(errs))
97+
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
98+
99+
read = read_opal_drive(TestSedcliBasic.NVME_DEV_PATH)
100+
self.assertEqual(read, 0, "Unable to read data from the disk when the user is supposed to: " + str(errs))
101+
102+
write = write_opal_drive(TestSedcliBasic.NVME_DEV_PATH)
103+
self.assertEqual(write, 0, "Unable to write data to the disk when the user is supposed to: " + str(errs))
104+
105+
# Lock Disk
106+
outs, errs = run_cmd(["sedcli", "--lock-unlock", "--device", self.NVME_DEV_PATH, "--accesstype", "LK"], nvme_sid_key + b'\n')
107+
108+
self.assertEqual(pipe.returncode, 0, "sedcli returned error while Locking the disk:\n" + str(errs))
109+
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
110+
111+
read = read_opal_drive(TestSedcliBasic.NVME_DEV_PATH)
112+
self.assertEqual(read, 1, "Able to read data from the disk when the user is NOT supposed to: " + str(errs))
113+
114+
write = write_opal_drive(TestSedcliBasic.NVME_DEV_PATH)
115+
self.assertEqual(write, 1, "Able to write data to the disk when the user is NOT supposed to: " + str(errs))
116+
117+
# Randomly generate the new amin1 password
118+
self.new_admin1_paswd = gen_rand_key(32)
119+
f.write("Radomly generated new Admin-1 Passwd: " + str(self.new_admin1_paswd) + "\n")
120+
f.close()
121+
122+
# Set password (Update/Change password for Admin1 authority in Locking SP)
123+
outs, errs = run_cmd(["sedcli", "--set-password", "--device", self.NVME_DEV_PATH], nvme_sid_key + b'\n' + self.new_admin1_paswd + b'\n' + self.new_admin1_paswd + b'\n')
124+
125+
self.assertEqual(pipe.returncode, 0, "sedcli returned error while Setting new password for the disk:\n" + str(errs))
126+
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
127+
128+
# Now check if the newly set password works fine
129+
# 1. Try to Set RLE and WLE on global locking range using old Admin-1 password
130+
outs, errs = run_cmd(["sedcli", "--setup-global-range", "--device", self.NVME_DEV_PATH], nvme_sid_key + b'\n')
131+
132+
self.assertEqual(pipe.returncode, 1, "Able to access LSP using the old admin-1 password: " + str(errs))
133+
134+
# 2. Try to Set RLE and WLE on global locking range usign new Admin-1 password
135+
outs, errs = run_cmd(["sedcli", "--setup-global-range", "--device", self.NVME_DEV_PATH], self.new_admin1_paswd + b'\n')
136+
137+
self.assertEqual(pipe.returncode, 0, "sedcli returned error while setting RLE and WLE on global range with new admin-1 password:\n" + str(errs))
138+
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
139+
140+
def test_revert_drive(self):
141+
# Revert the TPer with SID authority
142+
outs, errs = run_cmd(["sedcli", "--revert", "--device", self.NVME_DEV_PATH], nvme_sid_key + b'\n')
143+
144+
self.assertEqual(pipe.returncode, 0, "sedcli returned error while Reverting TPer using SID authority:\n" + str(errs))
145+
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
146+
147+
# Revert the TPer with PSID authority
148+
outs, errs = run_cmd(["sedcli", "--revert", "--device", self.NVME_DEV_PATH, "--psid"], TestSedcliBasic.NVME_DEV_PSID + b'\n')
149+
150+
self.assertEqual(pipe.returncode, 0, "sedcli returned error while Reverting TPer using PSID authority:\n" + str(errs))
151+
self.assertEqual(len(errs), 0, "sedcli returned success code but error message has been printed on stderr:\n" + str(errs))
152+
64153
# -----------------------------------------------------------------------------
65154
if __name__ == '__main__':
66-
if len(sys.argv) > 1:
155+
if len(sys.argv) == 3:
156+
TestSedcliBasic.NVME_DEV_PSID = bytes(sys.argv.pop(), 'utf-8')
67157
TestSedcliBasic.NVME_DEV_PATH = sys.argv.pop()
68-
unittest.main()
158+
print("Provided Device-Path: " + TestSedcliBasic.NVME_DEV_PATH)
159+
print(b'Provided Device-PSID: ' + TestSedcliBasic.NVME_DEV_PSID)
160+
unittest.main()
161+
else:
162+
print("The user must provide\n\t1. Device Path\n\t2. Device PSID\n")

0 commit comments

Comments
 (0)