Exemple #1
0
    def test_no_ips(self):
        """RuntimeError is raised if all IPs are taken."""
        counter = itertools.count()
        virnetwork = mock.Mock()
        hypervisor = mock.Mock()
        virnetwork.XMLDesc.side_effect = lambda x: '<a><ip address="192.168.{}.1"/></a>'.format(next(counter))
        hypervisor.listNetworks.return_value = range(0, 256)
        hypervisor.networkLookupByName.return_value = virnetwork

        with self.assertRaises(RuntimeError):
            network.valid_address(hypervisor)
Exemple #2
0
    def test_no_ips(self):
        """RuntimeError is raised if all IPs are taken."""
        counter = itertools.count()
        virnetwork = mock.Mock()
        hypervisor = mock.Mock()
        virnetwork.XMLDesc.side_effect = lambda x: '<a><ip address="192.168.{}.1"/></a>'.format(
            next(counter))
        hypervisor.listNetworks.return_value = range(0, 256)
        hypervisor.networkLookupByName.return_value = virnetwork

        with self.assertRaises(RuntimeError):
            network.valid_address(hypervisor)
Exemple #3
0
    def test_valid(self):
        """A valid address is retrieved."""
        virnetwork = mock.Mock()
        hypervisor = mock.Mock()
        virnetwork.XMLDesc.side_effect = lambda x: '<a><ip address="192.168.{}.1"/></a>'.format(random.randint(1, 256))
        hypervisor.listNetworks.return_value = ('foo', 'bar', 'baz')
        hypervisor.networkLookupByName.return_value = virnetwork

        self.assertTrue(network.valid_address(hypervisor) in ["192.168.{}.1".format(i) for i in range(1, 256)])
Exemple #4
0
    def test_valid(self):
        """A valid address is retrieved."""
        virnetwork = mock.Mock()
        hypervisor = mock.Mock()
        virnetwork.XMLDesc.side_effect = lambda x: '<a><ip address="192.168.{}.1"/></a>'.format(
            random.randint(1, 256))
        hypervisor.listNetworks.return_value = ('foo', 'bar', 'baz')
        hypervisor.networkLookupByName.return_value = virnetwork

        self.assertTrue(
            network.valid_address(hypervisor) in
            ["192.168.{}.1".format(i) for i in range(1, 256)])