Integration Tests for Unimgr 01/33501/1
authorRashmi Pujar <rpujar@inocybe.com>
Mon, 25 Jan 2016 20:27:05 +0000 (15:27 -0500)
committerRashmi Pujar <rpujar@inocybe.com>
Mon, 25 Jan 2016 20:27:05 +0000 (15:27 -0500)
- IT module structure
- IT for create and delete evc

Change-Id: I06866f2f464a8efd6052afaf241652a5af51abfc
Signed-off-by: Rashmi Pujar <rpujar@inocybe.com>
it/pom.xml
it/src/test/java/org/opendaylight/unimgr/it/UnimgrIT.java [new file with mode: 0644]
karaf/pom.xml
pom.xml

index cb51cf39a9400b4fca8c5f571f39f8c97cf03735..7d53c6a8a306ca49f241367f2ad644eda99d4b88 100644 (file)
@@ -10,8 +10,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
 
   <parent>
     <groupId>org.opendaylight.controller</groupId>
-    <artifactId>config-parent</artifactId>
-    <version>0.4.0-SNAPSHOT</version>
+    <artifactId>mdsal-it-parent</artifactId>
+    <version>1.3.0-SNAPSHOT</version>
     <relativePath/>
   </parent>
 
@@ -19,46 +19,21 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
   <groupId>org.opendaylight.unimgr</groupId>
   <artifactId>unimgr-it</artifactId>
   <version>0.0.1-SNAPSHOT</version>
-  <packaging>jar</packaging>
-  <dependencyManagement>
-    <dependencies>
-      <dependency>
-        <groupId>${project.groupId}</groupId>
-        <artifactId>unimgr-artifacts</artifactId>
-        <version>${project.version}</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
-      <dependency>
-        <groupId>org.opendaylight.controller</groupId>
-        <artifactId>config-artifacts</artifactId>
-        <version>0.4.0-SNAPSHOT</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
-      <dependency>
-        <groupId>org.opendaylight.controller</groupId>
-        <artifactId>mdsal-artifacts</artifactId>
-        <version>${mdsal.version}</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
-    </dependencies>
-  </dependencyManagement>
+  <packaging>bundle</packaging>
+
+  <properties>
+    <skipITs>false</skipITs>
+    <karaf.distro.groupId>org.opendaylight.unimgr</karaf.distro.groupId>
+    <karaf.distro.artifactId>unimgr-karaf</karaf.distro.artifactId>
+    <karaf.distro.version>${project.version}</karaf.distro.version>
+    <karaf.distro.type>zip</karaf.distro.type>
+  </properties>
+
   <dependencies>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal-binding-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal-common-api</artifactId>
-    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>unimgr-features</artifactId>
-      <classifier>features</classifier>
-      <type>xml</type>
+      <version>${project.version}</version>
     </dependency>
   </dependencies>
 
diff --git a/it/src/test/java/org/opendaylight/unimgr/it/UnimgrIT.java b/it/src/test/java/org/opendaylight/unimgr/it/UnimgrIT.java
new file mode 100644 (file)
index 0000000..c8cb871
--- /dev/null
@@ -0,0 +1,362 @@
+/*
+ * Copyright © 2016 Inocybe Technologies and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.unimgr.it;
+
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Destination;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
+import org.ops4j.pax.exam.options.MavenUrlReference;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class UnimgrIT extends AbstractMdsalTestBase {
+    private static final Logger LOG = LoggerFactory.getLogger(UnimgrIT.class);
+    private DataBroker dataBroker;
+
+    private static final String MAC_ADDRESS_1 = "68:5b:35:bc:0f:7d";
+    private static final String MAC_ADDRESS_2 = "68:5b:35:bc:0f:7e";
+    private static final String MAC_LAYER = "IEEE 802.3-2005";
+    private static final String MODE = "Full Duplex";
+    private static final String MTU_SIZE = "0";
+    private static final String PHY_MEDIUM = "UNI TypeFull Duplex 2 Physical Interface";
+    private static final String TYPE = "";
+    private static final String IP_1 = "10.0.0.1";
+    private static final String IP_2 = "10.0.0.2";
+    private static final String EVC_ID_1 = "1";
+
+    @Override
+    public void setup() throws Exception {
+        super.setup();
+        Thread.sleep(3000);
+        dataBroker =  getSession().getSALService(DataBroker.class);
+        Assert.assertNotNull("db should not be null", dataBroker);
+    }
+
+    @Override
+    public String getModuleName() {
+        return "unimgr";
+    }
+
+    @Override
+    public String getInstanceName() {
+        return "unimgr-default";
+    }
+
+    @Override
+    public MavenUrlReference getFeatureRepo() {
+        return maven()
+                .groupId("org.opendaylight.unimgr")
+                .artifactId("unimgr-features")
+                .classifier("features")
+                .type("xml")
+                .versionAsInProject();
+    }
+
+    @Override
+    public String getFeatureName() {
+        return "odl-unimgr";
+    }
+
+    @Override
+    public Option getLoggingOption() {
+        Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
+                logConfiguration(UnimgrIT.class),
+                LogLevel.INFO.name());
+        option = composite(option, super.getLoggingOption());
+        return option;
+    }
+
+    @Test
+    public void testUnimgrFeatureLoad() {
+        Assert.assertTrue(true);
+    }
+
+    @Test
+    public void testUnimgr() {
+        InstanceIdentifier<Topology> uniTopoPath = InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class,
+                        new TopologyKey(new TopologyId(new Uri("unimgr:uni"))));
+        InstanceIdentifier<Topology> evcTopoPath = InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class,
+                        new TopologyKey(new TopologyId(new Uri("unimgr:evc"))));
+        InstanceIdentifier<Topology> ovdbTopoPath = InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(new TopologyId(new Uri("ovsdb:1"))));
+
+        // Read from md-sal and check if it is initialized with Uni and Evc augmentations
+        Topology topology = read(LogicalDatastoreType.CONFIGURATION, uniTopoPath);
+        Assert.assertNotNull("UNI Topology could not be found in " + LogicalDatastoreType.CONFIGURATION,
+                topology);
+        topology = read(LogicalDatastoreType.OPERATIONAL, uniTopoPath);
+        Assert.assertNotNull("UNI Topology could not be found in " + LogicalDatastoreType.OPERATIONAL,
+                topology);
+        topology = read(LogicalDatastoreType.CONFIGURATION, evcTopoPath);
+        Assert.assertNotNull("EVC Topology could not be found in " + LogicalDatastoreType.CONFIGURATION,
+                topology);
+        topology = read(LogicalDatastoreType.OPERATIONAL, evcTopoPath);
+        Assert.assertNotNull("EVC Topology could not be found in " + LogicalDatastoreType.OPERATIONAL,
+                topology);
+        topology = read(LogicalDatastoreType.CONFIGURATION, ovdbTopoPath);
+        Assert.assertNotNull("OVSDB Topology could not be found in " + LogicalDatastoreType.CONFIGURATION,
+                topology);
+        topology = read(LogicalDatastoreType.CONFIGURATION, ovdbTopoPath);
+        Assert.assertNotNull("OVSDB Topology could not be found in " + LogicalDatastoreType.OPERATIONAL,
+                topology);
+    }
+
+    @Test
+    public void testCreateUni() {
+        LOG.info("Test for create Uni");
+    }
+
+    private void testDeleteUni() {
+        LOG.info("Test for delete Uni");
+    }
+
+    @Test
+    public void testCreateEvc() {
+        LOG.info("Test for create Evc");
+        // Create an evc between the two Uni nodes
+        InstanceIdentifier<Link> evcIid = createOrDeleteEvcLink(IP_1, MAC_ADDRESS_1, IP_2, MAC_ADDRESS_2, EVC_ID_1, true);
+        Assert.assertNotNull(evcIid);
+
+        // Validate Evc create operation
+        boolean status = validateEvc(true, EVC_ID_1);
+        Assert.assertTrue(status);
+    }
+
+    @Test
+    public void testDeleteEvc() {
+        LOG.info("Test for delete Evc");
+        // Create an evc between the two Uni nodes
+        InstanceIdentifier<Link> evcIid = createOrDeleteEvcLink(IP_1, MAC_ADDRESS_1, IP_2, MAC_ADDRESS_2, EVC_ID_1, true);
+        Assert.assertNotNull(evcIid);
+
+        //Delete the Evc
+        evcIid = createOrDeleteEvcLink(IP_1, MAC_ADDRESS_1, IP_2, MAC_ADDRESS_2, EVC_ID_1, false);
+        Assert.assertNotNull(evcIid);
+
+        // Validate Evc delete operation
+        boolean status = validateEvc(false, EVC_ID_1);
+        Assert.assertTrue(status);
+    }
+
+    private boolean validateEvc(boolean forCreate, String evcId) {
+        InstanceIdentifier<Link> iid = getEvcLinkIid(evcId);
+        Link evc = read(LogicalDatastoreType.CONFIGURATION, iid);
+        if (forCreate && evc != null) {
+            return true;
+        } else if (!forCreate && evc == null) {
+            return true;
+        }
+        return false;
+    }
+
+    private InstanceIdentifier<Node> createUniNode(String macAddress, String ipAddress) {
+        UniAugmentation uni = new UniAugmentationBuilder()
+                .setMacAddress(new MacAddress(macAddress))
+                .setMacLayer(MAC_LAYER)
+                .setMode(MODE)
+                .setMtuSize(BigInteger.valueOf(Long.valueOf(MTU_SIZE)))
+                .setPhysicalMedium(PHY_MEDIUM)
+                .setType(TYPE)
+                .setIpAddress(new IpAddress(ipAddress.toCharArray()))
+                .build();
+
+        NodeId uniNodeId = new NodeId(new NodeId("uni://" + uni.getIpAddress().getIpv4Address().getValue().toString()));
+        InstanceIdentifier<Node> uniNodeIid = null;
+        try {
+            uniNodeIid = getUniIid("uni://" + uni.getIpAddress().getIpv4Address().getValue().toString());
+            NodeKey uniNodeKey = new NodeKey(uniNodeId);
+            Node nodeData = new NodeBuilder()
+                                    .setNodeId(uniNodeId)
+                                    .setKey(uniNodeKey)
+                                    .addAugmentation(UniAugmentation.class, uni)
+                                    .build();
+            WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+            transaction.put(LogicalDatastoreType.CONFIGURATION, uniNodeIid, nodeData);
+            CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+            future.checkedGet();
+            LOG.info("Created and submitted a new Uni node {}", nodeData.getNodeId());
+        } catch (Exception e) {
+            LOG.error("Exception while creating Uni Node" + "Uni Node Id: {}, {}", uniNodeId, e);
+            return null;
+        }
+        return uniNodeIid;
+    }
+
+    private InstanceIdentifier<Link> createOrDeleteEvcLink(String srcUniIp, String srcMac,
+            String dstUniIp, String dstMac, String evcId,
+            boolean isCreate) {
+        // Create two Uni nodes before creating an Evc
+        InstanceIdentifier<Node> uniIid = createUniNode(srcMac, srcUniIp);
+        Assert.assertNotNull(uniIid);
+
+        uniIid = createUniNode(dstMac, dstUniIp);
+        Assert.assertNotNull(uniIid);
+
+        // Create Evc link between the two Uni Nodes
+        List<UniSource> src = new ArrayList<>();
+        InstanceIdentifier<?> srcUniIid = getUniIid("uni://" + srcUniIp);
+        UniSource uniSrc = new UniSourceBuilder()
+                .setIpAddress(new IpAddress(srcUniIp.toCharArray()))
+                .setOrder((short) 1)
+                .setKey(new UniSourceKey((short) 1))
+                .setUni(srcUniIid)
+                .build();
+        src.add(uniSrc);
+
+        List<UniDest> dst = new ArrayList<>();
+        InstanceIdentifier<?> dstUniIid = getUniIid("uni://" + dstUniIp);;
+        UniDest uniDst = new UniDestBuilder()
+                .setIpAddress(new IpAddress(dstUniIp.toCharArray()))
+                .setOrder((short) 2)
+                .setKey(new UniDestKey((short) 2))
+                .setUni(dstUniIid)
+                .build();
+        dst.add(uniDst);
+
+        EvcAugmentation evc = new EvcAugmentationBuilder()
+                .setUniDest(dst)
+                .setUniSource(src)
+                .build();
+
+        LinkId evcLinkId = new LinkId(new LinkId("evc://" + evcId));
+        InstanceIdentifier<Link> evcLinkIid = null;
+        try {
+            evcLinkIid = getEvcLinkIid(evcId);
+            if(isCreate) {
+                LinkKey evcLinkKey = new LinkKey(evcLinkId);
+                Source mandatorySrcNode = new SourceBuilder().setSourceNode(new NodeId("uni://" + srcUniIp)).build();
+                Destination mandatoryDstNode = new DestinationBuilder().setDestNode(new NodeId("uni://" + dstUniIp)).build();
+                Link linkData = new LinkBuilder()
+                        .setKey(evcLinkKey)
+                        .setSource(mandatorySrcNode)
+                        .setDestination(mandatoryDstNode)
+                        .setLinkId(evcLinkId)
+                        .addAugmentation(EvcAugmentation.class, evc)
+                        .build();
+                WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+                transaction.put(LogicalDatastoreType.CONFIGURATION, evcLinkIid, linkData);
+                CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+                future.checkedGet();
+                LOG.info("Created and submitted a new Evc link {}", evcLinkId);
+            } else {
+                WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+                transaction.delete(LogicalDatastoreType.CONFIGURATION, evcLinkIid);
+                CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+                future.checkedGet();
+                LOG.info("Deleted an Evc link {}", evcLinkId);
+            }
+        } catch (Exception e) {
+            if (isCreate) {
+                LOG.error("Exception while creating Evc " + "Evc link Id: {}, {}", evcLinkId, e);
+            } else {
+                LOG.error("Exception while deleting Evc " + "Evc link Id: {}, {}", evcLinkId, e);
+            }
+            return null;
+        }
+        return evcLinkIid;
+    }
+
+    private InstanceIdentifier<Node> getUniIid(String nodeId) {
+        NodeId uniNodeId = new NodeId(new NodeId(nodeId));
+        InstanceIdentifier<Node> uniNodeIid = InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(new TopologyId(new Uri("unimgr:uni"))))
+                .child(Node.class, new NodeKey(uniNodeId));
+        return uniNodeIid;
+    }
+
+    private InstanceIdentifier<Link> getEvcLinkIid(String linkId) {
+        LinkId evcLinkId = new LinkId(new LinkId("evc://" + linkId));
+        InstanceIdentifier<Link> linkPath = InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class,new TopologyKey(new TopologyId(new Uri("unimgr:evc"))))
+                .child(Link.class, new LinkKey(evcLinkId));
+        return linkPath;
+    }
+
+    private <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
+            final LogicalDatastoreType store, final InstanceIdentifier<D> path)  {
+        D result = null;
+        final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
+        Optional<D> optionalDataObject;
+        CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
+        try {
+            optionalDataObject = future.checkedGet();
+            if (optionalDataObject.isPresent()) {
+                result = optionalDataObject.get();
+            } else {
+                LOG.error("{}: Failed to read {}",
+                        Thread.currentThread().getStackTrace()[1], path);
+            }
+        } catch (ReadFailedException e) {
+            LOG.error("Failed to read {} ", path, e);
+        }
+        transaction.close();
+        return result;
+    }
+}
\ No newline at end of file
index 34e4946e6c2f9a34b528f9b8317057faffab880d..3c2c1f23aac6490fbd2ac127b24beaa10282f0f9 100644 (file)
@@ -62,13 +62,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
           <skip>true</skip>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-install-plugin</artifactId>
-        <configuration>
-          <skip>true</skip>
-        </configuration>
-      </plugin>
     </plugins>
   </build>
 </project>
diff --git a/pom.xml b/pom.xml
index 83661778819e00c8d63ceff0fbf016c46c73b25a..e2e3037e43b6a960821ccdb0d881d3900f7e7492 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -28,10 +28,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
     <module>api</module>
     <module>impl</module>
     <module>cli</module>
-    <module>it</module>
     <module>karaf</module>
     <module>features</module>
     <module>artifacts</module>
+    <module>it</module>
   </modules>
   <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
   <build>