Ejemplo n.º 1
0
    def test_started(self):
        '''
        Test to check if volume has been started
        '''
        name = 'salt'

        ret = {'name': name,
               'result': False,
               'comment': '',
               'changes': {}}

        mock = MagicMock(side_effect=[[], [name], [name], [name]])
        mock_t = MagicMock(return_value='started')
        mock_dict = MagicMock(side_effect=[{}, '', ''])
        with patch.dict(glusterfs.__salt__, {'glusterfs.list_volumes': mock,
                                             'glusterfs.status': mock_dict,
                                             'glusterfs.start_volume': mock_t}):
            comt = ('Volume {0} does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(glusterfs.started(name), ret)

            comt = ('Volume {0} is already started'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': True}):
                comt = ('Volume {0} will be started'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': False}):
                ret.update({'comment': 'started', 'result': True,
                            'change': {'new': 'started', 'old': 'stopped'}})
                self.assertDictEqual(glusterfs.started(name), ret)
Ejemplo n.º 2
0
    def test_started(self):
        """
        Test to check if volume has been started
        """
        name = "salt"

        ret = {"name": name, "result": False, "comment": "", "changes": {}}

        started_info = {name: {"status": "1"}}
        stopped_info = {name: {"status": "0"}}
        mock_info = MagicMock(return_value={})
        mock_start = MagicMock(return_value=True)

        with patch.dict(
                glusterfs.__salt__,
            {
                "glusterfs.info": mock_info,
                "glusterfs.start_volume": mock_start
            },
        ):
            comt = "Volume {0} does not exist".format(name)
            ret.update({"comment": comt})
            self.assertDictEqual(glusterfs.started(name), ret)

            mock_info.return_value = started_info
            comt = "Volume {0} is already started".format(name)
            ret.update({"comment": comt, "result": True})
            self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {"test": True}):
                mock_info.return_value = stopped_info
                comt = "Volume {0} will be started".format(name)
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {"test": False}):
                comt = "Volume {0} is started".format(name)
                ret.update({
                    "comment": comt,
                    "result": True,
                    "change": {
                        "new": "started",
                        "old": "stopped"
                    },
                })
                self.assertDictEqual(glusterfs.started(name), ret)
Ejemplo n.º 3
0
    def test_started(self):
        '''
        Test to check if volume has been started
        '''
        name = 'salt'

        ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}

        started_info = {name: {'status': '1'}}
        stopped_info = {name: {'status': '0'}}
        mock_info = MagicMock(return_value={})
        mock_start = MagicMock(return_value=True)

        with patch.dict(glusterfs.__salt__, {
                'glusterfs.info': mock_info,
                'glusterfs.start_volume': mock_start
        }):
            comt = ('Volume {0} does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(glusterfs.started(name), ret)

            mock_info.return_value = started_info
            comt = ('Volume {0} is already started'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': True}):
                mock_info.return_value = stopped_info
                comt = ('Volume {0} will be started'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': False}):
                comt = 'Volume {0} is started'.format(name)
                ret.update({
                    'comment': comt,
                    'result': True,
                    'change': {
                        'new': 'started',
                        'old': 'stopped'
                    }
                })
                self.assertDictEqual(glusterfs.started(name), ret)
Ejemplo n.º 4
0
    def test_started(self):
        '''
        Test to check if volume has been started
        '''
        name = 'salt'

        ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}

        mock = MagicMock(side_effect=[[], [name], [name], [name]])
        mock_t = MagicMock(return_value='started')
        mock_dict = MagicMock(side_effect=[{}, '', ''])
        with patch.dict(
                glusterfs.__salt__, {
                    'glusterfs.list_volumes': mock,
                    'glusterfs.status': mock_dict,
                    'glusterfs.start_volume': mock_t
                }):
            comt = ('Volume {0} does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(glusterfs.started(name), ret)

            comt = ('Volume {0} is already started'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': True}):
                comt = ('Volume {0} will be started'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': False}):
                ret.update({
                    'comment': 'started',
                    'result': True,
                    'change': {
                        'new': 'started',
                        'old': 'stopped'
                    }
                })
                self.assertDictEqual(glusterfs.started(name), ret)
Ejemplo n.º 5
0
    def test_started(self):
        '''
        Test to check if volume has been started
        '''
        name = 'salt'

        ret = {'name': name,
               'result': False,
               'comment': '',
               'changes': {}}

        started_info = {name: {'status': '1'}}
        stopped_info = {name: {'status': '0'}}
        mock_info = MagicMock(return_value={})
        mock_start = MagicMock(return_value=True)

        with patch.dict(glusterfs.__salt__,
                        {'glusterfs.info': mock_info,
                         'glusterfs.start_volume': mock_start}):
            comt = ('Volume {0} does not exist'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(glusterfs.started(name), ret)

            mock_info.return_value = started_info
            comt = ('Volume {0} is already started'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': True}):
                mock_info.return_value = stopped_info
                comt = ('Volume {0} will be started'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(glusterfs.started(name), ret)

            with patch.dict(glusterfs.__opts__, {'test': False}):
                comt = 'Volume {0} is started'.format(name)
                ret.update({'comment': comt, 'result': True,
                            'change': {'new': 'started', 'old': 'stopped'}})
                self.assertDictEqual(glusterfs.started(name), ret)