Ejemplo n.º 1
0
class IPRouteTest(unittest.TestCase):
    IPRoute = ip_route.driver(ip_route.Drivers.IPROUTE2)

    def test_add_delete_and_read_route(self):
        route = IPRouteData(to=IPV4_ADDRESS, via=None, family=4, device='lo')
        with self.create_route(route):
            routes = [r for r in IPRouteTest.IPRoute.routes(table='main')
                      if r.to == IPV4_ADDRESS]
            self.assertEqual(1, len(routes))
            self.assertEqual(routes[0].device, 'lo')
            self.assertEqual(routes[0].table, 'main')

    def test_delete_non_existing_route(self):
        route = IPRouteData(to=IPV4_ADDRESS, via=None, family=4, device='lo')
        with self.assertRaises(IPRouteDeleteError):
            IPRouteTest.IPRoute.delete(route)

    def test_add_route_with_non_existing_device(self):
        route = IPRouteData(to=IPV4_ADDRESS, via=None, family=4, device='NoNe')
        with self.assertRaises(IPRouteAddError):
            IPRouteTest.IPRoute.add(route)

    @contextmanager
    def create_route(self, route_data):
        IPRouteTest.IPRoute.add(route_data)
        try:
            yield
        finally:
            IPRouteTest.IPRoute.delete(route_data)
Ejemplo n.º 2
0
from vdsm.common.constants import P_VDSM_RUN
from vdsm.network.ip import route as ip_route
from vdsm.network.ip import rule as ip_rule
from vdsm.network.ip.route import IPRouteData
from vdsm.network.ip.route import IPRouteError, IPRouteDeleteError
from vdsm.network.ip.rule import IPRuleData
from vdsm.network.ip.rule import IPRuleError

from .ipwrapper import Route
from .ipwrapper import routeShowTable
from .ipwrapper import Rule
from .ipwrapper import ruleList


IPRoute = ip_route.driver(ip_route.Drivers.IPROUTE2)
IPRule = ip_rule.driver(ip_rule.Drivers.IPROUTE2)

TRACKED_INTERFACES_FOLDER = P_VDSM_RUN + 'trackedInterfaces'

RULE_PRIORITY = 32000


class StaticSourceRoute(object):
    def __init__(self, device, ipaddr, mask, gateway):
        self.device = device
        self._ipaddr = ipaddr
        self._mask = mask
        self._gateway = gateway
        self._table = str(self._generateTableId(ipaddr)) if ipaddr else None
        self._network = self._parse_network(ipaddr, mask)
Ejemplo n.º 3
0
import netaddr

from vdsm.common.constants import P_VDSM_RUN
from vdsm.network.ip import route as ip_route
from vdsm.network.ip import rule as ip_rule
from vdsm.network.ip.route import IPRouteData
from vdsm.network.ip.route import IPRouteError, IPRouteDeleteError
from vdsm.network.ip.rule import IPRuleData
from vdsm.network.ip.rule import IPRuleError

from .ipwrapper import Route
from .ipwrapper import routeShowTable
from .ipwrapper import Rule
from .ipwrapper import ruleList

IPRoute = ip_route.driver(ip_route.Drivers.IPROUTE2)
IPRule = ip_rule.driver(ip_rule.Drivers.IPROUTE2)

TRACKED_INTERFACES_FOLDER = P_VDSM_RUN + 'trackedInterfaces'

RULE_PRIORITY = 32000


class StaticSourceRoute(object):
    def __init__(self, device, ipaddr, mask, gateway):
        self.device = device
        self._ipaddr = ipaddr
        self._mask = mask
        self._gateway = gateway
        self._table = str(self._generateTableId(ipaddr)) if ipaddr else None
        self._network = self._parse_network(ipaddr, mask)
Ejemplo n.º 4
0
def ip_route_driver():
    return ip_route.driver(ip_route.Drivers.IPROUTE2)