diff --git a/assets/responsibleai/environments/responsibleai-tabular/asset.yaml b/assets/responsibleai/environments/responsibleai-tabular/asset.yaml index c00c4b91fe..4e269e64cb 100644 --- a/assets/responsibleai/environments/responsibleai-tabular/asset.yaml +++ b/assets/responsibleai/environments/responsibleai-tabular/asset.yaml @@ -6,6 +6,6 @@ extra_config: environment.yaml test: pytest: enabled: true - pip_requirements: tests/requirements.txt + conda_environment: tests/test_conda_env.yaml tests_dir: tests categories: ["Responsible AI"] \ No newline at end of file diff --git a/assets/responsibleai/environments/responsibleai-tabular/tests/requirements.txt b/assets/responsibleai/environments/responsibleai-tabular/tests/requirements.txt index ee8748efec..c12e7a9183 100644 --- a/assets/responsibleai/environments/responsibleai-tabular/tests/requirements.txt +++ b/assets/responsibleai/environments/responsibleai-tabular/tests/requirements.txt @@ -1,4 +1,4 @@ -azure-ai-ml~=1.0.0 -azure.identity==1.10.0 -azureml-core~=1.53.0 +azure-ai-ml==1.22.4 +azure.identity==1.19.0 +azureml-core>=1.58.0 azureml-mlflow diff --git a/assets/responsibleai/environments/responsibleai-tabular/tests/responsibleai_sample_test.py b/assets/responsibleai/environments/responsibleai-tabular/tests/responsibleai_sample_test.py index 2950015eae..e6d1d92fb6 100644 --- a/assets/responsibleai/environments/responsibleai-tabular/tests/responsibleai_sample_test.py +++ b/assets/responsibleai/environments/responsibleai-tabular/tests/responsibleai_sample_test.py @@ -11,7 +11,7 @@ from azure.ai.ml.entities import Environment, BuildContext from azure.ai.ml import automl from azure.ai.ml.constants import AssetTypes -from azure.identity import AzureCliCredential +from azure.identity import DefaultAzureCredential BUILD_CONTEXT = Path("../context") @@ -53,8 +53,10 @@ def test_responsibleai(): resource_group = os.environ.get("resource_group") workspace_name = os.environ.get("workspace") + credential = DefaultAzureCredential() + ml_client = MLClient( - AzureCliCredential(), subscription_id, resource_group, workspace_name + credential, subscription_id, resource_group, workspace_name ) env_name = "responsibleai" diff --git a/assets/responsibleai/environments/responsibleai-tabular/tests/test_conda_env.yaml b/assets/responsibleai/environments/responsibleai-tabular/tests/test_conda_env.yaml new file mode 100644 index 0000000000..3552e3165e --- /dev/null +++ b/assets/responsibleai/environments/responsibleai-tabular/tests/test_conda_env.yaml @@ -0,0 +1,14 @@ +channels: + - conda-forge + - defaults + - anaconda +dependencies: + - python=3.12.0 + - pip + - pip: + - -r requirements.txt + ## Test requirements + - pytest + - tqdm + - azure-core +name: rai_test diff --git a/assets/responsibleai/environments/responsibleai-text/asset.yaml b/assets/responsibleai/environments/responsibleai-text/asset.yaml index 0ae9db86d7..d7c5fda6fc 100644 --- a/assets/responsibleai/environments/responsibleai-text/asset.yaml +++ b/assets/responsibleai/environments/responsibleai-text/asset.yaml @@ -5,7 +5,7 @@ spec: spec.yaml extra_config: environment.yaml test: pytest: - enabled: true - pip_requirements: tests/requirements.txt + enabled: true + conda_environment: tests/test_conda_env.yaml tests_dir: tests categories: ["Responsible AI"] \ No newline at end of file diff --git a/assets/responsibleai/environments/responsibleai-text/tests/responsibleai_text_sample_test.py b/assets/responsibleai/environments/responsibleai-text/tests/responsibleai_text_sample_test.py index 0750307f76..6fedaef701 100644 --- a/assets/responsibleai/environments/responsibleai-text/tests/responsibleai_text_sample_test.py +++ b/assets/responsibleai/environments/responsibleai-text/tests/responsibleai_text_sample_test.py @@ -9,7 +9,7 @@ from azure.ai.ml import command from azure.ai.ml.operations._run_history_constants import JobStatus from azure.ai.ml.entities import Environment, BuildContext -from azure.identity import AzureCliCredential +from azure.identity import DefaultAzureCredential BUILD_CONTEXT = Path("../context") JOB_SOURCE_CODE = "src" @@ -25,8 +25,10 @@ def test_responsibleai_text(): resource_group = os.environ.get("resource_group") workspace_name = os.environ.get("workspace") + credential = DefaultAzureCredential() + ml_client = MLClient( - AzureCliCredential(), subscription_id, resource_group, workspace_name + credential, subscription_id, resource_group, workspace_name ) env_name = "responsibleai-text" diff --git a/assets/responsibleai/environments/responsibleai-text/tests/test_conda_env.yaml b/assets/responsibleai/environments/responsibleai-text/tests/test_conda_env.yaml new file mode 100644 index 0000000000..3552e3165e --- /dev/null +++ b/assets/responsibleai/environments/responsibleai-text/tests/test_conda_env.yaml @@ -0,0 +1,14 @@ +channels: + - conda-forge + - defaults + - anaconda +dependencies: + - python=3.12.0 + - pip + - pip: + - -r requirements.txt + ## Test requirements + - pytest + - tqdm + - azure-core +name: rai_test diff --git a/assets/responsibleai/environments/responsibleai-vision/asset.yaml b/assets/responsibleai/environments/responsibleai-vision/asset.yaml index 9782ec7a65..c7ef0778bd 100644 --- a/assets/responsibleai/environments/responsibleai-vision/asset.yaml +++ b/assets/responsibleai/environments/responsibleai-vision/asset.yaml @@ -6,6 +6,6 @@ extra_config: environment.yaml test: pytest: enabled: true - pip_requirements: tests/requirements.txt + conda_environment: tests/test_conda_env.yaml tests_dir: tests categories: ["Responsible AI"] \ No newline at end of file diff --git a/assets/responsibleai/environments/responsibleai-vision/tests/responsibleai_vision_sample_test.py b/assets/responsibleai/environments/responsibleai-vision/tests/responsibleai_vision_sample_test.py index e299d37c08..ece02bb116 100644 --- a/assets/responsibleai/environments/responsibleai-vision/tests/responsibleai_vision_sample_test.py +++ b/assets/responsibleai/environments/responsibleai-vision/tests/responsibleai_vision_sample_test.py @@ -8,7 +8,9 @@ from azure.ai.ml import MLClient from azure.ai.ml import command from azure.ai.ml.entities import Environment, BuildContext -from azure.identity import AzureCliCredential +from azure.identity import DefaultAzureCredential +from azure.core.credentials import AccessToken, TokenCredential +from datetime import datetime, timedelta BUILD_CONTEXT = Path("../context") JOB_SOURCE_CODE = "src" @@ -16,6 +18,20 @@ STD_LOG = Path("artifacts/user_logs/std_log.txt") +class CustomTokenCredential(TokenCredential): + """Custom token credential class for runner.""" + + def __init__(self, token): + """Initialize custom token credential class.""" + self.token = token + + def get_token(self, *scopes): + """Get token.""" + two_hours_from_now = datetime.now() + timedelta(hours=2) + utc_timestamp = int(two_hours_from_now.timestamp()) + return AccessToken(self.token, utc_timestamp) + + def test_responsibleai_vision(): """Tests a sample job using responsibleai vision image as the environment.""" this_dir = Path(__file__).parent @@ -24,8 +40,13 @@ def test_responsibleai_vision(): resource_group = os.environ.get("resource_group") workspace_name = os.environ.get("workspace") + my_env = os.environ.copy() + if my_env['token']: + print("token is set in environment") + credential = CustomTokenCredential(my_env['token']) + ml_client = MLClient( - AzureCliCredential(), subscription_id, resource_group, workspace_name + credential, subscription_id, resource_group, workspace_name ) env_name = "responsibleai-vision" diff --git a/assets/responsibleai/environments/responsibleai-vision/tests/test_conda_env.yaml b/assets/responsibleai/environments/responsibleai-vision/tests/test_conda_env.yaml new file mode 100644 index 0000000000..3552e3165e --- /dev/null +++ b/assets/responsibleai/environments/responsibleai-vision/tests/test_conda_env.yaml @@ -0,0 +1,14 @@ +channels: + - conda-forge + - defaults + - anaconda +dependencies: + - python=3.12.0 + - pip + - pip: + - -r requirements.txt + ## Test requirements + - pytest + - tqdm + - azure-core +name: rai_test