-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fix up Pulp Issue #1937 #293
Conversation
repo_id1 = utils.uuid4() | ||
repo_id2 = utils.uuid4() | ||
if repo_id2 == repo_id1: | ||
repo_id2 = utils.uuid4() |
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 chance of producing duplicate values is approximately 1 in 340,000,000,000,000,000,000,000,000,000,000,000,000. No need to check for duplicates.
What happens if this test needs a third repo? Should a variable named repo_id3
be created? Naaah. Use a list to store this information.
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.
@Ichimonji10: so a simple repos = list(); repos.append(utils.uuid4()); repos.append(utils.uuid4())
would be fine?
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.
Yes, that's fine. A more concise way to write that is to use a list comprehension:
repo_ids = [utils.uuid4() for _ in range(2)]
Please add some assertions verifying Pulp's behaviour. Just because a sync succeeded doesn't mean that the desired content units are actually present in a repository. A good check would be to run Generate documentation with |
2. pulp-admin puppet repo sync run --repo-id=repo1 | ||
3. pulp-admin puppet repo create --repo-id=repo2 | ||
--feed=http://forge.puppetlabs.com --queries=torssh | ||
4. pulp-admin puppet repo sync run --repo-id=repo2 |
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.
Heh. I appreciate thorough documentation. Even so, this is a bit verbose. Aim to tell the reader what a test does, but not how the test does that. We want to be able to do things like change the --queries=torssh
in our test without having to also update this docstring.
@Ichimonji10 Thank you for the comments! While trying to extract the content-unit-counts for each repository, I found out a very subtle detail of this issue. The very first repository, at a clean state of db, would have count of 1 as:
However, for the rest of repositories, they would only have counts as:
And even though all those repositories have been deleted, the following new repos would still have no counts, until an execution of In that case. the code has been revised to react to the above output; it will verify that counts are non-zero and identical. |
3c39e0e
to
34f21f1
Compare
👍 I found the same thing. |
34f21f1
to
08d63df
Compare
'--fields content_unit_counts' | ||
).format(repo_id) | ||
completed_proc = client.run(cmd.split()) | ||
output = getattr(completed_proc, 'stdout').split('Puppet Module:') |
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 happens if there's more than one type of content unit in this repository? For example:
>>> mytext = (
... 'foo bar biz baz\n'
... 'Puppet Module: 5\n'
... 'one two three four'
... )
>>> mytext.split('Puppet Module:')
['foo bar biz baz\n', ' 5\none two three four']
In this case, the call to int(output[1].strip())
will fail. A more robust solution is to find the one line of text containing the keyword 'Puppet Module:', and to parse that one line. Also, this logic seems like something that other test cases might want to make use of. A standalone function will be more re-usable.
Use a function like the following instead:
def _get_n_puppet_modules(server_config, repo_id):
"""Tell how many puppet modules are in a repository.
:param pulp_smash.config.ServerConfig server_config: Information about the
Pulp server being targeted.
:param repo_id: A Puppet repository ID.
:returns: The number of puppet modules in a repository, as an ``int``.
"""
keyword = 'Puppet Module:'
completed_proc = cli.Client(server_config).run((
'pulp-admin puppet repo list --repo-id {} --fields content_unit_counts'
).format(repo_id).split())
lines = [
line for line in completed_proc.stdout.splitlines() if keyword in line
]
# If puppet modules are present, a "Puppet Module: n" line is printed.
# Otherwise, nothing is printed.
assert len(lines) in (0, 1)
if len(lines) == 0:
return 0
else:
return int(lines[0].split(keyword)[1].strip())
08d63df
to
4ed1881
Compare
This commit fixes the issue: pulp#269. It creates two repositories with the same feed content. By synchronizing both repos, check if the 2nd repo would have content; otherwise, the sync will fail. [1] https://pulp.plan.io/issues/1937
4ed1881
to
ca6a35e
Compare
Merged, with a follow-up commit of 56f4778. Closed #269. Thank you, @danuzclaudes! |
🎉 |
This commit fixes the issue: #269.
It creates two repositories with the same feed content. By synchronizing both repos, check if the 2nd repo would have content; otherwise, the sync will fail.
Test output:
The test fails due to either of the two cases:
[1] https://pulp.plan.io/issues/1937