예제 #1
0
    def test_delete_target_remote(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                return (True, "")

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        result = scput.delete_target_remote()
        assert result == None
예제 #2
0
    def test_check_target_exists(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                return (True, "")

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        result = scput.check_target_exists()
        assert result == True
예제 #3
0
    def test_compare_file_sizes_cmd_fail(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout=30):
                return False, ""

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        with raises(SystemExit):
            scput.compare_file_sizes(100000)
예제 #4
0
    def test_delete_target_remote_fail(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                return (False, "")

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.scs = MockSplitCopyShared()
        with raises(SystemExit):
            scput.delete_target_remote()
예제 #5
0
    def test_validate_remote_path_put_isdir(self):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                return (True, "")

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp"
        result = scput.validate_remote_path_put()
        assert result == None
예제 #6
0
    def test_compare_file_sizes(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout=30):
                stdout = (
                    b"foo@bar ~ % ls -l /var/tmp/foo\r\r\n"
                    b"-rw-r--r--  1 foo  bar  100000 19 Dec  2019 /var/tmp/foo\r\n"
                    b"foo@bar ~ % ").decode()
                return True, stdout

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        result = scput.compare_file_sizes(100000)
        assert result == None
예제 #7
0
    def test_compare_file_sizes_mismatch(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout=30):
                stdout = (
                    b"foo@bar ~ % ls -l /var/tmp/foo\r\r\n"
                    b"-rw-r--r--  1 foo  bar  400000 19 Dec  2019 /var/tmp/foo\r\n"
                    b"foo@bar ~ %").decode()
                return True, stdout

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        with raises(SystemExit):
            scput.compare_file_sizes(100000)
예제 #8
0
    def test_join_files_remote_exception(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout):
                raise SSHException

        chunks = [["somefile_aa", 10000], ["somefile_ab", 10000]]
        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        scput.remote_dir = "/var/tmp/foo"
        scput.remote_file = "somefile"
        monkeypatch.setattr("builtins.open", MockOpen)
        with raises(SystemExit):
            scput.join_files_remote(MockSCPClient, chunks, "/tmp/foo")
예제 #9
0
    def test_join_files_remote(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout):
                return True, ""

        chunks = [["somefile_aa", 10000], ["somefile_ab", 10000]]
        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        scput.remote_dir = "/var/tmp/foo"
        scput.remote_file = "somefile"
        monkeypatch.setattr("builtins.open", MockOpen)
        result = scput.join_files_remote(MockSCPClient, chunks, "/tmp/foo")
        assert result == None
예제 #10
0
    def test_validate_remote_path_existingfile_basename_match(self):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                if re.match(r"test -d", cmd):
                    return False, ""
                else:
                    return True, ""

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp/foo"
        result = scput.validate_remote_path_put()
        assert result == None
예제 #11
0
    def test_remote_sha_put_hash_fail(self):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout=30):
                return True, ""

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        sha_bin = "shasum"
        sha_len = 224
        sha_hash = {
            224: "d2a90f1c9edd2e9771306d8c8f4a4fc802181b973ee8167fcaff98f4"
        }
        with raises(SystemExit):
            scput.remote_sha_put(sha_bin, sha_len, sha_hash)
예제 #12
0
    def test_remote_sha_put_cmd_fail(self, capsys, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout=30):
                return False, ""

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        sha_bin = "shasum"
        sha_len = 224
        sha_hash = {
            224: "d2a90f1c9edd2e9771306d8c8f4a4fc802181b973ee8167fcaff98f4"
        }
        scput.remote_sha_put(sha_bin, sha_len, sha_hash)
        captured = capsys.readouterr()
        assert re.search(r"remote sha hash generation failed", captured.out)
예제 #13
0
    def test_validate_remote_path_put_fail(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(cmd):
                return (False, "")

        def dirname(path):
            return "/var/tmp"

        monkeypatch.setattr("os.path.dirname", dirname)
        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.scs = MockSplitCopyShared()
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp/foo"
        with raises(SystemExit):
            scput.validate_remote_path_put()
예제 #14
0
    def test_validate_remote_path_put_newfile_basename_nomatch(self):
        class MockSSHShell2(MockSSHShell):
            self.instance = 0

            def run(cmd):
                if re.match(r"test -d", cmd) and not self.instance:
                    self.instance += 1
                    return False, ""
                elif re.match(r"test -d", cmd):
                    return True, ""
                else:
                    return False, ""

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2
        scput.local_file = "foo"
        scput.remote_path = "/var/tmp/bar"
        result = scput.validate_remote_path_put()
        assert result == None
예제 #15
0
    def test_remote_sha_put_hash_mismatch(self):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout=30):
                stdout = (
                    "foo@bar ~ % shasum -a 224 /var/tmp/foo\n"
                    "d2a90f1c9edd2e9771306d8c8f4a4fc802181b973ee8167fceff98f4 "
                    "/var/tmp/foo\n"
                    "foo@bar ~ % \n")
                return True, stdout

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        sha_bin = "shasum"
        sha_len = 224
        sha_hash = {
            224: "d2a90f1c9edd2e9771306d8c8f4a4fc802181b973ee8167fcaff98f4"
        }
        with raises(SystemExit):
            scput.remote_sha_put(sha_bin, sha_len, sha_hash)
예제 #16
0
    def test_remote_sha_put(self, monkeypatch: MonkeyPatch):
        class MockSSHShell2(MockSSHShell):
            def run(self, cmd, timeout=30):
                stdout = (
                    "foo@bar ~ % sha224sum -a 224 /var/tmp/foo\n"
                    "d2a90f1c9edd2e9771306d8c8f4a4fc802181b973ee8167fcaff98f4 "
                    "/var/tmp/foo\n"
                    "foo@bar ~ % \n")
                return True, stdout

        scput = SplitCopyPut()
        scput.sshshell = MockSSHShell2()
        scput.scs = MockSplitCopyShared()
        sha_bin = "sha224sum"
        sha_len = 224
        sha_hash = {
            224: "d2a90f1c9edd2e9771306d8c8f4a4fc802181b973ee8167fcaff98f4"
        }
        result = scput.remote_sha_put(sha_bin, sha_len, sha_hash)
        expected = None
        assert expected == result