示例#1
0
    def test_absent(self):
        '''
            Test to verify that the raid is absent
        '''
        ret = [{
            'changes': {},
            'comment': 'Raid salt already absent',
            'name': 'salt',
            'result': True
        }, {
            'changes': {},
            'comment': 'Raid saltstack is set to be destroyed',
            'name': 'saltstack',
            'result': None
        }, {
            'changes': {},
            'comment': 'Raid saltstack has been destroyed',
            'name': 'saltstack',
            'result': True
        }]

        mock = MagicMock(return_value=["saltstack"])
        with patch.dict(mdadm.__salt__, {'raid.list': mock}):
            self.assertDictEqual(mdadm.absent("salt"), ret[0])

            with patch.dict(mdadm.__opts__, {'test': True}):
                self.assertDictEqual(mdadm.absent("saltstack"), ret[1])

            with patch.dict(mdadm.__opts__, {'test': False}):
                mock = MagicMock(return_value=True)
                with patch.dict(mdadm.__salt__, {'raid.destroy': mock}):
                    self.assertDictEqual(mdadm.absent("saltstack"), ret[2])
    def test_absent(self):
        """
            Test to verify that the raid is absent
        """
        ret = [
            {
                "changes": {},
                "comment": "Raid salt already absent",
                "name": "salt",
                "result": True,
            },
            {
                "changes": {},
                "comment": "Raid saltstack is set to be destroyed",
                "name": "saltstack",
                "result": None,
            },
            {
                "changes": {},
                "comment": "Raid saltstack has been destroyed",
                "name": "saltstack",
                "result": True,
            },
        ]

        mock = MagicMock(return_value=["saltstack"])
        with patch.dict(mdadm.__salt__, {"raid.list": mock}):
            self.assertDictEqual(mdadm.absent("salt"), ret[0])

            with patch.dict(mdadm.__opts__, {"test": True}):
                self.assertDictEqual(mdadm.absent("saltstack"), ret[1])

            with patch.dict(mdadm.__opts__, {"test": False}):
                mock = MagicMock(return_value=True)
                with patch.dict(mdadm.__salt__, {"raid.destroy": mock}):
                    self.assertDictEqual(mdadm.absent("saltstack"), ret[2])