Ensure flake8 tests run on all api code
We need to exclude the plugins/xenserver directory because the python2.4 code can't use as in except clauses. The existing exclude directory accidentally included some code in nova/api/openstack/compute/plugins and the related tests. This code is now included in the flake8 tests, and the current violations have been fixed up. Fixes bug 1197858 Change-Id: Ib5f1b65d5d793f0f5854e898ca3ce751e43ef233
This commit is contained in:
parent
ba70576a63
commit
707a7964f4
@ -168,5 +168,6 @@ class Agents(extensions.V3APIExtensionBase):
|
||||
|
||||
def get_controller_extensions(self):
|
||||
"""It's an abstract function V3APIExtensionBase and the extension
|
||||
will not be loaded without it."""
|
||||
will not be loaded without it.
|
||||
"""
|
||||
return []
|
||||
|
@ -39,9 +39,9 @@ ALIAS = "os-coverage"
|
||||
authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS)
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
def _import_coverage():
|
||||
""" This function ensure loading coverage module from python-coverage.
|
||||
"""
|
||||
"""This function ensure loading coverage module from python-coverage."""
|
||||
try:
|
||||
path = sys.path[:]
|
||||
if os.getcwd() in path:
|
||||
|
@ -69,7 +69,7 @@ class ExtensionInfoController(object):
|
||||
return ext_data
|
||||
|
||||
def _get_extensions(self, context):
|
||||
"""Filter extensions list based on policy"""
|
||||
"""Filter extensions list based on policy."""
|
||||
|
||||
discoverable_extensions = dict()
|
||||
for alias, ext in self.extension_info.get_extensions().iteritems():
|
||||
@ -78,7 +78,8 @@ class ExtensionInfoController(object):
|
||||
if authorize(context, action='discoverable'):
|
||||
discoverable_extensions[alias] = ext
|
||||
else:
|
||||
LOG.debug(_("Filter out extension %s from discover list"), alias)
|
||||
LOG.debug(_("Filter out extension %s from discover list"),
|
||||
alias)
|
||||
return discoverable_extensions
|
||||
|
||||
@wsgi.serializers(xml=ExtensionsTemplate)
|
||||
|
@ -146,7 +146,7 @@ class FlavorsController(wsgi.Controller):
|
||||
|
||||
|
||||
class Flavors(extensions.V3APIExtensionBase):
|
||||
""" Flavors Extension. """
|
||||
"""Flavors Extension."""
|
||||
name = "flavors"
|
||||
alias = "flavors"
|
||||
namespace = "http://docs.openstack.org/compute/core/flavors/v3"
|
||||
|
@ -201,7 +201,8 @@ class HostController(object):
|
||||
|
||||
def _set_host_maintenance(self, context, host_name, mode=True):
|
||||
"""Start/Stop host maintenance window. On start, it triggers
|
||||
guest VMs evacuation."""
|
||||
guest VMs evacuation.
|
||||
"""
|
||||
LOG.audit(_("Putting host %(host_name)s in maintenance mode "
|
||||
"%(mode)s."),
|
||||
{'host_name': host_name, 'mode': mode})
|
||||
@ -219,7 +220,8 @@ class HostController(object):
|
||||
def _set_enabled_status(self, context, host_name, enabled):
|
||||
"""Sets the specified host's ability to accept new instances.
|
||||
:param enabled: a boolean - if False no new VMs will be able to start
|
||||
on the host"""
|
||||
on the host.
|
||||
"""
|
||||
if enabled:
|
||||
LOG.audit(_("Enabling host %s.") % host_name)
|
||||
else:
|
||||
|
@ -138,5 +138,6 @@ class InstanceUsageAuditLog(extensions.V3APIExtensionBase):
|
||||
|
||||
def get_controller_extensions(self):
|
||||
"""It's an abstract function V3APIExtensionBase and the extension
|
||||
will not be loaded without it."""
|
||||
will not be loaded without it.
|
||||
"""
|
||||
return []
|
||||
|
@ -21,6 +21,7 @@ from nova.api.openstack import wsgi
|
||||
|
||||
ALIAS = "os-scheduler-hints"
|
||||
|
||||
|
||||
class SchedulerHintsController(wsgi.Controller):
|
||||
|
||||
@staticmethod
|
||||
|
@ -462,7 +462,7 @@ class ServersController(wsgi.Controller):
|
||||
# Check whitelist is either empty or if not then the extension
|
||||
# is in the whitelist
|
||||
if (not CONF.osapi_v3.extensions_whitelist or
|
||||
ext.obj.alias in CONF.osapi_v3.extensions_whitelist):
|
||||
ext.obj.alias in CONF.osapi_v3.extensions_whitelist):
|
||||
|
||||
# Check the extension is not in the blacklist
|
||||
if ext.obj.alias not in CONF.osapi_v3.extensions_blacklist:
|
||||
|
@ -289,5 +289,6 @@ class SimpleTenantUsage(extensions.V3APIExtensionBase):
|
||||
|
||||
def get_controller_extensions(self):
|
||||
"""It's an abstract function V3APIExtensionBase and the extension
|
||||
will not be loaded without it."""
|
||||
will not be loaded without it.
|
||||
"""
|
||||
return []
|
||||
|
@ -19,7 +19,6 @@ from lxml import etree
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import cells as cells_ext
|
||||
from nova.api.openstack import extensions
|
||||
from nova.api.openstack import xmlutil
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova import context
|
||||
|
@ -19,8 +19,8 @@ import uuid
|
||||
from oslo.config import cfg
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import config_drive
|
||||
from nova.api.openstack.compute import plugins
|
||||
from nova.api.openstack.compute.plugins.v3 import config_drive
|
||||
from nova.api.openstack.compute.plugins.v3 import servers
|
||||
from nova.compute import api as compute_api
|
||||
from nova.compute import flavors
|
||||
@ -62,7 +62,7 @@ class ConfigDriveTest(test.TestCase):
|
||||
req = webob.Request.blank('/v3/servers/1')
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
response = req.get_response(fakes.wsgi_app_v3(
|
||||
init_only=('servers','os-config-drive')))
|
||||
init_only=('servers', 'os-config-drive')))
|
||||
self.assertEquals(response.status_int, 200)
|
||||
res_dict = jsonutils.loads(response.body)
|
||||
self.assertTrue('config_drive' in res_dict['server'])
|
||||
@ -141,7 +141,7 @@ class ServersControllerCreateTest(test.TestCase):
|
||||
def rpc_call_wrapper(context, topic, msg, timeout=None):
|
||||
"""Stub out the scheduler creating the instance entry."""
|
||||
if (topic == CONF.scheduler_topic and
|
||||
msg['method'] == 'run_instance'):
|
||||
msg['method'] == 'run_instance'):
|
||||
request_spec = msg['args']['request_spec']
|
||||
num_instances = request_spec.get('num_instances', 1)
|
||||
instances = []
|
||||
@ -213,8 +213,8 @@ class ServersControllerCreateTest(test.TestCase):
|
||||
return old_create(*args, **kwargs)
|
||||
|
||||
self.stubs.Set(compute_api.API, 'create', create)
|
||||
self._test_create_extra(params, override_controller
|
||||
=self.no_config_drive_controller)
|
||||
self._test_create_extra(params,
|
||||
override_controller=self.no_config_drive_controller)
|
||||
|
||||
def test_create_instance_with_config_drive(self):
|
||||
def create(*args, **kwargs):
|
||||
@ -324,4 +324,3 @@ class TestServerCreateRequestXMLDeserializer(test.TestCase):
|
||||
},
|
||||
}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
|
@ -40,9 +40,11 @@ fake_extensions = {
|
||||
'ext3 namespace', 1)
|
||||
}
|
||||
|
||||
|
||||
def fake_policy_enforce(context, action, target, do_raise=True):
|
||||
return True
|
||||
|
||||
|
||||
def fake_policy_enforce_selective(context, action, target, do_raise=True):
|
||||
if action == 'compute_extension:v3:ext1-alias:discoverable':
|
||||
raise exception.NotAuthorized
|
||||
|
@ -18,8 +18,8 @@ import datetime
|
||||
from lxml import etree
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import flavor_access
|
||||
from nova.api.openstack.compute import flavors as flavors_api
|
||||
from nova.api.openstack.compute.plugins.v3 import flavor_access
|
||||
from nova.compute import flavors
|
||||
from nova import context
|
||||
from nova import exception
|
||||
|
@ -17,7 +17,6 @@ from lxml import etree
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import hypervisors
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova.db.sqlalchemy import api as db_api
|
||||
from nova import exception
|
||||
@ -324,8 +323,8 @@ class HypervisorsTest(test.TestCase):
|
||||
|
||||
def test_uptime_non_admin(self):
|
||||
req = fakes.HTTPRequestV3.blank('/os-hypervisors/1/uptime')
|
||||
self.assertRaises(exception.PolicyNotAuthorized, self.controller.uptime,
|
||||
req, '1')
|
||||
self.assertRaises(exception.PolicyNotAuthorized,
|
||||
self.controller.uptime, req, '1')
|
||||
|
||||
def test_search(self):
|
||||
req = fakes.HTTPRequestV3.blank('/os-hypervisors/hyper/search',
|
||||
|
@ -649,8 +649,10 @@ class ImagesControllerTest(test.TestCase):
|
||||
raise exception.Invalid('meow')
|
||||
|
||||
request = fakes.HTTPRequestV3.blank('/v3/os-images?marker=invalid')
|
||||
controller = images.ImagesController(image_service=InvalidImageService())
|
||||
self.assertRaises(webob.exc.HTTPBadRequest, controller.detail, request)
|
||||
controller = images.ImagesController(
|
||||
image_service=InvalidImageService())
|
||||
self.assertRaises(webob.exc.HTTPBadRequest, controller.detail,
|
||||
request)
|
||||
|
||||
def test_generate_alternate_link(self):
|
||||
view = images_view.ViewBuilder()
|
||||
|
@ -20,7 +20,6 @@ from lxml import etree
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import quota_sets as quotas
|
||||
from nova.api.openstack import extensions
|
||||
from nova.api.openstack import wsgi
|
||||
from nova import context as context_maker
|
||||
from nova import quota
|
||||
|
@ -180,7 +180,7 @@ class ServersControllerCreateTest(test.TestCase):
|
||||
def rpc_call_wrapper(context, topic, msg, timeout=None):
|
||||
"""Stub out the scheduler creating the instance entry."""
|
||||
if (topic == CONF.scheduler_topic and
|
||||
msg['method'] == 'run_instance'):
|
||||
msg['method'] == 'run_instance'):
|
||||
request_spec = msg['args']['request_spec']
|
||||
num_instances = request_spec.get('num_instances', 1)
|
||||
instances = []
|
||||
@ -253,8 +253,8 @@ class ServersControllerCreateTest(test.TestCase):
|
||||
return old_create(*args, **kwargs)
|
||||
|
||||
self.stubs.Set(compute_api.API, 'create', create)
|
||||
self._test_create_extra(params, override_controller
|
||||
=self.no_scheduler_hints_controller)
|
||||
self._test_create_extra(params,
|
||||
override_controller=self.no_scheduler_hints_controller)
|
||||
|
||||
def test_create_instance_with_scheduler_hints_enabled(self):
|
||||
hints = {'a': 'b'}
|
||||
@ -268,6 +268,7 @@ class ServersControllerCreateTest(test.TestCase):
|
||||
self.stubs.Set(compute_api.API, 'create', create)
|
||||
self._test_create_extra(params)
|
||||
|
||||
|
||||
class TestServerCreateRequestXMLDeserializer(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -306,4 +307,3 @@ class TestServerCreateRequestXMLDeserializer(test.TestCase):
|
||||
}
|
||||
}
|
||||
self.assertEquals(request['body'], expected)
|
||||
|
||||
|
@ -45,7 +45,8 @@ class ServerDiagnosticsTest(test.TestCase):
|
||||
fake_get_diagnostics)
|
||||
self.stubs.Set(compute_api.API, 'get', fake_instance_get)
|
||||
|
||||
self.router = compute.APIRouterV3(init_only=('servers', 'os-server-diagnostics'))
|
||||
self.router = compute.APIRouterV3(init_only=('servers',
|
||||
'os-server-diagnostics'))
|
||||
|
||||
def test_get_diagnostics(self):
|
||||
req = fakes.HTTPRequestV3.blank(
|
||||
|
@ -234,7 +234,8 @@ class ServersControllerTest(test.TestCase):
|
||||
|
||||
def test_unique_host_id(self):
|
||||
"""Create two servers with the same host and different
|
||||
project_ids and check that the hostId's are unique"""
|
||||
project_ids and check that the hostId's are unique.
|
||||
"""
|
||||
def return_instance_with_host(self, *args):
|
||||
project_id = str(uuid.uuid4())
|
||||
return fakes.stub_instance(id=1, uuid=FAKE_UUID,
|
||||
|
2
tox.ini
2
tox.ini
@ -41,7 +41,7 @@ commands = {posargs}
|
||||
[flake8]
|
||||
ignore = E121,E122,E123,E124,E126,E127,E128,E711,E712,H302,H303,H404,F403,F811,F841,N309
|
||||
builtins = _
|
||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,plugins,tools
|
||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,*plugins/xenserver*,tools
|
||||
|
||||
[hacking]
|
||||
local-check-factory = nova.hacking.checks.factory
|
||||
|
Loading…
x
Reference in New Issue
Block a user