Skip to content

Commit 24b0ba3

Browse files
committed
virt-test: Remove dependencies on autotest
Let's remove dependencies on autotest as much as possible, except in two instances where autotest can't be replaced right now: 1) utils_test.run_autotest() 2) utils_test.qemu.MultiHostMigrationTest() In such cases, let's restrict the autotest imports to those specific functions, so the rest of the suite can work without an autotest install. Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
1 parent 65e0ab4 commit 24b0ba3

File tree

122 files changed

+4647
-2850
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+4647
-2850
lines changed

samples/bad_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:difficulty: simple
55
:copyright: 2014 Red Hat Inc.
66
"""
7-
from autotest.client import utils
7+
from avocado.utils import process
88

99

1010
def run(test, params, env):
@@ -16,4 +16,4 @@ def run(test, params, env):
1616
:param params: Dictionary with the test parameters
1717
:param env: Dictionary with test environment.
1818
"""
19-
utils.run("missing_command")
19+
process.run("missing_command")

samples/hostname.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:copyright: 2014 Red Hat Inc.
88
"""
99
import logging
10-
from autotest.client import utils
10+
from avocado.utils import process
1111

1212

1313
def run(test, params, env):
@@ -18,5 +18,5 @@ def run(test, params, env):
1818
:param params: Dictionary with the test parameters
1919
:param env: Dictionary with test environment.
2020
"""
21-
result = utils.run("hostname")
21+
result = process.run("hostname")
2222
logging.info("Output of 'hostname' cmd is '%s'", result.stdout)

samples/service.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
import logging
1010
import time
1111

12-
from autotest.client import utils
13-
from autotest.client.shared import error
14-
from autotest.client.shared.service import SpecificServiceManager
12+
from avocado.utils import process
13+
from avocado.core import exceptions
14+
from avocado.utils.service import SpecificServiceManager
1515
from virttest import remote
16+
from virttest import error_context
1617

1718

18-
# error.context_aware decorator initializes context, which provides additional
19+
# error_context.context_aware decorator initializes context, which provides additional
1920
# information on exceptions.
20-
@error.context_aware
21+
@error_context.context_aware
2122
def run(test, params, env):
2223
"""
2324
Logs guest's hostname.
@@ -33,22 +34,23 @@ def run(test, params, env):
3334
:param env: Dictionary with test environment.
3435
"""
3536
if params.get('test_on_guest') == "yes":
36-
# error.context() is common method to log test steps used to verify
37+
# error_context.context() is common method to log test steps used to verify
3738
# what exactly was tested.
38-
error.context("Using guest.", logging.info)
39+
error_context.context("Using guest.", logging.info)
3940
vm = env.get_vm(params["main_vm"])
4041
session = vm.wait_for_login()
4142
# RemoteRunner is object, which simulates the utils.run() behavior
4243
# on remote consoles
4344
runner = remote.RemoteRunner(session=session).run
4445
else:
45-
error.context("Using host", logging.info)
46-
runner = utils.run
46+
error_context.context("Using host", logging.info)
47+
runner = process.run
4748

48-
error.context("Initialize service manager", logging.info)
49+
error_context.context("Initialize service manager", logging.info)
4950
service = SpecificServiceManager(params["test_service"], runner)
5051

51-
error.context("Testing service %s" % params["test_service"], logging.info)
52+
error_context.context("Testing service %s" %
53+
params["test_service"], logging.info)
5254
original_status = service.status()
5355
logging.info("Original status=%s", original_status)
5456

@@ -58,17 +60,17 @@ def run(test, params, env):
5860
if service.status() is not False:
5961
logging.error("Fail to stop service")
6062
service.start()
61-
raise error.TestFail("Fail to stop service")
63+
raise exceptions.TestFail("Fail to stop service")
6264
service.start()
6365
else:
6466
service.start()
6567
time.sleep(5)
6668
if service.status() is not True:
6769
logging.error("Fail to start service")
6870
service.stop()
69-
raise error.TestFail("Fail to start service")
71+
raise exceptions.TestFail("Fail to start service")
7072
service.start()
7173
time.sleep(5)
7274
if not service.status() is original_status:
73-
raise error.TestFail("Fail to restore original status of the %s "
74-
"service" % params["test_service"])
75+
raise exceptions.TestFail("Fail to restore original status of the %s "
76+
"service" % params["test_service"])

shared/deps/serial/VirtIoChannel_guest_send_receive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def md5_init(data=None):
127127
try:
128128
md5_value = hashlib.new("md5")
129129
except NameError:
130-
md5_value = md5.new()
130+
md5_value = md5.new()
131131
if data:
132132
md5_value.update(data)
133133
return md5_value

shared/deps/serial/serial_host_send_receive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def md5_init(data=None):
5050
try:
5151
md5_value = hashlib.new("md5")
5252
except NameError:
53-
md5_value = md5.new()
53+
md5_value = md5.new()
5454
if data:
5555
md5_value.update(data)
5656
return md5_value

tools/build_docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99
import common
1010

11-
from autotest.client import utils
11+
from avocado.utils import process
1212

1313

1414
def build_docs():
@@ -22,7 +22,7 @@ def build_docs():
2222
failure_lines = []
2323
root_dir = common.virt_test_dir
2424
doc_dir = os.path.join(root_dir, 'documentation')
25-
output = utils.system_output('make -C %s html 2>&1' % doc_dir)
25+
output = process.system_output('make -C %s html 2>&1' % doc_dir)
2626
output_lines = output.splitlines()
2727
for line in output_lines:
2828
ignore_msg = False

tools/cd_hash.py

+13-19
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
import os
99
import sys
1010
import optparse
11-
import logging
1211

13-
import common
14-
from autotest.client.shared import logging_manager
15-
from autotest.client import utils
16-
from virttest import utils_misc
12+
from avocado.utils import crypto
13+
from avocado.core import output
14+
from avocado.core import log
1715

1816

1917
if __name__ == "__main__":
2018
parser = optparse.OptionParser("usage: %prog [options] [filenames]")
2119
options, args = parser.parse_args()
2220

23-
logging_manager.configure_logging(utils_misc.VirtLoggingConfig())
21+
log.configure()
22+
view = output.View()
2423

2524
if args:
2625
filenames = args
@@ -34,20 +33,15 @@
3433
file_exists = os.path.isfile(filename)
3534
can_read_file = os.access(filename, os.R_OK)
3635
if not file_exists:
37-
logging.critical("File %s does not exist!", filename)
36+
view.notify(event='error', msg="File %s does not exist!" % filename)
3837
continue
3938
if not can_read_file:
40-
logging.critical("File %s does not have read permissions!",
41-
filename)
39+
view.notify(event='error',
40+
msg="File %s does not have read permissions!" % filename)
4241
continue
4342

44-
logging.info("Hash values for file %s", os.path.basename(filename))
45-
logging.info("md5 (1m): %s", utils.hash_file(filename, 1024 * 1024,
46-
method="md5"))
47-
logging.info("sha1 (1m): %s", utils.hash_file(filename, 1024 * 1024,
48-
method="sha1"))
49-
logging.info(
50-
"md5 (full): %s", utils.hash_file(filename, method="md5"))
51-
logging.info("sha1 (full): %s", utils.hash_file(filename,
52-
method="sha1"))
53-
logging.info("")
43+
view.notify(event='message', msg="Hash values for file %s" % os.path.basename(filename))
44+
view.notify(event='minor', msg="md5 (1m): %s" % crypto.hash_file(filename, 1024 * 1024, algorithm="md5"))
45+
view.notify(event='minor', msg="sha1 (1m): %s" % crypto.hash_file(filename, 1024 * 1024, algorithm="sha1"))
46+
view.notify(event='minor', msg="md5 (full): %s" % crypto.hash_file(filename, algorithm="md5"))
47+
view.notify(event='minor', msg="sha1 (full): %s" % crypto.hash_file(filename, algorithm="sha1"))

tools/common.py

-40
This file was deleted.

tools/download_manager.py

+21-16
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,38 @@
1818
1919
:copyright: Red Hat 2012
2020
"""
21-
import glob
22-
import os
2321
import sys
2422
import logging
25-
import time
26-
import common
27-
from autotest.client.shared import logging_manager
28-
from virttest import asset, utils_misc
23+
import os
24+
25+
# simple magic for using scripts within a source tree
26+
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
27+
if os.path.isdir(os.path.join(basedir, 'virttest')):
28+
sys.path.append(basedir)
29+
30+
from virttest import asset
31+
32+
from avocado.core import log
33+
from avocado.core import output
2934

3035

3136
def download_assets():
37+
view = output.View()
3238
all_assets = asset.get_all_assets()
3339
if all_assets:
34-
logging.info("Available download assets:")
35-
logging.info("")
40+
view.notify(msg="Available download assets:")
41+
view.notify(msg="")
3642
for asset_info in all_assets:
3743
asset_keys = asset_info.keys()
38-
logging.info("%d - %s" % (all_assets.index(asset_info) + 1,
39-
asset_info['title']))
44+
view.notify(event='minor', msg="%d - %s" % (all_assets.index(asset_info) + 1,
45+
asset_info['title']))
4046
asset_keys.pop(asset_keys.index('title'))
4147
asset_keys.sort()
4248
for k in asset_keys:
43-
logging.info(" %s = %s" % (k, asset_info[k]))
44-
logging.info("")
45-
indexes = raw_input("%s INFO | Type the index for the assets you want to "
46-
"download (comma separated, Ctrl+C to abort): " %
47-
time.strftime("%H:%M:%S", time.localtime()))
49+
view.notify(event='minor', msg=" %s = %s" % (k, asset_info[k]))
50+
view.notify(msg="")
51+
indexes = raw_input("Type the index for the assets you want to "
52+
"download (comma separated, leave empty to abort): ")
4853

4954
index_list = []
5055

@@ -62,7 +67,7 @@ def download_assets():
6267
asset.download_file(asset_info, interactive=True)
6368

6469
if __name__ == "__main__":
65-
logging_manager.configure_logging(utils_misc.VirtLoggingConfig())
70+
log.configure()
6671
try:
6772
download_assets()
6873
except KeyboardInterrupt:

tools/github/cache_populate.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env python
22

33
import sys
4-
import os
54
import getpass
6-
import datetime
5+
76
from github import Github
87
from github_issues import GithubIssues
98

tools/github/example.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22

33
import sys
4-
import os
54
import getpass
65
import datetime
76

tools/github/github_issues.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import datetime
77
import time
88
import shelve
9+
910
# Requires PyGithub version >= 1.13 for access to raw_data attribute
1011
import github
1112

tools/github/label_issues.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env python
22

3-
import sys
4-
import os
53
import getpass
6-
import datetime
4+
75
from github import Github
86
from github_issues import GithubIssues, MutableIssue
97

tools/github/pulls_applied.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env python
22

3-
import sys
4-
import os
53
import getpass
64
import datetime
5+
76
from github import Github
87
from github_issues import GithubIssues
98

tools/github/stale_pulls.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env python
22

3-
import sys
4-
import os
53
import getpass
64
import datetime
5+
76
from github import Github
87
from github_issues import GithubIssues
98

tools/github/unassigned_issues.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#!/usr/bin/env python
22

3-
import sys
4-
import os
53
import getpass
6-
import datetime
74
from github import Github
85
from github_issues import GithubIssues
96

0 commit comments

Comments
 (0)