From 1a4d3f4b7471d651ffe2a22cfa8bb620ab50b4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirko=20Stojiljkovi=C4=87?= <155116476+ms4ons@users.noreply.github.com> Date: Wed, 6 Aug 2025 10:01:12 +0200 Subject: [PATCH] B OpenNebula/one-ee#7194: Fix the check of datastore usage history (#3751) Signed-off-by: Mirko Stojiljkovic --- .../remotes/one_drs/lib/optimizer_parser.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/schedm_mad/remotes/one_drs/lib/optimizer_parser.py b/src/schedm_mad/remotes/one_drs/lib/optimizer_parser.py index 39b5cbd171..1a0b9a4cec 100644 --- a/src/schedm_mad/remotes/one_drs/lib/optimizer_parser.py +++ b/src/schedm_mad/remotes/one_drs/lib/optimizer_parser.py @@ -703,16 +703,16 @@ class OptimizerParser: } def _build_used_dstores(self, vm): - _, _, host_ds = self.get_ds_map() - vm_hist = vm.history_records.history - last_rec = max(vm_hist, key=lambda item: item.seq) - ds_id = last_rec.ds_id - # Host DS - if ds_id in host_ds.keys(): - self.used_host_dstores[vm.id, 0] = ds_id - # Shared system ds or image ds - else: - self.used_shared_dstores[vm.id, 0] = ds_id + if vm_hist := vm.history_records.history: + last_rec = max(vm_hist, key=lambda item: item.seq) + ds_id = last_rec.ds_id + # Host DS + _, _, host_ds = self.get_ds_map() + if ds_id in host_ds.keys(): + self.used_host_dstores[vm.id, 0] = ds_id + # Shared system ds or image ds + else: + self.used_shared_dstores[vm.id, 0] = ds_id def get_ds_map(self) -> tuple[set[int], set[int], dict[int, int]]: shared_ds, image_ds = set(), set() @@ -723,8 +723,7 @@ class OptimizerParser: } if ds_attrs.get("TYPE") == "IMAGE_DS": image_ds.add(int(ds.id)) - # elif ds_attrs.get("SHARED") == "YES": - else: + elif ds_attrs.get("SHARED") == "YES": shared_ds.add(int(ds.id)) host_ds_dict = { int(host_ds.id): int(host.id)