Skip to content
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

1366301: Entitlement regeneration no longer propagates server errors #179

Merged
merged 3 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/rhsm/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,20 +1345,56 @@ def regenIdCertificate(self, consumerId):
return self.conn.request_post(method)

def regenEntitlementCertificates(self, consumer_id, lazy_regen=True):
"""
Regenerates all entitlements for the given consumer
"""

method = "/consumers/%s/certificates" % self.sanitize(consumer_id)

if lazy_regen:
method += "?lazy_regen=true"

return self.conn.request_put(method)
result = False

try:
self.conn.request_put(method)
result = True
except RemoteServerException as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this to work, if the resource is truly not available, we should probably be catching BadStatusLine.

# 404s indicate that the service is unsupported (Candlepin too old, or SAM)
if e.code == 404:
log.debug("Unable to refresh entitlement certificates: Service currently unsupported.")
log.debug(e)
else:
# Something else happened that we should probabaly raise
raise e

return result

def regenEntitlementCertificate(self, consumer_id, entitlement_id, lazy_regen=True):
"""
Regenerates the specified entitlement for the given consumer
"""

method = "/consumers/%s/certificates?entitlement=%s" % (self.sanitize(consumer_id), self.sanitize(entitlement_id))

if lazy_regen:
method += "&lazy_regen=true"

return self.conn.request_put(method)
result = False

try:
self.conn.request_put(method)
result = True
except RemoteServerException as e:
# 404s indicate that the service is unsupported (Candlepin too old, or SAM)
if e.code == 404:
log.debug("Unable to refresh entitlement certificates: Service currently unsupported.")
log.debug(e)
else:
# Something else happened that we should probabaly raise
raise e

return result

def getStatus(self):
method = "/status"
Expand Down
18 changes: 12 additions & 6 deletions test/functional/connection-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,32 @@ def setUp(self):
self.entitlement_id = self.entitlement['id']

def test_regenerate_entitlements_default(self):
self.cp.regenEntitlementCertificates(self.consumer_uuid)
result = self.cp.regenEntitlementCertificates(self.consumer_uuid)
self.assertTrue(result)

def test_regenerate_entitlements_lazy(self):
self.cp.regenEntitlementCertificates(self.consumer_uuid, True)
result = self.cp.regenEntitlementCertificates(self.consumer_uuid, True)
self.assertTrue(result)

def test_regenerate_entitlements_eager(self):
self.cp.regenEntitlementCertificates(self.consumer_uuid, False)
result = self.cp.regenEntitlementCertificates(self.consumer_uuid, False)
self.assertTrue(result)

def test_regenerate_entitlements_bad_uuid(self):
with self.assertRaises(RestlibException):
self.cp.regenEntitlementCertificates("bad_consumer_uuid")

def test_regenerate_entitlement_default(self):
self.cp.regenEntitlementCertificate(self.consumer_uuid, self.entitlement_id)
result = self.cp.regenEntitlementCertificate(self.consumer_uuid, self.entitlement_id)
self.assertTrue(result)

def test_regenerate_entitlement_lazy(self):
self.cp.regenEntitlementCertificate(self.consumer_uuid, self.entitlement_id, True)
result = self.cp.regenEntitlementCertificate(self.consumer_uuid, self.entitlement_id, True)
self.assertTrue(result)

def test_regenerate_entitlement_eager(self):
self.cp.regenEntitlementCertificate(self.consumer_uuid, self.entitlement_id, False)
result = self.cp.regenEntitlementCertificate(self.consumer_uuid, self.entitlement_id, False)
self.assertTrue(result)

def test_regenerate_entitlement_bad_consumer_uuid(self):
with self.assertRaises(RestlibException):
Expand Down