New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create checksum for exported iso file #1118
Conversation
| @@ -87,6 +88,17 @@ def _make_iso(file_list, target_dir, output_dir, filename): | |||
| if status != 0: | |||
| log.error("Error creating iso %s; status code: %d; output: %s" % (file_path, status, out)) | |||
| else: | |||
| testFile = open(file_path, "rb") | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a method called _add_digests_file(file_path) and then call it from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testFile should probably be renamed to something more appropriate like exportedISO or ISOFile
| while True: | ||
| piece = testFile.read(1024) | ||
| if piece: | ||
| h.update(piece) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we want to calculate multiple digests, you should probably be iterating a list of hashers and updating all of them.
Some examples from Pulp 3:
https://github.com/pulp/pulp/blob/master/pulpcore/pulpcore/app/files.py#L13
https://github.com/pulp/pulp/blob/master/pulpcore/pulpcore/app/files.py#L44
|
Can one of the admins verify this patch? |
1 similar comment
|
Can one of the admins verify this patch? |
| hashers = {} | ||
| for hasher in hashlib.algorithms_guaranteed: | ||
| hashers[hasher] = getattr(hashlib, hasher)() | ||
| while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whilte loop should not be inside this loop. Instead you should add another loop inside the while loop. The inner loop should update each hasher.
| while True: | ||
| piece = exportedISO.read(1024) | ||
| if piece: | ||
| hashers[hasher].update(piece) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to put a loop here that updates all of the hashers with this piece.
|
Hello @rahulbajaj0509! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on July 12, 2018 at 13:02 Hours UTC |
|
As required, we have two files in the same folder with .iso and .iso.DIGEST Output: |
| for hasher in hashlib.algorithms_guaranteed: | ||
| hashers[hasher] = getattr(hashlib, hasher)() | ||
| chunk = 0 | ||
| while chunk != b'': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The content of the .DIGEST file is incorrect. Only one of the checksums matches the sum calculated on command line.
You should un-indent the code that reads the file. Line 104 needs to be inside a loop that looks exactly like line 99.
|
@rahulbajaj0509 if you rebase against the newest master then you'll get the necessary pep8speaks fixes onto your branch will remove the pep8 comment. |
| digestFile = open(file_path + ".DIGEST", "w+") | ||
| hashers = {} | ||
| for hasher in hashlib.algorithms_guaranteed: | ||
| hashers[hasher] = getattr(hashlib, hasher)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for hasher in hashlib.algorithms_guaranteed:
hashers[hasher] = getattr(hashlib, hasher)()
chunk = exportedISO.read(1024)
while len(chunk) > 0:
for hasher in hashlib.algorithms_guaranteed:
hashers[hasher].update(chunk)
chunk = exportedISO.read(1024)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkliban thanks, for your input on this.
I was trying something like:
import hashlib
import os
file_path="/home/vagrant/abc.iso"
exportedISO = open("/home/vagrant/abc.iso", "rb")
digestFile = open("/home/vagrant/abc.iso.DIGEST", "w+")
hashers = {}
for hasher in hashlib.algorithms_guaranteed:
hashers[hasher] = getattr(hashlib, hasher)()
exportedISO.seek(0)
chunk = exportedISO.read(1024)
while len(chunk) > 0:
hashers[hasher].update(chunk)
chunk = exportedISO.read(1024)
digestFile.write("{} *{}\n".format(hashers[hasher].hexdigest(),
os.path.basename(file_path)))
exportedISO.close()
digestFile.close()
This approach gave the right output but parsed the file multiple times, as pointed
out by you, is not an appropriate approach.
Thank you @dkliban for your inputs :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good. You just need to add some documentation. A release note for 2.17.0 should be added here: https://github.com/pulp/pulp_rpm/tree/master/docs/user-guide/release-notes
You will need to create a 2.17.x.rst file in there that has a similar format to 2.16.x.rst. In that file provide a brief description of this new feature.
The recipe section here https://github.com/pulp/pulp_rpm/blob/master/docs/user-guide/recipes.rst#export-repositories-and-repository-groups should be updated with information about the .DIGESTS file
Please also add a sentence at the end of the description here https://github.com/pulp/pulp_rpm/blob/master/docs/tech-reference/export-distributor.rst#export-distributors that says that along with the ISO there will also be a *.iso.DIGESTS file published.
Thank you for all your work!
| log.info('Successfully created iso %s' % file_path) | ||
|
|
||
|
|
||
| def _add_digest_file(file_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring that describes what this method does.
| log.info('Successfully created iso %s' % file_path) | ||
|
|
||
|
|
||
| def _add_digest_file(file_path): | ||
| exportedISO = open(file_path, "rb") | ||
| digestFile = open(file_path + ".DIGEST", "w+") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change .DIGEST to .DIGESTS (plural)
|
@dkliban done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will be ready to merge this PR after this set of changes. Thank you for doing this work! Good job!
| @@ -8,7 +8,8 @@ images, or to the directory of your choice as one or more yum repositories. The | |||
| distributor uses the ID ``export_distributor``. The repository group distributor uses the ID | |||
| ``group_export_distributor``. Exported repository ISOs will be published over HTTP or HTTPS at | |||
| the path ``/pulp/exports/repo/<repo-id>/``, and exported repository group ISOs can be found at | |||
| ``/pulp/exports/repo_group/<group-id>/``. | |||
| ``/pulp/exports/repo_group/<group-id>/``. Along with the ISO there will also be a ``*.iso.DIGISTS`` | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along with the ISO there will also be a *.iso.DIGESTS file published. This file will contain md5, sha1, sha224, sha256, sha384, and sha512 digests of the ISO.
| @@ -342,7 +342,8 @@ The general workflow is as follows: | |||
|
|
|||
| Which, if publishing over HTTP, could be found at | |||
| `http://localhost/pulp/exports/repo/demo-repo/ <http://localhost/pulp/exports/repo/demo-repo/>`_ | |||
| (adjust hostname and repo-id as necessary.) | |||
| (adjust hostname and repo-id as necessary). Along with the ISO there will also be a | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along with the ISO there will also be a *.iso.DIGESTS file published. This file will contain md5, sha1, sha224, sha256, sha384, and sha512 digests of the ISO.
| @@ -11,3 +11,8 @@ New Features | |||
| * The `gpg_key_id` yum distributor configuration value was previously ignored | |||
| unless `gpg_cmd` was configured. It is now used with the default GPG signing | |||
| command when `gpg_cmd` is not configured. | |||
|
|
|||
| * Added a `.DIGESTS` file that would calculate the checksums of the exported | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The export distributor now generates a *.iso.DIGESTS file along with the ISO. This file will contain md5, sha1, sha224, sha256, sha384, and sha512 digests of the ISO.
| :param file_path: The file path to the ISO image file | ||
| :param file_path: str | ||
|
|
||
| :return: Create a *.iso.DIGESTS file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't return anything. You can remove the return docstring.
|
@dkliban looks good? |
| digestFile = open(file_path + ".DIGESTS", "w+") | ||
| hashers = {} | ||
| for hasher in hashlib.algorithms_guaranteed: | ||
| hashers[hasher] = getattr(hashlib, hasher)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail on a FIPS environment. I think this should work:
from pulp.server.util import md5 as pulp_md5
# ...
if hasher == 'md5':
hashers[hasher] = pulp_md5()
else:
hashers[hasher] = getattr(hashlib, hasher)()There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daviddavis thanks 👍 now the pr is FIPS compliant too :)
| for hasher in hashlib.algorithms_guaranteed: | ||
| if hasher == 'md5': | ||
| hashers[hasher] = pulp_md5() | ||
| else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/else/else:/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this on FIPS enabled machine and it worked correctly. Thank you very much for the contribution.
|
ok test |
|
ok test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit tests are failing.The failures can be seen here (toward the end): https://pulpadmin.fedorapeople.org/jenkins/jobs/unittest-pulp_rpm-pr/builds/1135/node-type=rhel7-np-FAILED.txt
You can run them on your local machine by executing inside pulp_rpm directory: python run-tests.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just mock the _add_digest_file() method and ensure that it's called once.
After this PR is merge, I will file an issue to improve the tests[0] in pulp-smash to look for the new DIGESTS file.
When we export a .iso file, we must also export a checksum file with it. closes #3760 https://pulp.plan.io/issues/3760
|
ok test |
2 similar comments
|
ok test |
|
ok test |
When we export a .iso file, we must also export a checksum file with it.