Enhances pkg.list_downloaded information of a package

This commit is contained in:
Pablo Suarez Hernandez 2017-04-26 08:48:08 +01:00 committed by Pablo Suárez Hernández
parent bd1f170a05
commit ddf98e3fe3
3 changed files with 24 additions and 6 deletions

View File

@ -926,7 +926,13 @@ def list_downloaded():
for filename in fnmatch.filter(filenames, '*.rpm'):
package_path = os.path.join(root, filename)
pkg_info = __salt__['lowpkg.bin_pkg_info'](package_path)
ret.setdefault(pkg_info['name'], {})[pkg_info['version']] = package_path
pkg_timestamp = int(os.path.getctime(package_path))
ret.setdefault(pkg_info['name'], {})[pkg_info['version']] = {
'path': package_path,
'size': os.path.getsize(package_path),
'creation_date_time_t': pkg_timestamp,
'creation_date_time': datetime.datetime.fromtimestamp(pkg_timestamp).isoformat(),
}
return ret

View File

@ -1798,7 +1798,13 @@ def list_downloaded():
for filename in fnmatch.filter(filenames, '*.rpm'):
package_path = os.path.join(root, filename)
pkg_info = __salt__['lowpkg.bin_pkg_info'](package_path)
ret.setdefault(pkg_info['name'], {})[pkg_info['version']] = package_path
pkg_timestamp = int(os.path.getctime(package_path))
ret.setdefault(pkg_info['name'], {})[pkg_info['version']] = {
'path': package_path,
'size': os.path.getsize(package_path),
'creation_date_time_t': pkg_timestamp,
'creation_date_time': datetime.datetime.fromtimestamp(pkg_timestamp).isoformat(),
}
return ret

View File

@ -504,6 +504,8 @@ Repository 'DUMMY' not found by its alias, number, or URI.
self.assertDictEqual(list_patches, PATCHES_RET)
@patch('os.walk', MagicMock(return_value=[('test', 'test', 'test')]))
@patch('os.path.getsize', MagicMock(return_value=123456))
@patch('os.path.getmtime', MagicMock(return_value=1234567890.123456))
@patch('fnmatch.filter', MagicMock(return_value=['/var/cache/zypper/packages/foo/bar/test_package.rpm']))
def test_list_downloaded(self):
'''
@ -513,7 +515,11 @@ Repository 'DUMMY' not found by its alias, number, or URI.
'''
DOWNLOADED_RET = {
'test-package': {
'1.0': '/var/cache/zypper/packages/foo/bar/test_package.rpm'
'1.0': {
'path': '/var/cache/zypper/packages/foo/bar/test_package.rpm',
'size': 123456,
'timestamp': 1234567890.123456,
}
}
}
@ -548,7 +554,7 @@ Repository 'DUMMY' not found by its alias, number, or URI.
self.assertEqual(zypper.download("nmap", "foo"), test_out)
@patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False))
@patch('salt.modules.zypper.list_downloaded', MagicMock(side_effect=[{}, {'vim': {'1.1': '/foo/bar/test.rpm'}}]))
@patch('salt.modules.zypper.list_downloaded', MagicMock(side_effect=[{}, {'vim': {'1.1': {'path': '/foo/bar/test.rpm', 'size': 1234, 'timestamp': 1234567890}}}]))
def test_install_with_downloadonly(self):
'''
Test a package installation with downloadonly=True.
@ -566,10 +572,10 @@ Repository 'DUMMY' not found by its alias, number, or URI.
'--download-only',
'vim'
)
self.assertDictEqual(ret, {'vim': {'new': {'1.1': '/foo/bar/test.rpm'}, 'old': ''}})
self.assertDictEqual(ret, {'vim': {'new': {'1.1': {'path': '/foo/bar/test.rpm', 'size': 1234, 'timestamp': 1234567890}}, 'old': ''}})
@patch('salt.modules.zypper._systemd_scope', MagicMock(return_value=False))
@patch('salt.modules.zypper.list_downloaded', MagicMock(return_value={'vim': {'1.1': '/foo/bar/test.rpm'}}))
@patch('salt.modules.zypper.list_downloaded', MagicMock(return_value={'vim': {'1.1': {'path': '/foo/bar/test.rpm', 'size': 1234, 'timestamp': 1234567890}}}))
def test_install_with_downloadonly_already_downloaded(self):
'''
Test a package installation with downloadonly=True when package is already downloaded.