From 6103b4aede06924357eeeff2a0772cd4fd074890 Mon Sep 17 00:00:00 2001 From: Tomasz Tutka Date: Mon, 7 Oct 2024 08:55:41 +0200 Subject: [PATCH] added user prefix for creating resources, added protection to remove all created resources during tests --- .../fabric/tests/CloudRoutersApiTest.java | 12 ++++++++---- .../fabric/tests/ConnectionsApiTest.java | 19 +++++++++++-------- .../openapi/fabric/tests/NetworksApiTest.java | 9 ++++----- .../fabric/tests/RoutingProtocolsApiTest.java | 2 +- .../fabric/tests/ServiceProfilesApiTest.java | 15 +++++++++------ 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/CloudRoutersApiTest.java b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/CloudRoutersApiTest.java index 38708a6..40105ea 100644 --- a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/CloudRoutersApiTest.java +++ b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/CloudRoutersApiTest.java @@ -35,7 +35,11 @@ public class CloudRoutersApiTest { public static void removeCloudRouters(UsersItem.UserName userName) { users.get(userName).getUserResources().getCloudRoutersUuid().forEach(uuid -> { if (getCloudRouterStatus(uuid) == CloudRouterAccessPointState.PROVISIONED) { - deleteCloudRouter(uuid); + try { + deleteCloudRouter(uuid); + } catch (Exception e) { + + } } }); } @@ -192,7 +196,7 @@ public void searchCloudRouters() throws ApiException { @Test public void updateCloudRouterByUuid() throws ApiException { CloudRouter cloudRouter = createRouter(); - String updatedName = "panthers_new_fcr_name"; + String updatedName = "panthers_new_fcr_name" + getCurrentUser().getValue(); CloudRouterChangeOperation cloudRouterChangeOperation = new CloudRouterChangeOperation() .op(CloudRouterChangeOperation.OpEnum.REPLACE) @@ -209,7 +213,7 @@ public static void deleteCloudRouter(UUID uuid) { waitForCloudRouterIsProvisioned(uuid); cloudRoutersApi.deleteCloudRouterByUuid(uuid); } catch (ApiException e) { - throw new RuntimeException(e); + System.out.println("Cloud router has not been removed for " + uuid); } assertEquals(204, cloudRoutersApi.getApiClient().getStatusCode()); } @@ -225,7 +229,7 @@ public static CloudRouterAccessPointState getCloudRouterStatus(UUID cloudRouterU public static CloudRouter createRouter() throws ApiException { UsersItem user = Utils.getUserData(getCurrentUser()); - String cloudRouterName = "panthers-test-java-sdk"; + String cloudRouterName = "panthers-fcr-java" + getCurrentUser().getValue(); CloudRouterPostRequest cloudRouterPostRequest = new CloudRouterPostRequest(); cloudRouterPostRequest.type(CloudRouterPostRequest.TypeEnum.XF_ROUTER) .name(cloudRouterName) diff --git a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ConnectionsApiTest.java b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ConnectionsApiTest.java index 8b87a9d..9ed56c9 100644 --- a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ConnectionsApiTest.java +++ b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ConnectionsApiTest.java @@ -45,7 +45,6 @@ public static void removeConnections(UsersItem.UserName userName) { try { deleteConnection(uuid); } catch (ApiException e) { - throw new RuntimeException(e); } }); } @@ -212,7 +211,7 @@ public static Connection createConnectionFCR2ToPort() throws ApiException { public static ConnectionPostRequest getDefaultConnectionRequest(String name) { return new ConnectionPostRequest() - .name(name) + .name(name + getCurrentUser().getValue()) .notifications(singletonList(new SimplifiedNotification() .type(SimplifiedNotification.TypeEnum.ALL) .emails(singletonList("test@test.com")))); @@ -275,7 +274,7 @@ public static Connection createPort2SpConnection() throws ApiException { @Test public void updateConnectionByUuid() throws ApiException { Connection connection = createPort2Port(); - String updatedName = "updated_p2p_connection"; + String updatedName = "updated_p2p_connection" + getCurrentUser().getValue(); ConnectionChangeOperation connectionChangeOperation = new ConnectionChangeOperation() .op(OpEnum.REPLACE.getValue()) @@ -364,7 +363,7 @@ public static boolean waitForConnectionIsInState(String connectionUuid, EquinixS } } try { - Thread.sleep(30000); + Thread.sleep(15000); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -378,10 +377,14 @@ public static boolean waitForConnectionIsInState(String connectionUuid, EquinixS private static void deleteConnection(String uuid) throws ApiException { for (int i = 0; i < 3; i++) { - connectionsApi.deleteConnectionByUuid(uuid); - boolean isDeleted = waitForConnectionIsInState(uuid, EquinixStatus.DELETED, EquinixStatus.DEPROVISIONED); - if (isDeleted) { - break; + try { + connectionsApi.deleteConnectionByUuid(uuid); + boolean isDeleted = waitForConnectionIsInState(uuid, EquinixStatus.DELETED, EquinixStatus.DEPROVISIONED); + if (isDeleted) { + break; + } + } catch (Exception e) { + System.out.println("Connection has not been removed for " + uuid); } } } diff --git a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/NetworksApiTest.java b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/NetworksApiTest.java index f196088..ee21e9a 100644 --- a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/NetworksApiTest.java +++ b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/NetworksApiTest.java @@ -20,8 +20,7 @@ import java.util.UUID; -import static com.equinix.openapi.fabric.tests.helpers.Apis.networksApi; -import static com.equinix.openapi.fabric.tests.helpers.Apis.setUserName; +import static com.equinix.openapi.fabric.tests.helpers.Apis.*; import static com.equinix.openapi.fabric.tests.helpers.TokenGenerator.users; import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; @@ -50,7 +49,7 @@ public static void removeResources() { public Network createNetwork() throws ApiException { UsersItem user = Utils.getUserData(userName); NetworkPostRequest networkPostRequest = new NetworkPostRequest() - .name("network_panthers_test") + .name("network_panthers_test" + getCurrentUser().getValue()) .type(NetworkType.EVPLAN) .scope(NetworkScope.LOCAL) .project(new Project().projectId(user.getProjectId())) @@ -94,7 +93,7 @@ public static void deleteNetwork(UUID uuid) { assertEquals(202, networksApi.getApiClient().getStatusCode()); } } catch (ApiException e) { - throw new RuntimeException(e); + System.out.println("Network has not been removed for " + uuid); } } @@ -124,7 +123,7 @@ public void getNetworkByUuid() throws ApiException { */ @Test public void updateNetwork() throws ApiException { - String updatedName = "network_new_updatedName"; + String updatedName = "network_new_updatedName" + getCurrentUser().getValue(); Network network = createNetwork(); NetworkChangeOperation changeOperation = new NetworkChangeOperation() .op(NetworkChangeOperation.OpEnum.REPLACE) diff --git a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/RoutingProtocolsApiTest.java b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/RoutingProtocolsApiTest.java index fc47ec0..e8716b8 100644 --- a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/RoutingProtocolsApiTest.java +++ b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/RoutingProtocolsApiTest.java @@ -93,7 +93,7 @@ public static void deleteRoutingProtocol(UserResources.RoutingProtocolDto routin routingProtocolsApi.deleteConnectionRoutingProtocolByUuid(routingProtocolDto.getRoutingInstanceUuid(), String.valueOf(routingProtocolDto.getConnectionUuid())); assertEquals(202, routingProtocolsApi.getApiClient().getStatusCode()); } catch (ApiException e) { - throw new RuntimeException(e); + System.out.println("Routing protocol has not been removed for " + routingProtocolDto.getRoutingInstanceUuid()); } } diff --git a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ServiceProfilesApiTest.java b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ServiceProfilesApiTest.java index 25181c6..8215e5e 100644 --- a/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ServiceProfilesApiTest.java +++ b/equinix-openapi-fabric-tests/src/test/java/com/equinix/openapi/fabric/tests/ServiceProfilesApiTest.java @@ -25,8 +25,7 @@ import java.util.UUID; import static com.equinix.openapi.fabric.tests.PortsApiTest.getPorts; -import static com.equinix.openapi.fabric.tests.helpers.Apis.serviceProfilesApi; -import static com.equinix.openapi.fabric.tests.helpers.Apis.setUserName; +import static com.equinix.openapi.fabric.tests.helpers.Apis.*; import static com.equinix.openapi.fabric.tests.helpers.TokenGenerator.users; import static com.equinix.openapi.fabric.v4.model.Expression.OperatorEnum.EQUAL; import static java.util.Collections.singletonList; @@ -169,9 +168,13 @@ public void updateServiceProfileByUuid() throws ApiException { } private static void deleteServiceProfile(UUID uuid) throws ApiException { - serviceProfilesApi.deleteServiceProfileByUuid(uuid); - assertEquals(200, serviceProfilesApi.getApiClient().getStatusCode()); - waitForSpIsInState(uuid, ServiceProfileStateEnum.DELETED); + try { + serviceProfilesApi.deleteServiceProfileByUuid(uuid); + assertEquals(200, serviceProfilesApi.getApiClient().getStatusCode()); + waitForSpIsInState(uuid, ServiceProfileStateEnum.DELETED); + } catch (Exception e) { + System.out.println("Service profile has not been removed for " + uuid); + } } private static void waitForSpIsInState(UUID uuid, ServiceProfileStateEnum state) throws ApiException { @@ -208,7 +211,7 @@ private ServiceProfileRequest getServiceProfileRequest() throws ApiException { .filter(p -> p.getName().contains("Dot1q")) .findFirst().get(); return new ServiceProfileRequest() - .name("panthers-sp2-test" + RandomStringUtils.randomAlphabetic(5)) + .name("panthers-sp2-test" + RandomStringUtils.randomAlphabetic(5) + getCurrentUser().getValue()) .description("desc") .type(ServiceProfileTypeEnum.L2_PROFILE) .notifications(