feat: hand HPE MSA exports from the disk CSV import to the MSA wizard

An MSA disk export pasted or uploaded in Disks > Import failed with
"Unknown header: Location". The import now recognises the MSA columns and
opens the shelf assignment step of the MSA import instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-21 14:13:10 +02:00
1 parent 7754e823cb
commit 2a6abc396d
4 files changed
+32 -3

No files matched your search

+1 -1
View File
@@ -514,7 +514,7 @@ class MSAUploadForm(forms.Form):
if not export.disks:
raise ValidationError(export.errors)
cleaned_data["export"] = export
cleaned_data["raw"] = data if isinstance(data, str) else msa_import._decode(data)
cleaned_data["raw"] = data if isinstance(data, str) else msa_import.decode(data)
return cleaned_data
+16
View File
@@ -474,6 +474,22 @@ class DiskBulkImportView(generic.BulkImportView):
queryset = Disk.objects.all()
model_form = disk_forms.DiskImportForm
def post(self, request):
# An HPE MSA export pasted or uploaded here goes straight to the MSA wizard.
upload = request.FILES.get("upload_file")
if upload is not None:
raw = msa_import.decode(upload.read())
upload.seek(0)
else:
raw = request.POST.get("data", "")
if msa_import.looks_like_export(raw):
export = msa_import.parse_export(raw)
if export.disks:
messages.info(request, "Die Datei ist ein HPE-MSA-Export und wird mit dem MSA-Import eingelesen.")
view = MSADiskImportView()
return view._render_assign(request, raw, export, view._assign_form(request, export))
return super().post(request)
@register_model_view(Disk, "bulk_edit", path="edit", detail=False)
class DiskBulkEditView(generic.BulkEditView):
+8 -2
View File
@@ -54,7 +54,7 @@ def _natural(value):
return (0, int(value), "") if str(value).isdigit() else (1, 0, str(value))
def _decode(data):
def decode(data):
if isinstance(data, bytes):
for encoding in ("utf-8-sig", "cp1252"):
try:
@@ -71,6 +71,12 @@ def _int(value):
return None
def looks_like_export(text):
"""True if the first line carries the MSA columns "Location" and "Serial Number"."""
first_line = (text or "").lstrip("\ufeff").split("\n", 1)[0].casefold()
return COLUMN_LOCATION in first_line and "serial number" in first_line
def map_type(value, rpm=""):
"""Translate the MSA "Type" column, e.g. "SSD SAS", "SAS", "SAS MDL" or "SATA", into (type, interface)."""
text = (value or "").upper()
@@ -94,7 +100,7 @@ def map_status(usage, health):
def parse_export(data):
"""Parse the CSV export into an MSAExport; rows that cannot be read end up in errors."""
text = _decode(data).strip()
text = decode(data).strip()
export = MSAExport()
if not text:
export.errors.append("Die Datei ist leer.")
@@ -75,3 +75,10 @@ class ClassifyTest(SimpleTestCase):
self.assertEqual(
msa_import.classify(self.disk, 1, 24, serial_elsewhere="MSA2 – Front 7")[0], msa_import.ACTION_CONFLICT
)
class DetectionTest(SimpleTestCase):
def test_recognises_msa_header_only(self):
self.assertTrue(msa_import.looks_like_export(EXPORT))
self.assertTrue(msa_import.looks_like_export("\ufeffLocation;Serial Number\n1.1;X"))
self.assertFalse(msa_import.looks_like_export("device,slot,serial\nsrv-01,0,ABC"))