Esempio n. 1
0
    def test_add_route(self):
        tap = "tap" + str(uuid.uuid4())[:11]
        mac = stub_utils.get_mac()
        retcode = futils.CommandOutput("", "")

        type = futils.IPV4
        ip = "1.2.3.4"
        with mock.patch('calico.felix.futils.check_call', return_value=retcode):
            devices.add_route(type, ip, tap, mac)
            futils.check_call.assert_any_call(['arp', '-s', ip, mac, '-i', tap])
            futils.check_call.assert_called_with(["ip", "route", "replace", ip, "dev", tap])

        with self.assertRaisesRegexp(ValueError,
                                     "mac must be supplied if ip is provided"):
            devices.add_route(type, ip, tap, None)

        type = futils.IPV6
        ip = "2001::"
        with mock.patch('calico.felix.futils.check_call', return_value=retcode):
            devices.add_route(type, ip, tap, mac)
            futils.check_call.assert_called_with(["ip", "-6", "route", "replace", ip, "dev", tap])

        with self.assertRaisesRegexp(ValueError,
                                     "mac must be supplied if ip is provided"):
            devices.add_route(type, ip, tap, None)
Esempio n. 2
0
    def test_add_route(self):
        tap = "tap" + str(uuid.uuid4())[:11]
        mac = stub_utils.get_mac()
        retcode = futils.CommandOutput("", "")

        type = futils.IPV4
        ip = "1.2.3.4"
        with mock.patch('calico.felix.futils.check_call',
                        return_value=retcode):
            devices.add_route(type, ip, tap, mac)
            futils.check_call.assert_any_call(
                ['arp', '-s', ip, mac, '-i', tap])
            futils.check_call.assert_called_with(
                ["ip", "route", "replace", ip, "dev", tap])

        with mock.patch("calico.felix.futils.check_call") as m_check_call:
            devices.add_route(type, ip, tap, None)

        type = futils.IPV6
        ip = "2001::"
        with mock.patch('calico.felix.futils.check_call',
                        return_value=retcode):
            devices.add_route(type, ip, tap, mac)
            futils.check_call.assert_called_with(
                ["ip", "-6", "route", "replace", ip, "dev", tap])

        with mock.patch("calico.felix.futils.check_call") as m_check_call:
            devices.add_route(type, ip, tap, None)
Esempio n. 3
0
 def add_routes(routes, type):
     for route in routes:
         log.info("Add route to %s address %s for interface %s", type,
                  route, self.interface)
         devices.add_route(type, route, self.interface, self.mac)
Esempio n. 4
0
 def add_routes(routes, type):
     for route in routes:
         log.info("Add route to %s address %s for tap %s" %
                  (type, route, self.tap))
         devices.add_route(type, route, self.tap, self.mac)