示例#1
0
    def test_remove_secondaries(self):
        require_user('root')

        ifA = self.get_ifname()

        with self.ip.create(kind='dummy', ifname=ifA) as i:
            i.add_ip('172.16.0.1', 24)
            i.add_ip('172.16.0.2', 24)

        assert ifA in self.ip.interfaces
        assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
        assert ('172.16.0.2', 24) in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifA)
        assert '172.16.0.2/24' in get_ip_addr(interface=ifA)

        if i._mode == 'explicit':
            i.begin()

        i.del_ip('172.16.0.1', 24)
        i.del_ip('172.16.0.2', 24)
        i.commit()

        assert ('172.16.0.1', 24) not in self.ip.interfaces[ifA].ipaddr
        assert ('172.16.0.2', 24) not in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' not in get_ip_addr(interface=ifA)
        assert '172.16.0.2/24' not in get_ip_addr(interface=ifA)
示例#2
0
    def test_remove_secondaries(self):
        require_user('root')

        ifA = self.get_ifname()

        with self.ip.create(kind='dummy', ifname=ifA) as i:
            i.add_ip('172.16.0.1', 24)
            i.add_ip('172.16.0.2', 24)

        assert ifA in self.ip.interfaces
        assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
        assert ('172.16.0.2', 24) in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifA)
        assert '172.16.0.2/24' in get_ip_addr(interface=ifA)

        if i._mode == 'explicit':
            i.begin()

        i.del_ip('172.16.0.1', 24)
        i.del_ip('172.16.0.2', 24)
        i.commit()

        assert ('172.16.0.1', 24) not in self.ip.interfaces[ifA].ipaddr
        assert ('172.16.0.2', 24) not in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' not in get_ip_addr(interface=ifA)
        assert '172.16.0.2/24' not in get_ip_addr(interface=ifA)
示例#3
0
    def _create_master(self, kind, **kwarg):

        ifM = self.get_ifname()
        ifP1 = self.get_ifname()
        ifP2 = self.get_ifname()

        self.ip.create(kind='dummy', ifname=ifP1).commit()
        self.ip.create(kind='dummy', ifname=ifP2).commit()

        with self.ip.create(kind=kind, ifname=ifM, **kwarg) as i:
            i.add_port(self.ip.interfaces[ifP1])
            i.add_port(self.ip.interfaces[ifP2])
            i.add_ip('172.16.0.1/24')

        assert ('172.16.0.1', 24) in self.ip.interfaces[ifM].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifM)
        assert self.ip.interfaces[ifP1].if_master == \
            self.ip.interfaces[ifM].index
        assert self.ip.interfaces[ifP2].if_master == \
            self.ip.interfaces[ifM].index

        with self.ip.interfaces[ifM] as i:
            i.del_port(self.ip.interfaces[ifP1])
            i.del_port(self.ip.interfaces[ifP2])
            i.del_ip('172.16.0.1/24')

        assert ('172.16.0.1', 24) not in self.ip.interfaces[ifM].ipaddr
        assert '172.16.0.1/24' not in get_ip_addr(interface=ifM)
        assert self.ip.interfaces[ifP1].if_master is None
        assert self.ip.interfaces[ifP2].if_master is None
示例#4
0
    def _create_master(self, kind, **kwarg):
        require_user('root')
        assert 'bala' not in self.ip.interfaces
        assert 'bala_port0' not in self.ip.interfaces
        assert 'bala_port1' not in self.ip.interfaces

        self.ip.create(kind='dummy', ifname='bala_port0').commit()
        self.ip.create(kind='dummy', ifname='bala_port1').commit()

        with self.ip.create(kind=kind, ifname='bala', **kwarg) as i:
            i.add_port(self.ip.interfaces.bala_port0)
            i.add_port(self.ip.interfaces.bala_port1)
            i.add_ip('172.16.0.1/24')

        assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface='bala')
        assert self.ip.interfaces.bala_port0.if_master == \
            self.ip.interfaces.bala.index
        assert self.ip.interfaces.bala_port1.if_master == \
            self.ip.interfaces.bala.index

        with self.ip.interfaces.bala as i:
            i.del_port(self.ip.interfaces.bala_port0)
            i.del_port(self.ip.interfaces.bala_port1)
            i.del_ip('172.16.0.1/24')

        assert ('172.16.0.1', 24) not in self.ip.interfaces.bala.ipaddr
        assert '172.16.0.1/24' not in get_ip_addr(interface='bala')
        assert self.ip.interfaces.bala_port0.if_master is None
        assert self.ip.interfaces.bala_port1.if_master is None
示例#5
0
    def _create_master(self, kind):
        require_user('root')
        assert 'bala' not in self.ip.interfaces
        assert 'bala_port0' not in self.ip.interfaces
        assert 'bala_port1' not in self.ip.interfaces

        self.ip.create(kind='dummy', ifname='bala_port0').commit()
        self.ip.create(kind='dummy', ifname='bala_port1').commit()

        with self.ip.create(kind=kind, ifname='bala') as i:
            i.add_port(self.ip.interfaces.bala_port0)
            i.add_port(self.ip.interfaces.bala_port1)
            i.add_ip('172.16.0.1/24')

        assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface='bala')
        assert self.ip.interfaces.bala_port0.if_master == \
            self.ip.interfaces.bala.index
        assert self.ip.interfaces.bala_port1.if_master == \
            self.ip.interfaces.bala.index

        with self.ip.interfaces.bala as i:
            i.del_port(self.ip.interfaces.bala_port0)
            i.del_port(self.ip.interfaces.bala_port1)
            i.del_ip('172.16.0.1/24')

        assert ('172.16.0.1', 24) not in self.ip.interfaces.bala.ipaddr
        assert '172.16.0.1/24' not in get_ip_addr(interface='bala')
        assert self.ip.interfaces.bala_port0.if_master is None
        assert self.ip.interfaces.bala_port1.if_master is None
示例#6
0
文件: test_ipdb.py 项目: abn/pyroute2
    def test_remove_secondaries(self):
        require_user("root")

        ifA = self.get_ifname()

        with self.ip.create(kind="dummy", ifname=ifA) as i:
            i.add_ip("172.16.0.1", 24)
            i.add_ip("172.16.0.2", 24)

        assert ifA in self.ip.interfaces
        assert ("172.16.0.1", 24) in self.ip.interfaces[ifA].ipaddr
        assert ("172.16.0.2", 24) in self.ip.interfaces[ifA].ipaddr
        assert "172.16.0.1/24" in get_ip_addr(interface=ifA)
        assert "172.16.0.2/24" in get_ip_addr(interface=ifA)

        if i._mode == "explicit":
            i.begin()

        i.del_ip("172.16.0.1", 24)
        i.del_ip("172.16.0.2", 24)
        i.commit()

        assert ("172.16.0.1", 24) not in self.ip.interfaces[ifA].ipaddr
        assert ("172.16.0.2", 24) not in self.ip.interfaces[ifA].ipaddr
        assert "172.16.0.1/24" not in get_ip_addr(interface=ifA)
        assert "172.16.0.2/24" not in get_ip_addr(interface=ifA)
示例#7
0
 def test_create_plain(self):
     require_user('root')
     assert 'bala' not in self.ip.interfaces
     i = self.ip.create(kind='dummy', ifname='bala')
     i.add_ip('172.16.0.1/24')
     i.commit()
     assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
     assert '172.16.0.1/24' in get_ip_addr(interface='bala')
示例#8
0
 def test_create_plain(self):
     require_user('root')
     assert 'bala' not in self.ip.interfaces
     i = self.ip.create(kind='dummy', ifname='bala')
     i.add_ip('172.16.0.1/24')
     i.commit()
     assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
     assert '172.16.0.1/24' in get_ip_addr(interface='bala')
示例#9
0
文件: test_ipdb.py 项目: abn/pyroute2
    def test_create_plain(self):
        require_user("root")
        ifA = self.get_ifname()

        i = self.ip.create(kind="dummy", ifname=ifA)
        i.add_ip("172.16.0.1/24")
        i.commit()
        assert ("172.16.0.1", 24) in self.ip.interfaces[ifA].ipaddr
        assert "172.16.0.1/24" in get_ip_addr(interface=ifA)
示例#10
0
    def test_create_plain(self):
        require_user('root')
        ifA = self.get_ifname()

        i = self.ip.create(kind='dummy', ifname=ifA)
        i.add_ip('172.16.0.1/24')
        i.commit()
        assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifA)
示例#11
0
    def test_create_plain(self):
        require_user('root')
        ifA = self.get_ifname()

        i = self.ip.create(kind='dummy', ifname=ifA)
        i.add_ip('172.16.0.1/24')
        i.commit()
        assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifA)
示例#12
0
    def test_create_and_remove(self):
        require_user('root')
        assert 'bala' not in self.ip.interfaces

        with self.ip.create(kind='dummy', ifname='bala') as i:
            i.add_ip('172.16.0.1/24')
        assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface='bala')

        with self.ip.interfaces.bala as i:
            i.remove()
        assert 'bala' not in self.ip.interfaces
示例#13
0
    def test_create_and_remove(self):
        require_user('root')
        assert 'bala' not in self.ip.interfaces

        with self.ip.create(kind='dummy', ifname='bala') as i:
            i.add_ip('172.16.0.1/24')
        assert ('172.16.0.1', 24) in self.ip.interfaces.bala.ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface='bala')

        with self.ip.interfaces.bala as i:
            i.remove()
        assert 'bala' not in self.ip.interfaces
示例#14
0
    def test_create_and_remove(self):
        require_user('root')

        ifA = self.get_ifname()

        with self.ip.create(kind='dummy', ifname=ifA) as i:
            i.add_ip('172.16.0.1/24')
        assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifA)

        with self.ip.interfaces[ifA] as i:
            i.remove()
        assert ifA not in self.ip.interfaces
示例#15
0
文件: test_ipdb.py 项目: abn/pyroute2
    def test_create_and_remove(self):
        require_user("root")

        ifA = self.get_ifname()

        with self.ip.create(kind="dummy", ifname=ifA) as i:
            i.add_ip("172.16.0.1/24")
        assert ("172.16.0.1", 24) in self.ip.interfaces[ifA].ipaddr
        assert "172.16.0.1/24" in get_ip_addr(interface=ifA)

        with self.ip.interfaces[ifA] as i:
            i.remove()
        assert ifA not in self.ip.interfaces
示例#16
0
    def test_create_and_remove(self):
        require_user('root')

        ifA = self.get_ifname()

        with self.ip.create(kind='dummy', ifname=ifA) as i:
            i.add_ip('172.16.0.1/24')
        assert ('172.16.0.1', 24) in self.ip.interfaces[ifA].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifA)

        with self.ip.interfaces[ifA] as i:
            i.remove()
        assert ifA not in self.ip.interfaces
示例#17
0
    def _create_master(self, kind, **kwarg):

        ifM = self.get_ifname()
        ifP1 = self.get_ifname()
        ifP2 = self.get_ifname()

        self.ip.create(kind='dummy', ifname=ifP1).commit()
        self.ip.create(kind='dummy', ifname=ifP2).commit()

        with self.ip.create(kind=kind, ifname=ifM, **kwarg) as i:
            i.add_port(self.ip.interfaces[ifP1])
            i.add_ip('172.16.0.1/24')

        with self.ip.interfaces[ifM] as i:
            i.add_port(self.ip.interfaces[ifP2])
            i.add_ip('172.16.0.2/24')

        assert ('172.16.0.1', 24) in self.ip.interfaces[ifM].ipaddr
        assert ('172.16.0.2', 24) in self.ip.interfaces[ifM].ipaddr
        assert '172.16.0.1/24' in get_ip_addr(interface=ifM)
        assert '172.16.0.2/24' in get_ip_addr(interface=ifM)
        assert self.ip.interfaces[ifP1].if_master == \
            self.ip.interfaces[ifM].index
        assert self.ip.interfaces[ifP2].if_master == \
            self.ip.interfaces[ifM].index

        with self.ip.interfaces[ifM] as i:
            i.del_port(self.ip.interfaces[ifP1])
            i.del_port(self.ip.interfaces[ifP2])
            i.del_ip('172.16.0.1/24')
            i.del_ip('172.16.0.2/24')

        assert ('172.16.0.1', 24) not in self.ip.interfaces[ifM].ipaddr
        assert ('172.16.0.2', 24) not in self.ip.interfaces[ifM].ipaddr
        assert '172.16.0.1/24' not in get_ip_addr(interface=ifM)
        assert '172.16.0.2/24' not in get_ip_addr(interface=ifM)
        assert self.ip.interfaces[ifP1].if_master is None
        assert self.ip.interfaces[ifP2].if_master is None
示例#18
0
文件: test_ipdb.py 项目: abn/pyroute2
    def _create_master(self, kind, **kwarg):

        ifM = self.get_ifname()
        ifP1 = self.get_ifname()
        ifP2 = self.get_ifname()

        self.ip.create(kind="dummy", ifname=ifP1).commit()
        self.ip.create(kind="dummy", ifname=ifP2).commit()

        with self.ip.create(kind=kind, ifname=ifM, **kwarg) as i:
            i.add_port(self.ip.interfaces[ifP1])
            i.add_ip("172.16.0.1/24")

        with self.ip.interfaces[ifM] as i:
            i.add_port(self.ip.interfaces[ifP2])
            i.add_ip("172.16.0.2/24")

        assert ("172.16.0.1", 24) in self.ip.interfaces[ifM].ipaddr
        assert ("172.16.0.2", 24) in self.ip.interfaces[ifM].ipaddr
        assert "172.16.0.1/24" in get_ip_addr(interface=ifM)
        assert "172.16.0.2/24" in get_ip_addr(interface=ifM)
        assert self.ip.interfaces[ifP1].if_master == self.ip.interfaces[ifM].index
        assert self.ip.interfaces[ifP2].if_master == self.ip.interfaces[ifM].index

        with self.ip.interfaces[ifM] as i:
            i.del_port(self.ip.interfaces[ifP1])
            i.del_port(self.ip.interfaces[ifP2])
            i.del_ip("172.16.0.1/24")
            i.del_ip("172.16.0.2/24")

        assert ("172.16.0.1", 24) not in self.ip.interfaces[ifM].ipaddr
        assert ("172.16.0.2", 24) not in self.ip.interfaces[ifM].ipaddr
        assert "172.16.0.1/24" not in get_ip_addr(interface=ifM)
        assert "172.16.0.2/24" not in get_ip_addr(interface=ifM)
        assert self.ip.interfaces[ifP1].if_master is None
        assert self.ip.interfaces[ifP2].if_master is None
示例#19
0
 def test_addr(self):
     assert len(get_ip_addr()) == len(self.ip.get_addr())
示例#20
0
 def test_ips(self):
     for name in self.ip.by_name:
         assert len(self.ip.interfaces[name]['ipaddr']) == \
             len(get_ip_addr(name))
示例#21
0
import pygame
import time
import flask
import multiprocessing
import Queue
import socket
import sys
import threading
from flask import Flask
from flask import request
from constants import *
import utils
import os
import pickle
import collections
from replica_music_service import ReplicaMusicService
from election_service import ReplicaElectionService

if __name__ == "__main__":
    # start replica service
    ip_addr = utils.get_ip_addr()

    response_queue = multiprocessing.Queue()
    state_queue = multiprocessing.Queue()
    replica_service = ReplicaMusicService(collections.deque([]), ip_addr,
                                          state_queue, response_queue)
    election_service = ReplicaElectionService(ip_addr, state_queue,
                                              response_queue)
    replica_service.start()
    election_service.start()
示例#22
0
 def test_addr_add(self):
     require_user('root')
     ifaddr = self.ifaddr()
     self.ip.addr('add', self.ifaces[0], address=ifaddr, mask=24)
     assert '{0}/24'.format(ifaddr) in get_ip_addr()
示例#23
0
import pygame
import time
import flask
import multiprocessing
import Queue
import socket
import sys
import threading
from flask import Flask
from flask import request
from constants import *
import utils
import os
import pickle
import collections
from replica_music_service import ReplicaMusicService
from election_service import ReplicaElectionService


if __name__ == "__main__":
    # start replica service
    ip_addr = utils.get_ip_addr()

    response_queue = multiprocessing.Queue()
    state_queue = multiprocessing.Queue()
    replica_service = ReplicaMusicService(collections.deque([]), ip_addr, state_queue, response_queue)
    election_service = ReplicaElectionService(ip_addr, state_queue, response_queue)
    replica_service.start()
    election_service.start()
示例#24
0
 def test_addr_add(self):
     require_user('root')
     ifaddr = self.ifaddr()
     self.ip.addr('add', self.ifaces[0], address=ifaddr, mask=24)
     assert '{0}/24'.format(ifaddr) in get_ip_addr()
示例#25
0
 def test_add_addr(self):
     require_user('root')
     dev = self.dev[0]
     self.ip.addr('add', dev, address='172.16.0.1', mask=24)
     assert '172.16.0.1/24' in get_ip_addr()
示例#26
0
 def test_add_addr(self):
     require_user('root')
     self.ip.addr('add', self.ifaces[0], address='172.16.0.1', mask=24)
     assert '172.16.0.1/24' in get_ip_addr()
示例#27
0
文件: test_ipdb.py 项目: abn/pyroute2
 def test_addr_loaded(self):
     for name in self.ip.by_name:
         assert len(self.ip.interfaces[name]["ipaddr"]) == len(get_ip_addr(name))
示例#28
0
 def test_addr(self):
     assert len(get_ip_addr()) == len(self.ip.get_addr())
示例#29
0
 def test_ips(self):
     for name in self.ip.by_name:
         assert len(self.ip.interfaces[name]['ipaddr']) == \
             len(get_ip_addr(name))
示例#30
0
 def test_addr_add(self):
     require_user('root')
     self.ip.addr('add', self.ifaces[0], address='172.16.0.1', mask=24)
     assert '172.16.0.1/24' in get_ip_addr()
示例#31
0
 def test_add_addr(self):
     require_user('root')
     dev = self.dev[0]
     self.ip.addr('add', dev, address='172.16.0.1', mask=24)
     assert '172.16.0.1/24' in get_ip_addr()