@Test public void testTerminateNow() throws Exception { String managementPrefix = cloud.getProvider().getManagementGroup(); String agentPrefix = cloud.getProvider().getMachineNamePrefix(); // create a security group without the prefix, named : "TestTerminateNowSecurityGroup" SecurityGroup customSecurityGroup = createSecurityGroup(NON_CLOUDIFY_SECURITY_GROUP); // verify the expected resources are found assertServersCount(1, managementPrefix); assertServersCount(1, agentPrefix); assertRoutersCount(1, SHARED_TESTING_ROUTER); assertNetworksCount(2, managementPrefix); assertSecurityGroupsCount(5, managementPrefix); assertSecurityGroupsCount(1, NON_CLOUDIFY_SECURITY_GROUP); // run terminate-now this.cloudService.getBootstrapper().terminateNow(true); super.teardown(); // verify all resourced were removed, and only the custom security group is left assertServersCount(0, managementPrefix); teardownRequired = false; // if we got here the management server is down, cancel the teardown on @AfterClass assertServersCount(0, agentPrefix); assertRoutersCount(1, SHARED_TESTING_ROUTER); assertNetworksCount(0, managementPrefix); assertSecurityGroupsCount(0, managementPrefix); assertSecurityGroupsCount(1, NON_CLOUDIFY_SECURITY_GROUP); deleteSecurityGroup(customSecurityGroup.getId()); assertSecurityGroupsCount(0, NON_CLOUDIFY_SECURITY_GROUP); }
private SecurityGroup createSecurityGroup(final String securityGroupName) throws OpenstackException { final SecurityGroup request = new SecurityGroup(); request.setName(securityGroupName); request.setDescription("Cloudify generated security group " + securityGroupName); return networkClient.createSecurityGroupsIfNotExist(request); }
@AfterClass(alwaysRun = true) public void clean() throws Exception { if (teardownRequired) { super.teardown(); } // delete the custom security group if (networkClient != null) { List<SecurityGroup> customSecurityGroups = networkClient.getSecurityGroupsByPrefix(NON_CLOUDIFY_SECURITY_GROUP); for (SecurityGroup group : customSecurityGroups) { deleteSecurityGroup(group.getId()); } } }