def test_error_element_order(): #TODO When schema 1.3.0 is released, update version. dobj = Objects.DFXMLObject(version="1.2.0+") psobj = Objects.PartitionSystemObject() fobj = Objects.FileObject() psobj.pstype_str = "gpt" # The error element should come after the fileobject stream. psobj.error = "foo" # Add a unallocated file object found floating in the partition system. fobj.alloc_inode = False fobj.alloc_name = False dobj.append(psobj) psobj.append(fobj) el = dobj.to_Element() # Confirm error comes after file stream. assert el[-1][0].tag.endswith("pstype_str") assert el[-1][-2].tag.endswith("fileobject") assert el[-1][-1].tag.endswith("error") # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) psobj_reconst = dobj_reconst.partition_systems[0] try: assert psobj_reconst.pstype_str == "gpt" assert psobj_reconst.error == "foo" except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_partition_in_partition(): #TODO Remove "+" on DFXML Schema 1.3.0 tracking. dobj = Objects.DFXMLObject(version="1.2.0+") psobj = Objects.PartitionSystemObject() psobj.pstype_str = "mbr" dobj.append(psobj) pobj_outer = Objects.PartitionObject() psobj.append(pobj_outer) pobj_inner = Objects.PartitionObject() pobj_outer.append(pobj_inner) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: psobj_reconst = dobj_reconst.partition_systems[0] pobj_outer_reconst = psobj_reconst.partitions[0] pobj_inner_reconst = pobj_outer_reconst.partitions[0] assert isinstance(pobj_inner_reconst, Objects.PartitionObject) except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_error_after_partition_system(): #TODO Bump version when feature branch merged into schema. dobj = Objects.DFXMLObject(version="1.2.0+") diobj = Objects.DiskImageObject() dobj.append(diobj) diobj.error = ERROR_1 psobj = Objects.PartitionSystemObject() #TODO This should be uncommented after the branch add_partition_system_error is merged. #psobj.error = ERROR_2 diobj.append(psobj) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: diobj_reconst = dobj_reconst.disk_images[0] #TODO This should be uncommented after the branch add_partition_system_error is merged. #psobj_reconst = diobj_reconst.partitionsystems[0] assert diobj_reconst.error == ERROR_1 #TODO This should be uncommented after the branch add_partition_system_error is merged. #assert psobj_reconst.error == ERROR_2 except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_solaris_ps_in_partition(): dobj = Objects.DFXMLObject(version="1.2.0") psobj_outer = Objects.PartitionSystemObject() dobj.append(psobj_outer) # Add file to outer partition system. fobj_psobj_outer = Objects.FileObject() fobj_psobj_outer.alloc_inode = False fobj_psobj_outer.alloc_name = False fobj_psobj_outer.sha512 = TEST_HASH_1 psobj_outer.append(fobj_psobj_outer) pobj = Objects.PartitionObject() psobj_outer.append(pobj) # Add file to partition. fobj_pobj = Objects.FileObject() fobj_pobj.alloc_inode = False fobj_pobj.alloc_name = False fobj_pobj.sha512 = TEST_HASH_2 pobj.append(fobj_pobj) psobj_inner = Objects.PartitionSystemObject() pobj.append(psobj_inner) # Add file to inner partition system. fobj_psobj_inner = Objects.FileObject() fobj_psobj_inner.alloc_inode = False fobj_psobj_inner.alloc_name = False fobj_psobj_inner.sha512 = TEST_HASH_3 psobj_inner.append(fobj_psobj_inner) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: psobj_outer_reconst = dobj_reconst.partition_systems[0] pobj_reconst = psobj_outer_reconst.partitions[0] psobj_inner_reconst = pobj_reconst.partition_systems[0] assert psobj_outer_reconst.files[0].sha512 == TEST_HASH_1 assert pobj_reconst.files[0].sha512 == TEST_HASH_2 assert psobj_inner_reconst.files[0].sha512 == TEST_HASH_3 except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_empty_object(): dobj = Objects.DFXMLObject(version="1.2.0") psobj = Objects.PartitionSystemObject() dobj.append(psobj) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: psobj_reconst = dobj_reconst.partition_systems[0] except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_all(): dobj = Objects.DFXMLObject(version="1.2.0") # Make objects for simple appends. diobj_0 = Objects.DiskImageObject() psobj_0 = Objects.PartitionSystemObject() pobj_0 = Objects.PartitionObject() vobj_0 = Objects.VolumeObject() vobj_0.ftype_str = "hfs" fobj_0 = Objects.FileObject() # Make objects for more exotic appends. psobj_1 = Objects.PartitionSystemObject() vobj_1 = Objects.VolumeObject() vobj_1.ftype_str = "hfsplus" fobj_dobj_1 = Objects.FileObject() fobj_dobj_1.alloc_inode = False fobj_dobj_1.alloc_name = False fobj_psobj_1 = Objects.FileObject() fobj_psobj_1.alloc_inode = False fobj_psobj_1.alloc_name = False fobj_pobj_1 = Objects.FileObject() fobj_pobj_1.alloc_inode = False fobj_pobj_1.alloc_name = False # Do simple appends. dobj.append(diobj_0) diobj_0.append(psobj_0) psobj_0.append(pobj_0) pobj_0.append(vobj_0) vobj_0.append(fobj_0) # Do more exotic appends. pobj_0.append(psobj_1) vobj_0.append(vobj_1) dobj.append(fobj_dobj_1) psobj_0.append(fobj_psobj_1) pobj_0.append(fobj_pobj_1)
def _test_file_in_non_fs_levels_deep(include_disk_image, include_partition_system, include_partition, include_file_system): """ This test follows a simple, vertical storage layer stack, but adds a file at each layer. """ dobj = Objects.DFXMLObject(version="1.2.0") # Add file to top-level document. fobj_dobj = Objects.FileObject() fobj_dobj.alloc_inode = False fobj_dobj.alloc_name = False fobj_dobj.sha512 = TEST_HASH_1 dobj.append(fobj_dobj) appender_stack = [dobj] if include_disk_image: # Add disk image to top-level document. diobj = Objects.DiskImageObject() appender_stack[-1].append(diobj) appender_stack.append(diobj) # Add file to disk image. fobj_diobj = Objects.FileObject() fobj_diobj.alloc_inode = False fobj_diobj.alloc_name = False fobj_diobj.sha512 = TEST_HASH_2 diobj.append(fobj_diobj) if include_partition_system: # Add partition system to disk image. psobj = Objects.PartitionSystemObject() appender_stack[-1].append(psobj) appender_stack.append(psobj) # Add file to partition system. fobj_psobj = Objects.FileObject() fobj_psobj.alloc_inode = False fobj_psobj.alloc_name = False fobj_psobj.sha512 = TEST_HASH_3 psobj.append(fobj_psobj) if include_partition: # Add partition to partition system, but not disk image. if not (include_disk_image and not include_partition_system): pobj = Objects.PartitionObject() appender_stack[-1].append(pobj) appender_stack.append(pobj) # Add file to partition. fobj_pobj = Objects.FileObject() fobj_pobj.alloc_inode = False fobj_pobj.alloc_name = False fobj_pobj.sha512 = TEST_HASH_4 pobj.append(fobj_pobj) if include_file_system: # Add file system to anything but a partition system. if not (include_partition_system and not include_partition): vobj = Objects.VolumeObject() appender_stack[-1].append(vobj) appender_stack.append(vobj) # Add file to file system. fobj_vobj = Objects.FileObject() fobj_vobj.sha512 = TEST_HASH_5 vobj.append(fobj_vobj) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: container_stack = [dobj_reconst] assert dobj_reconst.files[0].sha512 == TEST_HASH_1 if include_disk_image: diobj_reconst = container_stack[-1].disk_images[0] container_stack.append(diobj_reconst) assert diobj_reconst.files[0].sha512 == TEST_HASH_2 if include_partition_system: psobj_reconst = container_stack[-1].partition_systems[0] container_stack.append(psobj_reconst) assert psobj_reconst.files[0].sha512 == TEST_HASH_3 if include_partition: if not (include_disk_image and not include_partition_system): pobj_reconst = container_stack[-1].partitions[0] container_stack.append(pobj_reconst) assert pobj_reconst.files[0].sha512 == TEST_HASH_4 if include_file_system: if not (include_partition_system and not include_partition): vobj_reconst = container_stack[-1].volumes[0] assert vobj_reconst.files[0].sha512 == TEST_HASH_5 except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def _test_file_in_non_fs_levels_flat(include_disk_image, include_partition_system, include_partition, include_file_system): """ This test follows a simple, horizontal storage layer stack (every container attached to top document object), and adds a file for each container. """ dobj = Objects.DFXMLObject(version="1.2.0") # Add file to top-level document. fobj_dobj = Objects.FileObject() fobj_dobj.alloc_inode = False fobj_dobj.alloc_name = False fobj_dobj.sha512 = TEST_HASH_1 dobj.append(fobj_dobj) if include_disk_image: # Add disk image. diobj = Objects.DiskImageObject() dobj.append(diobj) # Add file to disk image. fobj_diobj = Objects.FileObject() fobj_diobj.alloc_inode = False fobj_diobj.alloc_name = False fobj_diobj.sha512 = TEST_HASH_2 diobj.append(fobj_diobj) if include_partition_system: # Add partition system. psobj = Objects.PartitionSystemObject() dobj.append(psobj) # Add file to partition system. fobj_psobj = Objects.FileObject() fobj_psobj.alloc_inode = False fobj_psobj.alloc_name = False fobj_psobj.sha512 = TEST_HASH_3 psobj.append(fobj_psobj) if include_partition: # Add partition. pobj = Objects.PartitionObject() dobj.append(pobj) # Add file to partition. fobj_pobj = Objects.FileObject() fobj_pobj.alloc_inode = False fobj_pobj.alloc_name = False fobj_pobj.sha512 = TEST_HASH_4 pobj.append(fobj_pobj) if include_file_system: # Add file system. vobj = Objects.VolumeObject() dobj.append(vobj) # Add file to file system. fobj_vobj = Objects.FileObject() fobj_vobj.sha512 = TEST_HASH_5 vobj.append(fobj_vobj) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: assert dobj_reconst.files[0].sha512 == TEST_HASH_1 if include_disk_image: diobj_reconst = dobj_reconst.disk_images[0] assert diobj_reconst.files[0].sha512 == TEST_HASH_2 if include_partition_system: psobj_reconst = dobj_reconst.partition_systems[0] assert psobj_reconst.files[0].sha512 == TEST_HASH_3 if include_partition: pobj_reconst = dobj_reconst.partitions[0] assert pobj_reconst.files[0].sha512 == TEST_HASH_4 if include_file_system: vobj_reconst = dobj_reconst.volumes[0] assert vobj_reconst.files[0].sha512 == TEST_HASH_5 except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)