Debian Codegraph @

pytest_multihost.egg-info/PKG-INFO

raw
1 Metadata-Version: 1.1
2 Name: pytest-multihost
3 Version: 3.4
4 Summary: Utility for writing multi-host tests for pytest
5 Home-page: https://pagure.io/python-pytest-multihost
6 Author: Petr Viktorin
7 Author-email: [email protected]
8 License: GPL
9 Description: A pytest plugin for multi-host testing.
10
11
12 Downloading
13 -----------
14
15 Release tarballs will be made available for download from Pagure Releases:
16 https://pagure.io/releases/python-pytest-multihost/
17
18 The goal is to include this project in Fedora repositories. Until that happens,
19 you can use testing builds from COPR – see "Developer links" below.
20
21 You can also install using pip:
22 https://pypi.python.org/pypi/pytest-multihost
23
24
25 Usage
26 -----
27
28 This plugin takes a description of your infrastructure,
29 and provides, via a fixture, Host objects that commands can be called on.
30
31 It is intended as a general base for a framework; any project using it will
32 need to extend it for its own needs.
33
34
35 The object provided to tests is a Config object, which has (among others)
36 these attributes::
37
38 test_dir – directory to store test-specific data in,
39 defaults to /root/multihost_tests
40 ipv6 – true if connecting via IPv6
41
42 domains – the list of domains
43
44 Hosts to run on are arranged in domains, which have::
45
46 name – the DNS name of the domain
47 type – a string specifying the type of the domain ('default' by default)
48
49 config – the Config this domain is part of
50 hosts – list of hosts in this domain
51
52 And the hosts have::
53
54 role – type of this host; should encode the OS and installed packages
55 hostname – fully qualified hostname, usually reachable from other hosts
56 shortname – first component of hostname
57 external_hostname – hostname used to connect to this host
58 ip – IP address
59
60 domain – the Domain this host is part of
61
62 transport – allows operations like uploading and downloading files
63 run_command() – runs the given command on the host
64
65 For each object – Config, Domain, Host – one can provide subclasses
66 to modify the behavior (for example, FreeIPA would add Host methods
67 to run a LDAP query or to install an IPA server).
68 Each object has from_dict and to_dict methods, which can add additional
69 attributes – for example, Config.ntp_server.
70
71
72 To use the multihost plugin in tests, create a fixture listing the domains
73 and what number of which host role is needed::
74
75 import pytest
76 from pytest_multihost import make_multihost_fixture
77
78 @pytest.fixture(scope='class')
79 def multihost(request):
80 mh = make_multihost_fixture(
81 request,
82 descriptions=[
83 {
84 'type': 'ipa',
85 'hosts': {
86 'master': 1,
87 'replica': 2,
88 },
89 },
90 ],
91 )
92 return mh
93
94 If not enough hosts are available, all tests that use the fixture are skipped.
95
96 The object returned from ``make_multihost_fixture`` only has the "config"
97 attribute.
98 Users are expected to add convenience attributes.
99 For example, FreeIPA, which typically uses a single domain with one master,
100 several replicas and some clients, would do::
101
102 from pytest_multihost import make_multihost_fixture
103
104 @pytest.fixture(scope='class')
105 def multihost(request):
106 mh = make_multihost_fixture(request, descriptions=[
107 {
108 'type': 'ipa',
109 'hosts': {
110 'master': 1,
111 'replica': 1,
112 'client': 1,
113 },
114 },
115 ],
116 )
117
118 # Set convenience attributes
119 mh.domain = mh.config.domains[0]
120 [mh.master] = mh.domain.hosts_by_role('master')
121 mh.replicas = mh.domain.hosts_by_role('replica')
122 mh.clients = mh.domain.hosts_by_role('client')
123
124 # IPA-specific initialization/teardown of the hosts
125 request.cls().install(mh)
126 request.addfinalizer(lambda: request.cls().uninstall(mh))
127
128 # Return the fixture
129 return mh
130
131
132 As with any pytest fixture, this can be used by getting it as
133 a function argument.
134 For a simplified example, FreeIPA usage could look something like this::
135
136 class TestMultihost(object):
137 def install(self, multihost):
138 multihost.master.run_command(['ipa-server-install'])
139
140 def uninstall(self, multihost):
141 multihost.master.run_command(['ipa-server-install', '--uninstall'])
142
143 def test_installed(self, multihost):
144 multihost.master.run_command(['ipa', 'ping'])
145
146
147 The description of infrastructure is provided in a JSON or YAML file,
148 which is named on the py.test command line. For example::
149
150 ssh_key_filename: ~/.ssh/id_rsa
151 domains:
152 - name: adomain.test
153 type: test-a
154 hosts:
155 - name: master
156 ip: 192.0.2.1
157 role: master
158 - name: replica1
159 ip: 192.0.2.2
160 role: replica
161 - name: replica2
162 ip: 192.0.2.3
163 role: replica
164 external_hostname: r2.adomain.test
165 - name: client1
166 ip: 192.0.2.4
167 role: client
168 - name: extra
169 ip: 192.0.2.6
170 role: extrarole
171 - name: bdomain.test
172 type: test-b
173 hosts:
174 - name: master.bdomain.test
175 ip='192.0.2.65
176 role: master
177
178 $ py.test --multihost-config=/path/to/configfile.yaml
179
180 To use YAML files, the PyYAML package is required. Without it only JSON files
181 can be used.
182
183
184 Encoding and bytes/text
185 -----------------------
186
187 When writing files or issuing commands, bytestrings are passed through
188 unchanged, and text strings (``unicode`` in Python 2) are encoded using
189 a configurable encoding (``utf-8`` by default).
190
191 When reading files, bytestrings are returned by default,
192 but an encoding can be given to get a test string.
193
194 For command output, separate ``stdout_bytes`` and ``stdout_text`` attributes
195 are provided.
196 The latter uses a configurable encoding (``utf-8`` by default).
197
198
199 Contributing
200 ------------
201
202 The project is happy to accept patches!
203 Please file any patches as Pull Requests on the project's `Pagure repo`_.
204 Any development discussion should be in Pagure Pull Requests and Issues.
205
206
207 Developer links
208 ---------------
209
210 * Bug tracker: https://pagure.io/python-pytest-multihost/issues
211 * Code browser: https://pagure.io/python-pytest-multihost/tree/master
212 * git clone https://pagure.io/python-pytest-multihost.git
213 * Unstable packages for Fedora: https://copr.fedoraproject.org/coprs/pviktori/pytest-plugins/
214
215 To release, update version in setup.py, add a Git tag like "v0.3",
216 and run `make tarball`.
217 Running `make upload` will put the tarball to Fedora Hosted and PyPI,
218 and a SRPM on Fedorapeople, if you have the rights.
219 Running `make release` will upload and fire a COPR build.
220
221 .. _Pagure repo: https://pagure.io/python-pytest-multihost
222
223 Platform: UNKNOWN
224 Classifier: Development Status :: 4 - Beta
225 Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
226 Classifier: Operating System :: POSIX
227 Classifier: Framework :: Pytest
228 Classifier: Programming Language :: Python
229 Classifier: Programming Language :: Python :: 2.6
230 Classifier: Programming Language :: Python :: 2.7
231 Classifier: Programming Language :: Python :: 3
232 Classifier: Topic :: Software Development :: Quality Assurance