mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Remove useless default values for disks and vm_name in _disk_profile
This commit is contained in:
parent
95458aef46
commit
8ed54cd923
2 changed files with 13 additions and 12 deletions
|
@ -970,7 +970,7 @@ def _qemu_image_create(disk, create_overlay=False, saltenv="base"):
|
|||
return img_dest
|
||||
|
||||
|
||||
def _disk_profile(profile, hypervisor, disks=None, vm_name=None, **kwargs):
|
||||
def _disk_profile(profile, hypervisor, disks, vm_name, **kwargs):
|
||||
"""
|
||||
Gather the disk profile from the config or apply the default based
|
||||
on the active hypervisor
|
||||
|
@ -1065,6 +1065,10 @@ def _fill_disk_filename(vm_name, disk, hypervisor, **kwargs):
|
|||
"""
|
||||
Compute the disk file name and update it in the disk value.
|
||||
"""
|
||||
# Compute the filename
|
||||
disk["filename"] = "{0}_{1}.{2}".format(vm_name, disk["name"], disk["format"])
|
||||
|
||||
# Compute the source file path
|
||||
base_dir = disk.get("pool", None)
|
||||
if hypervisor in ["qemu", "kvm", "xen"]:
|
||||
# Compute the base directory from the pool property. We may have either a path
|
||||
|
@ -1087,16 +1091,13 @@ def _fill_disk_filename(vm_name, disk, hypervisor, **kwargs):
|
|||
"or is unsupported".format(disk["name"], base_dir)
|
||||
)
|
||||
base_dir = pool["target_path"]
|
||||
|
||||
if hypervisor == "bhyve" and vm_name:
|
||||
elif hypervisor == "bhyve" and vm_name:
|
||||
disk["filename"] = "{0}.{1}".format(vm_name, disk["name"])
|
||||
disk["source_file"] = os.path.join(
|
||||
"/dev/zvol", base_dir or "", disk["filename"]
|
||||
)
|
||||
elif vm_name:
|
||||
# Compute the filename and source file properties if possible
|
||||
disk["filename"] = "{0}_{1}.{2}".format(vm_name, disk["name"], disk["format"])
|
||||
disk["source_file"] = os.path.join(base_dir, disk["filename"])
|
||||
|
||||
disk["source_file"] = os.path.join(base_dir, disk["filename"])
|
||||
|
||||
|
||||
def _complete_nics(interfaces, hypervisor):
|
||||
|
|
|
@ -443,7 +443,7 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(
|
||||
virt.__salt__, {"config.get": mock} # pylint: disable=no-member
|
||||
):
|
||||
ret = virt._disk_profile("nonexistent", "vmware")
|
||||
ret = virt._disk_profile("nonexistent", "vmware", None, "test-vm")
|
||||
self.assertTrue(len(ret) == 1)
|
||||
found = [disk for disk in ret if disk["name"] == "system"]
|
||||
self.assertTrue(bool(found))
|
||||
|
@ -456,11 +456,11 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
|||
"""
|
||||
Test virt._disk_profile() default KVM profile
|
||||
"""
|
||||
mock = MagicMock(return_value={})
|
||||
mock = MagicMock(side_effect=[{}, "/images/dir"])
|
||||
with patch.dict(
|
||||
virt.__salt__, {"config.get": mock} # pylint: disable=no-member
|
||||
):
|
||||
ret = virt._disk_profile("nonexistent", "kvm")
|
||||
ret = virt._disk_profile("nonexistent", "kvm", None, "test-vm")
|
||||
self.assertTrue(len(ret) == 1)
|
||||
found = [disk for disk in ret if disk["name"] == "system"]
|
||||
self.assertTrue(bool(found))
|
||||
|
@ -473,11 +473,11 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
|||
"""
|
||||
Test virt._disk_profile() default XEN profile
|
||||
"""
|
||||
mock = MagicMock(return_value={})
|
||||
mock = MagicMock(side_effect=[{}, "/images/dir"])
|
||||
with patch.dict(
|
||||
virt.__salt__, {"config.get": mock} # pylint: disable=no-member
|
||||
):
|
||||
ret = virt._disk_profile("nonexistent", "xen")
|
||||
ret = virt._disk_profile("nonexistent", "xen", None, "test-vm")
|
||||
self.assertTrue(len(ret) == 1)
|
||||
found = [disk for disk in ret if disk["name"] == "system"]
|
||||
self.assertTrue(bool(found))
|
||||
|
|
Loading…
Add table
Reference in a new issue