-
Notifications
You must be signed in to change notification settings - Fork 189
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 zchunked updateinfo #2904
Conversation
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.
Cool, looks reasonable to me. We will need to get the coverage to 100% so that the diff cover tests also pass.
Since the if statement that isn't covered depends on having a createrepo with the new feature, I suggest adding one more test that uses mock
to fake createrepo having that feature, and then asserting that the right thing happens.
Alternatively, we can wait until a version of createrepo with that feature is in all supported versions of Fedora and this patch will then pass diff cover on its own (and we can drop the if statement and just say we require that newer version of createrepo).
How would you prefer to proceed?
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.
Actually, it looks like the rawhide tests are failing. For example:
Error Message
createrepo_c.CreaterepoCError: Error while closing /tmp/tmpm_3tvr7tbodhi/repodata/updateinfo.xml: Unable to end final chunk:
Stacktrace
self = <bodhi.tests.server.test_util.TestSanityCheckRepodata testMethod=test_comps_invalid_nonsense>
def test_comps_invalid_nonsense(self):
"""RepodataException should be raised if comps is invalid."""
comps = os.path.join(self.tempdir, 'comps.xml')
with open(comps, 'w') as uinfo:
uinfo.write('<whatever />')
> base.mkmetadatadir(self.tempdir, comps=comps)
bodhi/tests/server/test_util.py:615:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bodhi/tests/server/base.py:392: in mkmetadatadir
'xml', os.path.join(path, 'updateinfo.xml'))
bodhi/server/metadata.py:65: in insert_in_repo
rec_comp = rec.compress_and_fill(cr.SHA256, ct)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <createrepo_c.RepomdRecord updateinfo_zck object>, hashtype = 5
compresstype = 6
def compress_and_fill(self, hashtype, compresstype):
rec = RepomdRecord(self.type + "_gz", None)
_createrepo_c.RepomdRecord.compress_and_fill(self,
rec,
hashtype,
> compresstype)
E createrepo_c.CreaterepoCError: Error while closing /tmp/tmpm_3tvr7tbodhi/repodata/updateinfo.xml: Unable to end final chunk:
/usr/lib64/python3.7/site-packages/createrepo_c/__init__.py:191: CreaterepoCError
Standard Error
INFO:bodhi.server.metadata:Inserting updateinfo.xml into /tmp/tmpm_3tvr7tbodhi/repodata
Does rawhide have the createrepo with this feature?
Rawhide's createrepo_c is currently missing rpm-software-management/createrepo_c#115. When I did my testing, I did it on Rawhide against createrepo_c with that patch pulled in. Would it help if I pushed out a working version of createrepo_c at https://copr.fedorainfracloud.org/coprs/jdieter/dnf-zchunk/? |
As for the test coverage, I'd probably go with using mock to fake out createrepo_c, though I'm not sure how that would work. The problem with waiting is that createrepo_c will probably not be zchunk-enabled on <= F29. |
...and I've just looked up mock and realized you're not talking about the Fedora packaging tool, but the python tool. I'll take a look at it and see if I can something together. /me walks away feel slightly stupid. ;) |
So I've put something together that is designed to literally just go through the different code-paths. I've even had to wrap it in exception handling because the test won't actually write the file, but it's brought the coverage to 100% in bodhi/server/metadata.py. I've also pushed a working copy of createrepo_c to https://copr.fedorainfracloud.org/coprs/jdieter/dnf-zchunk/. I'm not sure if you want to go ahead and enable this copr (for Rawhide only), or if you'd rather wait until the patches make it into Rawhide's createrepo_c and librepo. |
On Thu, 2019-01-10 at 22:39 +0000, Jonathan Dieter wrote:
So I've put something together that is designed to literally just go
through the different code-paths. I've even had to wrap it in
exception handling because the test won't actually write the file,
but it's brought the coverage to 100% in bodhi/server/metadata.py.
Cool, I haven't had time to look at the code yet, but what you wrote
here sounds reasonable to me. Since Python is a dynamic language,
coverage is more important because without it things like typos can
cause problems.
I do have one suggestion on how we can do even better: in addition to
the mocked test, we could add a test that really uses createrepo_c if
it has the needed functionality, and then use a @skipif decorator to
skip that test when the system createrepo_c doesn't have it. This way
the first test ensures coverage, and the second test will ensure the
feature actually works for distros that have it.
|
If I understand you correctly, I think I've already done this. The test I changed in bodhi/tests/server/test_metadata.py, lines 278-290 originally just checked whether the stored updateinfo.xml.xz (or whatever the normal compression is) had a checksum that matched the checksum in repomd. I extended it to test both updateinfo.xml.xz and updateinfo.xml.zck if createrepo_c supports zchunk, and the test should fail if only updateinfo.xml.xz is created. |
bodhi/tests/server/test_metadata.py
Outdated
@mock.patch('bodhi.server.metadata.cr') | ||
def test_zchunk_metadata(self, mock_cr): | ||
mock_cr.ZCK_COMPRESSION = 99 | ||
assert(bodhi_metadata.cr.ZCK_COMPRESSION == 99) |
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.
We don't need to assert that mock works:
assert(bodhi_metadata.cr.ZCK_COMPRESSION == 99) |
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.
Ack. Fixed in next commit
bodhi/tests/server/test_metadata.py
Outdated
assert(bodhi_metadata.cr.ZCK_COMPRESSION == 99) | ||
try: | ||
bodhi_metadata.insert_in_repo(99, self.tempcompdir, 'garbage', 'zck', '/dev/null') | ||
except TypeError: |
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.
What would raise this TypeError
, and the other two below?
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.
Without this, I get
E TypeError: write() argument must be str, not MagicMock
at the line: repomd_file.write(repomd.xml_dump()) in insert_in_repo() in bodhi/server/metadata.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.
It seems to me that this probably happens because we need to do more mocking to get it to work - i.e., we need to make our mock work such that it hands out a str
to that write()
call.
bodhi/tests/server/test_metadata.py
Outdated
bodhi_metadata.insert_in_repo(bodhi_metadata.cr.XZ_COMPRESSION, self.tempcompdir, | ||
'garbage', 'xz', '/dev/null') | ||
except TypeError: | ||
pass |
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.
We should add assertions that the right calls were made when the zchunk compression was available, otherwise all we know is that it didn't blow up.
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.
insert_in_repo() is called by UpdateInfoMetadata(), which is tested by _test_extended_metadata(), and I piggybacked the zchunk tests there.
UpdateInfoMetadata() creates both the regular and zchunked metadata, _verify_updateinfos() validates that we have two updateinfos if zchunk is enabled, and _test_extended_metadata() validates that both updateinfo files match what they're supposed to be.
So far, test_zchunk_metadata is a bit of a misnomer as all it does is make sure that we reach 100% code coverage, and doesn't really test anything.
Is there other testing we should be doing to verify that the zchunk compression is working?
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's true that mock testing isn't nearly as valuable as testing that actually uses the code/resources you are mocking, but there is still something being tested, which is that the code is at least valid Python. Since Python is not a static language, mocking is a way to make sure that the code we have doesn't have problems like typos or things of that nature.
bodhi/tests/server/test_metadata.py
Outdated
except TypeError: | ||
pass | ||
del bodhi_metadata.cr.ZCK_COMPRESSION | ||
assert(not hasattr(bodhi_metadata.cr, 'ZCK_COMPRESSION')) |
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.
We don't need to assert that del
works.
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.
Fixed in next commit.
bodhi/tests/server/test_metadata.py
Outdated
assert(not hasattr(bodhi_metadata.cr, 'ZCK_COMPRESSION')) | ||
try: | ||
bodhi_metadata.insert_in_repo(bodhi_metadata.cr.XZ_COMPRESSION, self.tempcompdir, | ||
'garbage', 'xz', '/dev/null') |
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 this code path is adequately tested by other tests. What do you think?
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.
If we don't have this path and zchunk is enabled, we have no way to test what happens if zchunk isn't enabled, which will leave us with a hole in the coverage.
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.
Ah ok, that makes sense to me.
Randy, thanks for the review! I've answered your individual questions, and I hope I cleared up where insert_into_repo is actually being tested. I've pushed a fix for the unneeded assertions, but I think everything else is needed. If I'm missing something, please let me know. |
I would like to see that one mock test be a bit more thorough. If you don't have time/desire to do it, I can do it for you (though probably not this week) - just let me know! |
I thought about this some more, and I can think of two more reasonable options:
I think I'm fine with either of these if you prefer one of them over the previously suggested approach. What do you think? |
I don't mind making the mock test more thorough, but it might be a little while before I'm able to get to it. On the other hand, if bodhi's just going to lose the code anyway when all createrepo_c's support zchunk, maybe it's easier to just test that codepath. I don't feel strongly, so what would you prefer? |
@jdieter yeah the more I think about it, it seems better to just say we require the newer createrepo_c. Do you know what version has the needed feature? We can encode that in our requirements. We should add that to the release notes too. |
@bowlofeggs, yeah, it's 0.12.0, but only on F30+ (if we're talking Fedora). 0.12.0 on <F30 is built with zchunk disabled. I suspect that might cause a problem... |
On Thu, 2019-02-07 at 13:54 -0800, Jonathan Dieter wrote:
@bowlofeggs, yeah, it's 0.12.0, but only on F30+ (if we're talking
Fedora). 0.12.0 on <F30 is built with zchunk disabled. I suspect that
might cause a problem...
Ah, so we can't simply require a version of it - it also needs a build
flag set. Hmm. In that case, I think I do like the code you have here.
I'll see if I can find some time to get the tests more complete.
Thanks!
|
Ok, I've rebased to the latest develop head and have successfully managed to get rid of the try-except blocks. Please let me know if there's anything else you'd like me to do. |
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'm going to rebase this pull request, and I think I will add some more assertions to the mock test. I see that a folder with several RPMs was added - are those needed for this patch? I don't see a place where they get used.
Hey @jdieter! I finally got some time to sit down and look at this (sorry - things are always on $fire for me…). Looks pretty good! I added two commits on top of yours. The first removes the RPMs - I assume those were not intentionally added? The second breaks the mock test into three tests, since there are three conditions we want to test, and it also adds a lot of assertions to check that the mocks were used in an expected manner. Please review the patches I wrote and give me a +1/-1 - I want to make sure you agree too before merging. Once we both agree, I will squash all the commits into one. For the record (since the commits will be lost once we sqash), the test patch I wrote is here:
|
Also, note that I've force pushed to your branch after rebasing. |
We can ignore the |
This looks great! Yes, the RPMS were for testing, and should have never made it into the commit. So, a +1 from me. (I'm assuming the F28-python3-integration is also a known bug.) |
Yeah the |
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.
Thanks!
Thank you! I'm glad we managed to get it in! |
quay.io seems to be down right now, which is why the integration tests failed. |
Signed-off-by: Jonathan Dieter <jdieter@gmail.com> Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
This patch is planned for inclusion in the upcoming 4.0.0 release: #3221 |
Bodhi 4.0.0 beta is built and deployed to staging: https://copr.fedorainfracloud.org/coprs/bowlofeggs/bodhi-pre-release |
This patch will create both the regular and the zchunked updateinfo.xml if createrepo_c supports zchunk files.
For the tests to pass, you need librepo-1.9.3 and createrepo_c-0.12.0 with zchunk enabled and the pull request at rpm-software-management/createrepo_c#115 committed.