~canonical-platform-qa/ubuntu-system-tests/temp_config_files

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/ssh.py

  • Committer: Sergio Cazzolato
  • Date: 2015-08-23 01:42:35 UTC
  • mfrom: (147.1.33 trunk)
  • Revision ID: sergio.cazzolato@canonical.com-20150823014235-zjhwxta8s08imwze
Fix to make possible to use temp config file for regular config data

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import os
22
22
import paramiko
23
23
 
 
24
from ubuntu_system_tests import config
 
25
 
24
26
logger = logging.getLogger(__name__)
25
27
 
26
28
 
45
47
 
46
48
        return "".join(stdout.readlines())
47
49
 
48
 
    def copy(self, localpath, remotepath):
49
 
        """Copy a file through sftp from the localpath to the remotepath"""
50
 
        if not os.path.isfile(localpath):
 
50
    def put(self, local_path, remote_path):
 
51
        """Copy a file through sftp from the local_path to the remote_path"""
 
52
        if not os.path.isfile(local_path):
51
53
            raise RuntimeError("File to copy does not exist")
52
54
 
53
55
        sftp = self.client.open_sftp()
54
 
        sftp.put(localpath, remotepath)
 
56
        sftp.put(local_path, remote_path)
55
57
        sftp.close()
56
58
 
57
59
 
58
60
class LinuxRemoteHelper(SSH):
59
61
    """This class executes remote linux commands through the ssh connection"""
60
62
 
61
 
    def remove_remote_dir(self, dir_name):
 
63
    def __init__(self):
 
64
        config_stack = config.get_device_config_stack()
 
65
        host = config_stack.get('ssh_ip')
 
66
        user = config_stack.get('ssh_user')
 
67
        password = config_stack.get('ssh_password')
 
68
        super(LinuxRemoteHelper, self).__init__(host, user, password)
 
69
 
 
70
    def remove_dir(self, dir_name):
62
71
        self.run('rm -rf {}'.format(dir_name))
63
72
 
64
 
    def create_remote_dir(self, dir_name):
 
73
    def create_dir(self, dir_name):
65
74
        self.run('mkdir {}'.format(dir_name))
66
75
 
67
 
    def remove_remote_file(self, file_name):
 
76
    def remove_file(self, file_name):
68
77
        self.run('rm -f {}'.format(file_name))
69
78
 
70
79
    def copy_file(self, remote_from, remote_to):
77
86
        """
78
87
        self.run('cp -rf {rfrom} {rto}'.format(rfrom=remote_from,
79
88
                                               rto=remote_to))
 
89
 
 
90
    def create_random_file(self, file_path, kb=0, mb=0, gb=0):
 
91
        """ Create a file with random data in the remote host
 
92
        :param file_path: The path to store the file
 
93
        :param kb: The kilobytes of the file
 
94
        :param mb: The megabytes of the file
 
95
        :param gb: The gigabytes fo the file
 
96
        :return: The file path to the created file with random content and size
 
97
        equals to kb kilobytes + mb megabytes + gb gigabytes
 
98
        """
 
99
        count = kb + mb * 1024 + gb * 1024 * 1024
 
100
        self.run('dd if=/dev/urandom of={file} bs=1024 count={count}'.
 
101
                 format(file=file_path, count=count))
 
102
 
 
103
    def get_sha1(self, file_path):
 
104
        """Calculate the sha1 digest to the specified file"""
 
105
        res = self.run("sha1sum {file}".format(file=file_path))
 
106
        return res.split()[0]