def test_get_providers_for_existed_feature(pcw_file): set_pcw_ini( pcw_file, """ [providerfeature.namespace.fake] providers = azure """) providers = PCWConfig.get_providers_for('providerfeature', 'fake') assert not {'azure'} ^ set(providers)
def cleanup_run(): for namespace in PCWConfig.get_namespaces_for('cleanup'): try: providers = PCWConfig.get_providers_for('cleanup', namespace) logger.debug("[{}] Run cleanup for {}".format(namespace, ','.join(providers))) if 'azure' in providers: Azure(namespace).cleanup_all() if 'ec2' in providers: EC2(namespace).cleanup_all() if 'gce' in providers: GCE(namespace).cleanup_all() except Exception as e: logger.exception("[{}] Cleanup failed!".format(namespace)) send_mail('{} on Cleanup in [{}]'.format(type(e).__name__, namespace), traceback.format_exc())
def update_run(): ''' Each update is using Instance.active to mark the model is still availalbe on CSP. Instance.state is used to reflect the "local" state, e.g. if someone triggered a delete, the state will moved to DELETING. If the instance is gone from CSP, the state will set to DELETED. ''' global __running, __last_update __running = True max_retries = 3 error_occured = False for namespace in PCWConfig.get_namespaces_for('vault'): for provider in PCWConfig.get_providers_for('vault', namespace): logger.info("[%s] Check provider %s", namespace, provider) email_text = set() for n in range(max_retries): try: _update_provider(provider, namespace) except Exception: logger.exception("[{}] Update failed for {}".format( namespace, provider)) email_text.add(traceback.format_exc()) time.sleep(5) else: break else: error_occured = True send_mail( 'Error on update {} in namespace {}'.format( provider, namespace), "\n{}\n".format('#' * 79).join(email_text)) auto_delete_instances() send_leftover_notification() __running = False if not error_occured: __last_update = datetime.now(timezone.utc) if not getScheduler().get_job('update_db'): init_cron()
def test_get_providers_for_not_existed_feature(pcw_file): providers = PCWConfig.get_providers_for('get_providers_for', 'not_existent') assert type(providers) is list assert not {'ec2', 'azure', 'gce'} ^ set(providers)