コード例 #1
0
ファイル: netfunctestlib.py プロジェクト: vjuranek/vdsm
 def assertStaticIPv4(self, netattrs, ipinfo):
     address = netattrs['ipaddr']
     netmask = netattrs.get('netmask') or prefix2netmask(
         int(netattrs.get('prefix')))
     assert address == ipinfo['addr']
     assert netmask == ipinfo['netmask']
     ipv4 = ipaddress.IPv4Interface(u'{}/{}'.format(address, netmask))
     assert str(ipv4.with_prefixlen) in ipinfo['ipv4addrs']
コード例 #2
0
 def assertStaticIPv4(self, netattrs, ipinfo):
     requires_ipaddress()
     address = netattrs['ipaddr']
     netmask = (netattrs.get('netmask')
                or prefix2netmask(int(netattrs.get('prefix'))))
     self.assertEqual(address, ipinfo['addr'])
     self.assertEqual(netmask, ipinfo['netmask'])
     ipv4 = ipaddress.IPv4Interface(u'{}/{}'.format(address, netmask))
     self.assertIn(str(ipv4.with_prefixlen), ipinfo['ipv4addrs'])
コード例 #3
0
def _canonicalize_ipv4_netmask(data):
    prefix = data.pop('prefix', None)
    if prefix:
        if 'netmask' in data:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
                                     'Both PREFIX and NETMASK supplied')
        try:
            data['netmask'] = prefix2netmask(int(prefix))
        except ValueError as ve:
            raise ConfigNetworkError(ne.ERR_BAD_ADDR, 'Bad prefix: %s' % ve)
コード例 #4
0
 def test_netmask_conversions(self):
     path = os.path.join(os.path.dirname(__file__), "netmaskconversions")
     with open(path) as netmaskFile:
         for line in netmaskFile:
             if line.startswith('#'):
                 continue
             bitmask, address = [value.strip() for value in line.split()]
             assert prefix2netmask(int(bitmask)) == address
     pytest.raises(ValueError, prefix2netmask, -1)
     pytest.raises(ValueError, prefix2netmask, 33)
コード例 #5
0
ファイル: netinfo_test.py プロジェクト: nirs/vdsm
 def test_netmask_conversions(self):
     path = os.path.join(os.path.dirname(__file__), "netmaskconversions")
     with open(path) as netmaskFile:
         for line in netmaskFile:
             if line.startswith('#'):
                 continue
             bitmask, address = [value.strip() for value in line.split()]
             self.assertEqual(prefix2netmask(int(bitmask)), address)
     self.assertRaises(ValueError, prefix2netmask, -1)
     self.assertRaises(ValueError, prefix2netmask, 33)
コード例 #6
0
def _normalize_address(config_copy):
    for net_name, net_attr in six.iteritems(config_copy.networks):
        prefix = net_attr.pop('prefix', None)
        if prefix is not None:
            net_attr['netmask'] = prefix2netmask(int(prefix))
        if 'ipv6addr' in net_attr:
            net_attr['ipv6addr'] = [net_attr['ipv6addr']]
        if 'defaultRoute' not in net_attr:
            net_attr['defaultRoute'] = net_name in \
                constants.LEGACY_MANAGEMENT_NETWORKS
コード例 #7
0
ファイル: netfunctestlib.py プロジェクト: EdDev/vdsm
 def assertStaticIPv4(self, netattrs, ipinfo):
     requires_ipaddress()
     address = netattrs['ipaddr']
     netmask = (netattrs.get('netmask') or
                prefix2netmask(int(netattrs.get('prefix'))))
     self.assertEqual(address, ipinfo['addr'])
     self.assertEqual(netmask, ipinfo['netmask'])
     ipv4 = ipaddress.IPv4Interface(
         u'{}/{}'.format(address, netmask))
     self.assertIn(str(ipv4.with_prefixlen), ipinfo['ipv4addrs'])
コード例 #8
0
ファイル: canonicalize.py プロジェクト: nirs/vdsm
def _canonicalize_ipv4_netmask(data):
    prefix = data.pop('prefix', None)
    if prefix:
        if 'netmask' in data:
            raise ConfigNetworkError(
                ne.ERR_BAD_PARAMS, 'Both PREFIX and NETMASK supplied')
        try:
            data['netmask'] = prefix2netmask(int(prefix))
        except ValueError as ve:
            raise ConfigNetworkError(ne.ERR_BAD_ADDR, 'Bad prefix: %s' % ve)
コード例 #9
0
ファイル: netfunctestlib.py プロジェクト: nirs/vdsm
 def assertStaticIPv4(self, netattrs, ipinfo):
     requires_ipaddress()
     address = netattrs['ipaddr']
     netmask = (netattrs.get('netmask') or
                prefix2netmask(int(netattrs.get('prefix'))))
     assert address == ipinfo['addr']
     assert netmask == ipinfo['netmask']
     ipv4 = ipaddress.IPv4Interface(
         u'{}/{}'.format(address, netmask))
     assert str(ipv4.with_prefixlen) in ipinfo['ipv4addrs']
コード例 #10
0
ファイル: ip_address_test.py プロジェクト: emesika/vdsm
#

import itertools
import os

import pytest

from network.nettestlib import dummy_device
from network.nettestlib import nm_is_running
from network.nettestlib import preserve_default_route

from vdsm.network.ip import address
from vdsm.network.netinfo import routes

IPV4_PREFIX = 29
IPV4_NETMASK = address.prefix2netmask(IPV4_PREFIX)
IPV4_A_ADDRESS = '192.168.99.1'
IPV4_A_WITH_PREFIXLEN = '{}/{}'.format(IPV4_A_ADDRESS, IPV4_PREFIX)
IPV4_B_ADDRESS = '192.168.98.1'
IPV4_B_WITH_PREFIXLEN = '{}/{}'.format(IPV4_B_ADDRESS, IPV4_PREFIX)
IPV4_GATEWAY = '192.168.99.6'

IPV6_PREFIX = 64
IPV6_A_ADDRESS = '2001:99::1'
IPV6_A_WITH_PREFIXLEN = '{}/{}'.format(IPV6_A_ADDRESS, IPV6_PREFIX)
IPV6_B_ADDRESS = '2002:99::1'
IPV6_B_WITH_PREFIXLEN = '{}/{}'.format(IPV6_B_ADDRESS, IPV6_PREFIX)
IPV6_GATEWAY = '2001:99::99'

ipv6_broken_on_travis_ci = pytest.mark.skipif(
    'TRAVIS_CI' in os.environ, reason='IPv6 not supported on travis')
コード例 #11
0
ファイル: ip_address_test.py プロジェクト: EdDev/vdsm
#
from __future__ import absolute_import

from nose.plugins.attrib import attr

from testlib import VdsmTestCase

from .nettestlib import dummy_device, preserve_default_route

from vdsm.network.ip import address
from vdsm.network.netinfo import routes


IPV4_ADDRESS = '192.168.99.1'
IPV4_PREFIX = 29
IPV4_NETMASK = address.prefix2netmask(IPV4_PREFIX)
IPV4_GATEWAY = '192.168.99.6'

IPV6_ADDRESS = '2001:99::1/64'
IPV6_GATEWAY = '2001:99::99'


@attr(type='unit')
class TestAddressIP(VdsmTestCase):

    def test_ipv4_clean_init(self):
        ip = address.IPv4()
        self._assert_ip_clean_init(ip)
        self.assertEqual(None, ip.bootproto)
        self.assertEqual(None, ip.netmask)