Skip to content

Commit

Permalink
added user prefix for creating resources, added protection to remove …
Browse files Browse the repository at this point in the history
…all created resources during tests
  • Loading branch information
tutkat committed Oct 7, 2024
1 parent 10d2928 commit 6103b4a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
}
});
}
Expand Down Expand Up @@ -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)
Expand All @@ -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());
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static void removeConnections(UsersItem.UserName userName) {
try {
deleteConnection(uuid);
} catch (ApiException e) {
throw new RuntimeException(e);
}
});
}
Expand Down Expand Up @@ -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("[email protected]"))));
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6103b4a

Please sign in to comment.