Beispiel #1
0
 def test_reserve_is_functional(self, m_datastore):
     hostname = "metaman"
     ipv4_addrs = ["192.168.1.1", "192.168.1.2"]
     ipv6_addrs = ["dead::beef"]
     uid = "abc-def-gh"
     result = calico_mesos._reserve(hostname, uid, ipv4_addrs, ipv6_addrs)
     self.assertIsNone(result)
     for ip_addr in ipv4_addrs + ipv6_addrs:
         # TODO: workaround until hostname can be passed in
         m_datastore.assign_ip.assert_any_call(ip_addr, uid, {}, HOSTNAME)
Beispiel #2
0
 def test_reserve_is_functional(self, m_datastore):
     hostname = "metaman"
     ipv4_addrs = ["192.168.1.1", "192.168.1.2"]
     ipv6_addrs = ["dead::beef"]
     uid = "abc-def-gh"
     result = calico_mesos._reserve(hostname, uid, ipv4_addrs, ipv6_addrs)
     self.assertIsNone(result)
     for ip_addr in ipv4_addrs + ipv6_addrs:
         # TODO: workaround until hostname can be passed in
         m_datastore.assign_ip.assert_any_call(ip_addr, uid, {},
                                               host=HOSTNAME)
Beispiel #3
0
    def test_reserve_rolls_back(self, exception, m_datastore):
        hostname = "metaman"
        ipv4_addrs = [IPAddress("192.168.1.1"), IPAddress("192.168.1.2")]
        ipv6_addrs = [IPAddress("dead::beef")]
        uid = "abc-def-gh"

        def side_effect(address, handle_id, attributes, host=None):
            if address == IPAddress("192.168.1.2"):
                # Arbitrarily throw an error when the second address is passed in
                raise exception

        m_assign_ip = MagicMock(side_effect=side_effect)
        m_datastore.assign_ip = m_assign_ip

        # Test that error for second IP was ack'd
        with self.assertRaises(IsolatorException) as e:
            calico_mesos._reserve(hostname, uid, ipv4_addrs, ipv6_addrs)
        self.assertEqual(e.exception.message, "IP '192.168.1.2' already in use.")

        # Test that only the first IP was released
        m_datastore.release_ips.assert_called_once_with({IPAddress("192.168.1.1")})
Beispiel #4
0
    def test_reserve_is_functional(self, m_datastore):
        hostname = "metaman"
        ipv4_addrs = ["192.168.1.1", "192.168.1.2"]
        ipv6_addrs = ["dead::beef"]
        uid = "abc-def-gh"

        m_assign_ip = Mock()
        m_datastore.assign_ip = m_assign_ip
        result = calico_mesos._reserve(hostname, uid, ipv4_addrs, ipv6_addrs)
        self.assertIsNone(result)
        for ip_addr in ipv4_addrs + ipv6_addrs:
            m_assign_ip.assert_any_call(ip_addr, uid, {}, hostname)
Beispiel #5
0
    def test_reserve_rolls_back(self, exception, m_datastore):
        hostname = "metaman"
        ipv4_addrs = [IPAddress("192.168.1.1"), IPAddress("192.168.1.2")]
        ipv6_addrs = [IPAddress("dead::beef")]
        uid = "abc-def-gh"

        def side_effect(address, handle_id, attributes, host=None):
            if address == IPAddress("192.168.1.2"):
                # Arbitrarily throw an error when the second address is passed in
                raise exception

        m_assign_ip = MagicMock(side_effect=side_effect)
        m_datastore.assign_ip = m_assign_ip

        # Test that error for second IP was ack'd
        with self.assertRaises(IsolatorException) as e:
            calico_mesos._reserve(hostname, uid, ipv4_addrs, ipv6_addrs)
        self.assertEqual(e.exception.message, "IP '192.168.1.2' already in use.")

        # Test that only the first IP was released
        m_datastore.release_ips.assert_called_once_with({IPAddress("192.168.1.1")})
Beispiel #6
0
    def test_reserve_is_functional(self, m_datastore):
        hostname = "metaman"
        ipv4_addrs = ["192.168.1.1", "192.168.1.2"]
        ipv6_addrs = ["dead::beef"]
        uid = "abc-def-gh"

        m_assign_ip = Mock()
        m_datastore.assign_ip = m_assign_ip
        result = calico_mesos._reserve(hostname, uid, ipv4_addrs, ipv6_addrs)
        self.assertIsNone(result)
        for ip_addr in ipv4_addrs + ipv6_addrs:
            m_assign_ip.assert_any_call(ip_addr, uid, {}, hostname)