pyinfra 2.9.2__py2.py3-none-any.whl → 3.0b1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. pyinfra/api/__init__.py +3 -0
  2. pyinfra/api/arguments.py +261 -255
  3. pyinfra/api/arguments_typed.py +77 -0
  4. pyinfra/api/command.py +66 -53
  5. pyinfra/api/config.py +27 -22
  6. pyinfra/api/connect.py +1 -1
  7. pyinfra/api/connectors.py +2 -24
  8. pyinfra/api/deploy.py +21 -52
  9. pyinfra/api/exceptions.py +33 -8
  10. pyinfra/api/facts.py +77 -113
  11. pyinfra/api/host.py +150 -82
  12. pyinfra/api/inventory.py +17 -25
  13. pyinfra/api/operation.py +232 -198
  14. pyinfra/api/operations.py +102 -148
  15. pyinfra/api/state.py +137 -79
  16. pyinfra/api/util.py +55 -70
  17. pyinfra/connectors/base.py +150 -0
  18. pyinfra/connectors/chroot.py +160 -169
  19. pyinfra/connectors/docker.py +227 -237
  20. pyinfra/connectors/dockerssh.py +231 -253
  21. pyinfra/connectors/local.py +195 -207
  22. pyinfra/connectors/ssh.py +528 -615
  23. pyinfra/connectors/ssh_util.py +114 -0
  24. pyinfra/connectors/sshuserclient/client.py +5 -3
  25. pyinfra/connectors/terraform.py +86 -65
  26. pyinfra/connectors/util.py +212 -137
  27. pyinfra/connectors/vagrant.py +55 -48
  28. pyinfra/context.py +3 -2
  29. pyinfra/facts/docker.py +1 -0
  30. pyinfra/facts/files.py +45 -32
  31. pyinfra/facts/git.py +3 -1
  32. pyinfra/facts/gpg.py +1 -1
  33. pyinfra/facts/hardware.py +4 -2
  34. pyinfra/facts/iptables.py +5 -3
  35. pyinfra/facts/mysql.py +1 -0
  36. pyinfra/facts/postgres.py +168 -0
  37. pyinfra/facts/postgresql.py +5 -161
  38. pyinfra/facts/selinux.py +3 -1
  39. pyinfra/facts/server.py +77 -30
  40. pyinfra/facts/systemd.py +29 -12
  41. pyinfra/facts/sysvinit.py +10 -10
  42. pyinfra/facts/util/packaging.py +4 -2
  43. pyinfra/local.py +4 -5
  44. pyinfra/operations/apk.py +3 -3
  45. pyinfra/operations/apt.py +25 -47
  46. pyinfra/operations/brew.py +7 -14
  47. pyinfra/operations/bsdinit.py +4 -4
  48. pyinfra/operations/cargo.py +1 -1
  49. pyinfra/operations/choco.py +1 -1
  50. pyinfra/operations/dnf.py +4 -4
  51. pyinfra/operations/files.py +108 -321
  52. pyinfra/operations/gem.py +1 -1
  53. pyinfra/operations/git.py +6 -37
  54. pyinfra/operations/iptables.py +2 -10
  55. pyinfra/operations/launchd.py +1 -1
  56. pyinfra/operations/lxd.py +1 -9
  57. pyinfra/operations/mysql.py +5 -28
  58. pyinfra/operations/npm.py +1 -1
  59. pyinfra/operations/openrc.py +1 -1
  60. pyinfra/operations/pacman.py +3 -3
  61. pyinfra/operations/pip.py +14 -15
  62. pyinfra/operations/pkg.py +1 -1
  63. pyinfra/operations/pkgin.py +3 -3
  64. pyinfra/operations/postgres.py +347 -0
  65. pyinfra/operations/postgresql.py +17 -380
  66. pyinfra/operations/python.py +2 -17
  67. pyinfra/operations/selinux.py +5 -28
  68. pyinfra/operations/server.py +59 -84
  69. pyinfra/operations/snap.py +1 -3
  70. pyinfra/operations/ssh.py +8 -23
  71. pyinfra/operations/systemd.py +7 -7
  72. pyinfra/operations/sysvinit.py +3 -12
  73. pyinfra/operations/upstart.py +4 -4
  74. pyinfra/operations/util/__init__.py +12 -0
  75. pyinfra/operations/util/files.py +2 -2
  76. pyinfra/operations/util/packaging.py +6 -24
  77. pyinfra/operations/util/service.py +18 -37
  78. pyinfra/operations/vzctl.py +2 -2
  79. pyinfra/operations/xbps.py +3 -3
  80. pyinfra/operations/yum.py +4 -4
  81. pyinfra/operations/zypper.py +4 -4
  82. {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/METADATA +19 -22
  83. pyinfra-3.0b1.dist-info/RECORD +163 -0
  84. pyinfra-3.0b1.dist-info/entry_points.txt +11 -0
  85. pyinfra_cli/__main__.py +2 -0
  86. pyinfra_cli/commands.py +7 -2
  87. pyinfra_cli/exceptions.py +83 -42
  88. pyinfra_cli/inventory.py +19 -4
  89. pyinfra_cli/log.py +17 -3
  90. pyinfra_cli/main.py +133 -90
  91. pyinfra_cli/prints.py +93 -129
  92. pyinfra_cli/util.py +60 -29
  93. tests/test_api/test_api.py +2 -0
  94. tests/test_api/test_api_arguments.py +13 -13
  95. tests/test_api/test_api_deploys.py +28 -29
  96. tests/test_api/test_api_facts.py +60 -98
  97. tests/test_api/test_api_operations.py +100 -200
  98. tests/test_cli/test_cli.py +18 -49
  99. tests/test_cli/test_cli_deploy.py +11 -37
  100. tests/test_cli/test_cli_exceptions.py +50 -19
  101. tests/test_cli/util.py +1 -1
  102. tests/test_connectors/test_chroot.py +6 -6
  103. tests/test_connectors/test_docker.py +4 -4
  104. tests/test_connectors/test_dockerssh.py +38 -50
  105. tests/test_connectors/test_local.py +11 -12
  106. tests/test_connectors/test_ssh.py +66 -107
  107. tests/test_connectors/test_terraform.py +9 -15
  108. tests/test_connectors/test_util.py +24 -46
  109. tests/test_connectors/test_vagrant.py +4 -4
  110. pyinfra/api/operation.pyi +0 -117
  111. pyinfra/connectors/ansible.py +0 -171
  112. pyinfra/connectors/mech.py +0 -186
  113. pyinfra/connectors/pyinfrawinrmsession/__init__.py +0 -28
  114. pyinfra/connectors/winrm.py +0 -320
  115. pyinfra/facts/windows.py +0 -366
  116. pyinfra/facts/windows_files.py +0 -90
  117. pyinfra/operations/windows.py +0 -59
  118. pyinfra/operations/windows_files.py +0 -551
  119. pyinfra-2.9.2.dist-info/RECORD +0 -170
  120. pyinfra-2.9.2.dist-info/entry_points.txt +0 -14
  121. tests/test_connectors/test_ansible.py +0 -64
  122. tests/test_connectors/test_mech.py +0 -126
  123. tests/test_connectors/test_winrm.py +0 -76
  124. {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/LICENSE.md +0 -0
  125. {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/WHEEL +0 -0
  126. {pyinfra-2.9.2.dist-info → pyinfra-3.0b1.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,11 @@
1
1
  from unittest.mock import MagicMock, patch
2
2
 
3
3
  from pyinfra.api import Config, State
4
- from pyinfra.api.arguments import get_executor_kwarg_keys, pop_global_arguments
4
+ from pyinfra.api.arguments import CONNECTOR_ARGUMENT_KEYS, pop_global_arguments
5
5
  from pyinfra.api.connect import connect_all
6
6
  from pyinfra.api.exceptions import PyinfraError
7
7
  from pyinfra.api.facts import get_facts
8
+ from pyinfra.connectors.util import CommandOutput, OutputLine
8
9
  from pyinfra.facts.server import Arch, Command
9
10
 
10
11
  from ..paramiko_util import PatchSSHTestCase
@@ -16,7 +17,7 @@ def _get_executor_defaults(state, host):
16
17
  return {
17
18
  key: value
18
19
  for key, value in global_argument_defaults.items()
19
- if key in get_executor_kwarg_keys()
20
+ if key in CONNECTOR_ARGUMENT_KEYS
20
21
  }
21
22
 
22
23
 
@@ -29,19 +30,18 @@ class TestFactsApi(PatchSSHTestCase):
29
30
 
30
31
  connect_all(state)
31
32
 
32
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
33
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
33
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
34
+ fake_run_command.return_value = True, CommandOutput(
35
+ [OutputLine("stdout", "some-output")]
36
+ )
34
37
  fact_data = get_facts(state, Command, ("yes",))
35
38
 
36
39
  assert fact_data == {anotherhost: "some-output"}
37
40
 
38
41
  fake_run_command.assert_called_with(
39
- state,
40
- anotherhost,
41
42
  "yes",
42
43
  print_input=False,
43
44
  print_output=False,
44
- return_combined_output=True,
45
45
  **_get_executor_defaults(state, anotherhost),
46
46
  )
47
47
 
@@ -52,31 +52,29 @@ class TestFactsApi(PatchSSHTestCase):
52
52
  anotherhost = inventory.get_host("anotherhost")
53
53
 
54
54
  connect_all(state)
55
- anotherhost.current_op_global_kwargs = {
56
- "sudo": True,
57
- "sudo_user": "someuser",
58
- "use_sudo_password": True,
59
- "su_user": "someuser",
60
- "timeout": 10,
61
- "env": {"HELLO": "WORLD"},
55
+ anotherhost.current_op_global_arguments = {
56
+ "_sudo": True,
57
+ "_sudo_user": "someuser",
58
+ "_su_user": "someuser",
59
+ "_timeout": 10,
60
+ "_env": {"HELLO": "WORLD"},
62
61
  }
63
62
 
64
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
65
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
63
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
64
+ fake_run_command.return_value = True, CommandOutput(
65
+ [OutputLine("stdout", "some-output")]
66
+ )
66
67
  fact_data = get_facts(state, Command, ("yes",))
67
68
 
68
69
  assert fact_data == {anotherhost: "some-output"}
69
70
 
70
71
  defaults = _get_executor_defaults(state, anotherhost)
71
- defaults.update(anotherhost.current_op_global_kwargs)
72
+ defaults.update(anotherhost.current_op_global_arguments)
72
73
 
73
74
  fake_run_command.assert_called_with(
74
- state,
75
- anotherhost,
76
75
  "yes",
77
76
  print_input=False,
78
77
  print_output=False,
79
- return_combined_output=True,
80
78
  **defaults,
81
79
  )
82
80
 
@@ -88,7 +86,7 @@ class TestFactsApi(PatchSSHTestCase):
88
86
 
89
87
  connect_all(state)
90
88
 
91
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
89
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
92
90
  fake_run_command.return_value = False, MagicMock()
93
91
 
94
92
  with self.assertRaises(PyinfraError) as context:
@@ -97,12 +95,9 @@ class TestFactsApi(PatchSSHTestCase):
97
95
  assert context.exception.args[0] == "No hosts remaining!"
98
96
 
99
97
  fake_run_command.assert_called_with(
100
- state,
101
- anotherhost,
102
98
  "fail command",
103
99
  print_input=False,
104
100
  print_output=False,
105
- return_combined_output=True,
106
101
  **_get_executor_defaults(state, anotherhost),
107
102
  )
108
103
 
@@ -113,23 +108,21 @@ class TestFactsApi(PatchSSHTestCase):
113
108
  anotherhost = inventory.get_host("anotherhost")
114
109
 
115
110
  connect_all(state)
116
- anotherhost.current_op_global_kwargs = {
117
- "ignore_errors": True,
111
+ anotherhost.in_op = True
112
+ anotherhost.current_op_global_arguments = {
113
+ "_ignore_errors": True,
118
114
  }
119
115
 
120
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
116
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
121
117
  fake_run_command.return_value = False, MagicMock()
122
118
  fact_data = get_facts(state, Command, ("fail command",))
123
119
 
124
120
  assert fact_data == {anotherhost: None}
125
121
 
126
122
  fake_run_command.assert_called_with(
127
- state,
128
- anotherhost,
129
123
  "fail command",
130
124
  print_input=False,
131
125
  print_output=False,
132
- return_combined_output=True,
133
126
  **_get_executor_defaults(state, anotherhost),
134
127
  )
135
128
 
@@ -141,22 +134,21 @@ class TestFactsApi(PatchSSHTestCase):
141
134
 
142
135
  connect_all(state)
143
136
 
144
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
145
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
137
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
138
+ fake_run_command.return_value = MagicMock(), CommandOutput(
139
+ [OutputLine("stdout", "some-output")]
140
+ )
146
141
  fact_data = get_facts(state, Command, ("yes",), {"_sudo": True})
147
142
 
148
143
  assert fact_data == {anotherhost: "some-output"}
149
144
 
150
145
  defaults = _get_executor_defaults(state, anotherhost)
151
- defaults["sudo"] = True
146
+ defaults["_sudo"] = True
152
147
 
153
148
  fake_run_command.assert_called_with(
154
- state,
155
- anotherhost,
156
149
  "yes",
157
150
  print_input=False,
158
151
  print_output=False,
159
- return_combined_output=True,
160
152
  **defaults,
161
153
  )
162
154
 
@@ -169,22 +161,21 @@ class TestFactsApi(PatchSSHTestCase):
169
161
 
170
162
  connect_all(state)
171
163
 
172
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
173
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
164
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
165
+ fake_run_command.return_value = True, CommandOutput(
166
+ [OutputLine("stdout", "some-output")]
167
+ )
174
168
  fact_data = get_facts(state, Command, ("yes",))
175
169
 
176
170
  assert fact_data == {anotherhost: "some-output"}
177
171
 
178
172
  defaults = _get_executor_defaults(state, anotherhost)
179
- defaults["sudo"] = True
173
+ defaults["_sudo"] = True
180
174
 
181
175
  fake_run_command.assert_called_with(
182
- state,
183
- anotherhost,
184
176
  "yes",
185
177
  print_input=False,
186
178
  print_output=False,
187
- return_combined_output=True,
188
179
  **defaults,
189
180
  )
190
181
 
@@ -197,14 +188,16 @@ class TestFactsApi(PatchSSHTestCase):
197
188
  anotherhost.data._sudo_user = "this-should-be-overridden"
198
189
  anotherhost.data._su_user = "this-should-be-overridden"
199
190
 
200
- anotherhost.current_op_global_kwargs = {
201
- "su_user": "override-su-user",
191
+ anotherhost.current_op_global_arguments = {
192
+ "_su_user": "override-su-user",
202
193
  }
203
194
 
204
195
  connect_all(state)
205
196
 
206
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
207
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
197
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
198
+ fake_run_command.return_value = True, CommandOutput(
199
+ [OutputLine("stdout", "some-output")]
200
+ )
208
201
  fact_data = get_facts(
209
202
  state,
210
203
  Command,
@@ -215,44 +208,17 @@ class TestFactsApi(PatchSSHTestCase):
215
208
  assert fact_data == {anotherhost: "some-output"}
216
209
 
217
210
  defaults = _get_executor_defaults(state, anotherhost)
218
- defaults["sudo"] = True
219
- defaults["sudo_user"] = "override-sudo-user"
220
- defaults["su_user"] = "override-su-user"
211
+ defaults["_sudo"] = True
212
+ defaults["_sudo_user"] = "override-sudo-user"
213
+ defaults["_su_user"] = "override-su-user"
221
214
 
222
215
  fake_run_command.assert_called_with(
223
- state,
224
- anotherhost,
225
216
  "yes",
226
217
  print_input=False,
227
218
  print_output=False,
228
- return_combined_output=True,
229
219
  **defaults,
230
220
  )
231
221
 
232
- def test_get_fact_cached(self):
233
- inventory = make_inventory(hosts=("anotherhost",))
234
- state = State(inventory, Config())
235
-
236
- fact_hash = "a-fact-hash"
237
- cached_fact = {"this is a cached fact"}
238
- anotherhost = inventory.get_host("anotherhost")
239
- anotherhost.facts[fact_hash] = cached_fact
240
-
241
- connect_all(state)
242
-
243
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
244
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
245
- fact_data = get_facts(
246
- state,
247
- Command,
248
- args=("yes",),
249
- kwargs={"_sudo": True},
250
- fact_hash=fact_hash,
251
- )
252
-
253
- assert fact_data == {anotherhost: cached_fact}
254
- fake_run_command.assert_not_called()
255
-
256
222
  def test_get_fact_no_args(self):
257
223
  inventory = make_inventory(hosts=("host-1",))
258
224
  state = State(inventory, Config())
@@ -262,18 +228,17 @@ class TestFactsApi(PatchSSHTestCase):
262
228
  host_1 = inventory.get_host("host-1")
263
229
  defaults = _get_executor_defaults(state, host_1)
264
230
 
265
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
266
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
231
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
232
+ fake_run_command.return_value = MagicMock(), CommandOutput(
233
+ [OutputLine("stdout", "some-output")]
234
+ )
267
235
  fact_data = get_facts(state, Arch)
268
236
 
269
237
  assert fact_data == {host_1: "some-output"}
270
238
  fake_run_command.assert_called_with(
271
- state,
272
- host_1,
273
239
  Arch.command,
274
240
  print_input=False,
275
241
  print_output=False,
276
- return_combined_output=True,
277
242
  **defaults,
278
243
  )
279
244
 
@@ -288,18 +253,17 @@ class TestHostFactsApi(PatchSSHTestCase):
288
253
  host_1 = inventory.get_host("host-1")
289
254
  defaults = _get_executor_defaults(state, host_1)
290
255
 
291
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
292
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
256
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
257
+ fake_run_command.return_value = MagicMock(), CommandOutput(
258
+ [OutputLine("stdout", "some-output")]
259
+ )
293
260
  fact_data = host_1.get_fact(Command, command="echo hello world")
294
261
 
295
262
  assert fact_data == "some-output"
296
263
  fake_run_command.assert_called_with(
297
- state,
298
- host_1,
299
264
  "echo hello world",
300
265
  print_input=False,
301
266
  print_output=False,
302
- return_combined_output=True,
303
267
  **defaults,
304
268
  )
305
269
 
@@ -311,20 +275,19 @@ class TestHostFactsApi(PatchSSHTestCase):
311
275
 
312
276
  host_1 = inventory.get_host("host-1")
313
277
  defaults = _get_executor_defaults(state, host_1)
314
- defaults["sudo"] = True
278
+ defaults["_sudo"] = True
315
279
 
316
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
317
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
280
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
281
+ fake_run_command.return_value = MagicMock(), CommandOutput(
282
+ [OutputLine("stdout", "some-output")]
283
+ )
318
284
  fact_data = host_1.get_fact(Command, command="echo hello world", _sudo=True)
319
285
 
320
286
  assert fact_data == "some-output"
321
287
  fake_run_command.assert_called_with(
322
- state,
323
- host_1,
324
288
  "echo hello world",
325
289
  print_input=False,
326
290
  print_output=False,
327
- return_combined_output=True,
328
291
  **defaults,
329
292
  )
330
293
 
@@ -336,19 +299,18 @@ class TestHostFactsApi(PatchSSHTestCase):
336
299
 
337
300
  host_1 = inventory.get_host("host-1")
338
301
  defaults = _get_executor_defaults(state, host_1)
339
- defaults["sudo"] = True
302
+ defaults["_sudo"] = True
340
303
 
341
- with patch("pyinfra.connectors.ssh.run_shell_command") as fake_run_command:
342
- fake_run_command.return_value = MagicMock(), [("stdout", "some-output")]
304
+ with patch("pyinfra.connectors.ssh.SSHConnector.run_shell_command") as fake_run_command:
305
+ fake_run_command.return_value = MagicMock(), CommandOutput(
306
+ [OutputLine("stdout", "some-output")]
307
+ )
343
308
  fact_data = host_1.get_fact(Arch, _sudo=True)
344
309
 
345
310
  assert fact_data == "some-output"
346
311
  fake_run_command.assert_called_with(
347
- state,
348
- host_1,
349
312
  Arch.command,
350
313
  print_input=False,
351
314
  print_output=False,
352
- return_combined_output=True,
353
315
  **defaults,
354
316
  )