-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,112 @@ | ||
"""ssh_test | ||
Run SSH test. | ||
Usage: | ||
ssh_test [options] --host=N --prefix=N | ||
Options: | ||
-r, --host=N Host name. | ||
-p, --prefix=M Path on host. | ||
--version Print version. | ||
-g, --help Print this help. | ||
""" | ||
Run as:: | ||
(c - MIT) T.W.J. de Geus | tom@geus.me | www.geus.me | github.com/tdegeus/shelephant | ||
python ssh_test.py HOST PREFIX | ||
""" | ||
import os | ||
import subprocess | ||
import sys | ||
import unittest | ||
from functools import partialmethod | ||
|
||
import docopt | ||
from tqdm import tqdm | ||
|
||
import shelephant | ||
|
||
tqdm.__init__ = partialmethod(tqdm.__init__, disable=True) | ||
|
||
|
||
def run(cmd): | ||
print(cmd) | ||
return subprocess.check_output(cmd, shell=True).decode("utf-8") | ||
|
||
|
||
args = docopt.docopt(__doc__, version=shelephant.version) | ||
class Test_ssh(unittest.TestCase): | ||
def test_all(self): | ||
|
||
# shelephant_send - local checksum | ||
operations = [ | ||
"bar.txt -> bar.txt", | ||
"foo.txt == foo.txt", | ||
] | ||
|
||
operations = [ | ||
"bar.txt -> bar.txt", | ||
"foo.txt == foo.txt", | ||
] | ||
output = run( | ||
( | ||
"shelephant_hostinfo -o myssh_send/shelephant_hostinfo.yaml --force " | ||
'--host "{:s}" --prefix "{:s}" -f -c' | ||
).format(self.HOST, os.path.join(self.PREFIX, "myssh_get")) | ||
) | ||
|
||
output = run( | ||
( | ||
"shelephant_hostinfo -o myssh_send/shelephant_hostinfo.yaml --force " | ||
'--host "{:s}" --prefix "{:s}" -f -c' | ||
).format(args["--host"], os.path.join(args["--prefix"], "myssh_get")) | ||
) | ||
output = run( | ||
"shelephant_send --detail --colors none --force " | ||
"myssh_send/shelephant_dump.yaml myssh_send/shelephant_hostinfo.yaml" | ||
) | ||
|
||
output = run( | ||
"shelephant_send --detail --colors none --force " | ||
"myssh_send/shelephant_dump.yaml myssh_send/shelephant_hostinfo.yaml" | ||
) | ||
output = list(filter(None, output.split("\n"))) | ||
|
||
output = list(filter(None, output.split("\n"))) | ||
assert output == operations | ||
self.assertEqual(output, operations) | ||
|
||
operations = [ | ||
"bar.txt == bar.txt", | ||
"foo.txt -> foo.txt", | ||
] | ||
|
||
# shelephant_send - basic | ||
output = run( | ||
( | ||
"shelephant_hostinfo -o myssh_send/shelephant_hostinfo.yaml --force " | ||
'--host "{:s}" --prefix "{:s}" -f' | ||
).format(self.HOST, os.path.join(self.PREFIX, "myssh_get")) | ||
) | ||
|
||
operations = [ | ||
"bar.txt == bar.txt", | ||
"foo.txt -> foo.txt", | ||
] | ||
output = run( | ||
"shelephant_send --detail --colors none --force " | ||
"myssh_send/shelephant_dump.yaml myssh_send/shelephant_hostinfo.yaml" | ||
) | ||
|
||
output = run( | ||
( | ||
"shelephant_hostinfo -o myssh_send/shelephant_hostinfo.yaml --force " | ||
'--host "{:s}" --prefix "{:s}" -f' | ||
).format(args["--host"], os.path.join(args["--prefix"], "myssh_get")) | ||
) | ||
output = list(filter(None, output.split("\n"))) | ||
self.assertEqual(output, operations) | ||
|
||
output = run( | ||
"shelephant_send --detail --colors none --force " | ||
"myssh_send/shelephant_dump.yaml myssh_send/shelephant_hostinfo.yaml" | ||
) | ||
operations = { | ||
"<-": [], | ||
"->": [], | ||
"!=": [], | ||
"==": ["bar.txt", "foo.txt"], | ||
} | ||
|
||
output = list(filter(None, output.split("\n"))) | ||
assert output == operations | ||
output = run( | ||
"shelephant_diff -f --yaml shelephant_diff.yaml " | ||
"myssh_send/shelephant_dump.yaml myssh_send/shelephant_hostinfo.yaml" | ||
) | ||
|
||
# shelephant_diff | ||
output = shelephant.yaml.read("shelephant_diff.yaml") | ||
|
||
operations = { | ||
"<-": [], | ||
"->": [], | ||
"!=": [], | ||
"==": ["bar.txt", "foo.txt"], | ||
} | ||
for key in operations: | ||
self.assertListEqual(output[key], operations[key]) | ||
|
||
output = run( | ||
"shelephant_diff -f --yaml shelephant_diff.yaml " | ||
"myssh_send/shelephant_dump.yaml myssh_send/shelephant_hostinfo.yaml" | ||
) | ||
operations = [ | ||
"bar.txt -> bar.txt", | ||
"foo.txt == foo.txt", | ||
] | ||
|
||
output = shelephant.yaml.read("shelephant_diff.yaml") | ||
output = run( | ||
( | ||
"shelephant_hostinfo -o myssh_get/shelephant_hostinfo.yaml --force " | ||
'--host "{:s}" --prefix "{:s}" -f -c' | ||
).format(self.HOST, os.path.join(self.PREFIX, "myssh_send")) | ||
) | ||
|
||
for key in operations: | ||
assert output[key] == operations[key] | ||
output = run( | ||
"shelephant_get --detail --colors none --force myssh_get/shelephant_hostinfo.yaml" | ||
) | ||
|
||
# shelephant_get - basic | ||
output = list(filter(None, output.split("\n"))) | ||
self.assertEqual(output, operations) | ||
|
||
operations = [ | ||
"bar.txt -> bar.txt", | ||
"foo.txt == foo.txt", | ||
] | ||
os.remove("myssh_get/bar.txt") | ||
|
||
output = run( | ||
( | ||
"shelephant_hostinfo -o myssh_get/shelephant_hostinfo.yaml --force " | ||
'--host "{:s}" --prefix "{:s}" -f -c' | ||
).format(args["--host"], os.path.join(args["--prefix"], "myssh_send")) | ||
) | ||
|
||
output = run("shelephant_get --detail --colors none --force myssh_get/shelephant_hostinfo.yaml") | ||
if __name__ == "__main__": | ||
|
||
output = list(filter(None, output.split("\n"))) | ||
assert output == operations | ||
Test_ssh.PREFIX = sys.argv.pop() | ||
Test_ssh.HOST = sys.argv.pop() | ||
|
||
os.remove("myssh_get/bar.txt") | ||
unittest.main() |