|
24 | 24 | import time |
25 | 25 |
|
26 | 26 | from avocado import Test |
27 | | -from avocado.utils import disk |
28 | 27 | from avocado.utils import nvme |
29 | 28 | from avocado.utils import process |
30 | 29 | from avocado.utils.software_manager.manager import SoftwareManager |
@@ -121,6 +120,17 @@ def is_drive_locked(self, namespace): |
121 | 120 | lockdown_attr = self.get_nvme_sed_discover_parameters(namespace) |
122 | 121 | return lockdown_attr.get("Locked").lower() == "yes" |
123 | 122 |
|
| 123 | + def dd_read_records_device(self, disk, read_records="1", out_file="/tmp/data"): |
| 124 | + """ |
| 125 | + Reads mentioned number of blocks from device to destination |
| 126 | + :param disk: disk absolute path |
| 127 | + :param read_records: Numbers of blocks to read from disk |
| 128 | + :param out_file: Destination file |
| 129 | + :rtype: boolean |
| 130 | + """ |
| 131 | + cmd = f"dd count={read_records} if={disk} of={out_file}" |
| 132 | + return not process.system(cmd, ignore_status=True, sudo=True) |
| 133 | + |
124 | 134 | def initialize_sed_locking(self, namespace, password): |
125 | 135 | """ |
126 | 136 | Enables and initializes SED feature on nvme disk |
@@ -256,21 +266,21 @@ def lock_unlock(self): |
256 | 266 | Perform lock and unlock of nvme drive |
257 | 267 | """ |
258 | 268 | self.lock_drive(self.namespace) |
259 | | - if disk.dd_read_records_device(self.namespace): |
| 269 | + if self.dd_read_records_device(self.namespace): |
260 | 270 | self.log.fail(f"dd read command on {self.namespace} is successful, dd should fail when drive is locked") |
261 | 271 | self.unlock_drive(self.namespace) |
262 | | - if not disk.dd_read_records_device(self.namespace): |
| 272 | + if not self.dd_read_records_device(self.namespace): |
263 | 273 | self.log.fail(f"dd read command on {self.namespace} is failed, dd should success when drive is unlocked") |
264 | 274 |
|
265 | 275 | def lock_unlock_with_key(self, password): |
266 | 276 | """ |
267 | 277 | Perform lock and unlock with provided key |
268 | 278 | """ |
269 | 279 | self.lock_drive(self.namespace, with_pass_key=password) |
270 | | - if disk.dd_read_records_device(self.namespace): |
| 280 | + if self.dd_read_records_device(self.namespace): |
271 | 281 | self.log.fail(f"dd read command on {self.namespace} is successful, dd should fail when drive is locked") |
272 | 282 | self.unlock_drive(self.namespace, with_pass_key=password) |
273 | | - if not disk.dd_read_records_device(self.namespace): |
| 283 | + if not self.dd_read_records_device(self.namespace): |
274 | 284 | self.log.fail(f"dd read command on {self.namespace} is failed, dd should success when drive is unlocked") |
275 | 285 |
|
276 | 286 | def test_initialize_locking(self): |
|
0 commit comments