Skip to content

Commit 104629d

Browse files
CarstenGrohmannphilpep
authored andcommitted
Extend backend documentation with a general host spec section
1 parent 0df12c4 commit 104629d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

doc/source/backends.rst

+57
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,63 @@ system packaged tools may still be required). For example ::
1313
For all backends, commands can be run as superuser with the ``--sudo``
1414
option or as specific user with the ``--sudo-user`` option.
1515

16+
General Host specification
17+
~~~~~~~~~~~~~~~~~~~~~~~~~~
18+
19+
The ``--hosts`` parameter in Testinfra is used to specify the target hosts for the tests.
20+
21+
You can specify multiple hosts by separating each target with a comma, allowing you to run tests using different backends across different environments or machines.
22+
23+
The user, password, and port fields are optional, providing flexibility depending on your authentication and connection requirements.
24+
25+
Please also read the details for the individual backends, as the host spec is handled slightly differently from backend to backend.
26+
27+
**Syntax:**
28+
29+
::
30+
31+
--hosts=<backend>://<user>:<password>@<host>:<port>
32+
33+
34+
**Components:**
35+
36+
* ``<backend>``: type of backend to be used (e.g., ssh, docker, paramiko, local)
37+
* ``<user>``: username for authentication (optional)
38+
* ``<password>``: password for authentication (optional)
39+
* ``<host>``: target hostname or IP address
40+
* ``<port>``: target port number (optional)
41+
42+
Special characters (e.g. ":") in the user and password fields need to be percent-encoded according to RFC 3986. This can be done using ``urllib.parse.quote()`` in Python.
43+
44+
For example::
45+
46+
import urllib.parse
47+
48+
user = urllib.parse.quote('user:name')
49+
password = urllib.parse.quote('p@ssw:rd')
50+
host = 'hostname'
51+
port = 22
52+
53+
host_spec = f"ssh://{user}:{password}@{host}:{port}"
54+
print(host_spec)
55+
56+
This will ensure that any special characters are properly encoded, making the connection string valid.
57+
58+
**Examples:**
59+
60+
SSH Backend with Full Specification::
61+
62+
testinfra --hosts=ssh://user:password@hostname:22
63+
64+
Docker Backend::
65+
66+
testinfra --hosts=docker://container_id
67+
68+
Mixed Backends::
69+
70+
testinfra --hosts=ssh://user:password@hostname:22,docker://container_id,local://
71+
72+
1673
local
1774
~~~~~
1875

0 commit comments

Comments
 (0)