Esempio n. 1
0
    def test_history_success(self):
        """
        Tests history
        """
        ret = {}
        ret["stdout"] = "\n".join([
            "History for 'mypool':",
            "2018-01-18.16:56:12 zpool create -f mypool /dev/rdsk/c0t0d0",
            "2018-01-19.16:01:55 zpool attach -f mypool /dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1",
        ])
        ret["stderr"] = ""
        ret["retcode"] = 0
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {"cmd.run_all": mock_cmd}), patch.dict(
                zpool.__utils__, self.utils_patch):
            ret = zpool.history("mypool")
            res = OrderedDict([
                (
                    "mypool",
                    OrderedDict([
                        (
                            "2018-01-18.16:56:12",
                            "zpool create -f mypool /dev/rdsk/c0t0d0",
                        ),
                        (
                            "2018-01-19.16:01:55",
                            "zpool attach -f mypool /dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1",
                        ),
                    ]),
                ),
            ])
            self.assertEqual(ret, res)
Esempio n. 2
0
    def test_history_success(self):
        '''
        Tests history
        '''
        ret = {}
        ret['stdout'] = "\n".join([
            "History for 'mypool':",
            "2018-01-18.16:56:12 zpool create -f mypool /dev/rdsk/c0t0d0",
            "2018-01-19.16:01:55 zpool attach -f mypool /dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1",
        ])
        ret['stderr'] = ""
        ret['retcode'] = 0
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}), \
             patch.dict(zpool.__utils__, self.utils_patch):
            ret = zpool.history('mypool')
            res = OrderedDict([
                ('mypool',
                 OrderedDict([
                     ('2018-01-18.16:56:12',
                      'zpool create -f mypool /dev/rdsk/c0t0d0'),
                     ('2018-01-19.16:01:55',
                      'zpool attach -f mypool /dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1'
                      ),
                 ])),
            ])
            self.assertEqual(ret, res)
Esempio n. 3
0
    def test_history_nopool(self):
        """
        Tests history with missing pool
        """
        ret = {}
        ret["stdout"] = ""
        ret["stderr"] = "cannot open 'mypool': no such pool"
        ret["retcode"] = 1
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {"cmd.run_all": mock_cmd}), patch.dict(
                zpool.__utils__, self.utils_patch):
            ret = zpool.history("mypool")
            res = OrderedDict([("error", "cannot open 'mypool': no such pool")
                               ])
            self.assertEqual(ret, res)
Esempio n. 4
0
    def test_history_nopool(self):
        '''
        Tests history with missing pool
        '''
        ret = {}
        ret['stdout'] = ""
        ret['stderr'] = "cannot open 'mypool': no such pool"
        ret['retcode'] = 1
        mock_cmd = MagicMock(return_value=ret)

        with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}), \
             patch.dict(zpool.__utils__, self.utils_patch):
            ret = zpool.history('mypool')
            res = OrderedDict([
                ('error', "cannot open 'mypool': no such pool"),
            ])
            self.assertEqual(ret, res)