def test_file_exists_exhaustion(tmpdir): flock_processes = [] try: for x in range(100): flock_process = _flock_process( str(tmpdir.join('02:52:00:00:00:{:02x}'.format(x)))) flock_processes.append(flock_process) with pytest.raises(mac_address.MacAddressException): mac_address.reserve_unique_mac_address(str(tmpdir)) finally: [os.kill(p, signal.SIGKILL) for p in flock_processes]
def add_firewall(argv, service, instance): output = '' try: mac_address, lockfile = reserve_unique_mac_address(LOCK_DIRECTORY) except Exception as e: output = f'Unable to add mac address: {e}' else: argv = add_argument(argv, f'--mac-address={mac_address}') try: with firewall_flock(): prepare_new_container( DEFAULT_SOA_DIR, DEFAULT_SYNAPSE_SERVICE_DIR, service, instance, mac_address, ) except Exception as e: output = f'Unable to add firewall rules: {e}' if output: print(output, file=sys.stderr) return argv
def test_file_exists_flock(tmpdir): # it doesn't count if this process has the flock, so we need to spawn a different one to hold it flock_process = _flock_process(str(tmpdir.join('02:52:00:00:00:00'))) try: mac, lock_file = mac_address.reserve_unique_mac_address(str(tmpdir)) with contextlib.closing(lock_file): assert lock_file is not None assert mac == '02:52:00:00:00:01' finally: os.kill(flock_process, signal.SIGKILL)
def test_file_exists_no_flock(tmpdir): tmpdir.join('02:52:00:00:00:00').ensure() mac, lock_file = mac_address.reserve_unique_mac_address(str(tmpdir)) with contextlib.closing(lock_file): assert lock_file is not None assert mac == '02:52:00:00:00:00'
def test_dir_not_exist(tmpdir): with pytest.raises(IOError): mac_address.reserve_unique_mac_address(str(tmpdir.join('nonexistent')))
def test_simple(tmpdir): mac, lock_file = mac_address.reserve_unique_mac_address(str(tmpdir)) with contextlib.closing(lock_file): assert lock_file is not None assert mac == '02:52:00:00:00:00' assert tmpdir.join(mac).check()