Skip to content

Commit

Permalink
Move deploymentName from the Service config to the Environment config
Browse files Browse the repository at this point in the history
Needed so that we can support multiple Environment deployments under the same Service.

Closes microsoft#610
  • Loading branch information
bpkroth committed Nov 30, 2023
1 parent bab3ca5 commit ae45996
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
"description": "The name of the resource group to place the deployment in (typically provided in the global config in order to omit from source control).",
"type": "string"
},
"deploymentName": {
"$comment": "TODO: provide templating strings to augment names via experiment_id/trial_id, for instance.",
"description": "Name of the deployment to create for the experiment resources.",
"type": "string"
},
"deploymentTemplatePath": {
"description": "Path to an ARM template file.",
"type": "string",
Expand Down Expand Up @@ -56,7 +51,6 @@
}
},
"required": [
"deploymentName",
"deploymentTemplatePath"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// can be overridden by the parameters pushed from the caller Environment.
"subscription": "PLACEHOLDER; AZURE SUBSCRIPTION ID",
"resourceGroup": "PLACEHOLDER; e.g., os-autotune",
"deploymentName": "PLACEHOLDER; e.g., mlos-2vms",

"deploymentTemplatePath": "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def __init__(self,
])
)

def _set_default_params(self, params: dict) -> dict: # pylint: disable=no-self-use
# Try and provide a semi sane default for the deploymentName if not provided
# since this is a common way to set the deploymentName and can same some
# config work for the caller.
if 'vnetName' not in params:
raise ValueError("Required param 'vnetName' is missing.")
params.setdefault(f"{params['vnetName']}-deployment")
return params

def wait_network_deployment(self, params: dict, *, is_setup: bool) -> Tuple[Status, dict]:
"""
Waits for a pending operation on an Azure VM to resolve to SUCCEEDED or FAILED.
Expand Down Expand Up @@ -127,6 +136,7 @@ def deprovision_network(self, params: dict, ignore_errors: bool = True) -> Tuple
A pair of Status and result. The result is always {}.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(),
source=params,
Expand Down
27 changes: 24 additions & 3 deletions mlos_bench/mlos_bench/services/remote/azure/azure_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def __init__(self,
check_required_params(self.config, [
"subscription",
"resourceGroup",
"deploymentName",
"deploymentTemplatePath",
"deploymentTemplateParameters",
])
Expand Down Expand Up @@ -102,6 +101,23 @@ def deploy_params(self) -> dict:
"""
return self._deploy_params

@abc.abstractmethod
def _set_default_params(self, params: dict) -> dict:
"""
Optionally set some default parameters for the request.
Parameters
----------
params : dict
The parameters.
Returns
-------
dict
The updated parameters.
"""
raise NotImplementedError("Should be overridden by subclass.")

def _get_session(self, params: dict) -> requests.Session:
"""
Get a session object that includes automatic retries and headers for REST API calls.
Expand Down Expand Up @@ -250,7 +266,8 @@ def _wait_deployment(self, params: dict, *, is_setup: bool) -> Tuple[Status, dic
Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT}
Result is info on the operation runtime if SUCCEEDED, otherwise {}.
"""
_LOG.info("Wait for %s to %s", params.get("deploymentName") or self.config.get("deploymentName"),
params = self._set_default_params(params)
_LOG.info("Wait for %s to %s", params.get("deploymentName"),
"provision" if is_setup else "deprovision")
return self._wait_while(self._check_deployment, Status.PENDING, params)

Expand All @@ -268,12 +285,14 @@ def _wait_while(self, func: Callable[[dict], Tuple[Status, dict]],
Steady state status - keep polling `func` while it returns `loop_status`.
params : dict
Flat dictionary of (key, value) pairs of tunable parameters.
Requires deploymentName.
Returns
-------
result : (Status, dict)
A pair of Status and result.
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(), source=params, required_keys=["deploymentName"])

Expand Down Expand Up @@ -322,6 +341,7 @@ def _check_deployment(self, params: dict) -> Tuple[Status, dict]: # pylint: di
A pair of Status and result. The result is always {}.
Status is one of {SUCCEEDED, PENDING, FAILED}
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(),
source=params,
Expand Down Expand Up @@ -387,7 +407,8 @@ def _provision_resource(self, params: dict) -> Tuple[Status, dict]:
parameters extracted from the response JSON, or {} if the status is FAILED.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
config = merge_parameters(dest=self.config.copy(), source=params)
params = self._set_default_params(params)
config = merge_parameters(dest=self.config.copy(), source=params, required_keys=["deploymentName"])
_LOG.info("Deploy: %s :: %s", config["deploymentName"], params)

params = merge_parameters(dest=self._deploy_params.copy(), source=params)
Expand Down
17 changes: 17 additions & 0 deletions mlos_bench/mlos_bench/services/remote/azure/azure_vm_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ def __init__(self,
with open(self._custom_data_file, 'r', encoding='utf-8') as custom_data_fh:
self._deploy_params["customData"] = custom_data_fh.read()

def _set_default_params(self, params: dict) -> dict: # pylint: disable=no-self-use
# Try and provide a semi sane default for the deploymentName if not provided
# since this is a common way to set the deploymentName and can same some
# config work for the caller.
if 'vmName' not in params:
raise ValueError("Required param 'vmName' is missing.")
params.setdefault(f"{params['vmName']}-deployment")
return params

def wait_host_deployment(self, params: dict, *, is_setup: bool) -> Tuple[Status, dict]:
"""
Waits for a pending operation on an Azure VM to resolve to SUCCEEDED or FAILED.
Expand Down Expand Up @@ -203,6 +212,8 @@ def wait_host_operation(self, params: dict) -> Tuple[Status, dict]:
Result is info on the operation runtime if SUCCEEDED, otherwise {}.
"""
_LOG.info("Wait for operation on VM %s", params["vmName"])
# Try and provide a semi sane default for the deploymentName
params.setdefault(f"{params['vmName']}-deployment")
return self._wait_while(self._check_operation_status, Status.RUNNING, params)

def wait_os_operation(self, params: dict) -> Tuple["Status", dict]:
Expand Down Expand Up @@ -243,6 +254,7 @@ def deprovision_host(self, params: dict) -> Tuple[Status, dict]:
A pair of Status and result. The result is always {}.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(),
source=params,
Expand Down Expand Up @@ -280,6 +292,7 @@ def deallocate_host(self, params: dict) -> Tuple[Status, dict]:
A pair of Status and result. The result is always {}.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(),
source=params,
Expand Down Expand Up @@ -311,6 +324,7 @@ def start_host(self, params: dict) -> Tuple[Status, dict]:
A pair of Status and result. The result is always {}.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(),
source=params,
Expand Down Expand Up @@ -344,6 +358,7 @@ def stop_host(self, params: dict, force: bool = False) -> Tuple[Status, dict]:
A pair of Status and result. The result is always {}.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(),
source=params,
Expand Down Expand Up @@ -380,6 +395,7 @@ def restart_host(self, params: dict, force: bool = False) -> Tuple[Status, dict]
A pair of Status and result. The result is always {}.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
params = self._set_default_params(params)
config = merge_parameters(
dest=self.config.copy(),
source=params,
Expand Down Expand Up @@ -422,6 +438,7 @@ def remote_exec(self, script: Iterable[str], config: dict,
A pair of Status and result.
Status is one of {PENDING, SUCCEEDED, FAILED}
"""
config = self._set_default_params(config)
config = merge_parameters(
dest=self.config.copy(),
source=config,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"class": "mlos_bench.services.remote.azure.AzureNetworkService",
"config": {
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
//"deploymentTemplatePath": "some/path/to/deployment/template.jsonc", // <-- missing
"subscription": "subscription-id",
"resourceGroup": "rg"
//"deploymentName": "deployment" // <-- missing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"subscription": "subscription-id",

"resourceGroup": "rg",
"deploymentName": "deployment",
"deploymentTemplateParameters": {
"array": [ { "invalid": "type"} ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"subscription": "subscription-id",

"resourceGroup": "rg",
"deploymentName": "deployment",
"deploymentTemplateParameters": {
"array": [ ["nested", "array", "invalid"] ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"subscription": "subscription-id",

"resourceGroup": "rg",
"deploymentName": "deployment",
"deploymentTemplateParameters": {
"object": { "invalid": "type" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"config": {
"subscription": "subscription-id",
"resourceGroup": "rg",
"deploymentName": "deployment",
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
"deploymentTemplateParameters": {
// "param": "value" // <-- need at least one parameter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"class": "mlos_bench.services.remote.azure.AzureVMService",
"config": {
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
// "deploymentTemplatePath": "some/path/to/deployment/template.jsonc", // <-- missing
"subscription": "subscription-id",
"resourceGroup": "rg"
//"deploymentName": "deployment" // <-- missing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
"subscription": "subscription-id",
"resourceGroup": "rg",
"deploymentName": "deployment",
"vmName": "test-vm",
"extra": "invalid"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
"subscription": "subscription-id",
"resourceGroup": "rg",
"deploymentName": "deployment",
"vmName": "test-vm",
"extra": "invalid"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
"subscription": "subscription-id",
"resourceGroup": "rg",
"deploymentName": "${experiment_id}-vnet-deployment",

"deploymentTemplateParameters": {
"location": "westus2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
"subscription": "subscription-id",
"resourceGroup": "rg",
"deploymentName": "deployment",

"customDataFile": "some/path/to/custom/data.yml",
"deploymentTemplateParameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"config": {
"subscription": "subscription-id",
"resourceGroup": "rg",
"deploymentName": "deployment",
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
"deploymentTemplateParameters": {
"param": "value"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"class": "mlos_bench.services.remote.azure.AzureVMService",
"config": {
"deploymentName": "deployment",
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"config": {
"subscription": "subscription-id",
"resourceGroup": "rg",
"deploymentName": "deployment",
"deploymentTemplatePath": "some/path/to/deployment/template.jsonc",
"deploymentTemplateParameters": {
"param": "value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def test_azure_vm_service_recursive_template_params(azure_auth_service: AzureAut
"""
config = {
"deploymentTemplatePath": "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc",
"deploymentName": "TEST_DEPLOYMENT1",
"subscription": "TEST_SUB1",
"resourceGroup": "TEST_RG1",
"deploymentTemplateParameters": {
Expand All @@ -72,6 +71,7 @@ def test_azure_vm_service_recursive_template_params(azure_auth_service: AzureAut
},
}
global_config = {
"deploymentName": "TEST_DEPLOYMENT1",
"vmName": "test-vm",
"location": "eastus",
}
Expand All @@ -88,14 +88,14 @@ def test_azure_vm_service_custom_data(azure_auth_service: AzureAuthService) -> N
config = {
"customDataFile": "services/remote/azure/cloud-init/alt-ssh.yml",
"deploymentTemplatePath": "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc",
"deploymentName": "TEST_DEPLOYMENT1",
"subscription": "TEST_SUB1",
"resourceGroup": "TEST_RG1",
"deploymentTemplateParameters": {
"location": "eastus2",
},
}
global_config = {
"deploymentName": "TEST_DEPLOYMENT1",
"vmName": "test-vm",
}
with pytest.raises(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions mlos_bench/mlos_bench/tests/services/remote/azure/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def azure_network_service(azure_auth_service: AzureAuthService) -> AzureNetworkS
"""
return AzureNetworkService(config={
"deploymentTemplatePath": "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc",
"deploymentName": "TEST_DEPLOYMENT-VNET",
"subscription": "TEST_SUB",
"resourceGroup": "TEST_RG",
"deploymentTemplateParameters": {
Expand All @@ -56,6 +55,7 @@ def azure_network_service(azure_auth_service: AzureAuthService) -> AzureNetworkS
"pollInterval": 1,
"pollTimeout": 2
}, global_config={
"deploymentName": "TEST_DEPLOYMENT-VNET",
"vnetName": "test-vnet", # Should come from the upper-level config
}, parent=azure_auth_service)

Expand All @@ -67,7 +67,6 @@ def azure_vm_service(azure_auth_service: AzureAuthService) -> AzureVMService:
"""
return AzureVMService(config={
"deploymentTemplatePath": "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc",
"deploymentName": "TEST_DEPLOYMENT-VM",
"subscription": "TEST_SUB",
"resourceGroup": "TEST_RG",
"deploymentTemplateParameters": {
Expand All @@ -76,6 +75,7 @@ def azure_vm_service(azure_auth_service: AzureAuthService) -> AzureVMService:
"pollInterval": 1,
"pollTimeout": 2
}, global_config={
"deploymentName": "TEST_DEPLOYMENT-VM",
"vmName": "test-vm", # Should come from the upper-level config
}, parent=azure_auth_service)

Expand Down

0 comments on commit ae45996

Please sign in to comment.