tests: move create_*_file to SystemTestsMixin

This commit is contained in:
Marek Marczykowski-Górecki 2017-06-20 16:14:16 +02:00
parent f56f7d13fb
commit 984a070f3e
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 13 additions and 16 deletions

View File

@ -37,6 +37,7 @@ import functools
import logging import logging
import os import os
import pathlib import pathlib
import shlex
import shutil import shutil
import subprocess import subprocess
import sys import sys
@ -962,6 +963,16 @@ class SystemTestsMixin(object):
shutil.rmtree(mountpoint) shutil.rmtree(mountpoint)
subprocess.check_call(['sudo', 'losetup', '-d', loopdev]) subprocess.check_call(['sudo', 'losetup', '-d', loopdev])
def create_local_file(self, filename, content, mode='w'):
with open(filename, mode) as file:
file.write(content)
self.addCleanup(os.unlink, filename)
def create_remote_file(self, vm, filename, content):
self.loop.run_until_complete(vm.run_for_stdio(
'cat > {}'.format(shlex.quote(filename)),
user='root', input=content.encode('utf-8')))
def load_tests(loader, tests, pattern): # pylint: disable=unused-argument def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
# discard any tests from this module, because it hosts base classes # discard any tests from this module, because it hosts base classes

View File

@ -20,21 +20,17 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
from distutils import spawn
import asyncio import asyncio
import multiprocessing import multiprocessing
import os import os
import shlex
import subprocess import subprocess
import time
import unittest import unittest
from distutils import spawn
import qubes.config import qubes.config
import qubes.tests import qubes.tests
import qubes.vm.appvm import qubes.vm.appvm
import qubes.vm.templatevm import qubes.vm.templatevm
import re
TEST_DATA = b"0123456789" * 1024 TEST_DATA = b"0123456789" * 1024
@ -59,16 +55,6 @@ class TC_00_AppVMMixin(qubes.tests.SystemTestsMixin):
self.loop.run_until_complete(self.testvm2.create_on_disk()) self.loop.run_until_complete(self.testvm2.create_on_disk())
self.app.save() self.app.save()
def create_local_file(self, filename, content, mode='w'):
with open(filename, mode) as file:
file.write(content)
self.addCleanup(os.unlink, filename)
def create_remote_file(self, vm, filename, content):
self.loop.run_until_complete(vm.run_for_stdio(
'cat > {}'.format(shlex.quote(filename)),
user='root', input=content.encode('utf-8')))
def test_000_start_shutdown(self): def test_000_start_shutdown(self):
# TODO: wait_for, timeout # TODO: wait_for, timeout
self.loop.run_until_complete(self.testvm1.start()) self.loop.run_until_complete(self.testvm1.start())

View File

@ -169,4 +169,4 @@ def load_tests(loader, tests, pattern):
'TC_40_PVGrub_' + template, 'TC_40_PVGrub_' + template,
(TC_40_PVGrub, qubes.tests.QubesTestCase), (TC_40_PVGrub, qubes.tests.QubesTestCase),
{'template': template}))) {'template': template})))
return tests return tests