Esempio n. 1
0
 def remove_file_exports(self):
     try:
         NFS.run_command(self, "rm -rf /etc/exports".format(self.password))
     except Exception as e:
         logger.error(
             "File 'Exports' has not been removed. Error '{}' occurred".
             format(type(e)))
Esempio n. 2
0
 def reboot_system(self):
     try:
         __class__.run_command(self, "reboot")
     except Exception as e:
         logger.error(
             "Reboot has not been performed. Error '{}' occurred".format(
                 type(e)))
Esempio n. 3
0
 def copy_SSH_key(self, key):
     self.key = key
     try:
         SSH.run_command(self,
                         "echo '{}' >> .ssh/authorized_keys".format(key))
     except Exception as e:
         logger.error("Copy SSH key. Error '{}' occurred".format(type(e)))
Esempio n. 4
0
 def modify_file(self):
     try:
         self.text = ''.join(
             random.choice(string.ascii_letters) for _ in range(100))
         NFS.run_command(
             self, "echo '{}' >> {}".format(self.text, self.path_to_file))
     except Exception as e:
         logger.error("Modify file. Error '{}' occurred".format(type(e)))
Esempio n. 5
0
 def set_file_permissions(
         self, permissions):  # enter necessary permissions, e.g. '777'
     try:
         NFS.run_command(
             self, "chmod {} {}".format(permissions, self.path_to_file))
     except Exception as e:
         logger.error("Set file permissions. Error '{}' occurred".format(
             type(e)))
Esempio n. 6
0
 def create_file(self):
     try:
         _file = ''.join(
             random.choice(string.ascii_letters) for _ in range(10))
         self.shared_file = _file
         os.environ["SHARED_FILE"] = self.shared_file
         NFS.run_command(self, "touch {}".format(self.path_to_file))
     except Exception as e:
         logger.error("Create file. Error '{}' occurred".format(type(e)))
Esempio n. 7
0
 def set_rights_to_shared_folder(
         self, permissions):  # enter necessary permissions, e.g. '777'
     try:
         NFS.run_command(
             self, "chmod {} {}".format(permissions, self.path_to_folder))
     except Exception as e:
         logger.error(
             "Set rights to shared folder. Error '{}' occurred".format(
                 type(e)))
Esempio n. 8
0
 def create_folder(self):
     try:
         _folder = ''.join(
             random.choice(string.ascii_letters) for _ in range(10))
         self.shared_folder = _folder
         os.environ["SHARED_FOLDER"] = self.shared_folder
         NFS.run_command(self, "mkdir {}".format(self.path_to_folder))
     except Exception as e:
         logger.error("Create folder. Error '{}' occurred".format(type(e)))
Esempio n. 9
0
 def export_shared_folder(
         self, cmd):  # enter rights commands, e.g. 'rw' or 'all_squash'
     try:
         NFS.run_command(
             self, "echo '{} {}({})' > /etc/exports".format(
                 self.path_to_folder, config['hosts']['clients']['ip'],
                 cmd))
     except Exception as e:
         logger.error("Export shared folder. Error '{}' occurred".format(
             type(e)))
Esempio n. 10
0
 def mount_shared_folders(self):
     try:
         self.shared_folder = os.environ.get("SHARED_FOLDER")
         self.shared_file = os.environ.get("SHARED_FILE")
         self.path_to_folder = "/mnt/nfs/var/nfsshare/{}".format(
             self.shared_folder)
         self.path_to_file = "/mnt/nfs/var/nfsshare/{}/{}".format(
             self.shared_folder, self.shared_file)
         NFS.run_command(
             self, "mount {}:/var/nfsshare/{} {}".format(
                 config['hosts']['server']['ip'], self.shared_folder,
                 self.path_to_folder))
     except Exception as e:
         logger.error("Mount shared folder. Error '{}' occurred".format(
             type(e)))
Esempio n. 11
0
 def delete_file(self):
     try:
         NFS.run_command(self, "rm -rf {}".format(self.path_to_file))
     except Exception as e:
         logger.error("Delete file. Error '{}' occurred".format(type(e)))
Esempio n. 12
0
 def open_modified_file(self):
     try:
         NFS.run_command(self, "cat {}".format(self.path_to_file))
     except Exception as e:
         logger.error("Open modified file. Error '{}' occurred".format(
             type(e)))
Esempio n. 13
0
 def file_hash(self):
     try:
         NFS.run_command(self, "sha1sum {}".format(self.path_to_file))
     except Exception as e:
         logger.error("File hash. Error '{}' occurred".format(type(e)))
Esempio n. 14
0
 def logs(self):
     try:
         paramiko.util.log_to_file('log_file.txt')
     except Exception as e:
         logger.error("Logs. Error '{}' occurred".format(type(e)))