add tests for onedns.server (now at 100% coverage)
parent
4c245819ce
commit
5475be37f2
|
@ -3,6 +3,7 @@ import dnslib
|
||||||
from IPy import IP
|
from IPy import IP
|
||||||
|
|
||||||
from onedns import zone
|
from onedns import zone
|
||||||
|
from onedns import server
|
||||||
from onedns import resolver
|
from onedns import resolver
|
||||||
from onedns.tests import vcr
|
from onedns.tests import vcr
|
||||||
from onedns.clients import one
|
from onedns.clients import one
|
||||||
|
@ -39,7 +40,16 @@ def dns(request):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def oneclient(request):
|
def one_dns(request, oneclient):
|
||||||
|
dns = server.OneDNS(domain=DOMAIN)
|
||||||
|
dns._one = oneclient
|
||||||
|
dns.start(dns_address=INTERFACE, dns_port=PORT, tcp=True)
|
||||||
|
request.addfinalizer(dns.close)
|
||||||
|
return dns
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def oneclient():
|
||||||
"""
|
"""
|
||||||
NOTE: All fixtures must be function scope to work with VCRPY cassettes
|
NOTE: All fixtures must be function scope to work with VCRPY cassettes
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from onedns import exception
|
||||||
|
from onedns.tests import vcr
|
||||||
|
from onedns.tests import utils
|
||||||
|
|
||||||
|
|
||||||
|
def _get_vm_with_nics(one_dns, vms):
|
||||||
|
for vm in vms:
|
||||||
|
try:
|
||||||
|
one_dns._check_for_networks(vm)
|
||||||
|
return vm
|
||||||
|
except exception.NoNetworksError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
def _add_and_verify(one_dns, vm, by_id=False, dns_entries=None):
|
||||||
|
if by_id:
|
||||||
|
one_dns.add_vm_by_id(vm)
|
||||||
|
else:
|
||||||
|
one_dns.add_vm(vm)
|
||||||
|
dns_entries = dns_entries or one_dns._get_vm_dns_entries(vm)
|
||||||
|
utils.verify_vm_dns(dns_entries)
|
||||||
|
|
||||||
|
|
||||||
|
def test_onedns_sync(one_dns, vms):
|
||||||
|
one_dns.sync(vms=vms)
|
||||||
|
uniq_names = []
|
||||||
|
uniq_ips = []
|
||||||
|
for vm in vms:
|
||||||
|
try:
|
||||||
|
dns_entries = one_dns._get_vm_dns_entries(vm)
|
||||||
|
except exception.NoNetworksError:
|
||||||
|
continue
|
||||||
|
if vm.name not in uniq_names:
|
||||||
|
for name, ip in dns_entries.items():
|
||||||
|
dns_entry = {name: ip}
|
||||||
|
if ip not in uniq_ips:
|
||||||
|
uniq_ips.append(ip)
|
||||||
|
utils.verify_vm_dns(dns_entry)
|
||||||
|
else:
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
utils.verify_vm_dns(dns_entry)
|
||||||
|
uniq_names.append(vm.name)
|
||||||
|
else:
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
utils.verify_vm_dns(dns_entries)
|
||||||
|
|
||||||
|
|
||||||
|
def test_onedns_add_vm(one_dns, vms):
|
||||||
|
vm = _get_vm_with_nics(one_dns, vms)
|
||||||
|
_add_and_verify(one_dns, vm)
|
||||||
|
|
||||||
|
|
||||||
|
def test_onedns_remove_vm(one_dns, vms):
|
||||||
|
vm = _get_vm_with_nics(one_dns, vms)
|
||||||
|
dns_entries = one_dns._get_vm_dns_entries(vm)
|
||||||
|
_add_and_verify(one_dns, vm)
|
||||||
|
one_dns.remove_vm(vm)
|
||||||
|
utils.verify_vm_dns_absent(dns_entries)
|
||||||
|
|
||||||
|
|
||||||
|
@vcr.use_cassette()
|
||||||
|
def test_onedns_add_vm_by_id(oneclient, one_dns):
|
||||||
|
vms = oneclient.vms()
|
||||||
|
vm = _get_vm_with_nics(one_dns, vms)
|
||||||
|
dns_entries = one_dns._get_vm_dns_entries(vm)
|
||||||
|
_add_and_verify(one_dns, vm.id, by_id=True, dns_entries=dns_entries)
|
||||||
|
|
||||||
|
|
||||||
|
@vcr.use_cassette()
|
||||||
|
def test_onedns_remove_vm_by_id(oneclient, one_dns):
|
||||||
|
vms = oneclient.vms()
|
||||||
|
vm = _get_vm_with_nics(one_dns, vms)
|
||||||
|
dns_entries = one_dns._get_vm_dns_entries(vm)
|
||||||
|
_add_and_verify(one_dns, vm)
|
||||||
|
one_dns.remove_vm_by_id(vm.id)
|
||||||
|
utils.verify_vm_dns_absent(dns_entries)
|
Loading…
Reference in New Issue