Ejemplo n.º 1
0
def test_absent_busy(utils_patch):
    """
    Test zpool absent on a busy pool
    """
    ret = {
        "name":
        "myzpool",
        "result":
        False,
        "comment":
        "\n".join([
            "cannot unmount '/myzpool': Device busy",
            "cannot export 'myzpool': pool is busy",
        ]),
        "changes": {},
    }

    mock_exists = MagicMock(return_value=True)
    mock_destroy = MagicMock(return_value=OrderedDict([
        ("exported", False),
        (
            "error",
            "\n".join([
                "cannot unmount '/myzpool': Device busy",
                "cannot export 'myzpool': pool is busy",
            ]),
        ),
    ]))
    with patch.dict(zpool.__salt__, {"zpool.exists": mock_exists}), patch.dict(
            zpool.__salt__,
        {"zpool.export": mock_destroy}), patch.dict(zpool.__utils__,
                                                    utils_patch):
        assert zpool.absent("myzpool", export=True) == ret
Ejemplo n.º 2
0
    def test_absent_busy(self):
        '''
        Test zpool absent on a busy pool
        '''
        ret = {
            'name':
            'myzpool',
            'result':
            False,
            'comment':
            "\n".join([
                "cannot unmount '/myzpool': Device busy",
                "cannot export 'myzpool': pool is busy",
            ]),
            'changes': {},
        }

        mock_exists = MagicMock(return_value=True)
        mock_destroy = MagicMock(return_value=OrderedDict([
            ('exported', False),
            ('error', "\n".join([
                "cannot unmount '/myzpool': Device busy",
                "cannot export 'myzpool': pool is busy",
            ])),
        ]))
        with patch.dict(zpool.__salt__, {'zpool.exists': mock_exists}), \
             patch.dict(zpool.__salt__, {'zpool.export': mock_destroy}), \
             patch.dict(zpool.__utils__, utils_patch):
            self.assertEqual(zpool.absent('myzpool', export=True), ret)
Ejemplo n.º 3
0
    def test_absent_without_pool(self):
        '''
        Test zpool absent without a pool
        '''
        ret = {'name': 'myzpool',
               'result': True,
               'comment': 'storage pool myzpool is absent',
               'changes': {}}

        mock_exists = MagicMock(return_value=False)
        with patch.dict(zpool.__salt__, {'zpool.exists': mock_exists}), \
             patch.dict(zpool.__utils__, utils_patch):
            self.assertEqual(zpool.absent('myzpool'), ret)
Ejemplo n.º 4
0
def test_absent_without_pool(utils_patch):
    """
    Test zpool absent without a pool
    """
    ret = {
        "name": "myzpool",
        "result": True,
        "comment": "storage pool myzpool is absent",
        "changes": {},
    }

    mock_exists = MagicMock(return_value=False)
    with patch.dict(zpool.__salt__, {"zpool.exists": mock_exists}), patch.dict(
            zpool.__utils__, utils_patch):
        assert zpool.absent("myzpool") == ret
Ejemplo n.º 5
0
    def test_absent_exporty_pool(self):
        """
        Test zpool absent exporting pool
        """
        ret = {
            "name": "myzpool",
            "result": True,
            "comment": "storage pool myzpool was exported",
            "changes": {"myzpool": "exported"},
        }

        mock_exists = MagicMock(return_value=True)
        mock_destroy = MagicMock(return_value=OrderedDict([("exported", True)]))
        with patch.dict(zpool.__salt__, {"zpool.exists": mock_exists}), patch.dict(
            zpool.__salt__, {"zpool.export": mock_destroy}
        ), patch.dict(zpool.__utils__, self.utils_patch):
            self.assertEqual(zpool.absent("myzpool", export=True), ret)
Ejemplo n.º 6
0
def test_absent_destroy_pool(utils_patch):
    """
    Test zpool absent destroying pool
    """
    ret = {
        "name": "myzpool",
        "result": True,
        "comment": "storage pool myzpool was destroyed",
        "changes": {"myzpool": "destroyed"},
    }

    mock_exists = MagicMock(return_value=True)
    mock_destroy = MagicMock(return_value=OrderedDict([("destroyed", True)]))
    with patch.dict(zpool.__salt__, {"zpool.exists": mock_exists}), patch.dict(
        zpool.__salt__, {"zpool.destroy": mock_destroy}
    ), patch.dict(zpool.__utils__, utils_patch):
        assert zpool.absent("myzpool") == ret
Ejemplo n.º 7
0
    def test_absent_exporty_pool(self):
        '''
        Test zpool absent exporting pool
        '''
        ret = {
            'name': 'myzpool',
            'result': True,
            'comment': 'storage pool myzpool was exported',
            'changes': {'myzpool': 'exported'},
        }

        mock_exists = MagicMock(return_value=True)
        mock_destroy = MagicMock(return_value=OrderedDict([
            ('exported', True),
        ]))
        with patch.dict(zpool.__salt__, {'zpool.exists': mock_exists}), \
             patch.dict(zpool.__salt__, {'zpool.export': mock_destroy}), \
             patch.dict(zpool.__utils__, utils_patch):
            self.assertEqual(zpool.absent('myzpool', export=True), ret)