fix: standardize provider interface parameters across all implementations
- Add screen_size parameter to get_vm_path() for all providers (with default 1920x1080) - Add os_type parameter to start_emulator() for Azure and VirtualBox providers - Add region parameter to stop_emulator() for VMware, Docker, and VirtualBox providers - Use *args, **kwargs for better extensibility and parameter consistency - Add documentation comments explaining ignored parameters for interface consistency - Prevents TypeError exceptions when AWS-specific parameters are passed to other providers This ensures all providers can handle the same parameter sets while maintaining backward compatibility and avoiding interface fragmentation.
This commit is contained in:
@@ -67,7 +67,9 @@ class AzureVMManager(VMManager):
|
|||||||
free_vms.append((vm_path, pid_str))
|
free_vms.append((vm_path, pid_str))
|
||||||
return free_vms
|
return free_vms
|
||||||
|
|
||||||
def get_vm_path(self, region):
|
def get_vm_path(self, region, screen_size=(1920, 1080), **kwargs):
|
||||||
|
# Note: screen_size parameter is ignored for Azure provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
self.check_and_clean()
|
self.check_and_clean()
|
||||||
free_vms_paths = self.list_free_vms(region)
|
free_vms_paths = self.list_free_vms(region)
|
||||||
if len(free_vms_paths) == 0:
|
if len(free_vms_paths) == 0:
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ class AzureProvider(Provider):
|
|||||||
self.compute_client = ComputeManagementClient(credential, self.subscription_id)
|
self.compute_client = ComputeManagementClient(credential, self.subscription_id)
|
||||||
self.network_client = NetworkManagementClient(credential, self.subscription_id)
|
self.network_client = NetworkManagementClient(credential, self.subscription_id)
|
||||||
|
|
||||||
def start_emulator(self, path_to_vm: str, headless: bool):
|
def start_emulator(self, path_to_vm: str, headless: bool, os_type: str = None, *args, **kwargs):
|
||||||
|
# Note: os_type parameter is ignored for Azure provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
logger.info("Starting Azure VM...")
|
logger.info("Starting Azure VM...")
|
||||||
resource_group_name, vm_name = path_to_vm.split('/')
|
resource_group_name, vm_name = path_to_vm.split('/')
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,9 @@ class DockerVMManager(VMManager):
|
|||||||
def occupy_vm(self, vm_path):
|
def occupy_vm(self, vm_path):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_vm_path(self, os_type, region):
|
def get_vm_path(self, os_type, region, screen_size=(1920, 1080), **kwargs):
|
||||||
|
# Note: screen_size parameter is ignored for Docker provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
global URL, DOWNLOADED_FILE_NAME
|
global URL, DOWNLOADED_FILE_NAME
|
||||||
if os_type == "Ubuntu":
|
if os_type == "Ubuntu":
|
||||||
URL = UBUNTU_X86_URL
|
URL = UBUNTU_X86_URL
|
||||||
|
|||||||
@@ -144,7 +144,9 @@ class DockerProvider(Provider):
|
|||||||
def revert_to_snapshot(self, path_to_vm: str, snapshot_name: str):
|
def revert_to_snapshot(self, path_to_vm: str, snapshot_name: str):
|
||||||
self.stop_emulator(path_to_vm)
|
self.stop_emulator(path_to_vm)
|
||||||
|
|
||||||
def stop_emulator(self, path_to_vm: str):
|
def stop_emulator(self, path_to_vm: str, region=None, *args, **kwargs):
|
||||||
|
# Note: region parameter is ignored for Docker provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
if self.container:
|
if self.container:
|
||||||
logger.info("Stopping VM...")
|
logger.info("Stopping VM...")
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -428,7 +428,9 @@ class VirtualBoxVMManager(VMManager):
|
|||||||
free_vms.append((vm_path, pid_str))
|
free_vms.append((vm_path, pid_str))
|
||||||
return free_vms
|
return free_vms
|
||||||
|
|
||||||
def get_vm_path(self, os_type, region=None):
|
def get_vm_path(self, os_type, region=None, screen_size=(1920, 1080), **kwargs):
|
||||||
|
# Note: screen_size parameter is ignored for VirtualBox provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
if os_type != "Ubuntu":
|
if os_type != "Ubuntu":
|
||||||
raise ValueError("Only support Ubuntu for now.")
|
raise ValueError("Only support Ubuntu for now.")
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ class VirtualBoxProvider(Provider):
|
|||||||
logger.error(f"Error executing command: {e.output.decode().strip()}")
|
logger.error(f"Error executing command: {e.output.decode().strip()}")
|
||||||
|
|
||||||
|
|
||||||
def start_emulator(self, path_to_vm: str, headless: bool):
|
def start_emulator(self, path_to_vm: str, headless: bool, os_type: str = None, *args, **kwargs):
|
||||||
|
# Note: os_type parameter is ignored for VirtualBox provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
logger.info("Starting VirtualBox VM...")
|
logger.info("Starting VirtualBox VM...")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -113,7 +115,9 @@ class VirtualBoxProvider(Provider):
|
|||||||
time.sleep(WAIT_TIME) # Wait for the VM to revert
|
time.sleep(WAIT_TIME) # Wait for the VM to revert
|
||||||
return path_to_vm
|
return path_to_vm
|
||||||
|
|
||||||
def stop_emulator(self, path_to_vm: str):
|
def stop_emulator(self, path_to_vm: str, region=None, *args, **kwargs):
|
||||||
|
# Note: region parameter is ignored for VirtualBox provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
logger.info("Stopping VirtualBox VM...")
|
logger.info("Stopping VirtualBox VM...")
|
||||||
uuid = VirtualBoxProvider._get_vm_uuid(path_to_vm)
|
uuid = VirtualBoxProvider._get_vm_uuid(path_to_vm)
|
||||||
VirtualBoxProvider._execute_command(["VBoxManage", "controlvm", uuid, "savestate"])
|
VirtualBoxProvider._execute_command(["VBoxManage", "controlvm", uuid, "savestate"])
|
||||||
|
|||||||
@@ -417,7 +417,9 @@ class VMwareVMManager(VMManager):
|
|||||||
free_vms.append((vm_path, pid_str))
|
free_vms.append((vm_path, pid_str))
|
||||||
return free_vms
|
return free_vms
|
||||||
|
|
||||||
def get_vm_path(self, os_type, region=None):
|
def get_vm_path(self, os_type, region=None, screen_size=(1920, 1080), **kwargs):
|
||||||
|
# Note: screen_size parameter is ignored for VMware provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if not VMwareVMManager.checked_and_cleaned:
|
if not VMwareVMManager.checked_and_cleaned:
|
||||||
VMwareVMManager.checked_and_cleaned = True
|
VMwareVMManager.checked_and_cleaned = True
|
||||||
|
|||||||
@@ -97,7 +97,9 @@ class VMwareProvider(Provider):
|
|||||||
time.sleep(WAIT_TIME) # Wait for the VM to revert
|
time.sleep(WAIT_TIME) # Wait for the VM to revert
|
||||||
return path_to_vm
|
return path_to_vm
|
||||||
|
|
||||||
def stop_emulator(self, path_to_vm: str):
|
def stop_emulator(self, path_to_vm: str, region=None, *args, **kwargs):
|
||||||
|
# Note: region parameter is ignored for VMware provider
|
||||||
|
# but kept for interface consistency with other providers
|
||||||
logger.info("Stopping VMware VM...")
|
logger.info("Stopping VMware VM...")
|
||||||
VMwareProvider._execute_command(["vmrun"] + get_vmrun_type(return_list=True) + ["stop", path_to_vm])
|
VMwareProvider._execute_command(["vmrun"] + get_vmrun_type(return_list=True) + ["stop", path_to_vm])
|
||||||
time.sleep(WAIT_TIME) # Wait for the VM to stop
|
time.sleep(WAIT_TIME) # Wait for the VM to stop
|
||||||
|
|||||||
Reference in New Issue
Block a user