示例#1
0
    def test_init_only_static_routes(self):
        routes = [('0.0.0.0/0', '192.168.1.1'),
                  ('172.16.77.0/16', '192.168.1.254')]
        c = models.RouterConfiguration(dict(networks=[], static_routes=routes))

        self.assertEqual(len(c.static_routes), 2)
        self.assertEqual(
            c.static_routes,
            [models.StaticRoute(*routes[0]),
             models.StaticRoute(*routes[1])])
 def test_model_base_to_dict(self):
     data = dict(r=models.StaticRoute('192.168.1.0/24', '172.16.77.1'))
     expected = ('{"r": {"destination": "192.168.1.0/24", '
                 '"next_hop": "172.16.77.1"}}')
     serialized = json.dumps(data,
                             cls=utils.ModelSerializer,
                             sort_keys=True)
     self.assertEqual(serialized, expected)
示例#3
0
 def test_eq_not_equal(self):
     sr1 = models.StaticRoute('0.0.0.0/0', '192.168.1.1')
     sr2 = models.StaticRoute('172.16.0.0/16', '192.168.1.1')
     self.assertNotEqual(sr1, sr2)
示例#4
0
 def test_eq_none(self):
     sr = models.StaticRoute('0.0.0.0/0', '192.168.1.1')
     self.assertNotEqual(sr, None)
示例#5
0
 def test_static_route(self):
     sr = models.StaticRoute('0.0.0.0/0', '192.168.1.1')
     self.assertEqual(sr.destination, netaddr.IPNetwork('0.0.0.0/0'))
     self.assertEqual(sr.next_hop, netaddr.IPAddress('192.168.1.1'))
示例#6
0
# under the License.

from unittest2 import TestCase

import mock
import netaddr
from collections import OrderedDict

from astara_router import models
from astara_router.drivers import dnsmasq
ext_subnet = mock.Mock()
ext_subnet.gateway_ip = netaddr.IPAddress('dead:beef::1')

ext_subnet.cidr = netaddr.IPNetwork('dead:beef::/64')
ext_subnet.dns_nameservers = []
ext_subnet.host_routes = [models.StaticRoute('172.16.0.0/16', '192.168.1.1')]
ext_subnet.dns_nameservers = ['8.8.8.8', '8.8.4.4']

ext_net = mock.Mock()
ext_net.subnets = [ext_subnet]
ext_net.is_internal_network = False
ext_net.is_external_network = True
ext_net.is_tenant_network = False
ext_net.interface.ifname = 'ge0'
ext_net.address_allocations = [
    models.Allocation(
        'fa:da:fa:da:fa:da:',
        {
            '192.168.1.2': True,
            'dead:beef::2': False
        },  # ip: DHCP enabled