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