1#
2# SPDX-License-Identifier: MIT
3#
4
5import os
6from tempfile import mkstemp
7
8from oeqa.runtime.case import OERuntimeTestCase
9from oeqa.core.decorator.depends import OETestDepends
10from oeqa.runtime.decorator.package import OEHasPackage
11
12class ScpTest(OERuntimeTestCase):
13
14    @classmethod
15    def setUpClass(cls):
16        cls.tmp_fd, cls.tmp_path = mkstemp()
17        with os.fdopen(cls.tmp_fd, 'w') as f:
18            f.seek(2 ** 22 -1)
19            f.write(os.linesep)
20
21    @classmethod
22    def tearDownClass(cls):
23        os.remove(cls.tmp_path)
24
25    @OETestDepends(['ssh.SSHTest.test_ssh'])
26    @OEHasPackage(['openssh-scp', 'dropbear'])
27    def test_scp_file(self):
28        dst = '/tmp/test_scp_file'
29
30        (status, output) = self.target.copyTo(self.tmp_path, dst)
31        msg = 'File could not be copied. Output: %s' % output
32        self.assertEqual(status, 0, msg=msg)
33
34        (status, output) = self.target.run('ls -la %s' % dst)
35        self.assertEqual(status, 0, msg = 'SCP test failed')
36
37        self.target.run('rm %s' % dst)
38