Skip to content

Commit 519263b

Browse files
SRIKKANTHLiliDeng
authored andcommitted
Reduce latencies caused by frequent calls to"get_os_disk_controller_type"
VM's OS disk controller type doesn't change.
1 parent c3f2eeb commit 519263b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lisa/features/disks.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def remove_data_disk(self, names: Optional[List[str]] = None) -> None:
6868

6969
def _initialize(self, *args: Any, **kwargs: Any) -> None:
7070
self.disks: List[str] = []
71+
self._os_disk_controller_type: Optional[schema.DiskControllerType] = None
7172

7273
def get_resource_disk_mount_point(self) -> str:
7374
raise NotImplementedError
@@ -136,10 +137,13 @@ def get_disk_type(self, disk: str) -> schema.StorageInterfaceType:
136137

137138
# Get disk controller type from the VM by checking the boot partition
138139
def get_os_disk_controller_type(self) -> schema.DiskControllerType:
139-
boot_partition = self.get_os_boot_partition()
140-
assert boot_partition, "'boot_partition' must not be 'None'"
141-
os_disk_controller_type = self.get_disk_type(boot_partition.disk)
142-
return schema.DiskControllerType(os_disk_controller_type)
140+
if self._os_disk_controller_type is None:
141+
boot_partition = self.get_os_boot_partition()
142+
assert boot_partition, "'boot_partition' must not be 'None'"
143+
self._os_disk_controller_type = schema.DiskControllerType(
144+
self.get_disk_type(boot_partition.disk)
145+
)
146+
return self._os_disk_controller_type
143147

144148

145149
DiskEphemeral = partial(

0 commit comments

Comments
 (0)