Skip to content

Commit

Permalink
Ensure flake8 tests run on all api code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
John Garbutt committed Jul 9, 2013
1 parent ba70576 commit 707a796
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 32 deletions.
3 changes: 2 additions & 1 deletion nova/api/openstack/compute/plugins/v3/agents.py
Expand Up @@ -168,5 +168,6 @@ def get_resources(self):

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 []
4 changes: 2 additions & 2 deletions nova/api/openstack/compute/plugins/v3/coverage.py
Expand Up @@ -39,9 +39,9 @@
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:
Expand Down
5 changes: 3 additions & 2 deletions nova/api/openstack/compute/plugins/v3/extension_info.py
Expand Up @@ -69,7 +69,7 @@ def _translate(self, ext):
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():
Expand All @@ -78,7 +78,8 @@ def _get_extensions(self, context):
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)
Expand Down
2 changes: 1 addition & 1 deletion nova/api/openstack/compute/plugins/v3/flavors.py
Expand Up @@ -146,7 +146,7 @@ def _get_flavors(self, req):


class Flavors(extensions.V3APIExtensionBase):
""" Flavors Extension. """
"""Flavors Extension."""
name = "flavors"
alias = "flavors"
namespace = "http://docs.openstack.org/compute/core/flavors/v3"
Expand Down
6 changes: 4 additions & 2 deletions nova/api/openstack/compute/plugins/v3/hosts.py
Expand Up @@ -201,7 +201,8 @@ def read_enabled(orig_val, msg):

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})
Expand All @@ -219,7 +220,8 @@ def _set_host_maintenance(self, context, host_name, mode=True):
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:
Expand Down
Expand Up @@ -138,5 +138,6 @@ def get_resources(self):

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 []
1 change: 1 addition & 0 deletions nova/api/openstack/compute/plugins/v3/scheduler_hints.py
Expand Up @@ -21,6 +21,7 @@

ALIAS = "os-scheduler-hints"


class SchedulerHintsController(wsgi.Controller):

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion nova/api/openstack/compute/plugins/v3/servers.py
Expand Up @@ -462,7 +462,7 @@ def check_whiteblack_lists(ext):
# 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:
Expand Down
3 changes: 2 additions & 1 deletion nova/api/openstack/compute/plugins/v3/simple_tenant_usage.py
Expand Up @@ -289,5 +289,6 @@ def get_resources(self):

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 []
1 change: 0 additions & 1 deletion nova/tests/api/openstack/compute/plugins/v3/test_cells.py
Expand Up @@ -19,7 +19,6 @@
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
Expand Down
11 changes: 5 additions & 6 deletions nova/tests/api/openstack/compute/plugins/v3/test_config_drive.py
Expand Up @@ -19,8 +19,8 @@
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
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_show(self):
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'])
Expand Down Expand Up @@ -141,7 +141,7 @@ def instance_update(context, uuid, values):
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 = []
Expand Down Expand Up @@ -213,8 +213,8 @@ def create(*args, **kwargs):
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):
Expand Down Expand Up @@ -324,4 +324,3 @@ def test_request_with_config_drive(self):
},
}
self.assertEquals(request['body'], expected)

Expand Up @@ -40,9 +40,11 @@ def __init__(self, name, alias, description, namespace, version):
'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
Expand Down
Expand Up @@ -18,8 +18,8 @@
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
Expand Down
Expand Up @@ -17,7 +17,6 @@
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
Expand Down Expand Up @@ -324,8 +323,8 @@ def test_uptime_non_integer_id(self):

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',
Expand Down
6 changes: 4 additions & 2 deletions nova/tests/api/openstack/compute/plugins/v3/test_images.py
Expand Up @@ -649,8 +649,10 @@ def detail(self, *args, **kwargs):
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()
Expand Down
Expand Up @@ -20,7 +20,6 @@
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
Expand Down
Expand Up @@ -180,7 +180,7 @@ def instance_update(context, uuid, values):
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 = []
Expand Down Expand Up @@ -253,8 +253,8 @@ def create(*args, **kwargs):
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'}
Expand All @@ -268,6 +268,7 @@ def create(*args, **kwargs):
self.stubs.Set(compute_api.API, 'create', create)
self._test_create_extra(params)


class TestServerCreateRequestXMLDeserializer(test.TestCase):

def setUp(self):
Expand Down Expand Up @@ -306,4 +307,3 @@ def test_request_with_scheduler_hints_and_alternate_namespace_prefix(self):
}
}
self.assertEquals(request['body'], expected)

Expand Up @@ -45,7 +45,8 @@ def setUp(self):
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(
Expand Down
3 changes: 2 additions & 1 deletion nova/tests/api/openstack/compute/plugins/v3/test_servers.py
Expand Up @@ -234,7 +234,8 @@ def test_get_server_by_uuid(self):

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,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -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

0 comments on commit 707a796

Please sign in to comment.