diff --git a/workers/servicekeyworker/models_interface.py b/workers/servicekeyworker/models_interface.py index 6b9292b91..909ac2367 100644 --- a/workers/servicekeyworker/models_interface.py +++ b/workers/servicekeyworker/models_interface.py @@ -1,6 +1,7 @@ from abc import ABCMeta, abstractmethod from six import add_metaclass + @add_metaclass(ABCMeta) class ServiceKeyWorkerDataInterface(object): """ diff --git a/workers/servicekeyworker/models_pre_oci.py b/workers/servicekeyworker/models_pre_oci.py index 906572397..5a82d3127 100644 --- a/workers/servicekeyworker/models_pre_oci.py +++ b/workers/servicekeyworker/models_pre_oci.py @@ -1,13 +1,14 @@ from data import model from workers.servicekeyworker.models_interface import ServiceKeyWorkerDataInterface + class PreOCIModel(ServiceKeyWorkerDataInterface): def set_key_expiration(self, kid, expiration_date): model.service_keys.set_key_expiration(kid, expiration_date) def create_service_key_for_testing(self, expiration): - key = model.service_keys.create_service_key('test', 'somekid', 'quay', '', {}, expiration) - return key.kid + key = model.service_keys.create_service_key('test', 'somekid', 'quay', '', {}, expiration) + return key.kid def get_service_key_expiration(self, kid): try: @@ -16,4 +17,5 @@ class PreOCIModel(ServiceKeyWorkerDataInterface): except model.ServiceKeyDoesNotExist: return None + pre_oci_model = PreOCIModel() diff --git a/workers/servicekeyworker/servicekeyworker.py b/workers/servicekeyworker/servicekeyworker.py index 90ddd0e33..23ad26024 100644 --- a/workers/servicekeyworker/servicekeyworker.py +++ b/workers/servicekeyworker/servicekeyworker.py @@ -7,11 +7,12 @@ from workers.worker import Worker logger = logging.getLogger(__name__) + class ServiceKeyWorker(Worker): def __init__(self): super(ServiceKeyWorker, self).__init__() self.add_operation(self._refresh_service_key, - app.config.get('INSTANCE_SERVICE_KEY_REFRESH', 60)*60) + app.config.get('INSTANCE_SERVICE_KEY_REFRESH', 60) * 60) def _refresh_service_key(self): """ @@ -22,6 +23,7 @@ class ServiceKeyWorker(Worker): model.set_key_expiration(instance_keys.local_key_id, datetime.now() + expiration) logger.debug('Finished refresh of automatic service keys') + if __name__ == "__main__": worker = ServiceKeyWorker() worker.start() diff --git a/workers/servicekeyworker/test/test_servicekeyworker.py b/workers/servicekeyworker/test/test_servicekeyworker.py index 7db38c62b..2cf6103d3 100644 --- a/workers/servicekeyworker/test/test_servicekeyworker.py +++ b/workers/servicekeyworker/test/test_servicekeyworker.py @@ -13,7 +13,7 @@ def test_refresh_service_key(initialized_db): original_expiration = datetime.now() + timedelta(minutes=10) test_key_kid = model.create_service_key_for_testing(original_expiration) - instance_keys = AttrDict(dict(local_key_id=test_key_kid, service_key_expiration=10)) + instance_keys = AttrDict(dict(local_key_id=test_key_kid, service_key_expiration=30)) with patch('workers.servicekeyworker.servicekeyworker.instance_keys', instance_keys): worker = ServiceKeyWorker() worker._refresh_service_key()