Ejemplo n.º 1
0
 def test_create_no_file_throw_exception(
         self, mock_endpoint_operations: EndpointOperations,
         randstr: str) -> None:
     with pytest.raises(Exception):
         mock_endpoint_operations.create(type=ONLINE_ENDPOINT_TYPE,
                                         name=randstr,
                                         file=None)
Ejemplo n.º 2
0
 def test_online_create(
     self,
     mock_endpoint_operations: EndpointOperations,
     randstr: str,
     create_yaml_happy_path: str,
     mocker: MockFixture,
 ) -> None:
     mocker.patch(
         "azure.ml._operations.endpoint_operations.OperationOrchestrator.get_code_asset_arm_id",
         return_value="xxx")
     mocker.patch(
         "azure.ml._operations.endpoint_operations.OperationOrchestrator.get_environment_arm_id",
         return_value="xxx")
     mocker.patch(
         "azure.ml._operations.endpoint_operations.OperationOrchestrator.get_model_arm_id",
         return_value="xxx")
     mocker.patch(
         "azure.ml._operations.endpoint_operations.EndpointOperations._get_workspace_location",
         return_value="xxx")
     mocker.patch(
         "azure.ml._operations.endpoint_operations.OnlineEndpointArmGenerator.generate_online_endpoint_template",
         return_value=("xxx", []),
     )
     mocker.patch(
         "azure.ml._operations.endpoint_operations.ArmDeploymentExecutor.deploy_resource",
         return_value="xxx")
     mock_endpoint_operations._credentials = Mock(
         spec_set=DefaultAzureCredential)
     mock_endpoint_operations.create(type=ONLINE_ENDPOINT_TYPE,
                                     name=randstr,
                                     file=create_yaml_happy_path)
Ejemplo n.º 3
0
 def test_online_list_keys(self,
                           mock_endpoint_operations: EndpointOperations,
                           randstr: str, mock_aml_services: Mock) -> None:
     mock_aml_services.online_endpoints.get.return_value = OnlineEndpointPropertiesTrackedResource(
         name=randstr, properties=OnlineEndpointProperties(auth_mode="key"))
     mock_endpoint_operations.list_keys(type=ONLINE_ENDPOINT_TYPE,
                                        name=randstr)
     mock_endpoint_operations._online_operation.get.assert_called_once()
     mock_endpoint_operations._online_operation.list_keys.assert_called_once(
     )
Ejemplo n.º 4
0
 def test_online_get(self, mock_endpoint_operations: EndpointOperations,
                     randstr: str, mock_aml_services: Mock) -> None:
     mock_aml_services.online_endpoints.get.return_value = OnlineEndpointPropertiesTrackedResource(
         name=randstr,
         properties=OnlineEndpointProperties(
             compute_configuration=AksComputeConfiguration(
                 compute_name="compute"),
             auth_mode="key"),
     )
     mock_aml_services.online_deployments.list.return_value = None
     mock_endpoint_operations.get(type=ONLINE_ENDPOINT_TYPE, name=randstr)
     mock_endpoint_operations._online_operation.get.assert_called_once()
     mock_endpoint_operations._online_deployment.list.assert_called_once()
Ejemplo n.º 5
0
 def test_online_get_deployment_logs(
     self,
     mock_endpoint_operations: EndpointOperations,
     randstr: str,
     randint: int,
     deployment: str,
     mocker: MockFixture,
 ) -> None:
     mock_endpoint_operations.get_deployment_logs(randstr,
                                                  deployment,
                                                  randint,
                                                  type=ONLINE_ENDPOINT_TYPE)
     mock_endpoint_operations._online_deployment.get_logs.assert_called_once(
     )
Ejemplo n.º 6
0
 def test_online_delete_deployment_with_traffic_raise(
         self, mock_endpoint_operations: EndpointOperations, randstr: str,
         mock_aml_services: Mock) -> None:
     deployment_name = "blue"
     mock_aml_services.online_endpoints.get.return_value = OnlineEndpointPropertiesTrackedResource(
         name=randstr,
         properties=OnlineEndpointProperties(auth_mode="key",
                                             traffic_rules={
                                                 deployment_name: 1,
                                                 "red": 0
                                             }),
     )
     with pytest.raises(Exception):
         mock_endpoint_operations.delete(type=ONLINE_ENDPOINT_TYPE,
                                         name=randstr,
                                         deployment=deployment_name)
     mock_endpoint_operations._online_operation.get.assert_called_once()
Ejemplo n.º 7
0
    def __init__(
        self,
        subscription_id: str,
        resource_group_name: str,
        default_workspace_name: str = None,
        base_url: str = MFE_BASE_URL,
        credential: ChainedTokenCredential = None,
    ):
        base_url, enforce_https = _get_developer_override(base_url)
        kwargs = {"enforce_https": enforce_https}

        self._workspace_scope = WorkspaceScope(subscription_id, resource_group_name, default_workspace_name)

        if credential:
            self._credential = credential
        else:
            self._credential = self._default_chained_credentials()

        self._service_client = AzureMachineLearningWorkspaces(
            subscription_id=self._workspace_scope._subscription_id, credential=self._credential, base_url=base_url
        )

        self._operation_container = OperationsContainer()
        self._datastores = DatastoreOperations(self._workspace_scope, self._service_client, **kwargs)
        self._workspaces = WorkspaceOperations(self._workspace_scope, self._service_client)
        self._computes = ComputeOperations(self._workspace_scope, self._service_client)
        self._model = ModelOperations(self._workspace_scope, self._service_client, self._datastores)
        self._endpoints = EndpointOperations(
            self._workspace_scope, self._service_client, self._operation_container, self._credential, **kwargs
        )
        self._data = DataOperations(self._workspace_scope, self._service_client, self._datastores, **kwargs)
        self._code = CodeOperations(self._workspace_scope, self._service_client, self._datastores, **kwargs)
        self._environments = EnvironmentOperations(self._workspace_scope, self._service_client, **kwargs)
        self._jobs = JobOperations(self._workspace_scope, self._service_client, self._operation_container, **kwargs)

        self._operation_container.add(OperationTypes.WORKSPACES, self._workspaces)
        self._operation_container.add(OperationTypes.COMPUTES, self._computes)
        self._operation_container.add(OperationTypes.DATASTORES, self._datastores)
        self._operation_container.add(OperationTypes.MODELS, self._model)
        self._operation_container.add(OperationTypes.ENDPOINTS, self._endpoints)
        self._operation_container.add(OperationTypes.DATASETS, self._data)
        self._operation_container.add(OperationTypes.CODES, self._code)
        self._operation_container.add(OperationTypes.JOBS, self._jobs)
        self._operation_container.add(OperationTypes.ENVIRONMENTS, self._environments)
Ejemplo n.º 8
0
def mock_endpoint_operations(
    mock_workspace_scope: WorkspaceScope,
    mock_aml_services: Mock,
    mock_machinelearning_client: Mock,
    mock_environment_operations: Mock,
    mock_model_operations: Mock,
    mock_code_assets_operations: Mock,
) -> EndpointOperations:
    mock_machinelearning_client._operation_container.add(
        "code", mock_code_assets_operations)
    mock_machinelearning_client._operation_container.add(
        "model", mock_code_assets_operations)
    mock_machinelearning_client._operation_container.add(
        "environments", mock_code_assets_operations)
    yield EndpointOperations(
        workspace_scope=mock_workspace_scope,
        service_client=mock_aml_services,
        all_operations=mock_machinelearning_client._operation_container,
    )
Ejemplo n.º 9
0
 def test_batch_delete(self, mock_endpoint_operations: EndpointOperations,
                       randstr: str) -> None:
     mock_endpoint_operations.delete(type=BATCH_ENDPOINT_TYPE, name=randstr)
     mock_endpoint_operations._batch_operation.delete.assert_called_once()
Ejemplo n.º 10
0
 def test_batch_list(self,
                     mock_endpoint_operations: EndpointOperations) -> None:
     mock_endpoint_operations.list(type=BATCH_ENDPOINT_TYPE)
     mock_endpoint_operations._batch_operation.list.assert_called_once()
Ejemplo n.º 11
0
 def test_create_no_type_in_file_throw_exception(
         self, mock_endpoint_operations: EndpointOperations, randstr: str,
         create_yaml_no_type) -> None:
     with pytest.raises(Exception):
         mock_endpoint_operations.create(name=randstr, file=None)
Ejemplo n.º 12
0
 def test_online_delete(self, mock_endpoint_operations: EndpointOperations,
                        randstr: str) -> None:
     mock_endpoint_operations.delete(type=ONLINE_ENDPOINT_TYPE,
                                     name=randstr)
     mock_endpoint_operations._online_operation.delete.assert_called_once()
Ejemplo n.º 13
0
 def test_throw_if_random_type(
         self, mock_endpoint_operations: EndpointOperations) -> None:
     with pytest.raises(Exception):
         mock_endpoint_operations.list(type="test_type")
Ejemplo n.º 14
0
 def test_online_list(self,
                      mock_endpoint_operations: EndpointOperations) -> None:
     mock_endpoint_operations.list(type=ONLINE_ENDPOINT_TYPE)
     mock_endpoint_operations._online_operation.list.assert_called_once()