def test_assign_ip(self, m_allocate, m_pools):
     """
     Test assign_ip assigns an IP address.
     """
     m_pools.return_value = [IPNetwork("1.2.3.0/24"), IPNetwork("2.3.4.5/32")]
     m_allocate.return_value = IPAddress("1.2.3.6")
     ip = docker_plugin.assign_ip(4)
     assert_equal(ip, IPNetwork("1.2.3.6"))
     m_pools.assert_called_once_with(4)
     m_allocate.assert_called_once_with(ANY, IPNetwork("1.2.3.0/24"))
 def test_assign_ip(self, m_allocate, m_pools):
     """
     Test assign_ip assigns an IP address.
     """
     m_pools.return_value = [
         IPNetwork("1.2.3.0/24"),
         IPNetwork("2.3.4.5/32")
     ]
     m_allocate.return_value = IPAddress("1.2.3.6")
     ip = docker_plugin.assign_ip(4)
     assert_equal(ip, IPNetwork("1.2.3.6"))
     m_pools.assert_called_once_with(4)
     m_allocate.assert_called_once_with(ANY, IPNetwork("1.2.3.0/24"))
    def test_assign_ip_no_ip(self, m_allocate, m_pools):
        """
        Test assign_ip when no IP addresses can be allocated.
        """
        m_pools.return_value = [IPNetwork("1.2.3.0/24"),
                                IPNetwork("2.3.4.5/32")]
        m_allocate.return_value = None
        ip = docker_plugin.assign_ip(4)
        assert_equal(ip, None)
        m_pools.assert_called_once_with(4)

        # We should have attempted to allocate for each pool.
        m_allocate.assert_has_calls([call(ANY, IPNetwork("1.2.3.0/24")),
                                     call(ANY, IPNetwork("2.3.4.5/32"))])
    def test_assign_ip_no_ip(self, m_allocate, m_pools):
        """
        Test assign_ip when no IP addresses can be allocated.
        """
        m_pools.return_value = [
            IPNetwork("1.2.3.0/24"),
            IPNetwork("2.3.4.5/32")
        ]
        m_allocate.return_value = None
        ip = docker_plugin.assign_ip(4)
        assert_equal(ip, None)
        m_pools.assert_called_once_with(4)

        # We should have attempted to allocate for each pool.
        m_allocate.assert_has_calls([
            call(ANY, IPNetwork("1.2.3.0/24")),
            call(ANY, IPNetwork("2.3.4.5/32"))
        ])