Exemple #1
0
    def test_cmd_unzip(self):
        def _get_mock():
            '''
            Create a new MagicMock for each scenario in this test, so that
            assert_called_once_with doesn't complain that the same mock object
            is called more than once.
            '''
            return MagicMock(return_value={'stdout': 'salt',
                                           'stderr': '',
                                           'pid': 12345,
                                           'retcode': 0})

        with patch('salt.utils.which', lambda exe: exe):

            mock = _get_mock()
            with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
                ret = archive.cmd_unzip(
                    '/tmp/salt.{{grains.id}}.zip',
                    '/tmp/dest',
                    excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                    template='jinja'
                )
                self.assertEqual(['salt'], ret)
                mock.assert_called_once_with(
                    ['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                     '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    output_loglevel='debug',
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template='jinja'
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
                ret = archive.cmd_unzip(
                    '/tmp/salt.{{grains.id}}.zip',
                    '/tmp/dest',
                    excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    template='jinja'
                )
                self.assertEqual(['salt'], ret)
                mock.assert_called_once_with(
                    ['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                     '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    output_loglevel='debug',
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template='jinja'
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
                ret = archive.cmd_unzip(
                    '/tmp/salt.{{grains.id}}.zip',
                    '/tmp/dest',
                    excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                    template='jinja',
                    options='-fo'
                )
                self.assertEqual(['salt'], ret)
                mock.assert_called_once_with(
                    ['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                     '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    output_loglevel='debug',
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template='jinja'
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
                ret = archive.cmd_unzip(
                    '/tmp/salt.{{grains.id}}.zip',
                    '/tmp/dest',
                    excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    template='jinja',
                    options='-fo'
                )
                self.assertEqual(['salt'], ret)
                mock.assert_called_once_with(
                    ['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                     '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    output_loglevel='debug',
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template='jinja'
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
                ret = archive.cmd_unzip(
                    '/tmp/salt.{{grains.id}}.zip',
                    '/tmp/dest',
                    excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    template='jinja',
                    options='-fo',
                    password='******',
                )
                self.assertEqual(['salt'], ret)
                mock.assert_called_once_with(
                    ['unzip', '-P', 'asdf', '-fo', '/tmp/salt.{{grains.id}}.zip',
                     '-d', '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                    output_loglevel='quiet',
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template='jinja'
                )
Exemple #2
0
    def test_cmd_unzip(self):
        def _get_mock():
            '''
            Create a new MagicMock for each scenario in this test, so that
            assert_called_once_with doesn't complain that the same mock object
            is called more than once.
            '''
            return MagicMock(return_value={'stdout': 'salt',
                                           'stderr': '',
                                           'pid': 12345,
                                           'retcode': 0})

        mock = _get_mock()
        with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                template='jinja'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                 '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                output_loglevel='debug',
                python_shell=False,
                redirect_stderr=True,
                runas=None,
                template='jinja'
            )

        mock = _get_mock()
        with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                template='jinja'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                 '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                output_loglevel='debug',
                python_shell=False,
                redirect_stderr=True,
                runas=None,
                template='jinja'
            )

        mock = _get_mock()
        with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                template='jinja',
                options='-fo'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                 '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                output_loglevel='debug',
                python_shell=False,
                redirect_stderr=True,
                runas=None,
                template='jinja'
            )

        mock = _get_mock()
        with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                template='jinja',
                options='-fo'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                 '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                output_loglevel='debug',
                python_shell=False,
                redirect_stderr=True,
                runas=None,
                template='jinja'
            )

        mock = _get_mock()
        with patch.dict(archive.__salt__, {'cmd.run_all': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                template='jinja',
                options='-fo',
                password='******',
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '-P', 'asdf', '-fo', '/tmp/salt.{{grains.id}}.zip',
                 '-d', '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                output_loglevel='quiet',
                python_shell=False,
                redirect_stderr=True,
                runas=None,
                template='jinja'
            )
Exemple #3
0
    def test_cmd_unzip(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip('/tmp/salt.{{grains.id}}.zip',
                                    '/tmp/dest',
                                    excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                                    template='jinja')
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with([
                'unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'
            ],
                                         runas=None,
                                         python_shell=False,
                                         template='jinja')

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                template='jinja')
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with([
                'unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'
            ],
                                         runas=None,
                                         python_shell=False,
                                         template='jinja')

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip('/tmp/salt.{{grains.id}}.zip',
                                    '/tmp/dest',
                                    excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                                    template='jinja',
                                    options='fo')
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with([
                'unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'
            ],
                                         runas=None,
                                         python_shell=False,
                                         template='jinja')

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                template='jinja',
                options='fo')
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with([
                'unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'
            ],
                                         runas=None,
                                         python_shell=False,
                                         template='jinja')
Exemple #4
0
    def test_cmd_unzip(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                template='jinja'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                 '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                runas=None, python_shell=False, template='jinja'
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                template='jinja'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
                 '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                runas=None, python_shell=False, template='jinja'
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
                template='jinja',
                options='-fo'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                 '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                runas=None, python_shell=False, template='jinja'
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.cmd_unzip(
                '/tmp/salt.{{grains.id}}.zip',
                '/tmp/dest',
                excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                template='jinja',
                options='-fo'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
                 '/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
                runas=None, python_shell=False, template='jinja'
            )
Exemple #5
0
    def test_cmd_unzip(self):
        def _get_mock():
            """
            Create a new MagicMock for each scenario in this test, so that
            assert_called_once_with doesn't complain that the same mock object
            is called more than once.
            """
            return MagicMock(return_value={
                "stdout": "salt",
                "stderr": "",
                "pid": 12345,
                "retcode": 0,
            })

        with patch("salt.utils.path.which", lambda exe: exe):

            mock = _get_mock()
            with patch.dict(archive.__salt__, {"cmd.run_all": mock}):
                ret = archive.cmd_unzip(
                    "/tmp/salt.{{grains.id}}.zip",
                    "/tmp/dest",
                    excludes="/tmp/tmpePe8yO,/tmp/tmpLeSw1A",
                    template="jinja",
                )
                self.assertEqual(["salt"], ret)
                mock.assert_called_once_with(
                    [
                        "unzip",
                        "/tmp/salt.{{grains.id}}.zip",
                        "-d",
                        "/tmp/dest",
                        "-x",
                        "/tmp/tmpePe8yO",
                        "/tmp/tmpLeSw1A",
                    ],
                    output_loglevel="debug",
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template="jinja",
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {"cmd.run_all": mock}):
                ret = archive.cmd_unzip(
                    "/tmp/salt.{{grains.id}}.zip",
                    "/tmp/dest",
                    excludes=["/tmp/tmpePe8yO", "/tmp/tmpLeSw1A"],
                    template="jinja",
                )
                self.assertEqual(["salt"], ret)
                mock.assert_called_once_with(
                    [
                        "unzip",
                        "/tmp/salt.{{grains.id}}.zip",
                        "-d",
                        "/tmp/dest",
                        "-x",
                        "/tmp/tmpePe8yO",
                        "/tmp/tmpLeSw1A",
                    ],
                    output_loglevel="debug",
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template="jinja",
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {"cmd.run_all": mock}):
                ret = archive.cmd_unzip(
                    "/tmp/salt.{{grains.id}}.zip",
                    "/tmp/dest",
                    excludes="/tmp/tmpePe8yO,/tmp/tmpLeSw1A",
                    template="jinja",
                    options="-fo",
                )
                self.assertEqual(["salt"], ret)
                mock.assert_called_once_with(
                    [
                        "unzip",
                        "-fo",
                        "/tmp/salt.{{grains.id}}.zip",
                        "-d",
                        "/tmp/dest",
                        "-x",
                        "/tmp/tmpePe8yO",
                        "/tmp/tmpLeSw1A",
                    ],
                    output_loglevel="debug",
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template="jinja",
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {"cmd.run_all": mock}):
                ret = archive.cmd_unzip(
                    "/tmp/salt.{{grains.id}}.zip",
                    "/tmp/dest",
                    excludes=["/tmp/tmpePe8yO", "/tmp/tmpLeSw1A"],
                    template="jinja",
                    options="-fo",
                )
                self.assertEqual(["salt"], ret)
                mock.assert_called_once_with(
                    [
                        "unzip",
                        "-fo",
                        "/tmp/salt.{{grains.id}}.zip",
                        "-d",
                        "/tmp/dest",
                        "-x",
                        "/tmp/tmpePe8yO",
                        "/tmp/tmpLeSw1A",
                    ],
                    output_loglevel="debug",
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template="jinja",
                )

            mock = _get_mock()
            with patch.dict(archive.__salt__, {"cmd.run_all": mock}):
                ret = archive.cmd_unzip(
                    "/tmp/salt.{{grains.id}}.zip",
                    "/tmp/dest",
                    excludes=["/tmp/tmpePe8yO", "/tmp/tmpLeSw1A"],
                    template="jinja",
                    options="-fo",
                    password="******",
                )
                self.assertEqual(["salt"], ret)
                mock.assert_called_once_with(
                    [
                        "unzip",
                        "-P",
                        "asdf",
                        "-fo",
                        "/tmp/salt.{{grains.id}}.zip",
                        "-d",
                        "/tmp/dest",
                        "-x",
                        "/tmp/tmpePe8yO",
                        "/tmp/tmpLeSw1A",
                    ],
                    output_loglevel="quiet",
                    python_shell=False,
                    redirect_stderr=True,
                    runas=None,
                    template="jinja",
                )