Exemplo n.º 1
0
 def do_mount(credentials_file):
     for mtry in [1, 2, 3]:
         if mtry==1:
             options = ['noperm', 'credentials=%s' % credentials_file, 'sec=ntlmv2']
         elif mtry ==2:
             options = ['noperm', 'credentials=%s' % credentials_file, 'sec=ntlm']
         else:
             options = ['noperm', 'credentials=%s' % credentials_file]
         if self.connect_args.read_only:
             options.append('ro')
         else:
             options.append('rw')
         if self.connect_args.direct_attribute_access==True:
             options.append('actimeo=0')
         cmd = ['/sbin/mount.cifs', self.df_name, self.connect_args.mp, '-o'] + \
               [','.join(options)]
         if os.getuid()!=0:
             cmd = ['/usr/bin/sudo',] + cmd
         rc = process.run_and_log_program(cmd, None, logger)
         if rc!=0 and mtry==1:
             logger.warn("Unable to mount with sec=ntlmv2, will try again using sec=ntlm")
         elif rc!=0 and mtry==2:
             logger.warn("Unable to mount with sec=ntlm, will try again using no sec option.")
         elif rc!=0 and mtry==3:
             raise FsMgrError("mount failed: non-zero return code %d when running %s" %
                              (rc, ' '.join(cmd)))
         else:
             return
Exemplo n.º 2
0
def run_cmd(program_and_args, cwd, valid_return_codes=[0,],
            dry_run=False):
    cwd = fixpath(cwd)
    if dry_run:
        logger.info("[dry_run] %s" % ' '.join(program_and_args))
    else:
        rc = run_and_log_program(program_and_args, None, logger, cwd=cwd)
        if rc not in valid_return_codes:
            raise BadRcError(program_and_args, rc)
Exemplo n.º 3
0
 def is_file_available(self, parsed_url):
     """Returns True if file is present in the repository, False if
     not present, and None if it cannot be determined"""
     logger.debug("Checking for file %s at %s via ssh" % (parsed_url.path,
                                                          parsed_url.netloc))
     rc = run_and_log_program(['/usr/bin/ssh', parsed_url.netloc, '/bin/ls',
                               parsed_url.path], None, logger)
     if rc==0:
         return True
     else:
         return False
Exemplo n.º 4
0
 def _run_as_root(self, command_and_args, operation_name):
     """Utility function to run a command as root. If not already root, uses sudo.
     Note that we currently assume the system can call sudo without a password.
     This throws a FsMgrError if the command returns a non-zero return code.
     """
     if os.getuid()!=0:
         cmd = ['/usr/bin/sudo',] + command_and_args
     else:
         cmd = command_and_args
     rc = process.run_and_log_program(cmd, None, logger)
     if rc !=0:
         raise FsMgrError("%s failed: non-zero return code when running %s" %
                          (operation_name, ' '.join(cmd)))
Exemplo n.º 5
0
 def _run_as_root(self, command_and_args, operation_name):
     """If we know that everything is under the ownership
     of this user, we don't need to run as root. This is
     useful for testing.
     """
     if self.is_user:
         rc = process.run_and_log_program(command_and_args, None,
                                          logger)
         if rc != 0:
             raise FsMgrError("%s failed: non-zero return code when running %s" %
                              (operation_name, ' '.join(command_and_args)))
     else:
         FileSystemMgr._run_as_root(self, command_and_args,
                                    operation_name)
Exemplo n.º 6
0
 def _do_mount(self):
     self.created_for_mount = self._ensure_mount_dir_exists()
     if self.connect_args.read_only:
         ro_opt = '-r'
     else:
         ro_opt = '-w'
     base_cmd = ['/sbin/mount.nfs', self.df_name, self.connect_args.mp, ro_opt]
     if os.getuid()!=0:
         base_cmd = ['/usr/bin/sudo',] + base_cmd
     rc = process.run_and_log_program(base_cmd + ['-o', 'vers=3'],
                                      None, logger)
     if rc==0:
         logger.info("Mounted %s successfully, forced NFS protocol to version 3" %
                     self.df_name)
     else:
         logger.warn("Unable to mount nfs filesystem %s with vers=3, will try default option" %
                     self.df_name)
         rc = process.run_and_log_program(base_cmd, None, logger)
         if rc==0:
             logger.info("Mounted %s without specifying protocol version" %
                         self.df_name)
         else:
             raise FsMgrError("mount failed non-zero return code %d when running %s" %
                              (rc, ' '.join(base_cmd)))