]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
add tests to ensure we do the right thing with per subnet validation
authorAlfredo Deza <alfredo.deza@inktank.com>
Wed, 27 Aug 2014 19:21:06 +0000 (15:21 -0400)
committerAlfredo Deza <alfredo.deza@inktank.com>
Wed, 27 Aug 2014 20:41:13 +0000 (16:41 -0400)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/tests/unit/test_new.py [new file with mode: 0644]
ceph_deploy/tests/util.py [new file with mode: 0644]

diff --git a/ceph_deploy/tests/unit/test_new.py b/ceph_deploy/tests/unit/test_new.py
new file mode 100644 (file)
index 0000000..a32b2ea
--- /dev/null
@@ -0,0 +1,28 @@
+from ceph_deploy import new
+from ceph_deploy.tests import util
+import pytest
+
+
+class TestValidateHostIp(object):
+
+    def test_for_all_subnets_all_ips_match(self):
+        ips = util.generate_ips("10.0.0.1", "10.0.0.40")
+        ips.extend(util.generate_ips("10.0.1.1", "10.0.1.40"))
+        subnets = ["10.0.0.1/16", "10.0.1.1/16"]
+        assert new.validate_host_ip(ips, subnets) is None
+
+    def test_all_subnets_have_one_matching_ip(self):
+        ips = util.generate_ips("10.0.0.1", "10.0.0.40")
+        ips.extend(util.generate_ips("10.0.1.1", "10.0.1.40"))
+        # regardless of extra IPs that may not match. The requirement
+        # is already satisfied
+        ips.extend(util.generate_ips("10.1.2.1", "10.1.2.40"))
+        subnets = ["10.0.0.1/16", "10.0.1.1/16"]
+        assert new.validate_host_ip(ips, subnets) is None
+
+    def test_not_all_subnets_have_one_matching_ip(self):
+        ips = util.generate_ips("10.0.0.1", "10.0.0.40")
+        ips.extend(util.generate_ips("10.0.1.1", "10.0.1.40"))
+        subnets = ["10.0.0.1/16", "10.1.1.1/16"]
+        with pytest.raises(RuntimeError):
+            new.validate_host_ip(ips, subnets)
diff --git a/ceph_deploy/tests/util.py b/ceph_deploy/tests/util.py
new file mode 100644 (file)
index 0000000..88af892
--- /dev/null
@@ -0,0 +1,21 @@
+
+
+def generate_ips(start_ip, end_ip):
+    start = list(map(int, start_ip.split(".")))
+    end = list(map(int, end_ip.split(".")))
+    temp = start
+    ip_range = []
+
+    ip_range.append(start_ip)
+    while temp != end:
+        start[3] += 1
+        for i in (3, 2, 1):
+            if temp[i] == 256:
+                temp[i] = 0
+                temp[i-1] += 1
+        ip_range.append(".".join(map(str, temp)))
+
+    return ip_range
+
+
+