cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [5/6] git commit: updated refs/heads/master to b69dff7
Date Sun, 25 Oct 2015 20:03:45 GMT
unit test for interface patterns in libvirt compute resource


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5a134a6f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5a134a6f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5a134a6f

Branch: refs/heads/master
Commit: 5a134a6fe676d4461a2b5dbcc92057e18544718e
Parents: f1ea27e
Author: Daan Hoogland <daan@onecht.net>
Authored: Fri Oct 23 17:17:40 2015 +0200
Committer: Daan Hoogland <daan@onecht.net>
Committed: Sat Oct 24 00:57:01 2015 +0200

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java  | 31 ++++++++++++++++++--
 .../resource/LibvirtComputingResourceTest.java  | 13 ++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5a134a6f/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index ef6b827..11317af 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -1160,8 +1160,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         for (int i = 0; i < interfaces.length; i++) {
             final String fname = interfaces[i].getName();
             s_logger.debug("matchPifFileInDirectory: file name '" + fname + "'");
-            if (fname.startsWith("eth") || fname.startsWith("bond") || fname.startsWith("team")
|| fname.startsWith("vlan") || fname.startsWith("vx") || fname.startsWith("em") ||
-                    fname.matches("^p\\d+p\\d+.*") || fname.startsWith("ens") || fname.startsWith("eno")
|| fname.startsWith("enp") || fname.startsWith("enx")) {
+            if (isInterface(fname)) {
                 return fname;
             }
         }
@@ -1170,6 +1169,34 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         return "";
     }
 
+    String [] _ifNamePrefixes = {
+            "eth",
+            "bond",
+            "vlan",
+            "vx",
+            "em",
+            "ens",
+            "eno",
+            "enp",
+            "team",
+            "enx",
+            "^p\\d+p\\d+"
+    };
+    /**
+     * @param fname
+     * @return
+     */
+    boolean isInterface(final String fname) {
+        StringBuffer commonPattern = new StringBuffer();
+        for (String ifNamePrefix : _ifNamePrefixes) {
+            commonPattern.append("|(").append(ifNamePrefix).append(".*)");
+        }
+        if(fname.matches(commonPattern.toString())) {
+            return true;
+        }
+        return false;
+    }
+
     public boolean checkNetwork(final String networkName) {
         if (networkName == null) {
             return true;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5a134a6f/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index 920c86a..98a074a 100644
--- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -4999,4 +4999,17 @@ public class LibvirtComputingResourceTest {
 
         assertFalse(answer.getResult());
     }
+
+    @Test
+    public void testIsInterface () {
+        LibvirtComputingResource lvcr = new LibvirtComputingResource();
+        assertFalse(lvcr.isInterface("bla"));
+        assertTrue(lvcr.isInterface("p99p00"));
+        for  (String ifNamePrefix : lvcr._ifNamePrefixes) {
+            // excluding regexps as "\\\\d+" won't replace with String.replaceAll(String,String);
+            if (!ifNamePrefix.contains("\\")) {
+                assertTrue(lvcr.isInterface(ifNamePrefix + "0"));
+            }
+        }
+    }
 }
\ No newline at end of file


Mime
View raw message