tests/network: reduce code duplication
This commit is contained in:
parent
2edafacbe4
commit
cea9f66bc3
@ -1162,6 +1162,15 @@ class VmUpdatesMixin(object):
|
|||||||
return e.returncode
|
return e.returncode
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def assertRunCommandReturnCode(self, vm, cmd, expected_returncode):
|
||||||
|
p = self.loop.run_until_complete(
|
||||||
|
vm.run(cmd, user='root',
|
||||||
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE))
|
||||||
|
(stdout, stderr) = self.loop.run_until_complete(p.communicate())
|
||||||
|
self.assertIn(
|
||||||
|
self.loop.run_until_complete(p.wait()), expected_returncode,
|
||||||
|
'{}: {}\n{}'.format(cmd, stdout, stderr))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
'''
|
'''
|
||||||
:type self: qubes.tests.SystemTestCase | VmUpdatesMixin
|
:type self: qubes.tests.SystemTestCase | VmUpdatesMixin
|
||||||
@ -1210,12 +1219,8 @@ class VmUpdatesMixin(object):
|
|||||||
# default netvm)
|
# default netvm)
|
||||||
self.testvm1 = self.app.domains[self.testvm1.qid]
|
self.testvm1 = self.app.domains[self.testvm1.qid]
|
||||||
self.loop.run_until_complete(self.testvm1.start())
|
self.loop.run_until_complete(self.testvm1.start())
|
||||||
p = self.loop.run_until_complete(
|
self.assertRunCommandReturnCode(self.testvm1,
|
||||||
self.testvm1.run(self.update_cmd, user='root',
|
self.update_cmd, self.exit_code_ok)
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE))
|
|
||||||
(stdout, stderr) = self.loop.run_until_complete(p.communicate())
|
|
||||||
self.assertIn(p.returncode, self.exit_code_ok,
|
|
||||||
'{}: {}\n{}'.format(self.update_cmd, stdout, stderr))
|
|
||||||
|
|
||||||
def create_repo_apt(self):
|
def create_repo_apt(self):
|
||||||
'''
|
'''
|
||||||
@ -1373,28 +1378,16 @@ SHA256:
|
|||||||
with self.qrexec_policy('qubes.UpdatesProxy', self.testvm1,
|
with self.qrexec_policy('qubes.UpdatesProxy', self.testvm1,
|
||||||
'$default', action='allow,target=' + self.netvm_repo.name):
|
'$default', action='allow,target=' + self.netvm_repo.name):
|
||||||
# update repository metadata
|
# update repository metadata
|
||||||
p = self.loop.run_until_complete(self.testvm1.run(
|
self.assertRunCommandReturnCode(self.testvm1,
|
||||||
self.update_cmd, user='root', stdout=subprocess.PIPE,
|
self.update_cmd, self.exit_code_ok)
|
||||||
stderr=subprocess.PIPE))
|
|
||||||
(stdout, stderr) = self.loop.run_until_complete(p.communicate())
|
|
||||||
self.assertIn(self.loop.run_until_complete(p.wait()), self.exit_code_ok,
|
|
||||||
'{}: {}\n{}'.format(self.update_cmd, stdout, stderr))
|
|
||||||
|
|
||||||
# install test package
|
# install test package
|
||||||
p = self.loop.run_until_complete(self.testvm1.run(
|
self.assertRunCommandReturnCode(self.testvm1,
|
||||||
self.install_cmd.format('test-pkg'), user='root',
|
self.install_cmd.format('test-pkg'), self.exit_code_ok)
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE))
|
|
||||||
(stdout, stderr) = self.loop.run_until_complete(p.communicate())
|
|
||||||
self.assertIn(self.loop.run_until_complete(p.wait()), self.exit_code_ok,
|
|
||||||
'{}: {}\n{}'.format(self.update_cmd, stdout, stderr))
|
|
||||||
|
|
||||||
# verify if it was really installed
|
# verify if it was really installed
|
||||||
p = self.loop.run_until_complete(self.testvm1.run(
|
self.assertRunCommandReturnCode(self.testvm1,
|
||||||
self.install_test_cmd.format('test-pkg'), user='root',
|
self.install_test_cmd.format('test-pkg'), self.exit_code_ok)
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE))
|
|
||||||
(stdout, stderr) = self.loop.run_until_complete(p.communicate())
|
|
||||||
self.assertIn(self.loop.run_until_complete(p.wait()), self.exit_code_ok,
|
|
||||||
'{}: {}\n{}'.format(self.update_cmd, stdout, stderr))
|
|
||||||
|
|
||||||
def create_testcases_for_templates():
|
def create_testcases_for_templates():
|
||||||
yield from qubes.tests.create_testcases_for_templates('VmNetworking',
|
yield from qubes.tests.create_testcases_for_templates('VmNetworking',
|
||||||
|
Loading…
Reference in New Issue
Block a user