Fix and gate on H302 (import only modules)
H302 is already part of the OpenStack style guide, and we only had a few violations. This fixes and gates on H302, so there is one less thing for a reviewer to worry about. gettext import line is ignored using hacking 0.7's import_exceptions option. Reason for import only modules 'The namespace management convention is simple. The source of each identifier is indicated in a consistent way; x.Obj says that object Obj is defined in module x.' http://google-styleguide.googlecode.com/svn/trunk/pyguide.html Change-Id: I53e8039f1dd2ebf8ab5fcf5a561feb3ca3363107
This commit is contained in:
parent
1b96b77211
commit
686d48d386
@ -20,10 +20,10 @@ Unit tests for EC2 error responses.
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from nova.api.ec2 import ec2_error_ex
|
||||
from nova.context import RequestContext
|
||||
from nova.api import ec2
|
||||
from nova import context
|
||||
from nova import test
|
||||
from nova.wsgi import Request
|
||||
from nova import wsgi
|
||||
|
||||
|
||||
class TestClientExceptionEC2(Exception):
|
||||
@ -37,12 +37,13 @@ class Ec2ErrorResponseTestCase(test.TestCase):
|
||||
Test EC2 error responses.
|
||||
|
||||
This deals mostly with api/ec2/__init__.py code, especially
|
||||
the ec2_error_ex helper.
|
||||
the ec2.ec2_error_ex helper.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(Ec2ErrorResponseTestCase, self).setUp()
|
||||
self.context = RequestContext('test_user_id', 'test_project_id')
|
||||
self.req = Request.blank('/test')
|
||||
self.context = context.RequestContext('test_user_id',
|
||||
'test_project_id')
|
||||
self.req = wsgi.Request.blank('/test')
|
||||
self.req.environ['nova.context'] = self.context
|
||||
|
||||
def _validate_ec2_error(self, response, http_status, ec2_code, msg=None,
|
||||
@ -82,7 +83,7 @@ class Ec2ErrorResponseTestCase(test.TestCase):
|
||||
Test response to client (400) EC2 exception.
|
||||
"""
|
||||
msg = "Test client failure."
|
||||
err = ec2_error_ex(TestClientExceptionEC2(msg), self.req)
|
||||
err = ec2.ec2_error_ex(TestClientExceptionEC2(msg), self.req)
|
||||
self._validate_ec2_error(err, TestClientExceptionEC2.code,
|
||||
TestClientExceptionEC2.ec2_code, msg)
|
||||
|
||||
@ -91,7 +92,7 @@ class Ec2ErrorResponseTestCase(test.TestCase):
|
||||
Test response to an unexpected client (400) exception.
|
||||
"""
|
||||
msg = "Test client failure."
|
||||
err = ec2_error_ex(TestClientExceptionEC2(msg), self.req,
|
||||
err = ec2.ec2_error_ex(TestClientExceptionEC2(msg), self.req,
|
||||
unexpected=True)
|
||||
self._validate_ec2_error(err, TestClientExceptionEC2.code,
|
||||
TestClientExceptionEC2.ec2_code, msg)
|
||||
|
@ -17,7 +17,7 @@ import webob
|
||||
|
||||
from nova.api.ec2 import faults
|
||||
from nova import test
|
||||
from nova.wsgi import Request
|
||||
from nova import wsgi
|
||||
|
||||
|
||||
class TestFaults(test.TestCase):
|
||||
@ -40,7 +40,7 @@ class TestFaults(test.TestCase):
|
||||
message = 'test message'
|
||||
ex = webob.exc.HTTPNotFound(explanation=message)
|
||||
fault = faults.Fault(ex)
|
||||
req = Request.blank('/test')
|
||||
req = wsgi.Request.blank('/test')
|
||||
req.GET['AWSAccessKeyId'] = "test_user_id:test_project_id"
|
||||
self.mox.StubOutWithMock(faults, 'ec2_error_response')
|
||||
faults.ec2_error_response(mox.IgnoreArg(), 'HTTPNotFound',
|
||||
|
@ -77,11 +77,7 @@ from nova.tests.image import fake as fake_image
|
||||
from nova.tests import matchers
|
||||
from nova.tests.objects import test_migration
|
||||
from nova import utils
|
||||
from nova.virt.event import EVENT_LIFECYCLE_PAUSED
|
||||
from nova.virt.event import EVENT_LIFECYCLE_RESUMED
|
||||
from nova.virt.event import EVENT_LIFECYCLE_STARTED
|
||||
from nova.virt.event import EVENT_LIFECYCLE_STOPPED
|
||||
from nova.virt.event import LifecycleEvent
|
||||
from nova.virt import event
|
||||
from nova.virt import fake
|
||||
from nova.volume import cinder
|
||||
|
||||
@ -5284,26 +5280,27 @@ class ComputeTestCase(BaseTestCase):
|
||||
mox.ContainsKeyValue('uuid', uuid),
|
||||
power_state)
|
||||
self.mox.ReplayAll()
|
||||
self.compute.handle_events(LifecycleEvent(uuid, lifecycle_event))
|
||||
self.compute.handle_events(event.LifecycleEvent(uuid, lifecycle_event))
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def test_lifecycle_events(self):
|
||||
self._test_lifecycle_event(EVENT_LIFECYCLE_STOPPED,
|
||||
self._test_lifecycle_event(event.EVENT_LIFECYCLE_STOPPED,
|
||||
power_state.SHUTDOWN)
|
||||
self._test_lifecycle_event(EVENT_LIFECYCLE_STARTED,
|
||||
self._test_lifecycle_event(event.EVENT_LIFECYCLE_STARTED,
|
||||
power_state.RUNNING)
|
||||
self._test_lifecycle_event(EVENT_LIFECYCLE_PAUSED,
|
||||
self._test_lifecycle_event(event.EVENT_LIFECYCLE_PAUSED,
|
||||
power_state.PAUSED)
|
||||
self._test_lifecycle_event(EVENT_LIFECYCLE_RESUMED,
|
||||
self._test_lifecycle_event(event.EVENT_LIFECYCLE_RESUMED,
|
||||
power_state.RUNNING)
|
||||
self._test_lifecycle_event(-1, None)
|
||||
|
||||
def test_lifecycle_event_non_existent_instance(self):
|
||||
# No error raised for non-existent instance because of inherent race
|
||||
# between database updates and hypervisor events. See bug #1180501.
|
||||
event = LifecycleEvent('does-not-exist', EVENT_LIFECYCLE_STOPPED)
|
||||
self.compute.handle_events(event)
|
||||
event_instance = event.LifecycleEvent('does-not-exist',
|
||||
event.EVENT_LIFECYCLE_STOPPED)
|
||||
self.compute.handle_events(event_instance)
|
||||
|
||||
def test_allow_confirm_resize_on_instance_in_deleting_task_state(self):
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
@ -48,8 +48,7 @@ from nova.openstack.common.db import exception as db_exc
|
||||
from nova.openstack.common.db.sqlalchemy import session as db_session
|
||||
from nova.openstack.common import timeutils
|
||||
from nova.openstack.common import uuidutils
|
||||
from nova.quota import ReservableResource
|
||||
from nova.quota import resources
|
||||
from nova import quota
|
||||
from nova import test
|
||||
from nova.tests import matchers
|
||||
from nova import utils
|
||||
@ -95,7 +94,7 @@ def _quota_reserve(context, project_id, user_id):
|
||||
resource, i,
|
||||
user_id=user_id)
|
||||
sync_name = '_sync_%s' % resource
|
||||
resources[resource] = ReservableResource(
|
||||
resources[resource] = quota.ReservableResource(
|
||||
resource, sync_name, 'quota_res_%d' % i)
|
||||
deltas[resource] = i
|
||||
setattr(sqlalchemy_api, sync_name, get_sync(resource, i))
|
||||
@ -4899,8 +4898,8 @@ class QuotaTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
quotas = {}
|
||||
deltas = {}
|
||||
reservable_resources = {}
|
||||
for i, resource in enumerate(resources):
|
||||
if isinstance(resource, ReservableResource):
|
||||
for i, resource in enumerate(quota.resources):
|
||||
if isinstance(resource, quota.ReservableResource):
|
||||
quotas[resource.name] = db.quota_create(self.ctxt, 'project1',
|
||||
resource.name, 100)
|
||||
deltas[resource.name] = i
|
||||
|
@ -30,7 +30,7 @@ from oslo.config import cfg
|
||||
from nova.api.metadata import password
|
||||
from nova.api.openstack.compute.contrib import coverage_ext
|
||||
from nova.api.openstack.compute.contrib import fping
|
||||
from nova.api.openstack.compute.extensions import ExtensionManager as ext_mgr
|
||||
from nova.api.openstack.compute import extensions
|
||||
# Import extensions to pull in osapi_compute_extension CONF option used below.
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova.cells import state
|
||||
@ -1759,7 +1759,8 @@ class ServicesJsonTest(ApiSampleTestBaseV2):
|
||||
Return a list of all running services with the disable reason
|
||||
information if that exists.
|
||||
"""
|
||||
self.stubs.Set(ext_mgr, "is_loaded", self.fake_load)
|
||||
self.stubs.Set(extensions.ExtensionManager, "is_loaded",
|
||||
self.fake_load)
|
||||
response = self._do_get('os-services')
|
||||
self.assertEqual(response.status, 200)
|
||||
subs = {'binary': 'nova-compute',
|
||||
@ -1773,7 +1774,8 @@ class ServicesJsonTest(ApiSampleTestBaseV2):
|
||||
|
||||
def test_service_disable_log_reason(self):
|
||||
"""Disable an existing service and log the reason."""
|
||||
self.stubs.Set(ext_mgr, "is_loaded", self.fake_load)
|
||||
self.stubs.Set(extensions.ExtensionManager, "is_loaded",
|
||||
self.fake_load)
|
||||
subs = {"host": "host1",
|
||||
'binary': 'nova-compute',
|
||||
'disabled_reason': 'test2'}
|
||||
@ -2140,7 +2142,8 @@ class UserQuotasSampleJsonTests(ApiSampleTestBaseV2):
|
||||
|
||||
def test_delete_quotas_for_user(self):
|
||||
# Get api sample to delete quota for user.
|
||||
self.stubs.Set(ext_mgr, "is_loaded", self.fake_load)
|
||||
self.stubs.Set(extensions.ExtensionManager, "is_loaded",
|
||||
self.fake_load)
|
||||
response = self._do_delete('os-quota-sets/fake_tenant?user_id=1')
|
||||
self.assertEqual(response.status, 202)
|
||||
self.assertEqual(response.read(), '')
|
||||
|
@ -17,7 +17,7 @@ import os
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from nova.api.openstack import API_V3_CORE_EXTENSIONS
|
||||
from nova.api.openstack import API_V3_CORE_EXTENSIONS # noqa
|
||||
from nova import test
|
||||
from nova.tests import fake_network
|
||||
from nova.tests import fake_utils
|
||||
|
@ -15,7 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
from nova import test
|
||||
from nova.virt.libvirt.designer import set_vif_bandwidth_config
|
||||
from nova.virt.libvirt import designer
|
||||
|
||||
|
||||
class DesignerTestCase(test.TestCase):
|
||||
@ -27,6 +27,6 @@ class DesignerTestCase(test.TestCase):
|
||||
# The conf will never be user be used, so we can use 'None'.
|
||||
# An empty dictionary is fine: all that matters it that there is no
|
||||
# 'extra_specs' field.
|
||||
set_vif_bandwidth_config(None, {})
|
||||
designer.set_vif_bandwidth_config(None, {})
|
||||
except KeyError as e:
|
||||
self.fail('KeyError: %s' % e)
|
||||
|
@ -16,7 +16,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from collections import namedtuple
|
||||
import collections
|
||||
import re
|
||||
|
||||
from nova import exception
|
||||
@ -159,9 +159,9 @@ class VMwareVMUtilTestCase(test.TestCase):
|
||||
|
||||
def test_property_from_property_set(self):
|
||||
|
||||
ObjectContent = namedtuple('ObjectContent', ['propSet'])
|
||||
DynamicProperty = namedtuple('Property', ['name', 'val'])
|
||||
MoRef = namedtuple('Val', ['value'])
|
||||
ObjectContent = collections.namedtuple('ObjectContent', ['propSet'])
|
||||
DynamicProperty = collections.namedtuple('Property', ['name', 'val'])
|
||||
MoRef = collections.namedtuple('Val', ['value'])
|
||||
|
||||
good_objects = fake.FakeRetrieveResult()
|
||||
results_good = [
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
from nova.tests.virt.xenapi import stubs
|
||||
from nova.virt import fake
|
||||
from nova.virt.xenapi import XenAPIDriver
|
||||
from nova.virt import xenapi
|
||||
|
||||
|
||||
class XenAPIDriverTestCase(stubs.XenAPITestBase):
|
||||
@ -37,7 +37,7 @@ class XenAPIDriverTestCase(stubs.XenAPITestBase):
|
||||
xenapi_connection_password='test_pass')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
|
||||
driver = XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
driver = xenapi.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
driver._session.product_version = (6, 8, 2)
|
||||
|
||||
self.stubs.Set(driver, 'get_host_stats', self.host_stats)
|
||||
|
3
tox.ini
3
tox.ini
@ -46,8 +46,9 @@ commands = {posargs}
|
||||
# TODO Hacking 0.6 checks to fix
|
||||
# H102 Apache 2.0 license header not found
|
||||
|
||||
ignore = E121,E122,E123,E124,E126,E127,E128,E711,E712,H102,H302,H404,F403,F811,F841
|
||||
ignore = E121,E122,E123,E124,E126,E127,E128,E711,E712,H102,H404,F403,F811,F841
|
||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,*plugins/xenserver*,tools
|
||||
|
||||
[hacking]
|
||||
local-check-factory = nova.hacking.checks.factory
|
||||
import_exceptions = nova.openstack.common.gettextutils._
|
||||
|
Loading…
Reference in New Issue
Block a user