pyinfra 2.9.1__py2.py3-none-any.whl → 3.0__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.
- pyinfra/api/__init__.py +3 -0
- pyinfra/api/arguments.py +265 -253
- pyinfra/api/arguments_typed.py +80 -0
- pyinfra/api/command.py +68 -53
- pyinfra/api/config.py +139 -32
- pyinfra/api/connect.py +1 -1
- pyinfra/api/connectors.py +7 -26
- pyinfra/api/deploy.py +21 -52
- pyinfra/api/exceptions.py +33 -8
- pyinfra/api/facts.py +102 -137
- pyinfra/api/host.py +150 -82
- pyinfra/api/inventory.py +21 -25
- pyinfra/api/operation.py +240 -198
- pyinfra/api/operations.py +102 -148
- pyinfra/api/state.py +137 -79
- pyinfra/api/util.py +79 -86
- pyinfra/connectors/base.py +147 -0
- pyinfra/connectors/chroot.py +160 -169
- pyinfra/connectors/docker.py +220 -237
- pyinfra/connectors/dockerssh.py +231 -253
- pyinfra/connectors/local.py +196 -208
- pyinfra/connectors/ssh.py +530 -613
- pyinfra/connectors/ssh_util.py +114 -0
- pyinfra/connectors/sshuserclient/client.py +5 -3
- pyinfra/connectors/terraform.py +86 -65
- pyinfra/connectors/util.py +211 -137
- pyinfra/connectors/vagrant.py +60 -53
- pyinfra/context.py +4 -2
- pyinfra/facts/apk.py +2 -0
- pyinfra/facts/apt.py +2 -0
- pyinfra/facts/brew.py +2 -0
- pyinfra/facts/bsdinit.py +2 -0
- pyinfra/facts/cargo.py +2 -0
- pyinfra/facts/choco.py +2 -0
- pyinfra/facts/deb.py +7 -2
- pyinfra/facts/dnf.py +2 -0
- pyinfra/facts/docker.py +19 -0
- pyinfra/facts/files.py +47 -32
- pyinfra/facts/gem.py +2 -0
- pyinfra/facts/git.py +3 -1
- pyinfra/facts/gpg.py +3 -1
- pyinfra/facts/hardware.py +34 -24
- pyinfra/facts/iptables.py +5 -3
- pyinfra/facts/launchd.py +2 -0
- pyinfra/facts/lxd.py +2 -0
- pyinfra/facts/mysql.py +13 -6
- pyinfra/facts/npm.py +1 -0
- pyinfra/facts/openrc.py +2 -0
- pyinfra/facts/pacman.py +6 -2
- pyinfra/facts/pip.py +2 -0
- pyinfra/facts/pkg.py +2 -0
- pyinfra/facts/pkgin.py +2 -0
- pyinfra/facts/postgres.py +168 -0
- pyinfra/facts/postgresql.py +6 -160
- pyinfra/facts/rpm.py +12 -9
- pyinfra/facts/runit.py +68 -0
- pyinfra/facts/selinux.py +3 -1
- pyinfra/facts/server.py +80 -36
- pyinfra/facts/snap.py +2 -0
- pyinfra/facts/systemd.py +31 -12
- pyinfra/facts/sysvinit.py +10 -10
- pyinfra/facts/upstart.py +2 -0
- pyinfra/facts/util/packaging.py +7 -4
- pyinfra/facts/vzctl.py +2 -0
- pyinfra/facts/xbps.py +2 -0
- pyinfra/facts/yum.py +2 -0
- pyinfra/facts/zypper.py +2 -0
- pyinfra/local.py +4 -5
- pyinfra/operations/apk.py +6 -4
- pyinfra/operations/apt.py +46 -65
- pyinfra/operations/brew.py +17 -22
- pyinfra/operations/bsdinit.py +9 -7
- pyinfra/operations/cargo.py +4 -2
- pyinfra/operations/choco.py +4 -2
- pyinfra/operations/dnf.py +19 -23
- pyinfra/operations/docker.py +339 -0
- pyinfra/operations/files.py +188 -386
- pyinfra/operations/gem.py +4 -2
- pyinfra/operations/git.py +24 -53
- pyinfra/operations/iptables.py +29 -35
- pyinfra/operations/launchd.py +6 -7
- pyinfra/operations/lxd.py +8 -13
- pyinfra/operations/mysql.py +62 -81
- pyinfra/operations/npm.py +9 -2
- pyinfra/operations/openrc.py +6 -4
- pyinfra/operations/pacman.py +7 -8
- pyinfra/operations/pip.py +25 -24
- pyinfra/operations/pkg.py +4 -2
- pyinfra/operations/pkgin.py +6 -4
- pyinfra/operations/postgres.py +349 -0
- pyinfra/operations/postgresql.py +18 -379
- pyinfra/operations/puppet.py +3 -1
- pyinfra/operations/python.py +8 -19
- pyinfra/operations/runit.py +182 -0
- pyinfra/operations/selinux.py +47 -44
- pyinfra/operations/server.py +111 -127
- pyinfra/operations/snap.py +4 -4
- pyinfra/operations/ssh.py +20 -33
- pyinfra/operations/systemd.py +19 -15
- pyinfra/operations/sysvinit.py +9 -16
- pyinfra/operations/upstart.py +9 -7
- pyinfra/operations/util/__init__.py +12 -0
- pyinfra/operations/util/docker.py +177 -0
- pyinfra/operations/util/files.py +24 -16
- pyinfra/operations/util/packaging.py +55 -57
- pyinfra/operations/util/service.py +39 -51
- pyinfra/operations/vzctl.py +12 -10
- pyinfra/operations/xbps.py +6 -4
- pyinfra/operations/yum.py +18 -22
- pyinfra/operations/zypper.py +12 -13
- pyinfra/version.py +5 -2
- {pyinfra-2.9.1.dist-info → pyinfra-3.0.dist-info}/METADATA +40 -41
- pyinfra-3.0.dist-info/RECORD +167 -0
- {pyinfra-2.9.1.dist-info → pyinfra-3.0.dist-info}/WHEEL +1 -1
- pyinfra-3.0.dist-info/entry_points.txt +11 -0
- pyinfra_cli/__main__.py +4 -3
- pyinfra_cli/commands.py +7 -2
- pyinfra_cli/exceptions.py +78 -42
- pyinfra_cli/inventory.py +40 -6
- pyinfra_cli/log.py +17 -3
- pyinfra_cli/main.py +133 -90
- pyinfra_cli/prints.py +95 -127
- pyinfra_cli/util.py +62 -29
- tests/test_api/test_api.py +2 -0
- tests/test_api/test_api_arguments.py +13 -13
- tests/test_api/test_api_deploys.py +28 -29
- tests/test_api/test_api_facts.py +60 -98
- tests/test_api/test_api_operations.py +101 -201
- tests/test_cli/test_cli.py +18 -49
- tests/test_cli/test_cli_deploy.py +11 -37
- tests/test_cli/test_cli_exceptions.py +50 -19
- tests/test_cli/util.py +1 -1
- tests/test_connectors/test_chroot.py +6 -6
- tests/test_connectors/test_docker.py +4 -4
- tests/test_connectors/test_dockerssh.py +38 -50
- tests/test_connectors/test_local.py +11 -12
- tests/test_connectors/test_ssh.py +105 -93
- tests/test_connectors/test_terraform.py +9 -15
- tests/test_connectors/test_util.py +24 -46
- tests/test_connectors/test_vagrant.py +7 -7
- pyinfra/api/operation.pyi +0 -117
- pyinfra/connectors/ansible.py +0 -171
- pyinfra/connectors/mech.py +0 -186
- pyinfra/connectors/pyinfrawinrmsession/__init__.py +0 -28
- pyinfra/connectors/winrm.py +0 -320
- pyinfra/facts/windows.py +0 -366
- pyinfra/facts/windows_files.py +0 -90
- pyinfra/operations/windows.py +0 -59
- pyinfra/operations/windows_files.py +0 -551
- pyinfra-2.9.1.dist-info/RECORD +0 -170
- pyinfra-2.9.1.dist-info/entry_points.txt +0 -14
- tests/test_connectors/test_ansible.py +0 -64
- tests/test_connectors/test_mech.py +0 -126
- tests/test_connectors/test_winrm.py +0 -76
- {pyinfra-2.9.1.dist-info → pyinfra-3.0.dist-info}/LICENSE.md +0 -0
- {pyinfra-2.9.1.dist-info → pyinfra-3.0.dist-info}/top_level.txt +0 -0
tests/test_api/test_api_facts.py
CHANGED
|
@@ -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
|
|
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
|
|
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 =
|
|
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.
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
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 =
|
|
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.
|
|
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.
|
|
117
|
-
|
|
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(),
|
|
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["
|
|
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 =
|
|
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["
|
|
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.
|
|
201
|
-
"
|
|
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 =
|
|
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["
|
|
219
|
-
defaults["
|
|
220
|
-
defaults["
|
|
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(),
|
|
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(),
|
|
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["
|
|
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(),
|
|
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["
|
|
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(),
|
|
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
|
)
|