Ejemplo n.º 1
0
def test_upgrade_allow_downgrades(uninstall_var, upgrade_var):
    """
    Tests the allow_downgrades option for upgrade.
    """
    with patch("salt.utils.pkg.clear_rtag", MagicMock()):
        with patch("salt.modules.aptpkg.list_pkgs",
                   MagicMock(return_value=uninstall_var)):
            mock_cmd = MagicMock(return_value={
                "retcode": 0,
                "stdout": upgrade_var
            })
            patch_kwargs = {
                "__salt__": {
                    "config.get": MagicMock(return_value=True),
                    "cmd.run_all": mock_cmd,
                },
            }
            with patch.multiple(aptpkg, **patch_kwargs):
                aptpkg.upgrade()
                args_matching = [
                    True for args in patch_kwargs["__salt__"]
                    ["cmd.run_all"].call_args[0]
                    if "--allow-downgrades" in args
                ]
                # Here we shouldn't see the parameter and args_matching should be empty.
                assert any(args_matching) is False

                aptpkg.upgrade(allow_downgrades=True)
                args_matching = [
                    True for args in patch_kwargs["__salt__"]
                    ["cmd.run_all"].call_args[0]
                    if "--allow-downgrades" in args
                ]
                # --allow-downgrades should be in the args list and we should have at least on True in the list.
                assert any(args_matching) is True
Ejemplo n.º 2
0
def test_upgrade(uninstall_var, upgrade_var):
    """
    Test - Upgrades all packages.
    """
    with patch("salt.utils.pkg.clear_rtag", MagicMock()):
        with patch(
            "salt.modules.aptpkg.list_pkgs", MagicMock(return_value=uninstall_var)
        ):
            mock_cmd = MagicMock(return_value={"retcode": 0, "stdout": upgrade_var})
            patch_kwargs = {
                "__salt__": {
                    "config.get": MagicMock(return_value=True),
                    "cmd.run_all": mock_cmd,
                }
            }
            with patch.multiple(aptpkg, **patch_kwargs):
                assert aptpkg.upgrade() == dict()
                kwargs = {"force_conf_new": True}
                assert aptpkg.upgrade(**kwargs) == dict()
Ejemplo n.º 3
0
 def test_upgrade(self):
     """
     Test - Upgrades all packages.
     """
     with patch("salt.utils.pkg.clear_rtag", MagicMock()):
         with patch(
             "salt.modules.aptpkg.list_pkgs", MagicMock(return_value=UNINSTALL)
         ):
             mock_cmd = MagicMock(return_value={"retcode": 0, "stdout": UPGRADE})
             patch_kwargs = {
                 "__salt__": {
                     "config.get": MagicMock(return_value=True),
                     "cmd.run_all": mock_cmd,
                 }
             }
             with patch.multiple(aptpkg, **patch_kwargs):
                 self.assertEqual(aptpkg.upgrade(), dict())
                 kwargs = {"force_conf_new": True}
                 self.assertEqual(aptpkg.upgrade(**kwargs), dict())
Ejemplo n.º 4
0
    def test_upgrade_downloadonly(self):
        '''
        Tests the download-only options for upgrade.
        '''
        with patch('salt.utils.pkg.clear_rtag', MagicMock()):
            with patch('salt.modules.aptpkg.list_pkgs',
                       MagicMock(return_value=UNINSTALL)):
                mock_cmd = MagicMock(return_value={
                    'retcode': 0,
                    'stdout': UPGRADE
                })
                patch_kwargs = {
                    '__salt__': {
                        'config.get': MagicMock(return_value=True),
                        'cmd.run_all': mock_cmd
                    },
                }
                with patch.multiple(aptpkg, **patch_kwargs):
                    aptpkg.upgrade()
                    args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args[0] if "--download-only" in args]
                    # Here we shouldn't see the parameter and args_matching should be empty.
                    self.assertFalse(any(args_matching))

                    aptpkg.upgrade(downloadonly=True)
                    args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args[0] if "--download-only" in args]
                    # --download-only should be in the args list and we should have at least on True in the list.
                    self.assertTrue(any(args_matching))

                    aptpkg.upgrade(download_only=True)
                    args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args[0] if "--download-only" in args]
                    # --download-only should be in the args list and we should have at least on True in the list.
                    self.assertTrue(any(args_matching))
Ejemplo n.º 5
0
 def test_upgrade(self):
     '''
     Test - Upgrades all packages.
     '''
     mock_cmd = MagicMock(return_value={'retcode': 0, 'stdout': UPGRADE})
     patch_kwargs = {
         '__salt__': {
             'config.get': MagicMock(return_value=True),
             'cmd.run_all': mock_cmd
         }
     }
     with patch.multiple(aptpkg, **patch_kwargs):
         self.assertEqual(aptpkg.upgrade(), dict())
Ejemplo n.º 6
0
    def test_purge(self):
        """
        Test - Remove packages along with all configuration files.
        '''
        assert aptpkg.purge(name='tmux') == UNINSTALL

    @patch('salt.utils.pkg.clear_rtag', MagicMock())
    @patch('salt.modules.aptpkg.list_pkgs', MagicMock(return_value=UNINSTALL))
    @patch.multiple(aptpkg, **{'__salt__': {'config.get': MagicMock(return_value=True),
                                            'cmd.run_all': MagicMock(return_value={'retcode': 0, 'stdout': UPGRADE})}})
    def test_upgrade(self):
        """
        Test - Upgrades all packages.
        '''
        assert aptpkg.upgrade() == {}
Ejemplo n.º 7
0
 def test_upgrade(self):
     '''
     Test - Upgrades all packages.
     '''
     mock_cmd = MagicMock(return_value={
         'retcode': 0,
         'stdout': UPGRADE
     })
     patch_kwargs = {
         '__salt__': {
             'config.get': MagicMock(return_value=True),
             'cmd.run_all': mock_cmd
         }
     }
     with patch.multiple(aptpkg, **patch_kwargs):
         self.assertEqual(aptpkg.upgrade(), dict())
Ejemplo n.º 8
0
 def test_upgrade(self):
     '''
     Test - Upgrades all packages.
     '''
     with patch('salt.utils.pkg.clear_rtag', MagicMock()):
         with patch('salt.modules.aptpkg.list_pkgs',
                    MagicMock(return_value=UNINSTALL)):
             mock_cmd = MagicMock(return_value={
                 'retcode': 0,
                 'stdout': UPGRADE
             })
             patch_kwargs = {
                 '__salt__': {
                     'config.get': MagicMock(return_value=True),
                     'cmd.run_all': mock_cmd
                 }
             }
             with patch.multiple(aptpkg, **patch_kwargs):
                 self.assertEqual(aptpkg.upgrade(), dict())
Ejemplo n.º 9
0
    def test_upgrade_downloadonly(self):
        """
        Tests the download-only options for upgrade.
        """
        with patch("salt.utils.pkg.clear_rtag", MagicMock()):
            with patch("salt.modules.aptpkg.list_pkgs",
                       MagicMock(return_value=UNINSTALL)):
                mock_cmd = MagicMock(return_value={
                    "retcode": 0,
                    "stdout": UPGRADE
                })
                patch_kwargs = {
                    "__salt__": {
                        "config.get": MagicMock(return_value=True),
                        "cmd.run_all": mock_cmd,
                    },
                }
                with patch.multiple(aptpkg, **patch_kwargs):
                    aptpkg.upgrade()
                    args_matching = [
                        True for args in patch_kwargs["__salt__"]
                        ["cmd.run_all"].call_args[0]
                        if "--download-only" in args
                    ]
                    # Here we shouldn't see the parameter and args_matching should be empty.
                    self.assertFalse(any(args_matching))

                    aptpkg.upgrade(downloadonly=True)
                    args_matching = [
                        True for args in patch_kwargs["__salt__"]
                        ["cmd.run_all"].call_args[0]
                        if "--download-only" in args
                    ]
                    # --download-only should be in the args list and we should have at least on True in the list.
                    self.assertTrue(any(args_matching))

                    aptpkg.upgrade(download_only=True)
                    args_matching = [
                        True for args in patch_kwargs["__salt__"]
                        ["cmd.run_all"].call_args[0]
                        if "--download-only" in args
                    ]
                    # --download-only should be in the args list and we should have at least on True in the list.
                    self.assertTrue(any(args_matching))
Ejemplo n.º 10
0
 def test_upgrade(self):
     '''
     Test - Upgrades all packages.
     '''
     assert aptpkg.upgrade() == {}