def run_on_all_enabled_modules(): """Run diagnostics on all the enabled modules and store the result.""" global current_results current_results = { 'apps': [], 'results': collections.OrderedDict(), 'progress_percentage': 0 } apps = [] for app in App.list(): # XXX: Implement more cleanly. # Don't run diagnostics on apps have not been setup yet. # However, run on apps that need an upgrade. module = importlib.import_module(app.__class__.__module__) if module.setup_helper.get_state() == 'needs-setup': continue if not app.is_enabled(): continue if not app.has_diagnostics(): continue apps.append((app.app_id, app)) current_results['results'][app.app_id] = None current_results['apps'] = apps for current_index, (app_id, app) in enumerate(apps): current_results['results'][app_id] = app.diagnose() current_results['progress_percentage'] = \ int((current_index + 1) * 100 / len(apps))
def diagnose_app(request, app_id): """Return diagnostics for a particular app.""" try: app = App.get(app_id) except KeyError: raise Http404('App does not exist') return TemplateResponse(request, 'diagnostics_app.html', { 'title': _('Diagnostic Test'), 'app_id': app_id, 'results': app.diagnose() })
def set_domains(primary_domain=None): """Set the primary domain and all the domains for postfix.""" all_domains = DomainName.list_names() if not primary_domain: primary_domain = get_domains()['primary_domain'] if primary_domain not in all_domains: primary_domain = config.get_domainname() or list(all_domains)[0] # Update configuration and don't restart daemons superuser_run( 'email', ['domain', 'set_domains', primary_domain, ','.join(all_domains)]) superuser_run('email', ['dkim', 'setup_dkim', primary_domain]) # Copy certificates (self-signed if needed) and restart daemons app = App.get('email') app.get_component('letsencrypt-email-postfix').setup_certificates() app.get_component('letsencrypt-email-dovecot').setup_certificates()
def diagnose_app(request, app_id): """Return diagnostics for a particular app.""" try: app = App.get(app_id) except KeyError: raise Http404('App does not exist') app_name = app.info.name or app_id diagnosis = None diagnosis_exception = None try: diagnosis = app.diagnose() except Exception as exception: logger.exception('Error running %s diagnostics - %s', app_id, exception) diagnosis_exception = str(exception) return TemplateResponse( request, 'diagnostics_app.html', { 'title': _('Diagnostic Test'), 'app_name': app_name, 'results': diagnosis, 'exception': diagnosis_exception, })
def test_app_list(): """Test listing all apps.""" app = AppTest() assert list(App.list()) == [app]
def test_app_get(): """Test that an app can be correctly retrieved.""" app = AppTest() assert App.get(app.app_id) == app