|
1 | 1 | import os,sys,json,glob,shutil,uuid,getpass |
2 | 2 | import unittest |
3 | | -from pathlib import Path |
| 3 | +import pathlib |
4 | 4 | from paramiko.ssh_exception import NoValidConnectionsError |
| 5 | +from paramiko.ssh_exception import SSHException |
5 | 6 |
|
6 | 7 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) |
7 | 8 | __package__ = 'tests' |
8 | 9 | from .context import SSHContext, SSHSession |
| 10 | +from .context import Machine |
| 11 | +from .sample_class import SampleClass |
9 | 12 |
|
10 | 13 | class TestSSHContext(unittest.TestCase): |
| 14 | + @classmethod |
| 15 | + def setUpClass(cls): |
| 16 | + with open('jsons/machine_ali_ehpc.json', 'r') as f: |
| 17 | + mdata = json.load(f) |
| 18 | + try: |
| 19 | + cls.machine = Machine.load_from_dict(mdata['machine']) |
| 20 | + except SSHException: |
| 21 | + self.skipTest("SSHException cannot connect") |
| 22 | + cls.submission = SampleClass.get_sample_submission() |
| 23 | + cls.submission.bind_machine(cls.machine) |
| 24 | + cls.submission_hash = cls.submission.submission_hash |
| 25 | + file_list = ['bct-1/log.lammps', 'bct-2/log.lammps', 'bct-3/log.lammps', 'bct-4/log.lammps'] |
| 26 | + for file in file_list: |
| 27 | + cls.machine.context.write_file(file, '# mock log') |
| 28 | + |
11 | 29 | def setUp(self): |
12 | | - self.tmp_local_root = 'test_context_dir/' |
13 | | - self.tmp_remote_root = 'tmp_ssh_context_dir/' |
| 30 | + self.context = self.__class__.machine.context |
14 | 31 |
|
15 | | - self.username = getpass.getuser() |
16 | | - # try: |
17 | | - self.ssh_session = SSHSession( |
18 | | - hostname='localhost', |
19 | | - username=self.username |
| 32 | + def test_ssh_session(self): |
| 33 | + self.assertIsInstance( |
| 34 | + self.__class__.machine.context.ssh_session, SSHSession |
20 | 35 | ) |
21 | | - # except NoValidConnectionsError: |
22 | | - # self.skipTest("skip ssh tests due to ssh connection errors") |
23 | 36 |
|
24 | | - def test_ssh_session(self): |
25 | | - pass |
26 | | - # with self. |
| 37 | + def test_upload(self): |
| 38 | + self.context.upload(self.__class__.submission) |
| 39 | + check_file_list = ['graph.pb', 'bct-1/conf.lmp', 'bct-4/input.lammps'] |
| 40 | + for file in check_file_list: |
| 41 | + self.assertTrue(self.context.check_file_exists(os.path.join(self.context.remote_root, file))) |
| 42 | + |
| 43 | + def test_download(self): |
| 44 | + self.context.download(self.__class__.submission) |
| 45 | + |
27 | 46 |
|
28 | 47 |
|
0 commit comments