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)
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
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
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
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)
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')
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)
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)
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
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
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
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
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
def test_addr(self): assert len(get_ip_addr()) == len(self.ip.get_addr())
def test_ips(self): for name in self.ip.by_name: assert len(self.ip.interfaces[name]['ipaddr']) == \ len(get_ip_addr(name))
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()
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()
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()
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()
def test_addr_loaded(self): for name in self.ip.by_name: assert len(self.ip.interfaces[name]["ipaddr"]) == len(get_ip_addr(name))
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()