Skip to content

Commit

Permalink
tests: port network tests to core3 API
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarek committed Mar 7, 2016
1 parent 90795af commit bcc785d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 53 deletions.
2 changes: 1 addition & 1 deletion qubes/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
# integration tests
'qubes.tests.int.basic',
'qubes.tests.int.dom0_update',
# 'qubes.tests.network',
'qubes.tests.int.network',
# 'qubes.tests.vm_qrexec_gui',
# 'qubes.tests.backup',
# 'qubes.tests.backupcompatibility',
Expand Down
98 changes: 46 additions & 52 deletions tests/network.py → qubes/tests/int/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
import unittest
import time

from qubes.qubes import QubesVmCollection, defaults

import qubes.tests
import qubes.vm.appvm

class NcVersion:
Trad = 1
Expand All @@ -54,16 +53,18 @@ def run_cmd(self, vm, cmd, user="root"):

def setUp(self):
super(VmNetworkingMixin, self).setUp()
self.testnetvm = self.qc.add_new_vm("QubesNetVm",
self.init_default_template(self.template)
self.testnetvm = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=self.make_vm_name('netvm1'),
template=self.qc.get_vm_by_name(self.template))
self.testnetvm.create_on_disk(verbose=False)
self.testvm1 = self.qc.add_new_vm("QubesAppVm",
label='red')
self.testnetvm.create_on_disk()
self.testnetvm.provides_network = True
self.testvm1 = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=self.make_vm_name('vm2'),
template=self.qc.get_vm_by_name(self.template))
self.testvm1.create_on_disk(verbose=False)
label='red')
self.testvm1.create_on_disk()
self.testvm1.netvm = self.testnetvm
self.qc.save()
self.app.save()

self.configure_netvm()

Expand Down Expand Up @@ -93,21 +94,19 @@ def run_netvm_cmd(cmd):


def test_000_simple_networking(self):
self.qc.unlock_db()
self.testvm1.start()
self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
self.assertEqual(self.run_cmd(self.testvm1, self.ping_name), 0)


def test_010_simple_proxyvm(self):
self.proxy = self.qc.add_new_vm("QubesProxyVm",
self.proxy = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=self.make_vm_name('proxy'),
template=self.qc.get_vm_by_name(self.template))
self.proxy.create_on_disk(verbose=False)
label='red')
self.proxy.provides_network = True
self.proxy.netvm = self.testnetvm
self.proxy.create_on_disk()
self.testvm1.netvm = self.proxy
self.qc.save()
self.qc.unlock_db()

self.testvm1.start()
self.assertTrue(self.proxy.is_running())
Expand All @@ -124,15 +123,15 @@ def test_010_simple_proxyvm(self):
@unittest.skipUnless(spawn.find_executable('xdotool'),
"xdotool not installed")
def test_020_simple_proxyvm_nm(self):
self.proxy = self.qc.add_new_vm("QubesProxyVm",
self.proxy = self.app.add_new_vm("QubesProxyVm",
name=self.make_vm_name('proxy'),
template=self.qc.get_vm_by_name(self.template))
self.proxy.create_on_disk(verbose=False)
label='red')
self.proxy.provides_network = True
self.proxy.create_on_disk()
self.proxy.netvm = self.testnetvm
self.proxy.services['network-manager'] = True
self.testvm1.netvm = self.proxy
self.qc.save()
self.qc.unlock_db()
self.app.save()

self.testvm1.start()
self.assertTrue(self.proxy.is_running())
Expand Down Expand Up @@ -169,14 +168,14 @@ def test_020_simple_proxyvm_nm(self):


def test_030_firewallvm_firewall(self):
self.proxy = self.qc.add_new_vm("QubesProxyVm",
self.proxy = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=self.make_vm_name('proxy'),
template=self.qc.get_vm_by_name(self.template))
self.proxy.create_on_disk(verbose=False)
label='red')
self.proxy.provides_network = True
self.proxy.create_on_disk()
self.proxy.netvm = self.testnetvm
self.testvm1.netvm = self.proxy
self.qc.save()
self.qc.unlock_db()
self.app.save()

if self.run_cmd(self.testnetvm, 'nc -h 2>&1|grep -q nmap.org') == 0:
nc_version = NcVersion.Nmap
Expand Down Expand Up @@ -279,20 +278,19 @@ def test_030_firewallvm_firewall(self):


def test_040_inter_vm(self):
self.proxy = self.qc.add_new_vm("QubesProxyVm",
self.proxy = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=self.make_vm_name('proxy'),
template=self.qc.get_vm_by_name(self.template))
self.proxy.create_on_disk(verbose=False)
label='red')
self.proxy.create_on_disk()
self.proxy.netvm = self.testnetvm
self.testvm1.netvm = self.proxy

self.testvm2 = self.qc.add_new_vm("QubesAppVm",
self.testvm2 = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=self.make_vm_name('vm3'),
template=self.qc.get_vm_by_name(self.template))
self.testvm2.create_on_disk(verbose=False)
label='red')
self.testvm2.create_on_disk()
self.testvm2.netvm = self.proxy
self.qc.save()
self.qc.unlock_db()
self.app.save()

self.testvm1.start()
self.testvm2.start()
Expand All @@ -316,7 +314,6 @@ def test_040_inter_vm(self):

def test_050_spoof_ip(self):
"""Test if VM IP spoofing is blocked"""
self.qc.unlock_db()
self.testvm1.start()

self.assertEqual(self.run_cmd(self.testvm1, self.ping_ip), 0)
Expand Down Expand Up @@ -433,18 +430,18 @@ def setUp(self):
self.skipTest("Template {} not supported by this test".format(
self.template))

self.testvm1 = self.qc.add_new_vm(
"QubesAppVm",
self.init_default_template(self.template)
self.testvm1 = self.app.add_new_vm(
qubes.vm.appvm.AppVM,
name=self.make_vm_name('vm1'),
template=self.qc.get_vm_by_name(self.template))
self.testvm1.create_on_disk(verbose=False)
label='red')
self.testvm1.create_on_disk()

def test_000_simple_update(self):
self.save_and_reload_db()
self.qc.unlock_db()
# reload the VM to have all the properties properly set (especially
# default netvm)
self.testvm1 = self.qc[self.testvm1.qid]
self.testvm1 = self.app.domains[self.testvm1.qid]
self.testvm1.start()
p = self.testvm1.run(self.update_cmd, wait=True, user="root",
passio_popen=True, passio_stderr=True)
Expand Down Expand Up @@ -591,18 +588,18 @@ def test_010_update_via_proxy(self):
self.skipTest("Template {} not supported by this test".format(
self.template))

self.netvm_repo = self.qc.add_new_vm(
"QubesNetVm",
self.netvm_repo = self.app.add_new_vm(
qubes.vm.appvm.AppVM,
name=self.make_vm_name('net'),
template=self.qc.get_vm_by_name(self.template))
self.netvm_repo.create_on_disk(verbose=False)
label='red')
self.netvm_repo.provides_network = True
self.netvm_repo.create_on_disk()
self.testvm1.netvm = self.netvm_repo
# NetVM should have qubes-updates-proxy enabled by default
#self.netvm_repo.services['qubes-updates-proxy'] = True
# TODO: consider also adding a test for the template itself
self.testvm1.services['updates-proxy-setup'] = True
self.qc.save()
self.qc.unlock_db()
self.app.save()

# Setup test repo
self.netvm_repo.start()
Expand Down Expand Up @@ -640,12 +637,9 @@ def test_010_update_via_proxy(self):

def load_tests(loader, tests, pattern):
try:
qc = qubes.qubes.QubesVmCollection()
qc.lock_db_for_reading()
qc.load()
qc.unlock_db()
templates = [vm.name for vm in qc.values() if
isinstance(vm, qubes.qubes.QubesTemplateVm)]
app = qubes.Qubes()
templates = [vm.name for vm in app.domains if
isinstance(vm, qubes.vm.templatevm.TemplateVM)]
except OSError:
templates = []
for template in templates:
Expand Down
1 change: 1 addition & 0 deletions rpm_spec/core-dom0.spec
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ fi
%{python_sitelib}/qubes/tests/int/__init__.py*
%{python_sitelib}/qubes/tests/int/basic.py*
%{python_sitelib}/qubes/tests/int/dom0_update.py*
%{python_sitelib}/qubes/tests/int/network.py*

%dir %{python_sitelib}/qubes/tests/int/tools
%{python_sitelib}/qubes/tests/int/tools/__init__.py*
Expand Down

0 comments on commit bcc785d

Please sign in to comment.