Fixes Bug 4769
authorAswin Suryanarayanan <aswin.suryanarayanan@hp.com>
Tue, 26 Jan 2016 14:23:16 +0000 (19:53 +0530)
committerAswin Suryanarayanan <aswin.suryanarayanan@hp.com>
Tue, 26 Jan 2016 14:23:16 +0000 (19:53 +0530)
Back-merging Change-Id: Ic69142c1804a37725a9dc9c611d583302284d18c

Change-Id: I809430e58b939dd91ad09c4fa27cb7ae7c1d40ed
Signed-off-by: Aswin Suryanarayanan <aswin.suryanarayanan@hp.com>
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/NeutronL3Adapter.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityServicesImpl.java
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityServicesImplTest.java

index 18ce60cccc8802b927975e37a2a605d6bfc7bbd2..b453eb16d8ee00af97cc0e99cafdc4c1b92c7c6f 100644 (file)
@@ -1437,6 +1437,10 @@ public class NeutronL3Adapter extends AbstractHandler implements GatewayMacResol
         storePortInCleanupCache(updatedPort);
     }
 
+    public Set<NeutronPort> getPortCleanupCache() {
+        return this.portCleanupCache;
+    }
+
     public NeutronPort getPortFromCleanupCache(String portid) {
         for (NeutronPort neutronPort : this.portCleanupCache) {
             if (neutronPort.getPortUUID() != null ) {
index a7eee6740a1bfec09dc29e5e4faaf70074bc9140..f6784a50a4df25efdf2bbc863f2a41e4c0c78503 100644 (file)
@@ -61,7 +61,12 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
         if (neutronPort == null) {
-            return false;
+            neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("isPortSecurityReady for {}", terminationPointAugmentation.getName()
+                          + "not found");
+                return false;
+            }
         }
         String deviceOwner = neutronPort.getDeviceOwner();
         if (!deviceOwner.contains("compute")) {
@@ -86,7 +91,7 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
             LOG.error("neutron port is null");
             return neutronSecurityGroups;
         }
-        LOG.trace("isPortSecurityReady for {}", terminationPointAugmentation.getName());
+        LOG.trace("getSecurityGroupInPortList for {}", terminationPointAugmentation.getName());
         String neutronPortId = southbound.getInterfaceExternalIdsValue(terminationPointAugmentation,
                                                                        Constants.EXTERNAL_ID_INTERFACE_ID);
         if (neutronPortId == null) {
@@ -94,7 +99,12 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
         if (neutronPort == null) {
-            return neutronSecurityGroups;
+            neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("getSecurityGroupInPortList for {}", terminationPointAugmentation.getName()
+                          + "not found.");
+                return neutronSecurityGroups;
+            }
         }
         neutronSecurityGroups = neutronPort.getSecurityGroups();
         return neutronSecurityGroups;
@@ -120,11 +130,11 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
                 neutronPort = neutronPortCache.getPort(neutronPortId);
 
             }
-            if (neutronPort == null ){
+            if (neutronPort == null){
                 neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
                 if (neutronPort == null)
                 {
-                    LOG.info("getDHCPServerPort: neutron port of {} is not found", neutronPortId);
+                    LOG.error("getDHCPServerPort: neutron port of {} is not found", neutronPortId);
                     return null;
                 }
                 LOG.info("getDHCPServerPort: neutron port of {} got from cleanupcache", neutronPortId);
@@ -180,8 +190,11 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         NeutronPort neutronPort = neutronPortCache.getPort(neutronPortId);
         if (neutronPort == null) {
-            LOG.error("getNeutronPortFromDhcpIntf: neutron port of {} is not found", neutronPortId);
-            return null;
+            neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
+            if (neutronPort == null) {
+                LOG.error("getNeutronPortFromDhcpIntf: neutron port of {} is not found", neutronPortId);
+                return null;
+            }
         }
         /* if the current port is a DHCP port, return true*/
         if (neutronPort.getDeviceOwner().contains("dhcp")) {
@@ -207,19 +220,19 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
                 neutronPort = neutronPortCache.getPort(neutronPortId);
 
             }
-            if (neutronPort == null ){
+            if (neutronPort == null{
                 LOG.trace("getNeutronPortFromCache: neutron port of {} search in cleanupcache", neutronPortId);
 
                 neutronPort = neutronL3Adapter.getPortFromCleanupCache(neutronPortId);
                 if (neutronPort == null)
                 {
-                    LOG.info("getNeutronPortFromCache: neutron port of {} is not found", neutronPortId);
+                    LOG.error("getNeutronPortFromCache: neutron port of {} is not found", neutronPortId);
                     return null;
                 }
                 LOG.trace("getNeutronPortFromCache: neutron port of {} got from cleanupcache", neutronPortId);
 
             }
-        }catch (Exception e) {
+        } catch (Exception e) {
             LOG.warn("getNeutronPortFromCache:getNeutronPortFromCache failed due to ", e);
             return null;
         }
@@ -231,7 +244,7 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
     @Override
     public boolean isComputePort(OvsdbTerminationPointAugmentation terminationPointAugmentation) {
         if (neutronPortCache == null) {
-            LOG.warn("neutronPortCache null");
+             LOG.warn("neutronPortCache null");
         }
         NeutronPort neutronPort = null;
         LOG.trace("isComputePort for {}", terminationPointAugmentation.getName());
@@ -245,8 +258,9 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         }
         if (neutronPort == null) {
             neutronPort = getNeutronPortFromCache(terminationPointAugmentation);
-            if (neutronPort == null)
-            return false;
+            if (neutronPort == null) {
+                return false;
+            }
         }
         /*Check the device owner and if it contains compute to identify
          * whether it is a compute port.*/
@@ -380,7 +394,7 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         /*For every port check whether security grouplist contains the current
          * security group.*/
         try {
-            for (NeutronPort neutronPort:neutronPortCache.getAllPorts()) {
+            for (NeutronPort neutronPort:neutronL3Adapter.getPortCleanupCache()) {
                 if (!neutronPort.getDeviceOwner().contains("compute")) {
                     LOG.debug("getVMListForSecurityGroup : the port {} is not "
                             + "compute port belongs to {}", neutronPort.getID(), neutronPort.getDeviceOwner());
index 15eb1364aeafacc532f8fd49b88beb13adc503f3..fd78ac675f0a144f584a59d8bb93bad69985631c 100644 (file)
@@ -20,6 +20,7 @@ import static org.mockito.Mockito.when;
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 
 import org.junit.Before;
@@ -82,6 +83,7 @@ public class SecurityServicesImplTest {
     @Mock OvsdbTerminationPointAugmentation tp;
     @Mock IngressAclProvider ingressAclService;
     @Mock EgressAclProvider egressAclService;
+    @Mock NeutronL3Adapter neutronL3Adapter;
 
     private static final String NEUTRON_PORT_ID_VM_1 = "neutronID_VM_1";
     private static final String NEUTRON_PORT_ID_VM_2 = "neutronID_VM_2";
@@ -370,7 +372,7 @@ public class SecurityServicesImplTest {
         portList.add(neutronPort_Vm2);
         portList.add(neutronPort_Vm3);
         portList.add(neutronPort_Dhcp);
-        when(neutronPortCache.getAllPorts()).thenReturn(portList);
+        when(neutronL3Adapter.getPortCleanupCache()).thenReturn(new HashSet<NeutronPort>(portList));
         List<Neutron_IPs> ipList = securityServicesImpl.getVmListForSecurityGroup(NEUTRON_PORT_ID_VM_1, SECURITY_GROUP_ID_2);
         assertEquals(ipList,neutron_IPs_2);
     }