Example #1
0
 def create(self, option=None):
     """
     Create the dataset with options.
     """
     if option is None:
         cmd = [Env.syspaths.zfs, 'create', self.name]
     else:
         cmd = [Env.syspaths.zfs, 'create'] + option + [self.name]
     ret, _, _ = vcall(cmd, log=self.log)
     if ret == 0:
         return True
     else:
         return False
Example #2
0
 def rename(self, name=None, option=None):
     """
     Rename the dataset.
     """
     if option is None:
         cmd = [Env.syspaths.zfs, 'rename', self.name, name]
     else:
         cmd = [Env.syspaths.zfs, 'rename'] + option + [self.name, name]
     ret, _, _ = vcall(cmd, log=self.log)
     if ret == 0:
         return True
     else:
         return False
Example #3
0
 def setprop(self, propname, propval, err_to_warn=False, err_to_info=False):
     """
     Set Dataset property value.
     Return True is success else return False.
     """
     cmd = [Env.syspaths.zfs, 'set', propname + '=' + propval, self.name]
     ret, out, err = vcall(cmd,
                           log=self.log,
                           err_to_warn=err_to_warn,
                           err_to_info=err_to_info)
     if ret == 0:
         return True
     else:
         return False
Example #4
0
 def clone(self, name, option=None):
     """
     Clone the dataset with options
     Return the clone dataset object.
     Return False on failure.
     """
     if option is None:
         cmd = [Env.syspaths.zfs, 'clone', self.name, name]
     else:
         cmd = [Env.syspaths.zfs, 'clone'] + option + [self.name, name]
     ret, _, _ = vcall(cmd, log=self.log)
     if ret == 0:
         return Dataset(name)
     else:
         return False
Example #5
0
 def snapshot(self, snapname=None, recursive=False):
     """
     Snapshot the dataset.
     Return the snapshot dataset object.
     Return False on error.
     """
     if snapname is None:
         raise ex.Error("snapname should be defined")
     snapdataset = self.name + "@" + snapname
     cmd = [Env.syspaths.zfs, 'snapshot']
     if recursive:
         cmd.append("-r")
     cmd.append(snapdataset)
     ret, _, _ = vcall(cmd, log=self.log)
     if ret == 0:
         return Dataset(snapdataset)
     else:
         return False
Example #6
0
def zfs_setprop(dataset='undef_ds',
                propname='undef_prop',
                propval='undef_val',
                log=None):
    """
    Set the dataset property <propname> to value <propval>.
    """
    current = zfs_getprop(dataset, propname)
    if current == "":
        # dataset does not exist
        return False
    if current == propval:
        return True
    cmd = [Env.syspaths.zfs, 'set', propname + '=' + propval, dataset]
    ret, _, _ = vcall(cmd, log=log)
    if ret == 0:
        return True
    else:
        return False
Example #7
0
def zpool_setprop(pool='undef_pool',
                  propname='undef_prop',
                  propval='undef_val',
                  log=None):
    """
    Set the dataset property <propname> to value <propval>.
    """
    current = zpool_getprop(pool, propname)
    if current == "":
        # pool does not exist
        return False
    if current == propval:
        return True
    cmd = [Env.syspaths.zpool, 'set', propname + '=' + propval, pool]
    ret, _, _ = vcall(cmd, log=log)
    if ret == 0:
        return True
    else:
        return False
Example #8
0
 def vcall(self, *args, **kwargs):
     """
     Wrap vcall, setting the resource logger
     """
     kwargs["log"] = self.log
     return vcall(*args, **kwargs)
Example #9
0
    def vcall(self, cmd):
        if self.node is not None:
            cmd = [' '.join(cmd)]
            cmd = Env.rsh.split() + [self.node] + cmd

        return vcall(cmd, log=self.log)
Example #10
0
    def test_vcall(non_existing_file):
        """
        vcall()
        """
        ret, out, err = vcall([])
        assert ret == 0
        assert out == ""
        assert err == ""

        ret, out, err = vcall(["ls2"])
        assert ret == 1

        ret, out, err = vcall(["ls", non_existing_file])
        assert is_string(out) is True
        assert is_string(err) is True
        assert ret > 0

        # redirects
        cmd1 = 'ls'
        _, _, _ = vcall([cmd1, non_existing_file], err_to_warn=True)
        _, _, _ = vcall([cmd1, non_existing_file], err_to_info=True)
        _, _, _ = call([cmd1], info=False, outlog=False, outdebug=True)

        cmd2 = "ls " + non_existing_file + " 2>/dev/stdout"
        _, _, _ = vcall(cmd2, shell=True, err_to_info=True)
        _, _, _ = vcall(cmd2, shell=True, err_to_warn=True)
        _, _, _ = vcall(cmd2, shell=True, warn_to_info=False)
        _, _, _ = vcall(cmd2, shell=True, outlog=False, outdebug=True)

        cmd3 = "ls >/dev/stderr"
        _, _, _ = vcall(cmd3, shell=True, warn_to_info=True)
        _, _, _ = vcall(cmd3, shell=True, warn_to_info=False)
        _, _, _ = vcall(cmd3, shell=True, errlog=False, errdebug=True)

        # to cache
        ret, out, err = vcall(cmd1, shell=True, cache=True)
        assert is_string(out) is True
        assert is_string(err) is True
        assert ret == 0

        # from cache
        _, out2, _ = vcall(cmd1, shell=True, cache=True)
        assert out == out2

        # cache discard
        _, _, _ = vcall("touch " + non_existing_file, shell=True, cache=True)
        _, _, _ = vcall("test -f " + non_existing_file, shell=True, cache=True)
        try:
            os.unlink(non_existing_file)
        except:
            pass
        ret, _, _ = vcall("test -f " + non_existing_file, shell=True, cache=False)
        assert ret == 1