def _GetListDisksArtifact(self): """Generates a StringArtifact containing information about all disks. Returns: StringArtifact: the artifact. """ if self._platform == 'darwin': #pylint: disable=protected-access diskutil_artifact = base.StringArtifact( 'Disks/diskutil.txt', json.dumps([md._attributes for md in macdisk.WholeDisks()])) return diskutil_artifact lsblk_artifact = base.StringArtifact('Disks/lsblk.txt', json.dumps(self._GetLsblkDict())) return lsblk_artifact
def GetArtifacts(self): """Selects the Artifacts to acquire. This tries to return as many Artifacts as possible even if some collection raised an exception. Returns: list(DiskArtifact): the artifacts corresponding to copy. Raises: errors.RecipeException: when no disk is to be collected. """ artifacts = [] disks_to_collect = [] if getattr(self._options, 'select_disks', None): all_disks = self._ListDisks(all_devices=True) disks_to_collect = gui.AskDiskList(all_disks) elif getattr(self._options, 'disk', None): disks_to_collect = self._ListDisks(names=self._options.disk) else: disks_to_collect = self._ListDisks() if not disks_to_collect: raise errors.RecipeException('No disk to collect') lsblk_artifact = base.StringArtifact('Disks/lsblk.txt', json.dumps(self._GetLsblkDict())) for disk in disks_to_collect: udevadm_artifact = base.StringArtifact( 'Disks/{0:s}.udevadm.txt'.format(disk.name), disk.GetUdevadmProperty('udevadm_text_output')) hashlog_artifact = base.FileArtifact(disk.hashlog_filename) hashlog_artifact.remote_path = 'Disks/{0:s}'.format( hashlog_artifact.name) # It is necessary for the DiskArtifact to be appended before the # hashlog, as the hashlog is generated when dcfldd completes. artifacts.append(udevadm_artifact) artifacts.append(lsblk_artifact) artifacts.append(disk) artifacts.append(hashlog_artifact) return artifacts
def testLogProgress(self): """Tests _LogProgress.""" # For reporting purposes set the artifact to 1MiB self.progress_reporter._artifact = base.StringArtifact( 'fake/path', 'A' * (1024**2)) artifact = self.progress_reporter._artifact update_callback = self.progress_reporter.update_with_total logger = self.progress_reporter._progress_logger reporting_frequency = self.progress_reporter._reporting_frequency expected_log_entries = 100 // reporting_frequency gcs_uploader = FakeGCSUploader() gcs_uploader.UploadArtifact(artifact, update_callback) self.assertEqual(len(logger.logs), expected_log_entries)
def _GetDiskInfoArtifact(self, disk): """Returns an StringArtifact containing information about a disk being copied. Args: disk(DiskArtifact): the disk object to get info from. Returns: StringArtifact: the disk info artifact. """ if self._platform == 'darwin': # TODO return None #pylint: disable=protected-access udevadm_artifact = base.StringArtifact( 'Disks/{0:s}.udevadm.txt'.format(disk.name), disk._GetUdevadmProperty('udevadm_text_output')) return udevadm_artifact
def GetArtifacts(self): return [base.StringArtifact('fake/path', DEFAULT_ARTIFACT_CONTENT)]