fix: explain why native discovery cannot scan stopped containers

This commit is contained in:
VAIO73
2026-10-18 17:48:48 +00:00
parent c6f919b085
commit b5a2a3f52b
5 changed files with 64 additions and 3 deletions
+5 -1
View File
@@ -125,6 +125,7 @@ interface PortDetail {
interface NativeDiscovery {
vmid: number
status: "not_scanned" | "complete" | "partial" | "error" | "busy"
issues?: string[]
stale: boolean
candidates: DetectedApp[]
}
@@ -804,7 +805,10 @@ export function LxcAppPanel({ vmid, ctIp, onChange, managed, initialData, oci }:
if (!isCurrent()) return
setNativeDiscovery(native)
if (native.status === "error" || native.status === "busy") {
setDetectionNotice({ found: false, text: t("vmLxc.appEditor.nativeScanFailed") })
const stopped = native.status === "error" && Array.isArray(native.issues)
&& native.issues.includes("guest_stopped")
setDetectionNotice({ found: false, text: t(stopped
? "vmLxc.appEditor.nativeScanStopped" : "vmLxc.appEditor.nativeScanFailed") })
return
}
const result: Suggestions = await fetchApi(`/api/vms/${vmid}/apps/suggestions`, {
+1
View File
@@ -1746,6 +1746,7 @@
"nativeEvidenceDirectory": "Working directory",
"nativeEvidenceService": "Service definition",
"nativeScanFailed": "Application search could not finish. Previous evidence may be outdated; try again.",
"nativeScanStopped": "This container is stopped. Application search is only available while the container is running.",
"nativeScanPartial": "Application search is incomplete. Review the available evidence and try again.",
"nativeVersionUnknown": "Installed version unknown",
"nativeEvidenceStale": "Evidence may be outdated or incomplete.",
+1
View File
@@ -1690,6 +1690,7 @@
"nativeEvidenceDirectory": "Pracovný priečinok",
"nativeEvidenceService": "Definícia služby",
"nativeScanFailed": "Vyhľadávanie aplikácií sa nepodarilo dokončiť. Predchádzajúce dôkazy môžu byť zastarané; skús to znova.",
"nativeScanStopped": "Kontajner je vypnutý. Vyhľadávanie aplikácií je dostupné iba v spustenom kontajneri.",
"nativeScanPartial": "Vyhľadávanie aplikácií je neúplné. Skontroluj dostupné dôkazy a skús to znova.",
"nativeVersionUnknown": "Nainštalovaná verzia nie je známa",
"nativeEvidenceStale": "Dôkazy môžu byť zastarané alebo neúplné.",
@@ -746,6 +746,27 @@ class Routes(unittest.TestCase):
scan.assert_not_called()
read.assert_not_called()
def test_stopped_scan_route_exposes_reason_and_keeps_cached_evidence(self):
item = {'discovery_id': 'native-retained', 'name': 'Retained app',
'installation_path': '/opt/retained/server'}
previous = {'vmid': 101, 'status': 'complete', 'stale': False,
'scanned_at': time.time(), 'candidates': [item]}
native._cache[101] = copy.deepcopy(previous)
with patch.object(native, 'scan', side_effect=native.ProbeError('guest_stopped')), \
patch.object(lxc_apps, 'load_sidecar', return_value={'apps': []}), \
patch.object(lxc_apps, 'get_suggestions') as suggestions, \
patch.object(lxc_apps, '_write_sidecar') as write:
response = self.client.post('/api/vms/101/apps/native-discovery')
self.assertEqual(response.status_code, 200)
result = response.get_json()
self.assertEqual(result['status'], 'error')
self.assertEqual(result['issues'], ['guest_stopped'])
self.assertTrue(result['stale'])
self.assertEqual(result['candidates'], [item])
self.assertEqual(result['scanned_at'], previous['scanned_at'])
suggestions.assert_not_called()
write.assert_not_called()
def test_actual_lifecycle_marks_last_known_stale_without_scanning(self):
native._cache[101] = {'vmid': 101, 'status': 'complete', 'stale': False,
'candidates': [], 'scanned_at': time.time()}