def test_get_default_with_secrets( self, mock_datastore_operation: DatastoreOperations): mock_datastore_operation.get_default(include_secrets=True) mock_datastore_operation._operation.list.assert_called_once() assert "is_default=True" in str( mock_datastore_operation._operation.list.call_args) mock_datastore_operation._operation.list_secrets.assert_called_once()
def test_list_with_secrets( self, mock_datastore_operation: DatastoreOperations) -> None: mock_datastore_operation._operation.list.return_value = [ Mock() for _ in range(5) ] mock_datastore_operation.list(include_secrets=True) mock_datastore_operation._operation.list.assert_called_once() assert mock_datastore_operation._operation.list_secrets.call_count == 5
def test_attach_azure_blob_storage( self, mock_datastore_operation: DatastoreOperations, datastore_name: str, azure_storage_account_name: str, azure_storage_container_name: str, ) -> None: mock_datastore_operation.attach_azure_blob_storage( datastore_name, azure_storage_container_name, azure_storage_account_name) mock_datastore_operation._operation.create_or_update.assert_called_once( )
def _upload_to_datastore(workspace_scope: WorkspaceScope, datastore_operation: DatastoreOperations, path: Union[str, Path, os.PathLike], datastore_name: str = None, show_progress: bool = True, include_container_in_asset_path: bool = False) -> Tuple[AssetPath, str]: _validate_path(path) datastore_name = datastore_name or datastore_operation.get_default().name asset_hash = get_object_hash(path) asset_path = upload_artifact(str(path), datastore_operation, datastore_name, show_progress=show_progress, asset_hash=asset_hash, include_container_in_asset_path=include_container_in_asset_path) datastore_resource_id = get_datastore_arm_id(datastore_name, workspace_scope) return asset_path, datastore_resource_id
def get_datastore_info(operations: DatastoreOperations, name: str) -> Dict[str, str]: """ Get datastore account, type, and auth information """ datastore_info = {} datastore_resource = operations.show(name, include_secrets=True) storage_section = datastore_resource.properties.contents.azure_storage credentials = storage_section.credentials datastore_info["storage_type"] = str(datastore_resource.properties.contents.type) datastore_info["storage_account"] = storage_section.account_name datastore_info["container_name"] = str(storage_section.container_name) datastore_info["credential"] = credentials.account_key.key or credentials.sas.sas_token datastore_info["storage_type"] = str(datastore_resource.properties.contents.type) return datastore_info
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)
def mock_datastore_operation(mock_workspace_scope: WorkspaceScope, mock_aml_services: Mock) -> DatastoreOperations: yield DatastoreOperations(workspace_scope=mock_workspace_scope, service_client=mock_aml_services)
def test_get_default(self, mock_datastore_operation: DatastoreOperations): mock_datastore_operation.get_default() mock_datastore_operation._operation.list.assert_called_once() assert "is_default=True" in str( mock_datastore_operation._operation.list.call_args)
def test_show_no_secrets_with_secrets( self, mock_datastore_operation: DatastoreOperations, randstr: str) -> None: mock_datastore_operation.show(randstr, include_secrets=True) mock_datastore_operation._operation.get.assert_called_once() mock_datastore_operation._operation.list_secrets.assert_called_once()
def test_delete(self, mock_datastore_operation: DatastoreOperations, randstr: str) -> None: mock_datastore_operation.delete(randstr) mock_datastore_operation._operation.delete.assert_called_once()
def test_list(self, mock_datastore_operation: DatastoreOperations) -> None: mock_datastore_operation.list() mock_datastore_operation._operation.list.assert_called_once() mock_datastore_operation._operation.list_secrets.assert_not_called()