]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/rgw_multisite_tests.py
5354e756fd737715bb4da5bf9f43f0f25989d7a2
[ceph.git] / ceph / qa / tasks / rgw_multisite_tests.py
1 """
2 rgw multisite testing
3 """
4 import importlib.util
5 import logging
6 import nose.core
7 import nose.config
8 import sys
9
10 from teuthology.config import config as teuth_config
11 from teuthology.exceptions import ConfigError
12 from teuthology.repo_utils import fetch_repo
13 from teuthology.task import Task
14 from teuthology import misc
15
16 log = logging.getLogger(__name__)
17
18
19 class RGWMultisiteTests(Task):
20 """
21 Runs the rgw_multi tests against a multisite configuration created by the
22 rgw-multisite task. Tests are run with nose, using any additional 'args'
23 provided. Overrides for tests.Config can be set in 'config'. The 'branch'
24 and 'repo' can be overridden to clone the rgw_multi tests from another
25 release.
26
27 - rgw-multisite-tests:
28 args:
29 - tests.py:test_object_sync
30 config:
31 reconfigure_delay: 60
32 branch: octopus
33 repo: https://github.com/ceph/ceph.git
34
35 """
36 def __init__(self, ctx, config):
37 super(RGWMultisiteTests, self).__init__(ctx, config)
38
39 def setup(self):
40 super(RGWMultisiteTests, self).setup()
41
42 overrides = self.ctx.config.get('overrides', {})
43 misc.deep_merge(self.config, overrides.get('rgw-multisite-tests', {}))
44
45 if not self.ctx.rgw_multisite:
46 raise ConfigError('rgw-multisite-tests must run after the rgw-multisite task')
47 realm = self.ctx.rgw_multisite.realm
48 master_zone = realm.meta_master_zone()
49
50 branch = self.config.get('branch')
51 if not branch:
52 # run from suite_path
53 suite_path = self.ctx.config.get('suite_path')
54 self.module_path = suite_path + '/../src/test/rgw/rgw_multi'
55 else:
56 # clone the qa branch
57 repo = self.config.get('repo', teuth_config.get_ceph_qa_suite_git_url())
58 log.info("cloning suite branch %s from %s...", branch, repo)
59 clonedir = fetch_repo(repo, branch)
60 # import its version of rgw_multi
61 self.module_path = clonedir + '/src/test/rgw/rgw_multi'
62
63 log.info("importing tests from %s", self.module_path)
64 spec = importlib.util.spec_from_file_location('rgw_multi', self.module_path + '/__init__.py')
65 module = importlib.util.module_from_spec(spec)
66 sys.modules[spec.name] = module
67 spec.loader.exec_module(module)
68
69 from rgw_multi import multisite, tests
70
71 # create the test user
72 log.info('creating test user..')
73 user = multisite.User('rgw-multisite-test-user')
74 user.create(master_zone, ['--display-name', 'Multisite Test User',
75 '--gen-access-key', '--gen-secret'])
76
77 config = self.config.get('config', {})
78 tests.init_multi(realm, user, tests.Config(**config))
79 tests.realm_meta_checkpoint(realm)
80
81 def begin(self):
82 # extra arguments for nose can be passed as a string or list
83 extra_args = self.config.get('args', [])
84 if not isinstance(extra_args, list):
85 extra_args = [extra_args]
86 argv = [__name__] + extra_args
87
88 log.info("running rgw multisite tests on '%s' with args=%r",
89 self.module_path, extra_args)
90
91 # run nose tests in the module path
92 conf = nose.config.Config(stream=get_log_stream(), verbosity=2, workingDir=self.module_path)
93 assert nose.run(argv=argv, config=conf), 'rgw multisite test failures'
94
95
96 def get_log_stream():
97 """ return a log stream for nose output """
98 # XXX: this is a workaround for IOErrors when nose writes to stderr,
99 # copied from vstart_runner.py
100 class LogStream(object):
101 def __init__(self):
102 self.buffer = ""
103
104 def write(self, data):
105 self.buffer += data
106 if "\n" in self.buffer:
107 lines = self.buffer.split("\n")
108 for line in lines[:-1]:
109 log.info(line)
110 self.buffer = lines[-1]
111
112 def flush(self):
113 pass
114
115 return LogStream()
116
117
118 task = RGWMultisiteTests