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