Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Run retry list and report errors in summary
Browse files Browse the repository at this point in the history
Executing the retry list will run the task with valid
items and will ignore errors. The response will include
a summary of items that were sent to task creation and
items that were ignored because of errors.

Change-Id: Ic3898434df1ae0c63d8116423449818d09de605e
  • Loading branch information
isaacm committed Jun 14, 2016
1 parent 857a8a4 commit afa41d8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 25 deletions.
50 changes: 36 additions & 14 deletions poppy/manager/default/ssl_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ def update_san_retry_list(self, queue_data_list):
akamai_driver.mod_san_queue.put_queue_data(new_queue_data)]

deleted = tuple(x for x in orig if x not in res)

# other provider's retry-list implementation goes here
return res, deleted

def rerun_san_retry_list(self):
run_list = []
ignore_list = []
if 'akamai' in self._driver.providers:
akamai_driver = self._driver.providers['akamai'].obj
retry_list = []
Expand All @@ -181,25 +184,41 @@ def remove_duplicates(data):
# double check in POST. This check should really be first done in
# PUT
for r in retry_list:
err_state = False
service_obj = self.service_storage\
.get_service_details_by_domain_name(r['domain_name'])
if service_obj is None and r.get('validate_service', True):
raise LookupError(u'Domain {0} does not exist on any '
'service, are you sure you want to '
'proceed request, {1}? You can set '
'validate_service to False to retry this'
' san-retry request forcefully'.
format(r['domain_name'], r))
err_state = True
LOG.error(
u'Domain {0} does not exist on any service, are you '
'sure you want to proceed request, {1}? You can set '
'validate_service to False to retry this san-retry '
'request forcefully'.format(r['domain_name'], r)
)

cert_for_domain = self.storage.get_certs_by_domain(
r['domain_name'])
if cert_for_domain != []:
if cert_for_domain.get_cert_status() == "deployed":
raise ValueError(u'Certificate on {0} has already been'
' provisioned successfully.'.
format(r['domain_name']))
err_state = True
LOG.error(
u'Certificate on {0} has already been provisioned '
'successfully.'.format(r['domain_name']))

if err_state is False:
run_list.append(r)
else:
ignore_list.append(r)
akamai_driver.mod_san_queue.enqueue_mod_san_request(
json.dumps(r)
)
LOG.warn(
"{0} was skipped because it failed validation.".format(
r['domain_name']
)
)

for cert_obj_dict in retry_list:
for cert_obj_dict in run_list:
try:
cert_obj = ssl_certificate.SSLCertificate(
cert_obj_dict['flavor_id'],
Expand Down Expand Up @@ -244,15 +263,18 @@ def remove_duplicates(data):
# When exception happens we log it and re-queue this
# request
LOG.exception(e)
run_list.remove(cert_obj_dict)
ignore_list.append(cert_obj_dict)
akamai_driver.mod_san_queue.enqueue_mod_san_request(
json.dumps(cert_obj_dict)
)
# For other providers post san_retry_list implementation goes here
else:
# if not using akamai driver just return None
# if not using akamai driver just return summary of run list and
# ignore list
pass

return None
return run_list, ignore_list

def get_san_cert_configuration(self, san_cert_name):
if 'akamai' in self._driver.providers:
Expand Down Expand Up @@ -307,6 +329,6 @@ def update_san_cert_configuration(self, san_cert_name, new_cert_config):
return res

def get_certs_by_status(self, status):
services_project_ids = self.storage.get_certs_by_status(status)
certs_by_status = self.storage.get_certs_by_status(status)

return services_project_ids
return certs_by_status
10 changes: 8 additions & 2 deletions poppy/transport/pecan/controllers/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def __init__(self, driver):

@pecan.expose('json')
def get_all(self):
retry_list = None
try:
retry_list = (
self._driver.manager.ssl_certificate_controller.
Expand All @@ -173,12 +174,17 @@ def get_all(self):
@pecan.expose('json')
def post(self):
"""Rerun retry-list mod-san requests."""
sent, ignored = None, None
try:
self._driver.manager.ssl_certificate_controller.\
sent, ignored = self._driver.manager.ssl_certificate_controller.\
rerun_san_retry_list()
except Exception as e:
pecan.abort(404, str(e))
return pecan.Response(None, 202)

return pecan.Response(
json_body={"processing": sent, "failed_validation": ignored},
status=202
)

@pecan.expose('json')
@decorators.validate(
Expand Down
45 changes: 36 additions & 9 deletions tests/unit/manager/default/test_ssl_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,31 @@ def test_rerun_san_retry_list_exception_service_validation(self):
'akamai'].obj.mod_san_queue
mod_san_queue.mod_san_queue_backend = mock.MagicMock()
mod_san_queue.mod_san_queue_backend.__len__.side_effect = [1, 0]
test_queue_item = {
"domain_name": "a_domain",
"project_id": "00000",
"flavor_id": "flavor",
"validate_service": True
}
mod_san_queue.dequeue_mod_san_request.side_effect = [
bytearray(json.dumps({
"domain_name": "a_domain",
"project_id": "00000",
"flavor_id": "flavor",
"validate_service": True
}), encoding='utf-8')
bytearray(json.dumps(test_queue_item), encoding='utf-8')
]

self.scc.service_storage.get_service_details_by_domain_name. \
return_value = None

with testtools.ExpectedException(LookupError):
with mock.patch('oslo_log.log.KeywordArgumentAdapter.error') as logger:
self.scc.rerun_san_retry_list()

self.assertTrue(logger.called)
args, _ = logger.call_args
self.assertTrue(test_queue_item["domain_name"] in args[0])
self.assertTrue(test_queue_item["project_id"] in args[0])
self.assertTrue(test_queue_item["flavor_id"] in args[0])
self.assertTrue(
str(test_queue_item["validate_service"]) in args[0]
)

self.assertEqual(
False,
self.scc.distributed_task_controller.submit_task.called
Expand All @@ -303,9 +313,10 @@ def test_rerun_san_retry_list_exception_cert_already_deployed(self):
'akamai'].obj.mod_san_queue
mod_san_queue.mod_san_queue_backend = mock.MagicMock()
mod_san_queue.mod_san_queue_backend.__len__.side_effect = [1, 0]
test_domain = "a_domain"
mod_san_queue.dequeue_mod_san_request.side_effect = [
bytearray(json.dumps({
"domain_name": "a_domain",
"domain_name": test_domain,
"project_id": "00000",
"flavor_id": "flavor",
"validate_service": True
Expand All @@ -317,9 +328,17 @@ def test_rerun_san_retry_list_exception_cert_already_deployed(self):
self.scc.storage.get_certs_by_domain. \
return_value = cert_domain_mock

with testtools.ExpectedException(ValueError):
with mock.patch('oslo_log.log.KeywordArgumentAdapter.error') as logger:
self.scc.rerun_san_retry_list()

self.assertTrue(logger.called)
args, _ = logger.call_args
self.assertEqual(
(u'Certificate on {0} has already been provisioned '
'successfully.'.format(test_domain), ),
args
)

self.assertEqual(
False,
self.scc.distributed_task_controller.submit_task.called
Expand Down Expand Up @@ -405,3 +424,11 @@ def test_rerun_san_retry_list_cert_create_in_progress_second_check(self):
True,
self.scc.distributed_task_controller.submit_task.called
)

def test_get_certs_by_status(self):
result_list_mock = [mock.Mock()]
self.scc.storage.get_certs_by_status.return_value = result_list_mock

results = self.scc.get_certs_by_status("create_in_progress")

self.assertEqual(result_list_mock, results)

0 comments on commit afa41d8

Please sign in to comment.