Skip to content

Commit

Permalink
Merge branch 'develop' into 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSaleh committed Nov 8, 2021
2 parents affd659 + 54686c4 commit 78ffedf
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 291 deletions.
2 changes: 1 addition & 1 deletion bodhi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Fedora's update manager."""

__version__ = "5.7.1b0"
__version__ = "5.7.1"

# This is a regular expression used to match username mentions in comments.
MENTION_RE = r'(?<!\S)(@\w+)'
50 changes: 25 additions & 25 deletions bodhi/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,12 +2150,13 @@ def greenwave_request_batches(self, verbose):
subjects = self.greenwave_subject
data = []
while count < len(subjects):
data.append({
'product_version': self.product_version,
'decision_context': self._greenwave_decision_context,
'subject': subjects[count:count + batch_size],
'verbose': verbose,
})
for context in self._greenwave_decision_contexts:
data.append({
'product_version': self.product_version,
'decision_context': context,
'subject': subjects[count:count + batch_size],
'verbose': verbose,
})
count += batch_size
return data

Expand Down Expand Up @@ -2183,37 +2184,32 @@ def _greenwave_api_url(self):
return '{}/decision'.format(config.get('greenwave_api_url'))

@property
def _greenwave_decision_context(self):
def _greenwave_decision_contexts(self):
# We retrieve updates going to testing (status=pending) and updates
# (status=testing) going to stable.
# We also query on different contexts for critpath and non-critpath
# updates.
# this is correct if update is already in testing...
context = "bodhi_update_push_stable"
contexts = ["bodhi_update_push_stable"]
if self.request == UpdateRequest.testing and self.status == UpdateStatus.pending:
# ...but if it is pending, we want to know if it can go to testing
context = "bodhi_update_push_testing"
contexts = ["bodhi_update_push_testing"]
if self.critpath:
context = context + "_critpath"
return context
contexts.insert(0, contexts[0] + "_critpath")
return contexts

def get_test_gating_info(self):
"""
Query Greenwave about this update and return the information retrieved.
Returns:
dict: The response from Greenwave for this update.
list: A list of response dicts from Greenwave for this update.
Raises:
BodhiException: When the ``greenwave_api_url`` is undefined in configuration.
RuntimeError: If Greenwave did not give us a 200 code.
"""
data = {
'product_version': self.product_version,
'decision_context': self._greenwave_decision_context,
'subject': self.greenwave_subject,
'verbose': True,
}
return util.greenwave_api_post(self._greenwave_api_url, data)
return [util.greenwave_api_post(self._greenwave_api_url, data)
for data in self.greenwave_request_batches(verbose=True)]

@property
def _greenwave_requirements_generator(self):
Expand Down Expand Up @@ -2540,30 +2536,34 @@ def edit(cls, request, data):
data['karma_critipath'] = 0
up.date_testing = None

# Remove all koji tags and change the status back to pending
if up.status is not UpdateStatus.pending:
if up.status != UpdateStatus.pending:
# Remove all koji tags and change the status back to pending
up.unpush(db)
caveats.append({
'name': 'status',
'description': 'Builds changed. Your update is being '
'sent back to testing.',
})
builds_to_tag = [b.nvr for b in up.builds]
else:
# No need to unpush the update, just tag new builds
builds_to_tag = new_builds

# Add the pending_signing_tag to all new builds
# Add the pending_signing_tag to builds where needed
tag = None
if up.from_tag:
if up.from_tag and not up.release.composed_by_bodhi:
tag = up.release.get_pending_signing_side_tag(up.from_tag)
elif up.release.pending_signing_tag:
tag = up.release.pending_signing_tag

if tag is not None:
tag_update_builds_task.delay(tag=tag, builds=new_builds)
tag_update_builds_task.delay(tag=tag, builds=builds_to_tag)

new_bugs = up.update_bugs(data['bugs'], db)
del(data['bugs'])

req = data.pop("request", None)
if req is not None and not data.get("from_tag"):
if req is not None and up.release.composed_by_bodhi and not data.get("from_tag"):
up.set_request(db, req, request.user.name)

for key, value in data.items():
Expand Down
5 changes: 0 additions & 5 deletions bodhi/server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,6 @@ class SaveUpdateSchema(CSRFProtectedSchema, colander.MappingSchema):
colander.String(),
validator=colander.OneOf(list(UpdateType.values())),
)
request = colander.SchemaNode(
colander.String(),
validator=colander.OneOf(list(UpdateRequest.values())),
missing='testing',
)
severity = colander.SchemaNode(
colander.String(),
validator=colander.OneOf(list(UpdateSeverity.values())),
Expand Down
8 changes: 4 additions & 4 deletions bodhi/server/services/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,13 @@ def get_test_results(request):
Args:
request (pyramid.request): The current request.
Returns:
dict: A dictionary mapping the key "update" to the update.
dict: A dictionary mapping the key 'decisions' to a list of result dictionaries.
"""
update = request.validated['update']

decision = None
decisions = []
try:
decision = update.get_test_gating_info()
decisions = update.get_test_gating_info()
except RequestsTimeout as e:
log.error("Error querying greenwave for test results - timed out")
request.errors.add('body', 'request', str(e))
Expand All @@ -722,7 +722,7 @@ def get_test_results(request):
request.errors.add('body', 'request', str(e))
request.errors.status = 500

return dict(decision=decision)
return dict(decisions=decisions)


@update_trigger_tests.post(schema=bodhi.server.schemas.TriggerTestsSchema,
Expand Down
5 changes: 2 additions & 3 deletions bodhi/server/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,8 @@ def bug_link(context, bug, short=False):
Returns:
str: The requested link.
"""
url = "https://bugzilla.redhat.com/show_bug.cgi?id=" + str(bug.bug_id)
display = "BZ#%i" % bug.bug_id
link = "<a target='_blank' href='%s' class='notblue'>%s</a>" % (url, display)
url = config.get('buglink') % str(bug.bug_id)
link = f"<a target='_blank' href='{url}' class='notblue'>BZ#{bug.bug_id}</a>"
if not short:
if bug.title:
# We're good, but we do need to clean the bug title in case it contains malicious
Expand Down
91 changes: 56 additions & 35 deletions bodhi/tests/server/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,42 @@ def test_edit_testing_update_with_new_builds_with_stable_request(self, *args):
assert up['builds'][0]['nvr'] == 'bodhi-2.0.0-3.fc17'
assert self.db.query(RpmBuild).filter_by(nvr='bodhi-2.0.0-2.fc17').first() is None

@mock.patch('bodhi.server.services.updates.handle_side_and_related_tags_task', mock.Mock())
@mock.patch('bodhi.server.models.tag_update_builds_task', mock.Mock())
@mock.patch(**mock_valid_requirements)
def test_edit_testing_update_with_stable_request_no_edit_build(self, *args):
"""An update with stable request should not be pushed back to testing if
build list is not changed."""
nvr = 'bodhi-2.0.0-2.fc17'
args = self.get_update(nvr)

with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1):
r = self.app.post_json('/updates/', args)

# Mark it as testing
upd = Update.get(r.json['alias'])
upd.status = UpdateStatus.testing
upd.request = UpdateRequest.stable
# Clear pending messages
self.db.info['messages'] = []
self.db.commit()

args['edited'] = upd.alias
args['notes'] = 'A nifty description.'

with fml_testing.mock_sends(update_schemas.UpdateEditV1):
r = self.app.post_json('/updates/', args)

up = r.json_body
assert up['title'] == 'bodhi-2.0.0-2.fc17'
assert up['status'] == 'testing'
assert up['request'] == 'stable'
assert up['notes'] == 'A nifty description.'
assert up['comments'][-1]['text'] == 'guest edited this update.'
assert up['comments'][-3]['text'] == 'This update has been submitted for testing by guest. '
assert len(up['builds']) == 1
assert up['builds'][0]['nvr'] == 'bodhi-2.0.0-2.fc17'

@mock.patch('bodhi.server.services.updates.handle_side_and_related_tags_task', mock.Mock())
@mock.patch('bodhi.server.models.tag_update_builds_task', mock.Mock())
@mock.patch(**mock_valid_requirements)
Expand Down Expand Up @@ -3463,23 +3499,6 @@ def test_edit_locked_update(self, *args):
build = self.db.query(RpmBuild).filter_by(nvr=nvr).one()
assert up.builds == [build]

# Changing the request should fail
args['notes'] = 'Still new notes'
args['builds'] = nvr
args['request'] = 'stable'
r = self.app.post_json('/updates/', args, status=400).json_body
assert r['status'] == 'error'
assert 'errors' in r
assert {'description': "Can't change the request on a locked update",
'location': 'body', 'name': 'builds'} in r['errors']
up = self.db.query(Update).get(up_id)
assert up.notes == 'Some new notes'
# We need to re-retrieve the build since we started a new transaction in the call to
# /updates
build = self.db.query(RpmBuild).filter_by(nvr=nvr).one()
assert up.builds == [build]
assert up.request is None

@mock.patch(**mock_valid_requirements)
def test_pending_update_on_stable_karma_reached_autopush_enabled(self, *args):
"""Ensure that a pending update stays in testing if it hits stable karma while pending."""
Expand Down Expand Up @@ -6449,7 +6468,7 @@ def test_get_test_results_calling_greenwave(self, call_api, *args):
service_name='Greenwave'
)

assert res.json_body == {'decision': {'foo': 'bar'}}
assert res.json_body == {'decisions': [{'foo': 'bar'}]}

@mock.patch.dict(config, [('greenwave_api_url', 'https://greenwave.api')])
@mock.patch('bodhi.server.util.call_api')
Expand All @@ -6464,23 +6483,25 @@ def test_get_test_results_calling_greenwave_critpath(self, call_api, *args):

res = self.app.get(f'/updates/{update.alias}/get-test-results')

call_api.assert_called_once_with(
'https://greenwave.api/decision',
data={
'product_version': 'fedora-17',
'decision_context': 'bodhi_update_push_testing_critpath',
'subject': [
{'item': 'bodhi-2.0-1.fc17', 'type': 'koji_build'},
{'item': update.alias, 'type': 'bodhi_update'}
],
'verbose': True,
},
method='POST',
retries=3,
service_name='Greenwave'
)
assert call_api.call_args_list == [
mock.call(
'https://greenwave.api/decision',
data={
'product_version': 'fedora-17',
'decision_context': context,
'subject': [
{'item': 'bodhi-2.0-1.fc17', 'type': 'koji_build'},
{'item': update.alias, 'type': 'bodhi_update'}
],
'verbose': True,
},
method='POST',
retries=3,
service_name='Greenwave'
) for context in ('bodhi_update_push_testing_critpath', 'bodhi_update_push_testing')
]

assert res.json_body == {'decision': {'foo': 'bar'}}
assert res.json_body == {'decisions': [{'foo': 'bar'}, {'foo': 'bar'}]}

@mock.patch('bodhi.server.util.call_api')
def test_get_test_results_calling_greenwave_no_session(self, call_api, *args):
Expand Down Expand Up @@ -6513,7 +6534,7 @@ def test_get_test_results_calling_greenwave_no_session(self, call_api, *args):
service_name='Greenwave'
)

assert res.json_body == {'decision': {'foo': 'bar'}}
assert res.json_body == {'decisions': [{'foo': 'bar'}]}

@mock.patch('bodhi.server.util.call_api')
def test_get_test_results_calling_greenwave_unauth(self, call_api, *args):
Expand Down

0 comments on commit 78ffedf

Please sign in to comment.