Skip to content

Commit b1bfe4a

Browse files
fix(drivers): address review comments on delete_machine idempotency
- Log at debug level when a domain is already gone during delete, so the missing-domain path stays traceable instead of silent. - Add a regression test confirming volume cleanup still runs via list_volumes when the domain was already gone (previously only the no-crash case was covered).
1 parent c6e0e9d commit b1bfe4a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

exordos_core/compute/pool/drivers/libvirt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,10 @@ def delete_machine(
13401340
except libvirt.libvirtError as e:
13411341
if e.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN:
13421342
raise
1343+
LOG.debug(
1344+
"Domain for machine %s not found, assuming already deleted",
1345+
machine.uuid,
1346+
)
13431347
domain = None
13441348

13451349
if domain is not None:

exordos_core/tests/unit/compute/pool/drivers/test_libvirt.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# under the License.
1616

1717
import uuid as sys_uuid
18+
from unittest import mock
1819
from xml.dom import minidom
1920
from xml.etree import ElementTree as ET
2021

@@ -117,3 +118,22 @@ def test_is_idempotent_when_the_domain_is_already_gone(self):
117118

118119
# Must not raise, even though no such domain was ever defined.
119120
driver.delete_machine(machine, delete_volumes=False)
121+
122+
def test_volume_cleanup_still_runs_when_the_domain_is_already_gone(self):
123+
driver = _local_driver()
124+
machine = models.Machine(
125+
uuid=sys_uuid.uuid4(),
126+
project_id=sys_uuid.uuid4(),
127+
name="never-existed",
128+
cores=1,
129+
ram=512,
130+
)
131+
132+
# The missing-domain path must fall through to volume cleanup,
133+
# not skip it.
134+
with mock.patch.object(
135+
driver, "list_volumes", return_value=[]
136+
) as mock_list_volumes:
137+
driver.delete_machine(machine, delete_volumes=True)
138+
139+
mock_list_volumes.assert_called_once_with(machine)

0 commit comments

Comments
 (0)