Exemple #1
0
    def test_volume_present(self):
        '''
        Test to check that a block volume exists.
        '''
        name = 'mycloud'

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

        mock = MagicMock(return_value=name)
        mock_lst = MagicMock(side_effect=[[name], [], []])
        with patch.dict(cloud.__salt__, {'cloud.volume_list': mock_lst,
                                         'cloud.volume_create': mock}):
            with patch.object(salt.utils.cloud, 'check_name',
                              MagicMock(return_value=True)):
                comt = ('Invalid characters in name.')
                ret.update({'comment': comt})
                self.assertDictEqual(cloud.volume_present(name), ret)

            comt = ('Volume exists: {0}'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(cloud.volume_present(name), ret)

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

            with patch.dict(cloud.__opts__, {'test': False}):
                comt = ('Volume {0} was created'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'old': None, 'new': name}})
                self.assertDictEqual(cloud.volume_present(name), ret)
Exemple #2
0
    def test_volume_present(self):
        '''
        Test to check that a block volume exists.
        '''
        name = 'mycloud'

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

        mock = MagicMock(return_value=name)
        mock_lst = MagicMock(side_effect=[[name], [], []])
        with patch.dict(cloud.__salt__, {'cloud.volume_list': mock_lst,
                                         'cloud.volume_create': mock}):
            with patch.object(salt.utils.cloud, 'check_name',
                              MagicMock(return_value=True)):
                comt = ('Invalid characters in name.')
                ret.update({'comment': comt})
                self.assertDictEqual(cloud.volume_present(name), ret)

            comt = ('Volume exists: {0}'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(cloud.volume_present(name), ret)

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

            with patch.dict(cloud.__opts__, {'test': False}):
                comt = ('Volume {0} was created'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'old': None, 'new': name}})
                self.assertDictEqual(cloud.volume_present(name), ret)
Exemple #3
0
def test_volume_present():
    """
    Test to check that a block volume exists.
    """
    name = "mycloud"

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

    mock = MagicMock(return_value=name)
    mock_lst = MagicMock(side_effect=[[name], [], []])
    with patch.dict(cloud.__salt__, {
            "cloud.volume_list": mock_lst,
            "cloud.volume_create": mock
    }):
        with patch.object(salt.utils.cloud, "check_name",
                          MagicMock(return_value=True)):
            comt = "Invalid characters in name."
            ret.update({"comment": comt})
            assert cloud.volume_present(name) == ret

        comt = "Volume exists: {}".format(name)
        ret.update({"comment": comt, "result": True})
        assert cloud.volume_present(name) == ret

        with patch.dict(cloud.__opts__, {"test": True}):
            comt = "Volume {} will be created.".format(name)
            ret.update({"comment": comt, "result": None})
            assert cloud.volume_present(name) == ret

        with patch.dict(cloud.__opts__, {"test": False}):
            comt = "Volume {} was created".format(name)
            ret.update({
                "comment": comt,
                "result": True,
                "changes": {
                    "old": None,
                    "new": name
                },
            })
            assert cloud.volume_present(name) == ret