Exemple #1
0
    def test_lv_present_with_valid_suffixes(self):
        """
        Test to create a new logical volume specifying valid suffixes
        """
        name = "testlv01"
        vgname = "testvg01"
        sizes_list = [
            "2048",
            "2048m",
            "2048M",
            "2048MB",
            "2048mb",
            "2g",
            "2G",
            "2GB",
            "2gb",
            "4194304s",
            "4194304S",
        ]
        comt = "Logical Volume {} already present".format(name)
        ret = {"name": name, "changes": {}, "result": True, "comment": comt}

        mock = MagicMock(return_value=STUB_LVDISPLAY_LV01)
        with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
            for size in sizes_list:
                self.assertDictEqual(
                    lvm.lv_present(name, vgname=vgname, size=size), ret)

        sizes_list = [
            "1G",
            "1g",
            "2M",
            "2m",
            "3T",
            "3t",
            "4P",
            "4p",
            "5s",
            "5S",
            "1GB",
            "1gb",
            "2MB",
            "2mb",
            "3TB",
            "3tb",
            "4PB",
            "4pb",
        ]
        mock = MagicMock(return_value=STUB_LVDISPLAY_LV02)
        with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
            comt = "Logical Volume {} is set to be created".format(name)
            ret.update({"comment": comt, "result": None})
            with patch.dict(lvm.__opts__, {"test": True}):
                for size in sizes_list:
                    self.assertDictEqual(
                        lvm.lv_present(name, vgname=vgname, size=size), ret)
Exemple #2
0
    def test_lv_present_with_force(self):
        '''
        Test to create a new logical volume with force=True
        '''
        name = '/dev/sda5'

        comt = ('Logical Volume {0} already present'.format(name))

        ret = {'name': name, 'changes': {}, 'result': True, 'comment': comt}

        mock = MagicMock(side_effect=[True, False])
        with patch.dict(lvm.__salt__, {'lvm.lvdisplay': mock}):
            self.assertDictEqual(lvm.lv_present(name, force=True), ret)

            comt = ('Logical Volume {0} is set to be created'.format(name))
            ret.update({'comment': comt, 'result': None})
            with patch.dict(lvm.__opts__, {'test': True}):
                self.assertDictEqual(lvm.lv_present(name, force=True), ret)
Exemple #3
0
    def test_lv_present_with_force(self):
        """
        Test to create a new logical volume with force=True
        """
        name = "/dev/sda5"

        comt = "Logical Volume {0} already present".format(name)

        ret = {"name": name, "changes": {}, "result": True, "comment": comt}

        mock = MagicMock(side_effect=[True, False])
        with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
            self.assertDictEqual(lvm.lv_present(name, force=True), ret)

            comt = "Logical Volume {0} is set to be created".format(name)
            ret.update({"comment": comt, "result": None})
            with patch.dict(lvm.__opts__, {"test": True}):
                self.assertDictEqual(lvm.lv_present(name, force=True), ret)
def test_lv_present_with_force(lv01, lv02):
    """
    Test to create a new logical volume with force=True
    """
    name = "testlv01"
    vgname = "testvg01"
    comt = "Logical Volume {} already present".format(name)
    ret = {"name": name, "changes": {}, "result": True, "comment": comt}

    mock = MagicMock(return_value=lv01)
    with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
        assert lvm.lv_present(name, vgname=vgname, force=True) == ret

    mock = MagicMock(return_value=lv02)
    with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
        comt = "Logical Volume {} is set to be created".format(name)
        ret.update({"comment": comt, "result": None})
        with patch.dict(lvm.__opts__, {"test": True}):
            assert lvm.lv_present(name, vgname=vgname, force=True) == ret
Exemple #5
0
    def test_lv_present(self):
        """
        Test to create a new logical volume
        """
        name = "testlv01"
        vgname = "testvg01"
        comt = "Logical Volume {0} already present".format(name)
        ret = {"name": name, "changes": {}, "result": True, "comment": comt}

        mock = MagicMock(return_value=STUB_LVDISPLAY_LV01)
        with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
            self.assertDictEqual(lvm.lv_present(name, vgname=vgname), ret)

        mock = MagicMock(return_value=STUB_LVDISPLAY_LV02)
        with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
            comt = "Logical Volume {0} is set to be created".format(name)
            ret.update({"comment": comt, "result": None})
            with patch.dict(lvm.__opts__, {"test": True}):
                self.assertDictEqual(lvm.lv_present(name, vgname=vgname), ret)
def test_lv_present_with_reduce_without_force(lv01):
    """
    Test to reduce a logical volume
    """
    name = "testlv01"
    vgname = "testvg01"
    comt = "To reduce a Logical Volume option 'force' must be True."
    ret = {"name": name, "changes": {}, "result": False, "comment": comt}

    mock = MagicMock(return_value=lv01)
    with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
        assert lvm.lv_present(name, vgname=vgname, size="1G") == ret
def test_lv_present_with_same_size(lv01):
    """
    Test to specify the same volume size as parameter
    """
    name = "testlv01"
    vgname = "testvg01"
    comt = "Logical Volume {} already present".format(name)
    ret = {"name": name, "changes": {}, "result": True, "comment": comt}

    mock = MagicMock(return_value=lv01)
    with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
        assert lvm.lv_present(name, vgname=vgname, size="2G") == ret
def test_lv_present_with_increase(lv01):
    """
    Test to increase a logical volume
    """
    name = "testlv01"
    vgname = "testvg01"
    comt = "Logical Volume {} is set to be resized".format(name)
    ret = {"name": name, "changes": {}, "result": None, "comment": comt}

    mock = MagicMock(return_value=lv01)
    with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
        with patch.dict(lvm.__opts__, {"test": True}):
            assert lvm.lv_present(name, vgname=vgname, size="10G") == ret
def test_lv_present_with_percentage_extents(lv01, lv02):
    """
    Test to create a new logical volume specifying extents as a percentage
    """
    name = "testlv01"
    vgname = "testvg01"
    extents = "42%FREE"
    comt = "Logical Volume {} already present, {} won't be resized.".format(
        name, extents)
    ret = {"name": name, "changes": {}, "result": True, "comment": comt}

    mock = MagicMock(return_value=lv01)
    with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
        assert lvm.lv_present(name, vgname=vgname, extents=extents) == ret

    extents = "42%VG"
    mock = MagicMock(return_value=lv02)
    with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
        comt = "Logical Volume {} is set to be created".format(name)
        ret.update({"comment": comt, "result": None})
        with patch.dict(lvm.__opts__, {"test": True}):
            assert lvm.lv_present(name, vgname=vgname, extents=extents) == ret
Exemple #10
0
    def test_lv_present_with_reduce(self):
        """
        Test to reduce a logical volume
        """
        name = "testlv01"
        vgname = "testvg01"
        comt = "Reducing a LV is not supported by now"
        ret = {"name": name, "changes": {}, "result": False, "comment": comt}

        mock = MagicMock(return_value=STUB_LVDISPLAY_LV01)
        with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
            self.assertDictEqual(
                lvm.lv_present(name, vgname=vgname, size="1G"), ret)
Exemple #11
0
    def test_lv_present_with_reduce_with_force(self):
        """
        Test to reduce a logical volume
        """
        name = "testlv01"
        vgname = "testvg01"
        comt = "Logical Volume {} is set to be resized".format(name)
        ret = {"name": name, "changes": {}, "result": None, "comment": comt}

        mock = MagicMock(return_value=STUB_LVDISPLAY_LV01)
        with patch.dict(lvm.__salt__, {"lvm.lvdisplay": mock}):
            with patch.dict(lvm.__opts__, {"test": True}):
                self.assertDictEqual(
                    lvm.lv_present(name, vgname=vgname, size="1G", force=True),
                    ret)