def testEnumerateIPs(self):
        conf = {
            'ip_start': '10.80.227.143',
            'ip_end': '10.80.227.151',
            'netmask': '255.255.0.0',
            'gw': '10.80.227.1'
        }

        full_list = [
            '10.80.227.143', '10.80.227.144', '10.80.227.145', '10.80.227.146',
            '10.80.227.147', '10.80.227.148', '10.80.227.149', '10.80.227.150',
            '10.80.227.151'
        ]

        sim = utils.StaticIPManager(conf)
        free_list = sim.ip_pool

        if len(free_list) != len(full_list):
            raise Exception(
                "Error: we expect there to be %d IPs, enumerate produced %d." %
                (len(full_list), len(free_list)))

        for i in range(len(full_list)):
            if free_list[i].addr != full_list[i]:
                raise Exception(
                    "Error: Enumerate IP returns %s, we expect %s" %
                    (free_list, full_list))
Beispiel #2
0
    def _test_increment_ip(self, start, result, expect=True):
        conf = {'ip_start': '192.168.0.1',
                'ip_end': '192.168.0.10',
                'netmask': '255.255.255.0',
                'gw': '192.168.0.1'}
        sim = utils.StaticIPManager(conf)

        res = sim.increment_ip_string(start)

        if res != result and expect:
            raise Exception("Error: '%s' incremeneted, should equal '%s' not '%s'" %
                            (start, result, res))
Beispiel #3
0
    def testLoanStaticIP(self):
        conf = {'ip_start': '192.168.0.5',
                'ip_end': '192.168.0.10',
                'netmask': '255.255.255.0',
                'gw': '192.168.0.1'}

        sim = utils.StaticIPManager(conf)

        borrowed_ip = sim.get_ip()
        assert(sim.available_ips() == 5)
        assert(len(sim.in_use) == 1)

        sim.return_ip(borrowed_ip)

        assert(sim.available_ips() == 6)
        assert(len(sim.in_use) == 0)