def isDataDiskPartitionFormatted(device): rv = Utils.runCommand("blkid -c /dev/null -o value %s" % device, output=True, root=True) if rv["Status"] != 0: return False uuid = getUuidByDiskPartition(device) if not uuid: return False for fsTabEntry in FsTabUtils.readFsTab(): if fsTabEntry["Device"] == ("UUID=%s" % uuid) or fsTabEntry["Device"] == device: return True return False
if DiskUtils.isDataDiskPartitionFormatted(device): Utils.removeFile(deviceFormatOutputFile) Utils.removeFile(deviceFormatLockFile) Utils.log("UUID device %s already has an entry in fstab" % device) writeStatus(deviceFormatStatusFile, "UUID device %s already has an entry in fstab\n" % sys.argv[3]) sys.exit(5) newFsTabEntry = {"Device" : "UUID=%s" % deviceUuid, "MountPoint" : mountPoint, "FsType" : fsType, "Options" : "defaults", "DumpOption" : "0", "fsckOrder" : "2"} if fsType in ['ext3', 'ext4', 'ext4dev']: newFsTabEntry["Options"] = "defaults,user_xattr" if not FsTabUtils.addFsTabEntry(newFsTabEntry): Utils.removeFile(deviceFormatOutputFile) Utils.removeFile(deviceFormatLockFile) writeStatus(deviceFormatStatusFile, "failed to update fstab") sys.exit(6) status = Utils.runCommand("mount %s" % mountPoint, output=True, root=True) if status["Status"] != 0: Utils.removeFile(deviceFormatOutputFile) Utils.removeFile(deviceFormatLockFile) Utils.log("Mounting device %s on %s failed" % (device, mountPoint)) writeStatus(deviceFormatStatusFile, "Mounting device %s on %s failed\n" % (sys.argv[3], mountPoint)) sys.exit(7) writeStatus(deviceFormatStatusFile, "Completed\n") Utils.removeFile(deviceFormatOutputFile)
writeStatus( deviceFormatStatusFile, "UUID device %s already has an entry in fstab\n" % sys.argv[3]) sys.exit(5) newFsTabEntry = { "Device": "UUID=%s" % deviceUuid, "MountPoint": mountPoint, "FsType": fsType, "Options": "defaults", "DumpOption": "0", "fsckOrder": "2" } if fsType in ['ext3', 'ext4', 'ext4dev']: newFsTabEntry["Options"] = "defaults,user_xattr" if not FsTabUtils.addFsTabEntry(newFsTabEntry): Utils.removeFile(deviceFormatOutputFile) Utils.removeFile(deviceFormatLockFile) writeStatus(deviceFormatStatusFile, "failed to update fstab") sys.exit(6) status = Utils.runCommand("mount %s" % mountPoint, output=True, root=True) if status["Status"] != 0: Utils.removeFile(deviceFormatOutputFile) Utils.removeFile(deviceFormatLockFile) Utils.log("Mounting device %s on %s failed" % (device, mountPoint)) writeStatus( deviceFormatStatusFile, "Mounting device %s on %s failed\n" % (sys.argv[3], mountPoint)) sys.exit(7)