fix: what bandit and the remaining lint rules found
- zip() in provisioning is strict (B905): the OVF asks for one adapter per requested NIC, so the two lists match. A VM that came back with fewer adapters used to get a seed that left a NIC unconfigured; it now fails, and create_vm_from_cloud_init discards it as on any other error after the import. A test covers it. - A failed abort of the import lease is logged at debug level instead of passed over (B110); the original error is still the one raised. - nosec for false positives, each with its reason: the 0.0.0.0 entries in the parsers are addresses vSphere reports, not binds (B104); qemu-img runs with a fixed argv and no shell (B404, B603); xml.sax.saxutils only escapes the OVF descriptor the driver writes, nothing is parsed (B406), so defusedxml would not apply.
This commit is contained in:
1 parent
1271218868
commit
06b446934f
6 files changed
+27
-10
No files matched your search
@@ -252,7 +252,7 @@ class VmwareProvisioningMixin:
|
||||
try:
|
||||
lease.HttpNfcLeaseAbort()
|
||||
except Exception: # noqa: BLE001 - the original error is the one to report
|
||||
pass
|
||||
logger.debug("Aborting the import lease failed: ignored", exc_info=True)
|
||||
raise
|
||||
return info["info"]["entity"]
|
||||
|
||||
@@ -279,13 +279,16 @@ class VmwareProvisioningMixin:
|
||||
changes = _mac_changes(adapters, nics) + _disk_growth(devices, disk_gb, image_size)
|
||||
macs = [
|
||||
(nic.get("mac") or adapter.macAddress or "").lower()
|
||||
for adapter, nic in zip(adapters, nics)
|
||||
for adapter, nic in zip(adapters, nics, strict=True)
|
||||
]
|
||||
seed = nocloud_iso(
|
||||
user,
|
||||
meta_data(name, f"iid-{uuid.uuid4()}"),
|
||||
network_config(
|
||||
[(mac, nic.get("dhcp", i == 0)) for i, (mac, nic) in enumerate(zip(macs, nics))]
|
||||
[
|
||||
(mac, nic.get("dhcp", i == 0))
|
||||
for i, (mac, nic) in enumerate(zip(macs, nics, strict=True))
|
||||
]
|
||||
),
|
||||
)
|
||||
vm_dir = posixpath.dirname(str(props["config.files.vmPathName"]).split("] ", 1)[1])
|
||||
@@ -365,7 +368,7 @@ class VmwareProvisioningMixin:
|
||||
def _mac_changes(adapters: list[Any], nics: list[NICConfigDict]) -> list[Any]:
|
||||
"""Device edits pinning the MACs the caller asked for."""
|
||||
changes = []
|
||||
for adapter, nic in zip(adapters, nics):
|
||||
for adapter, nic in zip(adapters, nics, strict=True):
|
||||
if not nic.get("mac"):
|
||||
continue
|
||||
adapter.addressType = "manual"
|
||||
|
||||
Reference in new issue
Block a user