Search in sources :

Example 1 with CloudInterface

use of org.apache.airavata.cloud.intf.CloudInterface in project airavata by apache.

the class CloudIntfTest method jetstreamCreateDeleteNetworkTest.

/**
 * Jetstream create delete network test.
 */
@Test
@Ignore
public void jetstreamCreateDeleteNetworkTest() {
    try {
        CloudInterface cloudIntf = new OpenstackIntfImpl("jetstream_openrc.properties");
        /* fetch sample data from properties file */
        String networkName = properties.getProperty("jetstream_network_name");
        String subnetCIDR = properties.getProperty("jetstream_subnet_cidr");
        Integer ipVersion = Integer.valueOf(properties.getProperty("jetstream_ip_version", Constants.OS_IP_VERSION_DEFAULT.toString()));
        String externalGateway = properties.getProperty("jetstream_public_network_name");
        /* build router and subnet names */
        String subnetName = "subnet-" + networkName;
        String routerName = "router-" + networkName;
        /*  create network */
        logger.info("Creating network with name = " + networkName);
        Network network = (Network) cloudIntf.createNetwork(networkName);
        assertTrue(network != null && network.getName().equals(networkName));
        /* create subnet for network */
        logger.info("Creating subnet with name = " + subnetName + ", and CIDR = " + subnetCIDR + ", and version = " + ipVersion);
        Subnet subnet = (Subnet) cloudIntf.createSubnet(subnetName, networkName, subnetCIDR, ipVersion);
        assertTrue(subnet != null && subnet.getName().equals(subnetName) && subnet.getCidr().equals(subnetCIDR) && subnet.getIpVersion().getVersion() == ipVersion.intValue());
        /* create router for external gateway */
        logger.info("Creating router with name = " + routerName + ", and external gateway = " + externalGateway);
        Router router = (Router) cloudIntf.createRouter(routerName, externalGateway);
        assertTrue(router != null && router.getName().equals(routerName));
        /* create router-subnet interface */
        logger.info("Creating interface between router = " + routerName + ", and subnet = " + subnetName);
        RouterInterface iface = (RouterInterface) cloudIntf.createRouterSubnetInterface(routerName, subnetName);
        assertTrue(iface != null && iface.getSubnetId().equals(subnet.getId()));
        /* delete router-subnet interface */
        logger.info("Deleting interface between router = " + routerName + ", and subnet = " + subnetName);
        cloudIntf.deleteRouterSubnetInterface(routerName, subnetName);
        /* delete router for external gateway */
        logger.info("Creating router with name = " + routerName);
        cloudIntf.deleteRouter(routerName);
        /* delete subnet for network */
        logger.info("Creating subnet with name = " + subnetName);
        cloudIntf.deleteSubnet(subnetName);
        /* delete network */
        logger.info("Deleting network with name = " + networkName);
        cloudIntf.deleteNetwork(networkName);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
}
Also used : CloudInterface(org.apache.airavata.cloud.intf.CloudInterface) OpenstackIntfImpl(org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl) Network(org.openstack4j.model.network.Network) Router(org.openstack4j.model.network.Router) RouterInterface(org.openstack4j.model.network.RouterInterface) Subnet(org.openstack4j.model.network.Subnet) FileNotFoundException(java.io.FileNotFoundException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with CloudInterface

use of org.apache.airavata.cloud.intf.CloudInterface in project airavata by apache.

the class CloudIntfTest method jetstreamCreateDeleteServerTest.

/**
 * Test that will create keypair, create server with keypair, delete server, delete keypair.
 */
@Test
@Ignore
public void jetstreamCreateDeleteServerTest() {
    try {
        CloudInterface cloudIntf = new OpenstackIntfImpl("jetstream_openrc.properties");
        // Sample data. This can be determined by the inputs from Airavata.
        String imageId = properties.getProperty("jetstream_imageId");
        String flavorId = properties.getProperty("jetstream_flavorId");
        // Delay in milliseconds used for waiting for server create and delete.
        Integer delay = 30000;
        /* Create Keypair */
        String publicKeyFile = properties.getProperty("publicKeyFile");
        String keyPairName = "testKey";
        Scanner fileScan = new Scanner(new FileInputStream(publicKeyFile));
        String publicKey = fileScan.nextLine();
        Keypair kp = (Keypair) cloudIntf.getKeyPair(keyPairName);
        if (kp == null) {
            kp = (Keypair) cloudIntf.createKeyPair(keyPairName, publicKey);
        }
        logger.info("Keypair created/ retrieved: " + kp.getFingerprint());
        /* Create Server */
        Server newServer = (Server) cloudIntf.createServer("AiravataTest", imageId, flavorId, kp.getName());
        logger.info("Server Created: " + newServer.getId());
        /* Wait 30 seconds until server is active */
        logger.info("Waiting for instance to go ACTIVE...");
        Thread.sleep(delay);
        /* Associate floating ip */
        cloudIntf.addFloatingIP(newServer.getId());
        /* Delete Server */
        cloudIntf.deleteServer(newServer.getId());
        logger.info("Server deleted: " + newServer.getId());
        /* Wait 30 seconds until server is terminated */
        logger.info("Waiting for instance to terminate...");
        Thread.sleep(delay);
        /* Delete Keypair */
        cloudIntf.deleteKeyPair(kp.getName());
        logger.info("Keypair deleted: " + kp.getName());
        Server deleted = (Server) cloudIntf.getServer(newServer.getId());
        assertTrue(newServer != null && deleted == null);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
}
Also used : Scanner(java.util.Scanner) CloudInterface(org.apache.airavata.cloud.intf.CloudInterface) Keypair(org.openstack4j.model.compute.Keypair) Server(org.openstack4j.model.compute.Server) OpenstackIntfImpl(org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl) FileInputStream(java.io.FileInputStream) FileNotFoundException(java.io.FileNotFoundException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 CloudInterface (org.apache.airavata.cloud.intf.CloudInterface)2 OpenstackIntfImpl (org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 Scanner (java.util.Scanner)1 Keypair (org.openstack4j.model.compute.Keypair)1 Server (org.openstack4j.model.compute.Server)1 Network (org.openstack4j.model.network.Network)1 Router (org.openstack4j.model.network.Router)1 RouterInterface (org.openstack4j.model.network.RouterInterface)1 Subnet (org.openstack4j.model.network.Subnet)1