Import cleanups, removing unused vars, exception handling, one test fix.
Change-Id: I98c49b70612c3dd762e2e8781bba1b06aae95642
This commit is contained in:
@@ -19,18 +19,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
|
||||
from django import http
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import redirect
|
||||
from mox import IsA, IgnoreArg
|
||||
from mox import IsA
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
from horizon import api
|
||||
from horizon import test
|
||||
from horizon.dashboards.nova.access_and_security.floating_ips.forms import \
|
||||
FloatingIpAssociate
|
||||
|
||||
|
||||
INDEX_URL = reverse('horizon:nova:access_and_security:index')
|
||||
@@ -82,8 +77,6 @@ class FloatingIpViewTests(test.BaseViewTests):
|
||||
'nova/access_and_security/floating_ips/associate.html')
|
||||
|
||||
def test_associate_post(self):
|
||||
server = self.server
|
||||
|
||||
self.mox.StubOutWithMock(api, 'server_list')
|
||||
api.server_list = self.mox.CreateMockAnything()
|
||||
api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)
|
||||
@@ -114,8 +107,6 @@ class FloatingIpViewTests(test.BaseViewTests):
|
||||
self.assertRedirects(res, INDEX_URL)
|
||||
|
||||
def test_associate_post_with_exception(self):
|
||||
server = self.server
|
||||
|
||||
self.mox.StubOutWithMock(api, 'server_list')
|
||||
api.server_list = self.mox.CreateMockAnything()
|
||||
api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)
|
||||
|
||||
@@ -24,6 +24,7 @@ Views for managing Nova floating IPs.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from django import http
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ from django import shortcuts
|
||||
from django.contrib import messages
|
||||
from django.core import validators
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.utils.http import urlquote
|
||||
from django.utils.translation import ugettext as _
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
# under the License.
|
||||
|
||||
from django import http
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from mox import IsA
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
@@ -42,9 +42,9 @@ class CreateGroup(forms.SelfHandlingForm):
|
||||
try:
|
||||
LOG.info('Add security_group: "%s"' % data)
|
||||
|
||||
security_group = api.security_group_create(request,
|
||||
data['name'],
|
||||
data['description'])
|
||||
api.security_group_create(request,
|
||||
data['name'],
|
||||
data['description'])
|
||||
messages.success(request,
|
||||
_('Successfully created security_group: %s')
|
||||
% data['name'])
|
||||
@@ -70,7 +70,6 @@ class AddRule(forms.SelfHandlingForm):
|
||||
tenant_id = forms.CharField(widget=forms.HiddenInput())
|
||||
|
||||
def handle(self, request, data):
|
||||
tenant_id = data['tenant_id']
|
||||
try:
|
||||
LOG.info('Add security_group_rule: "%s"' % data)
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django import shortcuts
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from horizon import api
|
||||
from horizon import tables
|
||||
|
||||
@@ -21,10 +21,9 @@
|
||||
from django import http
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from glance.common import exception as glance_exception
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
from novaclient.v1_1 import security_group_rules as nova_rules
|
||||
from mox import IgnoreArg, IsA
|
||||
from mox import IsA
|
||||
|
||||
from horizon import api
|
||||
from horizon import test
|
||||
@@ -188,7 +187,6 @@ class SecurityGroupsViewTests(test.BaseViewTests):
|
||||
exception = novaclient_exceptions.ClientException('ClientException',
|
||||
message='ClientException')
|
||||
|
||||
RULE_ID = '1'
|
||||
FROM_PORT = '-1'
|
||||
TO_PORT = '-1'
|
||||
IP_PROTOCOL = 'icmp'
|
||||
|
||||
@@ -19,10 +19,8 @@
|
||||
# under the License.
|
||||
|
||||
from django import http
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from mox import IsA
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
from horizon import api
|
||||
from horizon import test
|
||||
|
||||
@@ -29,6 +29,7 @@ from django.utils.translation import ugettext as _
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
from horizon import api
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
from .keypairs.tables import KeypairsTable
|
||||
from .floating_ips.tables import FloatingIPsTable
|
||||
@@ -45,11 +46,10 @@ class IndexView(tables.MultiTableView):
|
||||
def get_keypairs_data(self):
|
||||
try:
|
||||
keypairs = api.nova.keypair_list(self.request)
|
||||
except Exception, e:
|
||||
except:
|
||||
keypairs = []
|
||||
LOG.exception("Exception in keypair index")
|
||||
messages.error(self.request,
|
||||
_('Keypair list is currently unavailable.'))
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve keypair list.'))
|
||||
return keypairs
|
||||
|
||||
def get_security_groups_data(self):
|
||||
|
||||
@@ -25,6 +25,7 @@ from django.utils import http
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from horizon import api
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
|
||||
|
||||
@@ -44,7 +45,7 @@ class DeleteContainer(tables.Action):
|
||||
try:
|
||||
api.swift_delete_container(request, obj_id)
|
||||
deleted.append(obj)
|
||||
except ContainerNotEmpty, e:
|
||||
except ContainerNotEmpty:
|
||||
LOG.exception('Unable to delete container "%s".' % obj.name)
|
||||
messages.error(request,
|
||||
_('Unable to delete non-empty container: %s') %
|
||||
@@ -126,10 +127,8 @@ class DeleteObject(tables.Action):
|
||||
try:
|
||||
api.swift_delete_object(request, container_name, obj_id)
|
||||
deleted.append(obj)
|
||||
except Exception, e:
|
||||
msg = 'Unable to delete object.'
|
||||
LOG.exception(msg)
|
||||
messages.error(request, _(msg))
|
||||
except:
|
||||
exceptions.handle(request, _('Unable to delete object.'))
|
||||
if deleted:
|
||||
messages.success(request,
|
||||
_('Successfully deleted objects: %s')
|
||||
|
||||
@@ -22,10 +22,8 @@ import tempfile
|
||||
|
||||
from cloudfiles.errors import ContainerNotEmpty
|
||||
from django import http
|
||||
from django import template
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from mox import IgnoreArg, IsA
|
||||
from mox import IsA
|
||||
|
||||
from horizon import api
|
||||
from horizon import test
|
||||
@@ -127,10 +125,10 @@ class ObjectViewTests(test.BaseViewTests):
|
||||
|
||||
super(ObjectViewTests, self).setUp()
|
||||
swift_object = api.swift.SwiftObject(FakeCloudFile())
|
||||
swift_object.name = "test_object"
|
||||
swift_object.name = u"test_object"
|
||||
swift_object.size = '128'
|
||||
swift_object.container = api.swift.Container(None)
|
||||
swift_object.container.name = 'container_name'
|
||||
swift_object.container.name = self.CONTAINER_NAME
|
||||
self.swift_objects = [swift_object]
|
||||
|
||||
def test_index(self):
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
from django import http
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from glance.common import exception as glance_exception
|
||||
from keystoneclient import exceptions as keystone_exceptions
|
||||
from mox import IgnoreArg, IsA
|
||||
|
||||
|
||||
@@ -19,11 +19,9 @@
|
||||
# under the License.
|
||||
|
||||
from django import http
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from glance.common import exception as glance_exception
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
from mox import IgnoreArg, IsA
|
||||
from mox import IsA
|
||||
|
||||
from horizon import api
|
||||
from horizon import test
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
# under the License.
|
||||
|
||||
from django import http
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from glance.common import exception as glance_exception
|
||||
from mox import IsA
|
||||
|
||||
@@ -25,11 +25,7 @@ Views for managing Images and Snapshots.
|
||||
|
||||
import logging
|
||||
|
||||
from django import shortcuts
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext as _
|
||||
from glance.common import exception as glance_exception
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
from horizon import api
|
||||
from horizon import exceptions
|
||||
|
||||
@@ -20,12 +20,11 @@
|
||||
|
||||
from django.conf.urls.defaults import *
|
||||
|
||||
import horizon
|
||||
|
||||
from .instances import urls as instance_urls
|
||||
from .views import IndexView
|
||||
from .volumes import urls as volume_urls
|
||||
|
||||
|
||||
urlpatterns = patterns('horizon.dashboards.nova.instances_and_volumes',
|
||||
url(r'^$', IndexView.as_view(), name='index'),
|
||||
url(r'^instances/', include(instance_urls, namespace='instances')),
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django import shortcuts
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template.defaultfilters import filesizeformat, title
|
||||
from django.template.defaultfilters import title
|
||||
from django.utils import safestring
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from horizon import api
|
||||
from horizon import tables
|
||||
|
||||
@@ -67,13 +67,21 @@ class EditAttachmentsView(tables.DataTableView):
|
||||
table_class = AttachmentsTable
|
||||
template_name = 'nova/instances_and_volumes/volumes/attach.html'
|
||||
|
||||
def get_object(self):
|
||||
if not hasattr(self, "object"):
|
||||
volume_id = self.kwargs['volume_id']
|
||||
try:
|
||||
self.object = api.volume_get(self.request, volume_id)
|
||||
except:
|
||||
self.object = None
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve volume information.'))
|
||||
return self.object
|
||||
|
||||
def get_data(self):
|
||||
volume_id = self.kwargs['volume_id']
|
||||
try:
|
||||
self.object = api.volume_get(self.request, volume_id)
|
||||
attachments = [att for att in self.object.attachments if att]
|
||||
except:
|
||||
self.object = None
|
||||
attachments = []
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve volume information.'))
|
||||
@@ -89,8 +97,7 @@ class EditAttachmentsView(tables.DataTableView):
|
||||
form, handled = self.handle_form()
|
||||
if handled:
|
||||
return handled
|
||||
tables = self.get_tables()
|
||||
if not self.object:
|
||||
if not self.get_object():
|
||||
return shortcuts.redirect("horizon:nova:instances_and_volumes:"
|
||||
"index")
|
||||
context = self.get_context_data(**kwargs)
|
||||
|
||||
@@ -21,9 +21,8 @@
|
||||
import datetime
|
||||
|
||||
from django import http
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from mox import IsA, IgnoreArg
|
||||
from mox import IsA
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
|
||||
from horizon import api
|
||||
|
||||
@@ -23,19 +23,14 @@ from __future__ import division
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from django import http
|
||||
from django import shortcuts
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
import horizon
|
||||
from horizon import api
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import time
|
||||
from horizon import views
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -53,7 +48,6 @@ def usage(request, tenant_id=None):
|
||||
usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
|
||||
except:
|
||||
usage = api.nova.Usage(None)
|
||||
redirect = reverse("horizon:nova:overview:index")
|
||||
exceptions.handle(request,
|
||||
_('Unable to retrieve usage information.'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user