|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Copyright 2022 Google LLC |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +import pytest |
| 18 | + |
| 19 | +from google.cloud import aiplatform |
| 20 | + |
| 21 | +from tests.system.aiplatform import e2e_base |
| 22 | + |
| 23 | +# permanent_custom_mnist_model |
| 24 | +_MODEL_ID = "6430031960164270080" |
| 25 | +_PRIVATE_ENDPOINT_NETWORK = "projects/580378083368/global/networks/private-endpoint-vpc" |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.usefixtures("tear_down_resources") |
| 29 | +class TestPrivateEndpoint(e2e_base.TestEndToEnd): |
| 30 | + |
| 31 | + _temp_prefix = "temp_vertex_sdk_e2e" |
| 32 | + |
| 33 | + def test_create_deploy_delete_private_endpoint(self, shared_state): |
| 34 | + # Collection of resources generated by this test, to be deleted during teardown |
| 35 | + shared_state["resources"] = [] |
| 36 | + |
| 37 | + aiplatform.init( |
| 38 | + project=e2e_base._PROJECT, |
| 39 | + location=e2e_base._LOCATION, |
| 40 | + ) |
| 41 | + |
| 42 | + private_endpoint = aiplatform.PrivateEndpoint.create( |
| 43 | + display_name=self._make_display_name("private_endpoint_test"), |
| 44 | + network=_PRIVATE_ENDPOINT_NETWORK, |
| 45 | + ) |
| 46 | + shared_state["resources"].append(private_endpoint) |
| 47 | + |
| 48 | + # Verify that the retrieved private Endpoint is the same |
| 49 | + my_private_endpoint = aiplatform.PrivateEndpoint( |
| 50 | + endpoint_name=private_endpoint.resource_name |
| 51 | + ) |
| 52 | + assert private_endpoint.resource_name == my_private_endpoint.resource_name |
| 53 | + assert private_endpoint.display_name == my_private_endpoint.display_name |
| 54 | + |
| 55 | + # Verify the endpoint is in the private Endpoint list |
| 56 | + list_private_endpoint = aiplatform.PrivateEndpoint.list() |
| 57 | + assert private_endpoint.resource_name in [ |
| 58 | + private_endpoint.resource_name for private_endpoint in list_private_endpoint |
| 59 | + ] |
| 60 | + |
| 61 | + # Retrieve permanent model, deploy to private Endpoint, then undeploy |
| 62 | + my_model = aiplatform.Model(model_name=_MODEL_ID) |
| 63 | + |
| 64 | + my_private_endpoint.deploy(model=my_model) |
| 65 | + assert my_private_endpoint._gca_resource.deployed_models |
| 66 | + |
| 67 | + deployed_model_id = my_private_endpoint.list_models()[0].id |
| 68 | + my_private_endpoint.undeploy(deployed_model_id=deployed_model_id) |
| 69 | + assert not my_private_endpoint._gca_resource.deployed_models |
0 commit comments