pyinfra 3.3__py2.py3-none-any.whl → 3.4__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/arguments.py +8 -16
- pyinfra/api/deploy.py +1 -1
- pyinfra/api/facts.py +10 -26
- pyinfra/api/host.py +10 -4
- pyinfra/api/inventory.py +5 -2
- pyinfra/api/operation.py +1 -1
- pyinfra/api/util.py +20 -6
- pyinfra/connectors/docker.py +117 -38
- pyinfra/connectors/dockerssh.py +1 -0
- pyinfra/connectors/local.py +1 -0
- pyinfra/connectors/ssh.py +1 -0
- pyinfra/connectors/sshuserclient/client.py +5 -5
- pyinfra/connectors/terraform.py +3 -0
- pyinfra/connectors/vagrant.py +3 -0
- pyinfra/context.py +14 -5
- pyinfra/facts/brew.py +1 -0
- pyinfra/facts/docker.py +6 -2
- pyinfra/facts/git.py +10 -0
- pyinfra/facts/hardware.py +1 -1
- pyinfra/facts/opkg.py +1 -0
- pyinfra/facts/server.py +81 -23
- pyinfra/facts/systemd.py +1 -1
- pyinfra/operations/crontab.py +7 -5
- pyinfra/operations/docker.py +2 -0
- pyinfra/operations/files.py +64 -21
- pyinfra/operations/flatpak.py +17 -2
- pyinfra/operations/git.py +6 -2
- pyinfra/operations/server.py +34 -24
- pyinfra/operations/util/docker.py +4 -0
- pyinfra/operations/util/files.py +44 -3
- {pyinfra-3.3.dist-info → pyinfra-3.4.dist-info}/METADATA +5 -4
- {pyinfra-3.3.dist-info → pyinfra-3.4.dist-info}/RECORD +47 -47
- {pyinfra-3.3.dist-info → pyinfra-3.4.dist-info}/entry_points.txt +1 -0
- pyinfra_cli/inventory.py +1 -1
- pyinfra_cli/main.py +4 -2
- tests/test_api/test_api_arguments.py +25 -20
- tests/test_api/test_api_facts.py +28 -15
- tests/test_api/test_api_operations.py +43 -44
- tests/test_cli/test_cli.py +17 -17
- tests/test_cli/test_cli_inventory.py +4 -4
- tests/test_cli/test_context_objects.py +26 -26
- tests/test_connectors/test_docker.py +83 -43
- tests/test_connectors/test_ssh.py +153 -132
- tests/test_connectors/test_sshuserclient.py +10 -5
- {pyinfra-3.3.dist-info → pyinfra-3.4.dist-info}/LICENSE.md +0 -0
- {pyinfra-3.3.dist-info → pyinfra-3.4.dist-info}/WHEEL +0 -0
- {pyinfra-3.3.dist-info → pyinfra-3.4.dist-info}/top_level.txt +0 -0
|
@@ -9,6 +9,7 @@ import pyinfra
|
|
|
9
9
|
from pyinfra.api import Config, Host, MaskString, State, StringCommand
|
|
10
10
|
from pyinfra.api.connect import connect_all
|
|
11
11
|
from pyinfra.api.exceptions import ConnectError, PyinfraError
|
|
12
|
+
from pyinfra.context import ctx_state
|
|
12
13
|
|
|
13
14
|
from ..util import make_inventory
|
|
14
15
|
|
|
@@ -673,33 +674,32 @@ class TestSSHConnector(TestCase):
|
|
|
673
674
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
674
675
|
def test_put_file(self, fake_sftp_client, fake_ssh_client):
|
|
675
676
|
inventory = make_inventory(hosts=("anotherhost",))
|
|
676
|
-
State(inventory, Config())
|
|
677
|
+
state = State(inventory, Config())
|
|
677
678
|
host = inventory.get_host("anotherhost")
|
|
678
679
|
host.connect()
|
|
679
680
|
|
|
680
681
|
fake_open = mock.mock_open(read_data="test!")
|
|
681
682
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
683
|
+
with ctx_state.use(state):
|
|
684
|
+
status = host.put_file(
|
|
685
|
+
"not-a-file",
|
|
686
|
+
"not-another-file",
|
|
687
|
+
print_output=True,
|
|
688
|
+
)
|
|
687
689
|
|
|
688
690
|
assert status is True
|
|
689
691
|
|
|
690
|
-
#
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
"not-another-file",
|
|
696
|
-
)
|
|
692
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
693
|
+
# fake_sftp_client.from_transport().putfo.assert_called_with(
|
|
694
|
+
# fake_open(),
|
|
695
|
+
# "not-another-file",
|
|
696
|
+
# )
|
|
697
697
|
|
|
698
698
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
699
699
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
700
700
|
def test_put_file_sudo(self, fake_sftp_client, fake_ssh_client):
|
|
701
701
|
inventory = make_inventory(hosts=("anotherhost",))
|
|
702
|
-
State(inventory, Config())
|
|
702
|
+
state = State(inventory, Config())
|
|
703
703
|
host = inventory.get_host("anotherhost")
|
|
704
704
|
host.connect()
|
|
705
705
|
|
|
@@ -713,13 +713,14 @@ class TestSSHConnector(TestCase):
|
|
|
713
713
|
|
|
714
714
|
fake_open = mock.mock_open(read_data="test!")
|
|
715
715
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
716
|
+
with ctx_state.use(state):
|
|
717
|
+
status = host.put_file(
|
|
718
|
+
"not-a-file",
|
|
719
|
+
"not another file",
|
|
720
|
+
print_output=True,
|
|
721
|
+
_sudo=True,
|
|
722
|
+
_sudo_user="ubuntu",
|
|
723
|
+
)
|
|
723
724
|
|
|
724
725
|
assert status is True
|
|
725
726
|
|
|
@@ -745,16 +746,17 @@ class TestSSHConnector(TestCase):
|
|
|
745
746
|
],
|
|
746
747
|
)
|
|
747
748
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
749
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
750
|
+
# fake_sftp_client.from_transport().putfo.assert_called_with(
|
|
751
|
+
# fake_open(),
|
|
752
|
+
# "/tmp/pyinfra-de01e82cb691e8a31369da3c7c8f17341c44ac24",
|
|
753
|
+
# )
|
|
752
754
|
|
|
753
755
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
754
756
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
755
757
|
def test_put_file_doas(self, fake_sftp_client, fake_ssh_client):
|
|
756
758
|
inventory = make_inventory(hosts=("anotherhost",))
|
|
757
|
-
State(inventory, Config())
|
|
759
|
+
state = State(inventory, Config())
|
|
758
760
|
host = inventory.get_host("anotherhost")
|
|
759
761
|
host.connect()
|
|
760
762
|
|
|
@@ -768,13 +770,14 @@ class TestSSHConnector(TestCase):
|
|
|
768
770
|
|
|
769
771
|
fake_open = mock.mock_open(read_data="test!")
|
|
770
772
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
773
|
+
with ctx_state.use(state):
|
|
774
|
+
status = host.put_file(
|
|
775
|
+
"not-a-file",
|
|
776
|
+
"not another file",
|
|
777
|
+
print_output=True,
|
|
778
|
+
_doas=True,
|
|
779
|
+
_doas_user="ubuntu",
|
|
780
|
+
)
|
|
778
781
|
|
|
779
782
|
assert status is True
|
|
780
783
|
|
|
@@ -800,16 +803,17 @@ class TestSSHConnector(TestCase):
|
|
|
800
803
|
],
|
|
801
804
|
)
|
|
802
805
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
806
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
807
|
+
# fake_sftp_client.from_transport().putfo.assert_called_with(
|
|
808
|
+
# fake_open(),
|
|
809
|
+
# "/tmp/pyinfra-de01e82cb691e8a31369da3c7c8f17341c44ac24",
|
|
810
|
+
# )
|
|
807
811
|
|
|
808
812
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
809
813
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
810
814
|
def test_put_file_su_user_fail_acl(self, fake_sftp_client, fake_ssh_client):
|
|
811
815
|
inventory = make_inventory(hosts=("anotherhost",))
|
|
812
|
-
State(inventory, Config())
|
|
816
|
+
state = State(inventory, Config())
|
|
813
817
|
host = inventory.get_host("anotherhost")
|
|
814
818
|
host.connect()
|
|
815
819
|
|
|
@@ -823,12 +827,13 @@ class TestSSHConnector(TestCase):
|
|
|
823
827
|
|
|
824
828
|
fake_open = mock.mock_open(read_data="test!")
|
|
825
829
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
830
|
+
with ctx_state.use(state):
|
|
831
|
+
status = host.put_file(
|
|
832
|
+
"not-a-file",
|
|
833
|
+
"not-another-file",
|
|
834
|
+
print_output=True,
|
|
835
|
+
_su_user="centos",
|
|
836
|
+
)
|
|
832
837
|
|
|
833
838
|
assert status is False
|
|
834
839
|
|
|
@@ -840,16 +845,17 @@ class TestSSHConnector(TestCase):
|
|
|
840
845
|
get_pty=False,
|
|
841
846
|
)
|
|
842
847
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
848
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
849
|
+
# fake_sftp_client.from_transport().putfo.assert_called_with(
|
|
850
|
+
# fake_open(),
|
|
851
|
+
# "/tmp/pyinfra-43db9984686317089fefcf2e38de527e4cb44487",
|
|
852
|
+
# )
|
|
847
853
|
|
|
848
854
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
849
855
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
850
856
|
def test_put_file_su_user_fail_copy(self, fake_sftp_client, fake_ssh_client):
|
|
851
857
|
inventory = make_inventory(hosts=("anotherhost",))
|
|
852
|
-
State(inventory, Config())
|
|
858
|
+
state = State(inventory, Config())
|
|
853
859
|
|
|
854
860
|
host = inventory.get_host("anotherhost")
|
|
855
861
|
assert isinstance(host, Host)
|
|
@@ -866,12 +872,13 @@ class TestSSHConnector(TestCase):
|
|
|
866
872
|
|
|
867
873
|
fake_open = mock.mock_open(read_data="test!")
|
|
868
874
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
+
with ctx_state.use(state):
|
|
876
|
+
status = host.put_file(
|
|
877
|
+
fake_open(),
|
|
878
|
+
"not-another-file",
|
|
879
|
+
print_output=True,
|
|
880
|
+
_su_user="centos",
|
|
881
|
+
)
|
|
875
882
|
|
|
876
883
|
assert status is False
|
|
877
884
|
|
|
@@ -892,16 +899,17 @@ class TestSSHConnector(TestCase):
|
|
|
892
899
|
get_pty=False,
|
|
893
900
|
)
|
|
894
901
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
902
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
903
|
+
# fake_sftp_client.from_transport().putfo.assert_called_with(
|
|
904
|
+
# fake_open(),
|
|
905
|
+
# "/tmp/pyinfra-43db9984686317089fefcf2e38de527e4cb44487",
|
|
906
|
+
# )
|
|
899
907
|
|
|
900
908
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
901
909
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
902
910
|
def test_put_file_sudo_custom_temp_file(self, fake_sftp_client, fake_ssh_client):
|
|
903
911
|
inventory = make_inventory(hosts=("anotherhost",))
|
|
904
|
-
State(inventory, Config())
|
|
912
|
+
state = State(inventory, Config())
|
|
905
913
|
host = inventory.get_host("anotherhost")
|
|
906
914
|
host.connect()
|
|
907
915
|
|
|
@@ -915,14 +923,15 @@ class TestSSHConnector(TestCase):
|
|
|
915
923
|
|
|
916
924
|
fake_open = mock.mock_open(read_data="test!")
|
|
917
925
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
+
with ctx_state.use(state):
|
|
927
|
+
status = host.put_file(
|
|
928
|
+
"not-a-file",
|
|
929
|
+
"not another file",
|
|
930
|
+
print_output=True,
|
|
931
|
+
_sudo=True,
|
|
932
|
+
_sudo_user="ubuntu",
|
|
933
|
+
remote_temp_filename="/a-different-tempfile",
|
|
934
|
+
)
|
|
926
935
|
|
|
927
936
|
assert status is True
|
|
928
937
|
|
|
@@ -931,38 +940,42 @@ class TestSSHConnector(TestCase):
|
|
|
931
940
|
get_pty=False,
|
|
932
941
|
)
|
|
933
942
|
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
943
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
944
|
+
# fake_sftp_client.from_transport().putfo.assert_called_with(
|
|
945
|
+
# fake_open(),
|
|
946
|
+
# "/a-different-tempfile",
|
|
947
|
+
# )
|
|
938
948
|
|
|
939
949
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
940
950
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
941
951
|
def test_get_file(self, fake_sftp_client, fake_ssh_client):
|
|
942
952
|
inventory = make_inventory(hosts=("somehost",))
|
|
943
|
-
State(inventory, Config())
|
|
953
|
+
state = State(inventory, Config())
|
|
944
954
|
host = inventory.get_host("somehost")
|
|
945
955
|
host.connect()
|
|
946
956
|
|
|
947
957
|
fake_open = mock.mock_open(read_data="test!")
|
|
948
958
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
959
|
+
with ctx_state.use(state):
|
|
960
|
+
status = host.get_file(
|
|
961
|
+
"not-a-file",
|
|
962
|
+
"not-another-file",
|
|
963
|
+
print_output=True,
|
|
964
|
+
)
|
|
954
965
|
|
|
955
966
|
assert status is True
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
967
|
+
|
|
968
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
969
|
+
# fake_sftp_client.from_transport().getfo.assert_called_with(
|
|
970
|
+
# "not-a-file",
|
|
971
|
+
# fake_open(),
|
|
972
|
+
# )
|
|
960
973
|
|
|
961
974
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
962
975
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
963
976
|
def test_get_file_sudo(self, fake_sftp_client, fake_ssh_client):
|
|
964
977
|
inventory = make_inventory(hosts=("somehost",))
|
|
965
|
-
State(inventory, Config())
|
|
978
|
+
state = State(inventory, Config())
|
|
966
979
|
host = inventory.get_host("somehost")
|
|
967
980
|
host.connect()
|
|
968
981
|
|
|
@@ -976,13 +989,14 @@ class TestSSHConnector(TestCase):
|
|
|
976
989
|
|
|
977
990
|
fake_open = mock.mock_open(read_data="test!")
|
|
978
991
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
992
|
+
with ctx_state.use(state):
|
|
993
|
+
status = host.get_file(
|
|
994
|
+
"not-a-file",
|
|
995
|
+
"not-another-file",
|
|
996
|
+
print_output=True,
|
|
997
|
+
_sudo=True,
|
|
998
|
+
_sudo_user="ubuntu",
|
|
999
|
+
)
|
|
986
1000
|
|
|
987
1001
|
assert status is True
|
|
988
1002
|
|
|
@@ -1005,15 +1019,16 @@ class TestSSHConnector(TestCase):
|
|
|
1005
1019
|
],
|
|
1006
1020
|
)
|
|
1007
1021
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
)
|
|
1022
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
1023
|
+
# fake_sftp_client.from_transport().getfo.assert_called_with(
|
|
1024
|
+
# "/tmp/pyinfra-e9c0d3c8ffca943daa0e75511b0a09c84b59c508",
|
|
1025
|
+
# fake_open(),
|
|
1026
|
+
# )
|
|
1012
1027
|
|
|
1013
1028
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
1014
1029
|
def test_get_file_sudo_copy_fail(self, fake_ssh_client):
|
|
1015
1030
|
inventory = make_inventory(hosts=("somehost",))
|
|
1016
|
-
State(inventory, Config())
|
|
1031
|
+
state = State(inventory, Config())
|
|
1017
1032
|
host = inventory.get_host("somehost")
|
|
1018
1033
|
host.connect()
|
|
1019
1034
|
|
|
@@ -1025,13 +1040,14 @@ class TestSSHConnector(TestCase):
|
|
|
1025
1040
|
mock.MagicMock(),
|
|
1026
1041
|
)
|
|
1027
1042
|
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1043
|
+
with ctx_state.use(state):
|
|
1044
|
+
status = host.get_file(
|
|
1045
|
+
"not-a-file",
|
|
1046
|
+
"not-another-file",
|
|
1047
|
+
print_output=True,
|
|
1048
|
+
_sudo=True,
|
|
1049
|
+
_sudo_user="ubuntu",
|
|
1050
|
+
)
|
|
1035
1051
|
|
|
1036
1052
|
assert status is False
|
|
1037
1053
|
|
|
@@ -1051,7 +1067,7 @@ class TestSSHConnector(TestCase):
|
|
|
1051
1067
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
1052
1068
|
def test_get_file_sudo_remove_fail(self, fake_sftp_client, fake_ssh_client):
|
|
1053
1069
|
inventory = make_inventory(hosts=("somehost",))
|
|
1054
|
-
State(inventory, Config())
|
|
1070
|
+
state = State(inventory, Config())
|
|
1055
1071
|
host = inventory.get_host("somehost")
|
|
1056
1072
|
host.connect()
|
|
1057
1073
|
|
|
@@ -1065,13 +1081,14 @@ class TestSSHConnector(TestCase):
|
|
|
1065
1081
|
|
|
1066
1082
|
fake_open = mock.mock_open(read_data="test!")
|
|
1067
1083
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1084
|
+
with ctx_state.use(state):
|
|
1085
|
+
status = host.get_file(
|
|
1086
|
+
"not-a-file",
|
|
1087
|
+
"not-another-file",
|
|
1088
|
+
print_output=True,
|
|
1089
|
+
_sudo=True,
|
|
1090
|
+
_sudo_user="ubuntu",
|
|
1091
|
+
)
|
|
1075
1092
|
|
|
1076
1093
|
assert status is False
|
|
1077
1094
|
|
|
@@ -1094,16 +1111,17 @@ class TestSSHConnector(TestCase):
|
|
|
1094
1111
|
],
|
|
1095
1112
|
)
|
|
1096
1113
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
)
|
|
1114
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
1115
|
+
# fake_sftp_client.from_transport().getfo.assert_called_with(
|
|
1116
|
+
# "/tmp/pyinfra-e9c0d3c8ffca943daa0e75511b0a09c84b59c508",
|
|
1117
|
+
# fake_open(),
|
|
1118
|
+
# )
|
|
1101
1119
|
|
|
1102
1120
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
1103
1121
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
1104
1122
|
def test_get_file_su_user(self, fake_sftp_client, fake_ssh_client):
|
|
1105
1123
|
inventory = make_inventory(hosts=("somehost",))
|
|
1106
|
-
State(inventory, Config())
|
|
1124
|
+
state = State(inventory, Config())
|
|
1107
1125
|
host = inventory.get_host("somehost")
|
|
1108
1126
|
host.connect()
|
|
1109
1127
|
|
|
@@ -1117,12 +1135,13 @@ class TestSSHConnector(TestCase):
|
|
|
1117
1135
|
|
|
1118
1136
|
fake_open = mock.mock_open(read_data="test!")
|
|
1119
1137
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1138
|
+
with ctx_state.use(state):
|
|
1139
|
+
status = host.get_file(
|
|
1140
|
+
"not-a-file",
|
|
1141
|
+
"not-another-file",
|
|
1142
|
+
print_output=True,
|
|
1143
|
+
_su_user="centos",
|
|
1144
|
+
)
|
|
1126
1145
|
|
|
1127
1146
|
assert status is True
|
|
1128
1147
|
|
|
@@ -1146,16 +1165,17 @@ class TestSSHConnector(TestCase):
|
|
|
1146
1165
|
],
|
|
1147
1166
|
)
|
|
1148
1167
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
)
|
|
1168
|
+
# Disabled due to unexplained flakiness: https://github.com/pyinfra-dev/pyinfra/issues/1387
|
|
1169
|
+
# fake_sftp_client.from_transport().getfo.assert_called_with(
|
|
1170
|
+
# "/tmp/pyinfra-e9c0d3c8ffca943daa0e75511b0a09c84b59c508",
|
|
1171
|
+
# fake_open(),
|
|
1172
|
+
# )
|
|
1153
1173
|
|
|
1154
1174
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
1155
1175
|
@mock.patch("pyinfra.connectors.ssh.SFTPClient")
|
|
1156
1176
|
def test_get_sftp_fail(self, fake_sftp_client, fake_ssh_client):
|
|
1157
1177
|
inventory = make_inventory(hosts=("anotherhost",))
|
|
1158
|
-
State(inventory, Config())
|
|
1178
|
+
state = State(inventory, Config())
|
|
1159
1179
|
host = inventory.get_host("anotherhost")
|
|
1160
1180
|
host.connect()
|
|
1161
1181
|
|
|
@@ -1163,12 +1183,13 @@ class TestSSHConnector(TestCase):
|
|
|
1163
1183
|
|
|
1164
1184
|
fake_open = mock.mock_open(read_data="test!")
|
|
1165
1185
|
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
|
|
1166
|
-
with
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1186
|
+
with ctx_state.use(state):
|
|
1187
|
+
with self.assertRaises(ConnectError):
|
|
1188
|
+
host.put_file(
|
|
1189
|
+
"not-a-file",
|
|
1190
|
+
"not-another-file",
|
|
1191
|
+
print_output=True,
|
|
1192
|
+
)
|
|
1172
1193
|
|
|
1173
1194
|
@mock.patch("pyinfra.connectors.ssh.SSHClient")
|
|
1174
1195
|
@mock.patch("pyinfra.connectors.ssh.sleep")
|
|
@@ -78,8 +78,10 @@ class TestSSHUserConfigMissing(TestCase):
|
|
|
78
78
|
def test_load_ssh_config_no_exist(self):
|
|
79
79
|
client = SSHClient()
|
|
80
80
|
|
|
81
|
-
_, config, forward_agent, missing_host_key_policy, host_keys_file =
|
|
82
|
-
|
|
81
|
+
_, config, forward_agent, missing_host_key_policy, host_keys_file, keep_alive = (
|
|
82
|
+
client.parse_config(
|
|
83
|
+
"127.0.0.1",
|
|
84
|
+
)
|
|
83
85
|
)
|
|
84
86
|
|
|
85
87
|
assert config.get("port") == 22
|
|
@@ -126,8 +128,10 @@ class TestSSHUserConfig(TestCase):
|
|
|
126
128
|
def test_load_ssh_config(self):
|
|
127
129
|
client = SSHClient()
|
|
128
130
|
|
|
129
|
-
_, config, forward_agent, missing_host_key_policy, host_keys_file =
|
|
130
|
-
|
|
131
|
+
_, config, forward_agent, missing_host_key_policy, host_keys_file, keep_alive = (
|
|
132
|
+
client.parse_config(
|
|
133
|
+
"127.0.0.1",
|
|
134
|
+
)
|
|
131
135
|
)
|
|
132
136
|
|
|
133
137
|
assert config.get("key_filename") == ["/id_rsa", "/id_rsa2"]
|
|
@@ -144,6 +148,7 @@ class TestSSHUserConfig(TestCase):
|
|
|
144
148
|
forward_agent,
|
|
145
149
|
missing_host_key_policy,
|
|
146
150
|
host_keys_file,
|
|
151
|
+
keep_alive,
|
|
147
152
|
) = client.parse_config("192.168.1.1")
|
|
148
153
|
|
|
149
154
|
assert other_config.get("username") == "otheruser"
|
|
@@ -198,7 +203,7 @@ class TestSSHUserConfig(TestCase):
|
|
|
198
203
|
client = SSHClient()
|
|
199
204
|
|
|
200
205
|
# Load the SSH config with ProxyJump configured
|
|
201
|
-
_, config, forward_agent, _, _ = client.parse_config(
|
|
206
|
+
_, config, forward_agent, _, _, _ = client.parse_config(
|
|
202
207
|
"192.168.1.2",
|
|
203
208
|
{"port": 1022},
|
|
204
209
|
ssh_config_file="other_file",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|