def test_install_with_options(self): parse_targets = MagicMock(return_value=({'foo': None}, 'repository')) with patch.object(yumpkg, 'list_pkgs', MagicMock(return_value={})), \ patch.object(yumpkg, 'list_holds', MagicMock(return_value=[])), \ patch.dict(yumpkg.__salt__, {'pkg_resource.parse_targets': parse_targets}), \ patch('salt.utils.systemd.has_scope', MagicMock(return_value=False)): # with fromrepo cmd = MagicMock(return_value={'retcode': 0}) with patch.dict(yumpkg.__salt__, {'cmd.run_all': cmd}): yumpkg.install(refresh=False, fromrepo='good', branch='foo') cmd.assert_called_once_with([ 'yum', '-y', '--disablerepo=*', '--enablerepo=good', '--branch=foo', 'install', 'foo' ], output_loglevel='trace', python_shell=False, redirect_stderr=True) # without fromrepo cmd = MagicMock(return_value={'retcode': 0}) with patch.dict(yumpkg.__salt__, {'cmd.run_all': cmd}): yumpkg.install(refresh=False, enablerepo='good', disablerepo='bad', branch='foo') cmd.assert_called_once_with([ 'yum', '-y', '--disablerepo=bad', '--enablerepo=good', '--branch=foo', 'install', 'foo' ], output_loglevel='trace', python_shell=False, redirect_stderr=True)
def test_install_with_epoch(self): ''' Tests that we properly identify a version containing an epoch as an upgrade instead of a downgrade. ''' name = 'foo' old = '8:3.8.12-6.n.el7' new = '9:3.8.12-4.n.el7' list_pkgs_mock = MagicMock( side_effect=lambda **kwargs: {name: [old] if kwargs.get('versions_as_list', False) else old}) cmd_mock = MagicMock(return_value={ 'pid': 12345, 'retcode': 0, 'stdout': '', 'stderr': '', }) salt_mock = { 'cmd.run_all': cmd_mock, 'lowpkg.version_cmp': rpm.version_cmp, 'pkg_resource.parse_targets': MagicMock(return_value=({ name: new }, 'repository')), } full_pkg_string = '-'.join((name, new[2:])) with patch.object(yumpkg, 'list_pkgs', list_pkgs_mock), \ patch('salt.utils.systemd.has_scope', MagicMock(return_value=False)), \ patch.dict(yumpkg.__salt__, salt_mock): # Test yum expected = ['yum', '-y', 'install', full_pkg_string] with patch.dict(yumpkg.__grains__, { 'os': 'CentOS', 'osrelease': 7 }): yumpkg.install('foo', version=new) call = cmd_mock.mock_calls[0][1][0] assert call == expected, call # Test dnf expected = [ 'dnf', '-y', '--best', '--allowerasing', 'install', full_pkg_string ] yumpkg.__context__.pop('yum_bin') cmd_mock.reset_mock() with patch.dict(yumpkg.__grains__, { 'os': 'Fedora', 'osrelease': 27 }): yumpkg.install('foo', version=new) call = cmd_mock.mock_calls[0][1][0] assert call == expected, call
def test_install_pkg(self): ''' Test package installation. :return: ''' def _add_data(data, key, value): data.setdefault(key, []).append(value) rpm_out = [ 'python-urlgrabber_|-(none)_|-3.10_|-8.el7_|-noarch_|-(none)_|-1487838471', 'alsa-lib_|-(none)_|-1.1.1_|-1.el7_|-x86_64_|-(none)_|-1487838475', 'gnupg2_|-(none)_|-2.0.22_|-4.el7_|-x86_64_|-(none)_|-1487838477', 'rpm-python_|-(none)_|-4.11.3_|-21.el7_|-x86_64_|-(none)_|-1487838477', 'pygpgme_|-(none)_|-0.3_|-9.el7_|-x86_64_|-(none)_|-1487838478', 'yum_|-(none)_|-3.4.3_|-150.el7.centos_|-noarch_|-(none)_|-1487838479', 'lzo_|-(none)_|-2.06_|-8.el7_|-x86_64_|-(none)_|-1487838479', 'qrencode-libs_|-(none)_|-3.4.1_|-3.el7_|-x86_64_|-(none)_|-1487838480', 'ustr_|-(none)_|-1.0.4_|-16.el7_|-x86_64_|-(none)_|-1487838480', 'shadow-utils_|-2_|-4.1.5.1_|-24.el7_|-x86_64_|-(none)_|-1487838481', 'util-linux_|-(none)_|-2.23.2_|-33.el7_|-x86_64_|-(none)_|-1487838484', 'openssh_|-(none)_|-6.6.1p1_|-33.el7_3_|-x86_64_|-(none)_|-1487838485', 'virt-what_|-(none)_|-1.13_|-8.el7_|-x86_64_|-(none)_|-1487838486', ] with patch.dict(yumpkg.__grains__, {'osarch': 'x86_64', 'os': 'RedHat'}), \ patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(rpm_out))}), \ patch.dict(yumpkg.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})}), \ patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data}), \ patch.dict(yumpkg.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'python-urlgrabber': '0.0.1'} , 'repository'))}), \ patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list}), \ patch.dict(yumpkg.__salt__, {'config.get': MagicMock()}), \ patch.dict(yumpkg.__salt__, {'lowpkg.version_cmp': MagicMock(return_value=-1)}): pkgs = yumpkg.install(name='python-urlgrabber') self.assertEqual(pkgs, {})
def test_install_pkg(self): ''' Test package installation. :return: ''' pkgs = yumpkg.install(name='python-urlgrabber') self.assertEqual(pkgs, {})
def test_install_pkg_with_diff_attr(self): ''' Test package installation with diff_attr. :return: ''' pkgs = yumpkg.install( name='python-urlgrabber', diff_attr=['version', 'epoch', 'release', 'arch']) self.assertEqual(pkgs, {})