Esempio n. 1
0
    def test_profile(self):
        '''
        Test to create a single instance on a cloud provider,
        using a salt-cloud profile.
        '''
        name = 'mycloud'
        profile = 'myprofile'

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

        mock = MagicMock(side_effect=[True, False])
        mock_dict = MagicMock(side_effect=[{'cloud': 'saltcloud'},
                                           {'Not Actioned': True},
                                           {'Not Actioned': True},
                                           {
                                                'Not Found': True,
                                                'Not Actioned/Not Running': True
                                           }])
        mock_d = MagicMock(return_value={})
        with patch.dict(cloud.__salt__, {'cmd.retcode': mock,
                                         'cloud.profile': mock_d,
                                         'cloud.action': mock_dict}):
            comt = ('onlyif execution failed')
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.profile(name, profile, onlyif=False),
                                 ret)

            self.assertDictEqual(cloud.profile(name, profile, onlyif=''), ret)

            comt = ('unless execution succeeded')
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.profile(name, profile, unless=True), ret)

            self.assertDictEqual(cloud.profile(name, profile, unless=''), ret)

            comt = ('Already present instance {0}'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(cloud.profile(name, profile), ret)

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

            with patch.dict(cloud.__opts__, {'test': False}):
                comt = (('Failed to create instance {0}'
                         'using profile {1}').format(name, profile))
                ret.update({'comment': comt, 'result': False})
                self.assertDictEqual(cloud.profile(name, profile), ret)

            with patch.dict(cloud.__opts__, {'test': False}):
                comt = (('Failed to create instance {0}'
                         'using profile {1}').format(name, profile))
                ret.update({'comment': comt, 'result': False})
                self.assertDictEqual(cloud.profile(name, profile), ret)
Esempio n. 2
0
def test_profile():
    """
    Test to create a single instance on a cloud provider,
    using a salt-cloud profile.
    """
    name = "mycloud"
    profile = "myprofile"

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

    mock = MagicMock(side_effect=[True, False])
    mock_dict = MagicMock(
        side_effect=[
            {"cloud": "saltcloud"},
            {"Not Actioned": True},
            {"Not Actioned": True},
            {"Not Found": True, "Not Actioned/Not Running": True},
        ]
    )
    mock_d = MagicMock(return_value={})
    with patch.dict(
        cloud.__salt__,
        {"cmd.retcode": mock, "cloud.profile": mock_d, "cloud.action": mock_dict},
    ):
        comt = "onlyif condition is false"
        ret.update({"comment": comt})
        assert cloud.profile(name, profile, onlyif=False) == ret

        assert cloud.profile(name, profile, onlyif="") == ret

        comt = "unless condition is true"
        ret.update({"comment": comt})
        assert cloud.profile(name, profile, unless=True) == ret

        assert cloud.profile(name, profile, unless="") == ret

        comt = "Already present instance {}".format(name)
        ret.update({"comment": comt})
        assert cloud.profile(name, profile) == ret

        with patch.dict(cloud.__opts__, {"test": True}):
            comt = "Instance {} needs to be created".format(name)
            ret.update({"comment": comt, "result": None})
            assert cloud.profile(name, profile) == ret

        with patch.dict(cloud.__opts__, {"test": False}):
            comt = "Failed to create instance {} using profile {}".format(name, profile)
            ret.update({"comment": comt, "result": False})
            assert cloud.profile(name, profile) == ret

        with patch.dict(cloud.__opts__, {"test": False}):
            comt = "Failed to create instance {} using profile {}".format(name, profile)
            ret.update({"comment": comt, "result": False})
            assert cloud.profile(name, profile) == ret