def test_prepare_persistent_root_volumes_vim_using_volume_id(self):
"""Existing persistent root volume with vim_volume_id."""
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("a")
disk = {"vim_volume_id": volume_id}
block_device_mapping = {}
expected_existing_vim_volumes = [{"id": volume_id}]
boot_volume_id = self.vimconn._prepare_persistent_root_volumes(
name,
- vm_av_zone,
+ storage_av_zone,
disk,
base_disk_index,
block_device_mapping,
self, mock_update_block_device_mapping
):
"""Existing persistent non root volume with vim_volume_id."""
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("b")
disk = {"vim_volume_id": volume_id}
block_device_mapping = {}
self.vimconn._prepare_non_root_persistent_volumes(
name,
disk,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
base_disk_index,
existing_vim_volumes,
self, mock_update_block_device_mapping
):
"""Existing persistent root volume with vim_id."""
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("a")
disk = {"vim_id": volume_id}
block_device_mapping = {}
expected_existing_vim_volumes = [{"id": volume_id}]
boot_volume_id = self.vimconn._prepare_persistent_root_volumes(
name,
- vm_av_zone,
+ storage_av_zone,
disk,
base_disk_index,
block_device_mapping,
self, mock_update_block_device_mapping
):
"""Existing persistent root volume with vim_id."""
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("b")
disk = {"vim_id": volume_id}
block_device_mapping = {}
self.vimconn._prepare_non_root_persistent_volumes(
name,
disk,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
base_disk_index,
existing_vim_volumes,
):
"""Create persistent root volume."""
self.vimconn.cinder.volumes.create.return_value.id = volume_id2
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("a")
disk = {"size": 10, "image_id": image_id}
block_device_mapping = {}
expected_boot_vol_id = volume_id2
boot_volume_id = self.vimconn._prepare_persistent_root_volumes(
name,
- vm_av_zone,
+ storage_av_zone,
disk,
base_disk_index,
block_device_mapping,
):
"""Create persistent root volume, disk has keep parameter."""
self.vimconn.cinder.volumes.create.return_value.id = volume_id2
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("a")
disk = {"size": 10, "image_id": image_id, "keep": True}
block_device_mapping = {}
expected_existing_vim_volumes = []
boot_volume_id = self.vimconn._prepare_persistent_root_volumes(
name,
- vm_av_zone,
+ storage_av_zone,
disk,
base_disk_index,
block_device_mapping,
"""Create persistent non-root volume."""
self.vimconn.cinder = CopyingMock()
self.vimconn.cinder.volumes.create.return_value.id = volume_id2
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("a")
disk = {"size": 10}
block_device_mapping = {}
self.vimconn._prepare_non_root_persistent_volumes(
name,
disk,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
base_disk_index,
existing_vim_volumes,
"""Create persistent non-root volume."""
self.vimconn.cinder = CopyingMock()
self.vimconn.cinder.volumes.create.return_value.id = volume_id2
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("a")
disk = {"size": 10, "keep": True}
block_device_mapping = {}
self.vimconn._prepare_non_root_persistent_volumes(
name,
disk,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
base_disk_index,
existing_vim_volumes,
class MyVolume:
name = "my-shared-volume"
id = volume_id4
+ availability_zone = ["nova"]
+ self.vimconn.storage_availability_zone = ["nova"]
self.vimconn.cinder.volumes.create.return_value = MyVolume()
shared_volume_data = {"size": 10, "name": "my-shared-volume"}
result = self.vimconn.new_shared_volumes(shared_volume_data)
self.vimconn.cinder.volumes.create.assert_called_once_with(
- size=10, name="my-shared-volume", volume_type="multiattach"
+ size=10,
+ name="my-shared-volume",
+ volume_type="multiattach",
+ availability_zone=["nova"],
)
self.assertEqual(result[0], "my-shared-volume")
self.assertEqual(result[1], volume_id4)
):
"""Create persistent root volume raise exception."""
self.vimconn.cinder.volumes.create.side_effect = Exception
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("a")
disk = {"size": 10, "image_id": image_id}
block_device_mapping = {}
with self.assertRaises(Exception):
result = self.vimconn._prepare_persistent_root_volumes(
name,
- vm_av_zone,
+ storage_av_zone,
disk,
base_disk_index,
block_device_mapping,
):
"""Create persistent non-root volume raise exception."""
self.vimconn.cinder.volumes.create.side_effect = Exception
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
base_disk_index = ord("b")
disk = {"size": 10}
block_device_mapping = {}
self.vimconn._prepare_non_root_persistent_volumes(
name,
disk,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
base_disk_index,
existing_vim_volumes,
existing_vim_volumes = []
created_items = {}
block_device_mapping = {}
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
mock_root_volumes.return_value = root_vol_id
mock_created_vol_availability.return_value = 10
name,
existing_vim_volumes,
created_items,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
disk_list2,
)
self.assertEqual(mock_non_root_volumes.call_count, 1)
mock_root_volumes.assert_called_once_with(
name="basicvm",
- vm_av_zone=["nova"],
+ storage_av_zone=["nova"],
disk={"size": 10, "image_id": image_id},
base_disk_index=97,
block_device_mapping={},
mock_non_root_volumes.assert_called_once_with(
name="basicvm",
disk={"size": 20},
- vm_av_zone=["nova"],
+ storage_av_zone=["nova"],
base_disk_index=98,
block_device_mapping={},
existing_vim_volumes=[],
"""Timeout exceeded while waiting for disks."""
existing_vim_volumes = []
created_items = {}
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
block_device_mapping = {}
mock_root_volumes.return_value = root_vol_id
name,
existing_vim_volumes,
created_items,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
disk_list2,
)
self.assertEqual(mock_non_root_volumes.call_count, 1)
mock_root_volumes.assert_called_once_with(
name="basicvm",
- vm_av_zone=["nova"],
+ storage_av_zone=["nova"],
disk={"size": 10, "image_id": image_id},
base_disk_index=97,
block_device_mapping={},
mock_non_root_volumes.assert_called_once_with(
name="basicvm",
disk={"size": 20},
- vm_av_zone=["nova"],
+ storage_av_zone=["nova"],
base_disk_index=98,
block_device_mapping={},
existing_vim_volumes=[],
existing_vim_volumes = []
created_items = {}
block_device_mapping = {}
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
mock_created_vol_availability.return_value = 2
mock_existing_vol_availability.return_value = 3
name,
existing_vim_volumes,
created_items,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
disk_list,
)
"""Persistent root volumes preparation raises error."""
existing_vim_volumes = []
created_items = {}
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
block_device_mapping = {}
mock_root_volumes.side_effect = Exception()
name,
existing_vim_volumes,
created_items,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
disk_list2,
)
mock_existing_vol_availability.assert_not_called()
mock_root_volumes.assert_called_once_with(
name="basicvm",
- vm_av_zone=["nova"],
+ storage_av_zone=["nova"],
disk={"size": 10, "image_id": image_id},
base_disk_index=97,
block_device_mapping={},
"""Non-root volumes preparation raises error."""
existing_vim_volumes = []
created_items = {}
- vm_av_zone = ["nova"]
+ storage_av_zone = ["nova"]
block_device_mapping = {}
mock_root_volumes.return_value = root_vol_id
name,
existing_vim_volumes,
created_items,
- vm_av_zone,
+ storage_av_zone,
block_device_mapping,
disk_list2,
)
self.assertEqual(mock_non_root_volumes.call_count, 1)
mock_root_volumes.assert_called_once_with(
name="basicvm",
- vm_av_zone=["nova"],
+ storage_av_zone=["nova"],
disk={"size": 10, "image_id": image_id},
base_disk_index=97,
block_device_mapping={},
mock_non_root_volumes.assert_called_once_with(
name="basicvm",
disk={"size": 20},
- vm_av_zone=["nova"],
+ storage_av_zone=["nova"],
base_disk_index=98,
block_device_mapping={},
existing_vim_volumes=[],
name=name,
existing_vim_volumes=[],
created_items={},
- vm_av_zone="nova",
+ storage_av_zone="nova",
block_device_mapping={},
disk_list=disk_list2,
)
name=name,
existing_vim_volumes=[],
created_items={},
- vm_av_zone="nova",
+ storage_av_zone="nova",
block_device_mapping={},
disk_list=disk_list2,
)
name=name,
existing_vim_volumes=[],
created_items={},
- vm_av_zone="nova",
+ storage_av_zone="nova",
block_device_mapping={},
disk_list=disk_list2,
)
name=name,
existing_vim_volumes=[],
created_items={},
- vm_av_zone="nova",
+ storage_av_zone="nova",
block_device_mapping={},
disk_list=disk_list2,
)
self.persistent_info = persistent_info
self.availability_zone = persistent_info.get("availability_zone", None)
+ self.storage_availability_zone = None
self.session = persistent_info.get("session", {"reload_client": True})
self.my_tenant_id = self.session.get("my_tenant_id")
self.nova = self.session.get("nova")
self.availability_zone = vim_availability_zones
else:
self.availability_zone = self._get_openstack_availablity_zones()
+ if "storage_availability_zone" in self.config:
+ self.storage_availability_zone = self.config.get(
+ "storage_availability_zone"
+ )
def _get_vm_availability_zone(
self, availability_zone_index, availability_zone_list
def _prepare_persistent_root_volumes(
self,
name: str,
- vm_av_zone: list,
+ storage_av_zone: list,
disk: dict,
base_disk_index: int,
block_device_mapping: dict,
Args:
name (str): Name of VM instance
- vm_av_zone (list): List of availability zones
+ storage_av_zone (list): Storage of availability zones
disk (dict): Disk details
base_disk_index (int): Disk index
block_device_mapping (dict): Block device details
# Disk may include only vim_volume_id or only vim_id."
# Use existing persistent root volume finding with volume_id or vim_id
key_id = "vim_volume_id" if "vim_volume_id" in disk.keys() else "vim_id"
-
if disk.get(key_id):
block_device_mapping["vd" + chr(base_disk_index)] = disk[key_id]
existing_vim_volumes.append({"id": disk[key_id]})
-
else:
# Create persistent root volume
volume = self.cinder.volumes.create(
name=name + "vd" + chr(base_disk_index),
imageRef=disk["image_id"],
# Make sure volume is in the same AZ as the VM to be attached to
- availability_zone=vm_av_zone,
+ availability_zone=storage_av_zone,
)
boot_volume_id = volume.id
self.update_block_device_mapping(
@catch_any_exception
def new_shared_volumes(self, shared_volume_data) -> (str, str):
+ availability_zone = (
+ self.storage_availability_zone
+ if self.storage_availability_zone
+ else self._get_vm_availability_zone
+ )
volume = self.cinder.volumes.create(
size=shared_volume_data["size"],
name=shared_volume_data["name"],
volume_type="multiattach",
+ availability_zone=availability_zone,
)
return volume.name, volume.id
self,
name: str,
disk: dict,
- vm_av_zone: list,
+ storage_av_zone: list,
block_device_mapping: dict,
base_disk_index: int,
existing_vim_volumes: list,
Args:
name (str): Name of VM instance
disk (dict): Disk details
- vm_av_zone (list): List of availability zones
+ storage_av_zone (list): Storage of availability zones
block_device_mapping (dict): Block device details
base_disk_index (int): Disk index
existing_vim_volumes (list): Existing disk details
size=disk["size"],
name=volume_name,
# Make sure volume is in the same AZ as the VM to be attached to
- availability_zone=vm_av_zone,
+ availability_zone=storage_av_zone,
)
self.update_block_device_mapping(
volume=volume,
name: str,
existing_vim_volumes: list,
created_items: dict,
- vm_av_zone: list,
+ storage_av_zone: list,
block_device_mapping: dict,
disk_list: list = None,
) -> None:
name (str): Name of Instance
existing_vim_volumes (list): List of existing volumes
created_items (dict): All created items belongs to VM
- vm_av_zone (list): VM availability zone
+ storage_av_zone (list): Storage availability zone
block_device_mapping (dict): Block devices to be attached to VM
disk_list (list): List of disks
base_disk_index = ord("a")
boot_volume_id = self._prepare_persistent_root_volumes(
name=name,
- vm_av_zone=vm_av_zone,
+ storage_av_zone=storage_av_zone,
disk=disk,
base_disk_index=base_disk_index,
block_device_mapping=block_device_mapping,
self._prepare_non_root_persistent_volumes(
name=name,
disk=disk,
- vm_av_zone=vm_av_zone,
+ storage_av_zone=storage_av_zone,
block_device_mapping=block_device_mapping,
base_disk_index=base_disk_index,
existing_vim_volumes=existing_vim_volumes,
availability_zone_index, availability_zone_list
)
+ storage_av_zone = (
+ self.storage_availability_zone
+ if self.storage_availability_zone
+ else vm_av_zone
+ )
+
if disk_list:
# Prepare disks
self._prepare_disk_for_vminstance(
name=name,
existing_vim_volumes=existing_vim_volumes,
created_items=created_items,
- vm_av_zone=vm_av_zone,
+ storage_av_zone=storage_av_zone,
block_device_mapping=block_device_mapping,
disk_list=disk_list,
)