|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import mock |
| 16 | +import os |
16 | 17 | from oslotest import base as test_base |
17 | 18 | import pyudev |
18 | 19 | import six |
@@ -454,6 +455,53 @@ def test_erase_block_device_notsupported_shred(self, mocked_execute): |
454 | 455 | '--iterations', '1', '/dev/sda') |
455 | 456 | ]) |
456 | 457 |
|
| 458 | + @mock.patch.object(hardware.GenericHardwareManager, |
| 459 | + '_is_virtual_media_device', autospec=True) |
| 460 | + def test_erase_block_device_virtual_media(self, vm_mock): |
| 461 | + vm_mock.return_value = True |
| 462 | + block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824, |
| 463 | + True) |
| 464 | + self.hardware.erase_block_device(block_device) |
| 465 | + vm_mock.assert_called_once_with(self.hardware, block_device) |
| 466 | + |
| 467 | + @mock.patch.object(os, 'readlink', autospec=True) |
| 468 | + @mock.patch.object(os.path, 'exists', autospec=True) |
| 469 | + def test__is_virtual_media_device_exists(self, mocked_exists, |
| 470 | + mocked_link): |
| 471 | + mocked_exists.return_value = True |
| 472 | + mocked_link.return_value = '../../sda' |
| 473 | + block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824, |
| 474 | + True) |
| 475 | + res = self.hardware._is_virtual_media_device(block_device) |
| 476 | + self.assertTrue(res) |
| 477 | + mocked_exists.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev') |
| 478 | + mocked_link.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev') |
| 479 | + |
| 480 | + @mock.patch.object(os, 'readlink', autospec=True) |
| 481 | + @mock.patch.object(os.path, 'exists', autospec=True) |
| 482 | + def test__is_virtual_media_device_exists_no_match(self, mocked_exists, |
| 483 | + mocked_link): |
| 484 | + mocked_exists.return_value = True |
| 485 | + mocked_link.return_value = '../../sdb' |
| 486 | + block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824, |
| 487 | + True) |
| 488 | + res = self.hardware._is_virtual_media_device(block_device) |
| 489 | + self.assertFalse(res) |
| 490 | + mocked_exists.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev') |
| 491 | + mocked_link.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev') |
| 492 | + |
| 493 | + @mock.patch.object(os, 'readlink', autospec=True) |
| 494 | + @mock.patch.object(os.path, 'exists', autospec=True) |
| 495 | + def test__is_virtual_media_device_path_doesnt_exist(self, mocked_exists, |
| 496 | + mocked_link): |
| 497 | + mocked_exists.return_value = False |
| 498 | + block_device = hardware.BlockDevice('/dev/sda', 'big', 1073741824, |
| 499 | + True) |
| 500 | + res = self.hardware._is_virtual_media_device(block_device) |
| 501 | + self.assertFalse(res) |
| 502 | + mocked_exists.assert_called_once_with('/dev/disk/by-label/ir-vfd-dev') |
| 503 | + self.assertFalse(mocked_link.called) |
| 504 | + |
457 | 505 | @mock.patch.object(utils, 'execute') |
458 | 506 | def test_erase_block_device_ata_security_enabled(self, mocked_execute): |
459 | 507 | hdparm_output = HDPARM_INFO_TEMPLATE % { |
|
0 commit comments