def test_try_write_zeroes_successful_nvme(self): disk_name = factory.make_name("nvme").encode("ascii") sec_info = { "format_supported": False, "writez_supported": True, "crypto_format": False, "nsze": 0x100A, "lbaf": 0, "ms": 0, } mock_check_output = self.patch(subprocess, "check_output") self.assertTrue(nvme_write_zeroes(disk_name, sec_info)) self.assertThat( mock_check_output, MockCalledOnceWith( [ "nvme", "write-zeroes", "-f", "-s", "0", "-c", "100a", maas_wipe.DEV_PATH % disk_name, ] ), ) self.assertThat( self.print_flush, MockCalledOnceWith( "%s: successfully zeroed (using write-zeroes)." % disk_name.decode("ascii") ), )
def test_try_write_zeroes_failed_nvme(self): disk_name = factory.make_name("nvme").encode("ascii") sec_info = { "format_supported": False, "writez_supported": True, "crypto_format": False, "nsze": 100, "lbaf": 0, "ms": 0, } mock_check_output = self.patch(subprocess, "check_output") mock_check_output.side_effect = subprocess.CalledProcessError( 1, "nvme write-zeroes") self.assertFalse(nvme_write_zeroes(disk_name, sec_info)) self.assertThat( self.print_flush, MockCalledOnceWith("Error with write-zeroes command (%s)" % "1"), )
def test_try_write_zeroes_not_supported_nvme(self): disk_name = factory.make_name("nvme").encode("ascii") sec_info = { "format_supported": False, "writez_supported": False, "crypto_format": False, "nsze": 1, "lbaf": 0, "ms": 0, } mock_print = self.patch(builtins, "print") self.assertFalse(nvme_write_zeroes(disk_name, sec_info)) self.assertThat( mock_print, MockCalledOnceWith("NVMe drive %s does not support write-zeroes" % disk_name.decode("ascii")), ) self.assertThat( self.print_flush, MockCalledOnceWith("Will fallback to regular drive zeroing."), )