From 6fee7f5b49375ecac8130d3d35cb946b39ee641f Mon Sep 17 00:00:00 2001 From: memo Date: Mon, 19 Oct 2015 21:21:20 +0100 Subject: [PATCH] Quick fix for backups backups views now are wrapped in try except block readme was updated to point to openstack repos remove sys.path from _50_freezer.py Change-Id: I917c33a1d8df04173acddc8eecf23f8bf8a22390 --- README.rst | 16 ++++++------ _50_freezer.py | 4 --- freezer_ui/backups/views.py | 52 ++++++++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/README.rst b/README.rst index 5288abc..a10de2e 100644 --- a/README.rst +++ b/README.rst @@ -7,20 +7,22 @@ Requirements Freezer Freezer Dashboard requires a freezer API client to be installed in the same environment as horizon:: - git clone https://github.com/stackforge/freezer + pip install parsedatetime>=1.4 + git clone https://github.com/openstack/freezer cd freezer - python setup.py install (is important that freezer is installed from source and not with pip) + python setup.py install (is important that freezer is installed from source and not with pip and + is installed on horizon virtual environment) Freezer Dashboard requires a freezer API endpoint which you can install following this steps:: - https://github.com/stackforge/freezer-api/blob/master/README.rst + https://github.com/openstack/freezer-api/blob/master/README.rst API registration ================ Register freezer api endpoint:: - https://github.com/stackforge/freezer-api/blob/master/README.rst#3-api-registration + https://github.com/openstack/freezer-api/blob/master/README.rst#3-api-registration If keystone service-create and endpoint-create are not available you can set as a fallback the following on:: @@ -38,7 +40,7 @@ directory is /opt/stack/horizon/openstack_dashboard/dashboards/. To install freezer dashboard for development you need to do the following:: - # git clone https://github.com/stackforge/freezer-web-ui + # git clone https://github.com/openstack/freezer-web-ui # cd freezer-web-ui @@ -59,14 +61,12 @@ Production Installation To deploy freezer dashboard in production you need to do the following:: - # git clone https://github.com/stackforge/freezer-web-ui + # git clone https://github.com/openstack/freezer-web-ui # cd freezer-web-ui # cp _50_freezer.py /opt/stack/horizon/openstack_dashboard/enabled/ - # modify _50_freezer.py (line 9) and point the path to the freezer repo. - # restart apache2 service diff --git a/_50_freezer.py b/_50_freezer.py index f2b52ad..8857929 100644 --- a/_50_freezer.py +++ b/_50_freezer.py @@ -4,10 +4,6 @@ DASHBOARD = 'freezer_ui' # If set to True, this dashboard will not be added to the settings. DISABLED = False -# Until there is a more elegant SYSPATH var scheme... -import sys -sys.path.append('/opt/stack/freezer') - # A list of applications to be added to INSTALLED_APPS. ADD_INSTALLED_APPS = [ 'freezer_ui', diff --git a/freezer_ui/backups/views.py b/freezer_ui/backups/views.py index 28ace53..27b4ea2 100644 --- a/freezer_ui/backups/views.py +++ b/freezer_ui/backups/views.py @@ -38,16 +38,27 @@ class IndexView(tables.DataTableView): template_name = "freezer_ui/backups/index.html" def get_data(self): - backups, self._has_more = freezer_api.backups_list(self.request) - return backups + try: + backups, self._has_more = freezer_api.backups_list(self.request) + return backups + except Exception: + redirect = reverse("horizon:freezer_ui:backups:index") + msg = _('Unable to retrieve backups.') + exceptions.handle(self.request, msg, redirect=redirect) class DetailView(generic.TemplateView): template_name = 'freezer_ui/backups/detail.html' def get_context_data(self, **kwargs): - backup = freezer_api.backup_get(self.request, kwargs['backup_id']) - return {'data': pprint.pformat(backup.data_dict)} + try: + backup = freezer_api.backup_get(self.request, + kwargs['backup_id']) + return {'data': pprint.pformat(backup.data_dict)} + except Exception: + redirect = reverse("horizon:freezer_ui:backups:index") + msg = _('Unable to retrieve backup.') + exceptions.handle(self.request, msg, redirect=redirect) class RestoreView(workflows.WorkflowView): @@ -66,19 +77,30 @@ class RestoreView(workflows.WorkflowView): return 'name' in self.kwargs and bool(self.kwargs['name']) def get_workflow_name(self): - backup_id = self.kwargs['backup_id'] - backup = freezer_api.backup_get(self.request, backup_id) - backup_date = datetime.datetime.fromtimestamp( - int(backup.data_dict['backup_metadata']['time_stamp'])) - backup_date_str = django_date(backup_date, 'SHORT_DATETIME_FORMAT') - return "Restore '{}' from {}".format( - backup.data_dict['backup_metadata']['backup_name'], - backup_date_str) + try: + backup_id = self.kwargs['backup_id'] + backup = freezer_api.backup_get(self.request, backup_id) + backup_date = datetime.datetime.fromtimestamp( + int(backup.data_dict['backup_metadata']['time_stamp'])) + backup_date_str = django_date(backup_date, + 'SHORT_DATETIME_FORMAT') + return "Restore '{}' from {}".format( + backup.data_dict['backup_metadata']['backup_name'], + backup_date_str) + except Exception: + redirect = reverse("horizon:freezer_ui:backups:index") + msg = _('Unable to retrieve backups.') + exceptions.handle(self.request, msg, redirect=redirect) def get_initial(self): return {"backup_id": self.kwargs['backup_id']} def get_workflow(self, *args, **kwargs): - workflow = super(RestoreView, self).get_workflow(*args, **kwargs) - workflow.name = self.get_workflow_name() - return workflow + try: + workflow = super(RestoreView, self).get_workflow(*args, **kwargs) + workflow.name = self.get_workflow_name() + return workflow + except Exception: + redirect = reverse("horizon:freezer_ui:backups:index") + msg = _('Unable to retrieve backups.') + exceptions.handle(self.request, msg, redirect=redirect)