From: Alfredo Deza Date: Wed, 27 Aug 2014 19:21:06 +0000 (-0400) Subject: add tests to ensure we do the right thing with per subnet validation X-Git-Tag: v1.5.13~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a1a7827ed3a8a4dd3fad7be9e14c8224fe714e9e;p=ceph-deploy.git add tests to ensure we do the right thing with per subnet validation Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/tests/unit/test_new.py b/ceph_deploy/tests/unit/test_new.py new file mode 100644 index 0000000..a32b2ea --- /dev/null +++ b/ceph_deploy/tests/unit/test_new.py @@ -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 index 0000000..88af892 --- /dev/null +++ b/ceph_deploy/tests/util.py @@ -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 + + +