@@ -1045,7 +1045,7 @@ def get(self, key, default=None):
10451045
10461046
10471047def test_create_model_version_with_path_source (mlflow_client ):
1048- name = "mode "
1048+ name = "model "
10491049 mlflow_client .create_registered_model (name )
10501050 exp_id = mlflow_client .create_experiment ("test" )
10511051 run = mlflow_client .create_run (experiment_id = exp_id )
@@ -1084,6 +1084,100 @@ def test_create_model_version_with_path_source(mlflow_client):
10841084 assert "To use a local path as a model version" in response .json ()["message" ]
10851085
10861086
1087+ def test_create_model_version_with_non_local_source (mlflow_client , monkeypatch ):
1088+ name = "model"
1089+ mlflow_client .create_registered_model (name )
1090+ exp_id = mlflow_client .create_experiment ("test" )
1091+ run = mlflow_client .create_run (experiment_id = exp_id )
1092+
1093+ response = requests .post (
1094+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1095+ json = {
1096+ "name" : name ,
1097+ "source" : run .info .artifact_uri [len ("file://" ) :],
1098+ "run_id" : run .info .run_id ,
1099+ },
1100+ )
1101+ assert response .status_code == 200
1102+
1103+ # Test that remote uri's supplied as a source with absolute paths work fine
1104+ response = requests .post (
1105+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1106+ json = {
1107+ "name" : name ,
1108+ "source" : "mlflow-artifacts:/models" ,
1109+ "run_id" : run .info .run_id ,
1110+ },
1111+ )
1112+ assert response .status_code == 200
1113+
1114+ response = requests .post (
1115+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1116+ json = {
1117+ "name" : name ,
1118+ "source" : "mlflow-artifacts://host:9000/models" ,
1119+ "run_id" : run .info .run_id ,
1120+ },
1121+ )
1122+ assert response .status_code == 200
1123+
1124+ # Test that invalid remote uri's cannot be created
1125+ response = requests .post (
1126+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1127+ json = {
1128+ "name" : name ,
1129+ "source" : "mlflow-artifacts://host:9000/models/../../../" ,
1130+ "run_id" : run .info .run_id ,
1131+ },
1132+ )
1133+ assert response .status_code == 400
1134+ assert "If supplying a source as an http, https," in response .json ()["message" ]
1135+
1136+ response = requests .post (
1137+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1138+ json = {
1139+ "name" : name ,
1140+ "source" : "http://host:9000/models/../../../" ,
1141+ "run_id" : run .info .run_id ,
1142+ },
1143+ )
1144+ assert response .status_code == 400
1145+ assert "If supplying a source as an http, https," in response .json ()["message" ]
1146+
1147+ response = requests .post (
1148+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1149+ json = {
1150+ "name" : name ,
1151+ "source" : "https://host/api/2.0/mlflow-artifacts/artifacts/../../../" ,
1152+ "run_id" : run .info .run_id ,
1153+ },
1154+ )
1155+ assert response .status_code == 400
1156+ assert "If supplying a source as an http, https," in response .json ()["message" ]
1157+
1158+ response = requests .post (
1159+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1160+ json = {
1161+ "name" : name ,
1162+ "source" : "s3a://my_bucket/api/2.0/mlflow-artifacts/artifacts/../../../" ,
1163+ "run_id" : run .info .run_id ,
1164+ },
1165+ )
1166+ assert response .status_code == 400
1167+ assert "If supplying a source as an http, https," in response .json ()["message" ]
1168+
1169+ response = requests .post (
1170+ f"{ mlflow_client .tracking_uri } /api/2.0/mlflow/model-versions/create" ,
1171+ json = {
1172+ "name" : name ,
1173+ "source" : "ftp://host:8888/api/2.0/mlflow-artifacts/artifacts/../../../" ,
1174+ "run_id" : run .info .run_id ,
1175+ },
1176+ )
1177+ assert response .status_code == 400
1178+ assert "If supplying a source as an http, https," in response .json ()["message" ]
1179+
1180+
10871181def test_create_model_version_with_file_uri (mlflow_client ):
10881182 name = "test"
10891183 mlflow_client .create_registered_model (name )
0 commit comments