Esempio n. 1
0
    def test_war_deployed_no_version(self):
        '''
        Tests that going from versions to no versions and back work, as well
        as not overwriting a WAR without version with another without version.
        '''
        ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''}

        mock_deploy = MagicMock(return_value='deploy')
        mock_undeploy = MagicMock(return_value='SUCCESS')
        mock_ls_version = MagicMock(
            return_value={'salt': {
                'version': '1.2.4',
                'mode': 'running'
            }})
        mock_ls_no_version = MagicMock(
            return_value={'salt': {
                'version': '',
                'mode': 'running'
            }})

        # We're just checking what it *would* do.
        with patch.dict(tomcat.__opts__, {"test": True}):
            with patch.dict(
                    tomcat.__salt__, {
                        "tomcat.ls": mock_ls_version,
                        "tomcat.deploy_war": mock_deploy,
                        "tomcat.undeploy": mock_undeploy
                    }):
                # We deploy from version to no version
                ret.update({
                    'changes': {
                        'deploy': 'will deploy salt with no version',
                        'undeploy': 'undeployed salt with version 1.2.4'
                    },
                })
                self.assertDictEqual(
                    tomcat.war_deployed('salt', 'salt://jenkins.war'), ret)

            with patch.dict(
                    tomcat.__salt__, {
                        "tomcat.ls": mock_ls_no_version,
                        "tomcat.deploy_war": mock_deploy,
                        "tomcat.undeploy": mock_undeploy
                    }):
                # Deploy from none to specified version
                ret.update({
                    'changes': {
                        'deploy': 'will deploy salt with version 1.2.4',
                        'undeploy': 'undeployed salt with no version'
                    },
                })
                self.assertDictEqual(
                    tomcat.war_deployed('salt',
                                        'salt://jenkins.war',
                                        version='1.2.4'), ret)
                # Deploy from none to extracted version
                self.assertDictEqual(
                    tomcat.war_deployed('salt', 'salt://jenkins-1.2.4.war'),
                    ret)
                # Don't deploy from no version to no version
                ret.update({
                    'changes': {},
                    'comment': 'salt with no version is already deployed',
                    'result': True
                })
                # Don't deploy from blank to blank version
                self.assertDictEqual(
                    tomcat.war_deployed('salt', 'salt://jenkins.war'), ret)
                # Don't deploy from blank to false version
                self.assertDictEqual(
                    tomcat.war_deployed('salt',
                                        'salt://jenkins-1.2.4.war',
                                        version=False), ret)
Esempio n. 2
0
    def test_war_deployed(self):
        '''
        Test to enforce that the WAR will be deployed and
        started in the context path it will make use of WAR versions
        '''
        ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
        mock_start = MagicMock(return_value='saltstack')
        mock_undeploy = MagicMock(side_effect=['FAIL', 'saltstack'])
        mock_deploy = MagicMock(return_value='deploy')
        mock_ls = MagicMock(side_effect=[{
            'salt': {
                'version': 'jenkins-1.20.4',
                'mode': 'running'
            }
        }, {
            'salt': {
                'version': '1'
            }
        }, {
            'salt': {
                'version': 'jenkins-1.2.4',
                'mode': 'run'
            }
        }, {
            'salt': {
                'version': '1'
            }
        }, {
            'salt': {
                'version': '1'
            }
        }, {
            'salt': {
                'version': '1'
            }
        }])
        with patch.dict(
                tomcat.__salt__, {
                    "tomcat.ls": mock_ls,
                    'tomcat.start': mock_start,
                    'tomcat.undeploy': mock_undeploy,
                    'tomcat.deploy_war': mock_deploy
                }):
            ret.update(
                {'comment': 'salt with version 1.20.4'
                 ' is already deployed'})
            self.assertDictEqual(
                tomcat.war_deployed('salt', 'salt://jenkins'
                                    '-1.20.4.war'), ret)

            with patch.dict(tomcat.__opts__, {"test": True}):
                ret.update({
                    'changes': {
                        'deploy': 'will deploy salt'
                        ' with version 1.2.4',
                        'undeploy': 'undeployed salt'
                        ' with version 1'
                    },
                    'result': None,
                    'comment': ''
                })
                self.assertDictEqual(
                    tomcat.war_deployed('salt', 'salt://jenkins'
                                        '-1.2.4.war'), ret)

            with patch.dict(tomcat.__opts__, {"test": False}):
                ret.update({
                    'changes': {
                        'start': 'starting salt'
                    },
                    'comment': 'saltstack',
                    'result': False
                })
                self.assertDictEqual(
                    tomcat.war_deployed('salt', 'salt://jenkins'
                                        '-1.2.4.war'), ret)

                ret.update({
                    'changes': {
                        'deploy': 'will deploy salt with'
                        ' version 1.2.4',
                        'undeploy': 'undeployed salt with'
                        ' version 1'
                    },
                    'comment': 'FAIL'
                })
                self.assertDictEqual(
                    tomcat.war_deployed('salt', 'salt://jenkins'
                                        '-1.2.4.war'), ret)

                ret.update({
                    'changes': {
                        'undeploy': 'undeployed salt'
                        ' with version 1'
                    },
                    'comment': 'deploy'
                })
                self.assertDictEqual(
                    tomcat.war_deployed('salt', 'salt://jenkins'
                                        '-1.2.4.war'), ret)
Esempio n. 3
0
    def test_war_deployed_no_version(self):
        '''
        Tests that going from versions to no versions and back work, as well
        as not overwriting a WAR without version with another without version.
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': None,
               'comment': ''}

        mock_deploy = MagicMock(return_value='deploy')
        mock_undeploy = MagicMock(return_value='SUCCESS')
        mock_ls_version = MagicMock(return_value={'salt': {'version': '1.2.4',
                                                           'mode': 'running'}})
        mock_ls_no_version = MagicMock(return_value={'salt': {'version': '',
                                                              'mode': 'running'}})

        # We're just checking what it *would* do.
        with patch.dict(tomcat.__opts__, {"test": True}):
            with patch.dict(tomcat.__salt__,
                            {"tomcat.ls": mock_ls_version,
                             "tomcat.deploy_war": mock_deploy,
                             "tomcat.undeploy": mock_undeploy}):
                # We deploy from version to no version
                ret.update({'changes':
                                {'deploy': 'will deploy salt with no version',
                                 'undeploy': 'undeployed salt with version 1.2.4'},
                            })
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins.war'),
                                     ret)

            with patch.dict(tomcat.__salt__,
                            {"tomcat.ls": mock_ls_no_version,
                             "tomcat.deploy_war": mock_deploy,
                             "tomcat.undeploy": mock_undeploy}):
                # Deploy from none to specified version
                ret.update({'changes':
                                {'deploy': 'will deploy salt with version 1.2.4',
                                 'undeploy': 'undeployed salt with no version'},
                            })
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins.war',
                                                         version='1.2.4'),
                                     ret)
                # Deploy from none to extracted version
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins-1.2.4.war'),
                                     ret)
                # Don't deploy from no version to no version
                ret.update({'changes': {},
                            'comment': 'salt with no version is already deployed',
                            'result': True
                            })
                # Don't deploy from blank to blank version
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins.war'),
                                     ret)
                # Don't deploy from blank to false version
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins-1.2.4.war',
                                                         version=False),
                                     ret)
Esempio n. 4
0
    def test_war_deployed(self):
        '''
        Test to enforce that the WAR will be deployed and
        started in the context path it will make use of WAR versions
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': True,
               'comment': ''}
        mock_start = MagicMock(return_value='saltstack')
        mock_undeploy = MagicMock(side_effect=['FAIL', 'saltstack'])
        mock_deploy = MagicMock(return_value='deploy')
        mock_ls = MagicMock(side_effect=[{'salt': {'version': 'jenkins-1.20.4',
                                                   'mode': 'running'}},
                                         {'salt': {'version': '1'}},
                                         {'salt': {'version': 'jenkins-1.2.4',
                                                   'mode': 'run'}},
                                         {'salt': {'version': '1'}},
                                         {'salt': {'version': '1'}},
                                         {'salt': {'version': '1'}}])
        with patch.dict(tomcat.__salt__, {"tomcat.ls": mock_ls,
                                          'tomcat.start': mock_start,
                                          'tomcat.undeploy': mock_undeploy,
                                          'tomcat.deploy_war': mock_deploy}):
            ret.update({'comment': 'salt with version 1.20.4'
                                   ' is already deployed'})
            self.assertDictEqual(tomcat.war_deployed('salt',
                                                     'salt://jenkins'
                                                     '-1.20.4.war'), ret)

            with patch.dict(tomcat.__opts__, {"test": True}):
                ret.update({'changes': {'deploy': 'will deploy salt'
                                                  ' with version 1.2.4',
                                        'undeploy': 'undeployed salt'
                                                    ' with version 1'},
                            'result': None, 'comment': ''})
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins'
                                                         '-1.2.4.war'), ret)

            with patch.dict(tomcat.__opts__, {"test": False}):
                ret.update({'changes': {'start': 'starting salt'},
                            'comment': 'saltstack', 'result': False})
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins'
                                                         '-1.2.4.war'), ret)

                ret.update({'changes': {'deploy': 'will deploy salt with'
                                                  ' version 1.2.4',
                                        'undeploy': 'undeployed salt with'
                                                    ' version 1'},
                            'comment': 'FAIL'})
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins'
                                                         '-1.2.4.war'), ret)

                ret.update({'changes': {'undeploy': 'undeployed salt'
                                                    ' with version 1'},
                            'comment': 'deploy'})
                self.assertDictEqual(tomcat.war_deployed('salt',
                                                         'salt://jenkins'
                                                         '-1.2.4.war'), ret)
Esempio n. 5
0
def test_war_deployed():
    """
    Test to enforce that the WAR will be deployed and
    started in the context path it will make use of WAR versions
    """
    ret = {"name": "salt", "changes": {}, "result": True, "comment": ""}
    mock_start = MagicMock(return_value="saltstack")
    mock_undeploy = MagicMock(side_effect=["FAIL", "saltstack"])
    mock_deploy = MagicMock(return_value="deploy")
    mock_ls = MagicMock(side_effect=[
        {
            "salt": {
                "version": "jenkins-1.20.4",
                "mode": "running"
            }
        },
        {
            "salt": {
                "version": "1"
            }
        },
        {
            "salt": {
                "version": "jenkins-1.2.4",
                "mode": "run"
            }
        },
        {
            "salt": {
                "version": "1"
            }
        },
        {
            "salt": {
                "version": "1"
            }
        },
        {
            "salt": {
                "version": "1"
            }
        },
    ])
    with patch.dict(
            tomcat.__salt__,
        {
            "tomcat.ls": mock_ls,
            "tomcat.extract_war_version": tomcatmod.extract_war_version,
            "tomcat.start": mock_start,
            "tomcat.undeploy": mock_undeploy,
            "tomcat.deploy_war": mock_deploy,
        },
    ):
        ret.update({"comment": "salt with version 1.20.4 is already deployed"})
        assert tomcat.war_deployed("salt", "salt://jenkins-1.20.4.war") == ret

        with patch.dict(tomcat.__opts__, {"test": True}):
            ret.update({
                "changes": {
                    "deploy": "will deploy salt with version 1.2.4",
                    "undeploy": "undeployed salt with version 1",
                },
                "result": None,
                "comment": "",
            })
            assert tomcat.war_deployed("salt",
                                       "salt://jenkins-1.2.4.war") == ret

        with patch.dict(tomcat.__opts__, {"test": False}):
            ret.update({
                "changes": {
                    "start": "starting salt"
                },
                "comment": "saltstack",
                "result": False,
            })
            assert tomcat.war_deployed("salt",
                                       "salt://jenkins-1.2.4.war") == ret

            ret.update({
                "changes": {
                    "deploy": "will deploy salt with version 1.2.4",
                    "undeploy": "undeployed salt with version 1",
                },
                "comment": "FAIL",
            })
            assert tomcat.war_deployed("salt",
                                       "salt://jenkins-1.2.4.war") == ret

            ret.update({
                "changes": {
                    "undeploy": "undeployed salt with version 1"
                },
                "comment": "deploy",
            })
            assert tomcat.war_deployed("salt",
                                       "salt://jenkins-1.2.4.war") == ret
Esempio n. 6
0
def test_war_deployed_no_version():
    """
    Tests that going from versions to no versions and back work, as well
    as not overwriting a WAR without version with another without version.
    """
    ret = {"name": "salt", "changes": {}, "result": None, "comment": ""}

    mock_deploy = MagicMock(return_value="deploy")
    mock_undeploy = MagicMock(return_value="SUCCESS")
    mock_ls_version = MagicMock(
        return_value={"salt": {
            "version": "1.2.4",
            "mode": "running"
        }})
    mock_ls_no_version = MagicMock(
        return_value={"salt": {
            "version": "",
            "mode": "running"
        }})

    with patch.dict(tomcat.__opts__, {"test": True}):
        with patch.dict(
                tomcat.__salt__,
            {
                "tomcat.ls": mock_ls_version,
                "tomcat.extract_war_version": tomcatmod.extract_war_version,
                "tomcat.deploy_war": mock_deploy,
                "tomcat.undeploy": mock_undeploy,
            },
        ):
            ret.update({
                "changes": {
                    "deploy": "will deploy salt with no version",
                    "undeploy": "undeployed salt with version 1.2.4",
                },
            })
            assert tomcat.war_deployed("salt", "salt://jenkins.war") == ret

        with patch.dict(
                tomcat.__salt__,
            {
                "tomcat.ls": mock_ls_no_version,
                "tomcat.extract_war_version": tomcatmod.extract_war_version,
                "tomcat.deploy_war": mock_deploy,
                "tomcat.undeploy": mock_undeploy,
            },
        ):
            ret.update({
                "changes": {
                    "deploy": "will deploy salt with version 1.2.4",
                    "undeploy": "undeployed salt with no version",
                },
            })
            assert (tomcat.war_deployed("salt",
                                        "salt://jenkins.war",
                                        version="1.2.4") == ret)
            assert tomcat.war_deployed("salt",
                                       "salt://jenkins-1.2.4.war") == ret
            ret.update({
                "changes": {},
                "comment": "salt with no version is already deployed",
                "result": True,
            })
            assert tomcat.war_deployed("salt", "salt://jenkins.war") == ret
            assert (tomcat.war_deployed("salt",
                                        "salt://jenkins-1.2.4.war",
                                        version=False) == ret)
Esempio n. 7
0
    def test_war_deployed_no_version(self):
        """
        Tests that going from versions to no versions and back work, as well
        as not overwriting a WAR without version with another without version.
        """
        ret = {"name": "salt", "changes": {}, "result": None, "comment": ""}

        mock_deploy = MagicMock(return_value="deploy")
        mock_undeploy = MagicMock(return_value="SUCCESS")
        mock_ls_version = MagicMock(
            return_value={"salt": {
                "version": "1.2.4",
                "mode": "running"
            }})
        mock_ls_no_version = MagicMock(
            return_value={"salt": {
                "version": "",
                "mode": "running"
            }})

        # We're just checking what it *would* do.
        with patch.dict(tomcat.__opts__, {"test": True}):
            with patch.dict(
                    tomcat.__salt__,
                {
                    "tomcat.ls": mock_ls_version,
                    "tomcat.extract_war_version":
                    tomcatmod.extract_war_version,
                    "tomcat.deploy_war": mock_deploy,
                    "tomcat.undeploy": mock_undeploy,
                },
            ):
                # We deploy from version to no version
                ret.update({
                    "changes": {
                        "deploy": "will deploy salt with no version",
                        "undeploy": "undeployed salt with version 1.2.4",
                    },
                })
                self.assertDictEqual(
                    tomcat.war_deployed("salt", "salt://jenkins.war"), ret)

            with patch.dict(
                    tomcat.__salt__,
                {
                    "tomcat.ls": mock_ls_no_version,
                    "tomcat.extract_war_version":
                    tomcatmod.extract_war_version,
                    "tomcat.deploy_war": mock_deploy,
                    "tomcat.undeploy": mock_undeploy,
                },
            ):
                # Deploy from none to specified version
                ret.update({
                    "changes": {
                        "deploy": "will deploy salt with version 1.2.4",
                        "undeploy": "undeployed salt with no version",
                    },
                })
                self.assertDictEqual(
                    tomcat.war_deployed("salt",
                                        "salt://jenkins.war",
                                        version="1.2.4"),
                    ret,
                )
                # Deploy from none to extracted version
                self.assertDictEqual(
                    tomcat.war_deployed("salt", "salt://jenkins-1.2.4.war"),
                    ret)
                # Don't deploy from no version to no version
                ret.update({
                    "changes": {},
                    "comment": "salt with no version is already deployed",
                    "result": True,
                })
                # Don't deploy from blank to blank version
                self.assertDictEqual(
                    tomcat.war_deployed("salt", "salt://jenkins.war"), ret)
                # Don't deploy from blank to false version
                self.assertDictEqual(
                    tomcat.war_deployed("salt",
                                        "salt://jenkins-1.2.4.war",
                                        version=False),
                    ret,
                )