Fix the new hacking rules

Change-Id: I256512780251b6c552af6babac3c0677c204aaaa
This commit is contained in:
Angus Salkeld
2014-06-12 16:19:40 +10:00
parent 4830e1c237
commit 4641b4cbe6
42 changed files with 127 additions and 113 deletions

View File

@@ -76,7 +76,7 @@ class AuthInformationHook(hooks.PecanHook):
def before(self, state):
if not CONF.get('enable_authentication'):
return
#Do not proceed for triggers as they use non authenticated service
# Do not proceed for triggers as they use non authenticated service
regexp = re.compile('^/v[0-9]+/public/')
if regexp.match(state.request.path):
return

View File

@@ -17,8 +17,8 @@ from solum.api.controllers.v1.datamodel import types as api_types
class Extension(api_types.Base):
"""The Extension resource represents changes that the Provider has added
onto a Platform in addition to the ones supplied by Solum by default.
"""The Extension resource represents Provider modifications.
This may include additional protocol semantics, resource types,
application lifecycle states, resource attributes, etc. Anything may be
added, as long as it does not contradict the base functionality offered

View File

@@ -176,7 +176,7 @@ class LanguagePack(api_types.Base):
runtime_versions=['1.4', '1.6', '1.7'],
language_implementation='Sun',
build_tool_chain=[BuildTool(type='ant', version='1.7'),
BuildTool(type='maven', version='1.2')],
BuildTool(type='maven', version='1.2')],
os_platform={'OS': 'Ubuntu', 'version': '12.04'},
attributes={'optional_attr1': 'value',
'admin_email': 'someadmin@somewhere.com'},

View File

@@ -15,8 +15,7 @@ from solum.api.controllers.v1.datamodel import types as api_types
class Operation(api_types.Base):
"""An Operation resource represents an operation or action available on a
target resource.
"""An Operation resource represents an operation or action.
This is for defining actions that may change the state of the resource they
are related to. For example, the API already provides ways to register,

View File

@@ -13,6 +13,7 @@
# under the License.
import uuid
import wsme
from wsme.rest import json as wjson
from wsme import types as wtypes

View File

@@ -24,8 +24,9 @@ SENSOR_TYPE = wtypes.Enum(str, 'str', 'float', 'int')
class Sensor(api_types.Base):
"""A Sensor resource represents exactly one supported sensor on one or
more resources. Sensor resources represent dynamic data about resources,
"""A Sensor resource represents exactly one supported sensor.
Sensor resources represent dynamic data about resources,
such as metrics or state. Sensor resources are useful for exposing data
that changes rapidly, or that may need to be fetched from a secondary
system.

View File

@@ -13,6 +13,7 @@
# under the License.
import string
import wsme
from wsme import types as wtypes

View File

@@ -15,6 +15,7 @@
import uuid
from oslo.config import cfg
from solum.api.handlers import handler
from solum.common import context
from solum.common import exception

View File

@@ -17,33 +17,32 @@ import os
from oslo.config import cfg
from solum.openstack.common.db.sqlalchemy.migration_cli \
import manager as migration_manager
from solum.openstack.common.db.sqlalchemy.migration_cli import manager
from solum.openstack.common.db.sqlalchemy import session
CONF = cfg.CONF
def do_version(manager):
print('Current DB revision is %s' % manager.version())
def do_version(mgr):
print('Current DB revision is %s' % mgr.version())
def do_upgrade(manager):
manager.upgrade(CONF.command.revision)
def do_upgrade(mgr):
mgr.upgrade(CONF.command.revision)
def do_downgrade(manager):
manager.downgrade(CONF.command.revision)
def do_downgrade(mgr):
mgr.downgrade(CONF.command.revision)
def do_stamp(manager):
manager.stamp(CONF.command.revision)
def do_stamp(mgr):
mgr.stamp(CONF.command.revision)
def do_revision(manager):
manager.revision(message=CONF.command.message,
autogenerate=CONF.command.autogenerate)
def do_revision(mgr):
mgr.revision(message=CONF.command.message,
autogenerate=CONF.command.autogenerate)
def add_command_parsers(subparsers):
@@ -84,7 +83,7 @@ def get_manager():
migration_config = {'alembic_ini_path': alembic_path,
'migration_repo_path': migrate_path,
'alembic_repo_path': migrate_path}
return migration_manager.MigrationManager(migration_config)
return manager.MigrationManager(migration_config)
def main():

View File

@@ -19,12 +19,12 @@ Includes decorator for re-raising Solum-type exceptions.
"""
import functools
import pecan
import sys
import uuid
from keystoneclient import exceptions as keystone_exceptions
from oslo.config import cfg
import pecan
import six
import wsme
@@ -48,8 +48,9 @@ CONF.register_opts(exc_log_opts)
def wrap_exception(notifier=None, publisher_id=None, event_type=None,
level=None):
"""This decorator wraps a method to catch any exceptions that may
get thrown. It logs the exception as well as optionally sending
"""This decorator wraps a method to catch any exceptions.
It logs the exception as well as optionally sending
it to the notification system.
"""
def inner(f):
@@ -158,9 +159,7 @@ def wrap_pecan_controller_exception(func):
def wrap_keystone_exception(func):
"""This decorator wraps keystone exception by throwing Solum specific
exceptions.
"""
"""Wrap keystone exceptions and throw Solum specific exceptions."""
@functools.wraps(func)
def wrapped(*args, **kw):
try:
@@ -196,8 +195,8 @@ class SolumException(Exception):
try:
self.message = self.msg_fmt % kwargs
except KeyError:
#kwargs doesn't match a variable in the message
#log the issue and the kwargs
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(_('Exception in string format operation'),
extra=dict(
private=dict(

View File

@@ -32,7 +32,7 @@ def getcallargs(function, *args, **kwargs):
keyed_args.update(kwargs)
#NOTE(alaski) the implicit 'self' or 'cls' argument shows up in
# NOTE(alaski) the implicit 'self' or 'cls' argument shows up in
# argnames but not in args or kwargs. Uses 'in' rather than '==' because
# some tests use 'self2'.
if 'self' in argnames[0] or 'cls' == argnames[0]:

View File

@@ -80,15 +80,15 @@ class TraceData(object):
"""
if self._auto_clear is not True:
return ({"request_id": self.request_id,
"user_trace": self._user_data,
"support_trace": self._support_data})
"user_trace": self._user_data,
"support_trace": self._support_data})
user_data = self._user_data.copy()
support_data = self._support_data.copy()
self.clear()
return ({"request_id": self.request_id,
"user_trace": user_data,
"support_trace": support_data})
"user_trace": user_data,
"support_trace": support_data})
@property
def auto_clear(self):

View File

@@ -15,6 +15,7 @@
"""API for interfacing with Solum Conductor."""
from oslo.config import cfg
from solum.common.rpc import service

View File

@@ -15,6 +15,7 @@
"""API for interfacing with Solum Deployer."""
from oslo.config import cfg
from solum.common.rpc import service

View File

@@ -16,10 +16,11 @@
import os
import time
import yaml
from heatclient import exc
from oslo.config import cfg
import yaml
from solum.common import clients
from solum import objects
from solum.objects import assembly
@@ -71,7 +72,7 @@ class Handler(object):
return template
def _get_network_parameters(self, osc):
#TODO(julienvey) In the long term, we should have optional parameters
# TODO(julienvey) In the long term, we should have optional parameters
# if the user wants to override this default behaviour
params = {}
tenant_networks = osc.neutron().list_networks()

View File

@@ -13,7 +13,6 @@
# limitations under the License.
from solum import objects
from solum.objects import assembly as abstract_assembly
from solum.objects import component as abstract_component
from solum.objects import extension as abstract_extension

View File

@@ -12,9 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import sqlalchemy as sa
import uuid
import sqlalchemy as sa
from solum import objects
from solum.objects import component as abstract
from solum.objects.sqlalchemy import models as sql

View File

@@ -17,14 +17,14 @@ SQLAlchemy models for application data.
"""
import json
import six
import yaml
from oslo.config import cfg
import six
from six import moves
from sqlalchemy.ext import declarative
from sqlalchemy.orm import exc
from sqlalchemy import types
import yaml
from solum.common import exception
from solum import objects

View File

@@ -23,8 +23,10 @@ __all__ = ['FunctionalTest']
class FunctionalTest(base.BaseTestCase):
"""Used for functional tests where you need to test your
literal application and its integration with the framework.
"""Used for functional tests.
Where you need to test your literal application and its
integration with the framework.
"""
def setUp(self):

View File

@@ -37,8 +37,8 @@ class TestAssemblyHandler(base.BaseTestCase):
handler = assembly_handler.AssemblyHandler(self.ctx)
res = handler.get('test_id')
self.assertIsNotNone(res)
mock_registry.Assembly.get_by_uuid.\
assert_called_once_with(self.ctx, 'test_id')
get_by_uuid = mock_registry.Assembly.get_by_uuid
get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
def test_assembly_get_all(self, mock_registry):
mock_registry.AssemblyList.get_all.return_value = {}

View File

@@ -31,8 +31,8 @@ class TestComponentHandler(base.BaseTestCase):
handler = component_handler.ComponentHandler(self.ctx)
res = handler.get('test_id')
self.assertIsNotNone(res)
mock_registry.Component.get_by_uuid.\
assert_called_once_with(self.ctx, 'test_id')
get_by_uuid = mock_registry.Component.get_by_uuid
get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
def test_get_all(self, mock_registry):
mock_registry.ComponentList.get_all.return_value = {}

View File

@@ -31,8 +31,8 @@ class TestPlanHandler(base.BaseTestCase):
handler = plan_handler.PlanHandler(self.ctx)
res = handler.get('test_id')
self.assertIsNotNone(res)
mock_registry.Plan.get_by_uuid.\
assert_called_once_with(self.ctx, 'test_id')
get_by_uuid = mock_registry.Plan.get_by_uuid
get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
def test_plan_get_all(self, mock_registry):
mock_registry.PlanList.get_all.return_value = {}

View File

@@ -31,8 +31,8 @@ class TestServiceHandler(base.BaseTestCase):
handler = service_handler.ServiceHandler(self.ctx)
res = handler.get('test_id')
self.assertIsNotNone(res)
mock_registry.Service.get_by_uuid.\
assert_called_once_with(self.ctx, 'test_id')
get_by_uuid = mock_registry.Service.get_by_uuid
get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
def test_get_all(self, mock_registry):
mock_registry.ServiceList.get_all.return_value = {}

View File

@@ -15,7 +15,6 @@
from solum.api import app as api_app
from solum.api import auth
from solum.api import config as api_config
from solum.tests import base

View File

@@ -29,8 +29,8 @@ class TestTriggerController(base.BaseTestCase):
obj = trigger.TriggerController()
obj.post('test_id')
self.assertEqual(202, resp_mock.status)
handler_mock.return_value.trigger_workflow.\
assert_called_once_with('test_id')
tw = handler_mock.return_value.trigger_workflow
tw.assert_called_once_with('test_id')
def test_trigger_post_error(self, handler_mock, resp_mock, request_mock):
obj = trigger.TriggerController()
@@ -38,5 +38,5 @@ class TestTriggerController(base.BaseTestCase):
exception.ResourceNotFound(name='trigger', id='test_id'))
obj.post('test_id')
self.assertEqual(404, resp_mock.status)
handler_mock.return_value.trigger_workflow.\
assert_called_once_with('test_id')
tw = handler_mock.return_value.trigger_workflow
tw.assert_called_once_with('test_id')

View File

@@ -13,6 +13,7 @@
# under the License.
import json
import mock
from solum.api.controllers.v1 import assembly

View File

@@ -13,6 +13,7 @@
# under the License.
import json
import mock
from solum.api.controllers.v1 import component

View File

@@ -13,6 +13,7 @@
# under the License.
import json
import mock
from solum.api.controllers.v1.datamodel import extension as model

View File

@@ -13,8 +13,8 @@
# under the License.
import json
import mock
import mock
import wsme
from solum.api.controllers.v1.datamodel import language_pack as lp_model
@@ -60,7 +60,7 @@ lp_sample = {
"version": "12.04"
},
"build_tool_chain": [lp_model.BuildTool(type="maven", version="3.0"),
lp_model.BuildTool(type="ant", version="2.1")],
lp_model.BuildTool(type="ant", version="2.1")],
"attributes": {
"attr1key": "attr1value",
"attr2key": "attr2value"

View File

@@ -13,6 +13,7 @@
# under the License.
import json
import mock
from solum.api.controllers.v1.datamodel import sensor as model

View File

@@ -12,12 +12,11 @@
from solum.api.controllers.v1.datamodel import component as component_api
from solum import objects
from solum.objects.sqlalchemy import component as component_model
from solum.tests import base
from solum.tests import utils
from solum import objects
class TestTypes(base.BaseTestCase):
def setUp(self):

View File

@@ -31,8 +31,8 @@ class TestImageHandler(base.BaseTestCase):
handler = image_handler.ImageHandler(self.ctx)
res = handler.get('test_id')
self.assertIsNotNone(res)
mock_registry.Image.get_by_uuid.\
assert_called_once_with(self.ctx, 'test_id')
mock_registry.Image.get_by_uuid.assert_called_once_with(
self.ctx, 'test_id')
@mock.patch('solum.builder.handlers.image_handler.'
'ImageHandler._start_build')

View File

@@ -13,6 +13,7 @@
# under the License.
import json
import mock
from solum.builder.controllers.v1 import image

View File

@@ -10,10 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from glanceclient import client as glanceclient
from heatclient import client as heatclient
import mock
from neutronclient.neutron import client as neutronclient
from swiftclient import client as swiftclient
@@ -28,9 +27,10 @@ class ClientsTest(base.BaseTestCase):
def test_url_for(self, mock_keystone):
obj = clients.OpenStackClients(None)
obj.url_for(service_type='fake_service', endpoint_type='fake_endpoint')
mock_keystone.return_value.client.service_catalog.url_for.\
assert_called_once_with(service_type='fake_service',
endpoint_type='fake_endpoint')
service_catalog = mock_keystone.return_value.client.service_catalog
service_catalog.url_for.assert_called_once_with(
service_type='fake_service',
endpoint_type='fake_endpoint')
@mock.patch.object(glanceclient, 'Client')
@mock.patch.object(clients.OpenStackClients, 'url_for')

View File

@@ -18,7 +18,7 @@ from oslo.config import cfg
cfg.CONF.import_group('keystone_authtoken',
'keystoneclient.middleware.auth_token')
import keystoneclient.exceptions as kc_exception
import keystoneclient.exceptions as kc_exception # noqa
from solum.common import exception
from solum.common import solum_keystoneclient

View File

@@ -13,9 +13,10 @@
# under the License.
import json
import mock
import mock
from oslo.config import cfg
from solum.deployer.handlers import heat as heat_handler
from solum.objects import assembly
from solum.tests import base
@@ -48,16 +49,18 @@ class HandlerTest(base.BaseTestCase):
fake_template = json.dumps({'description': 'test'})
mock_get_templ.return_value = fake_template
handler._find_id_if_stack_exists = mock.MagicMock(return_value=(None))
mock_clients.return_value.heat.return_value.stacks.create.\
return_value = {"stack": {"id": "fake_id",
"links": [{"href": "http://fake.ref",
"rel": "self"}]}}
mock_clients.return_value.neutron.return_value.list_networks.\
return_value = {"networks": [{"router:external": True,
"id": "public_net_id"},
{"router:external": False,
"id": "private_net_id",
"subnets": ["private_subnet_id"]}]}
stacks = mock_clients.return_value.heat.return_value.stacks
stacks.create.return_value = {"stack": {
"id": "fake_id",
"links": [{"href": "http://fake.ref",
"rel": "self"}]}}
neutron = mock_clients.return_value.neutron
neutron.return_value.list_networks.return_value = {
"networks": [{"router:external": True,
"id": "public_net_id"},
{"router:external": False,
"id": "private_net_id",
"subnets": ["private_subnet_id"]}]}
handler._update_assembly_status = mock.MagicMock()
handler.deploy(self.ctx, 77, 'created_image_id')
parameters = {'image': 'created_image_id',
@@ -65,12 +68,12 @@ class HandlerTest(base.BaseTestCase):
'private_net': 'private_net_id',
'public_net': 'public_net_id',
'private_subnet': 'private_subnet_id'}
mock_clients.return_value.heat.return_value.stacks.create.\
assert_called_once_with(stack_name='faker-test_uuid',
template=fake_template,
parameters=parameters)
mock_clients.return_value.neutron.return_value.list_networks.\
assert_called_once_with()
stacks = mock_clients.return_value.heat.return_value.stacks
stacks.create.assert_called_once_with(stack_name='faker-test_uuid',
template=fake_template,
parameters=parameters)
neutron = mock_clients.return_value.neutron
neutron.return_value.list_networks.assert_called_once_with()
assign_and_create_mock = mock_registry.Component.assign_and_create
assign_and_create_mock.assert_called_once_with(self.ctx,
fake_assembly,
@@ -91,18 +94,18 @@ class HandlerTest(base.BaseTestCase):
fake_template = json.dumps({'description': 'test'})
mock_get_templ.return_value = fake_template
handler._find_id_if_stack_exists = mock.MagicMock(return_value=(None))
mock_clients.return_value.heat.return_value.stacks.create.\
return_value = {"stack": {"id": "fake_id",
"links": [{"href": "http://fake.ref",
"rel": "self"}]}}
stacks = mock_clients.return_value.heat.return_value.stacks
stacks.create.return_value = {"stack": {
"id": "fake_id",
"links": [{"href": "http://fake.ref",
"rel": "self"}]}}
handler._update_assembly_status = mock.MagicMock()
handler.deploy(self.ctx, 77, 'created_image_id')
parameters = {'image': 'created_image_id',
'app_name': 'faker'}
mock_clients.return_value.heat.return_value.stacks.create.\
assert_called_once_with(stack_name='faker-test_uuid',
template=fake_template,
parameters=parameters)
stacks.create.assert_called_once_with(stack_name='faker-test_uuid',
template=fake_template,
parameters=parameters)
assign_and_create_mock = mock_registry.Component.assign_and_create
assign_and_create_mock.assert_called_once_with(self.ctx,
fake_assembly,
@@ -165,8 +168,8 @@ class HandlerTest(base.BaseTestCase):
mock_registry.Assembly.get_by_id.return_value = fake_assem
handler = heat_handler.Handler()
handler._find_id_if_stack_exists = mock.MagicMock(side_effect=
self._s_efct)
handler._find_id_if_stack_exists = mock.MagicMock(
side_effect=self._s_efct)
cfg.CONF.deployer.max_attempts = 1
cfg.CONF.deployer.wait_interval = 0

View File

@@ -25,17 +25,17 @@ class TestComponent(base.BaseTestCase):
super(TestComponent, self).setUp()
self.db = self.useFixture(utils.Database())
self.ctx = utils.dummy_context()
self.data_assembly = \
[{'project_id': 'project_id_blah',
'uuid': 'ce43e347f0b0422825245b3e5f140a81cef6e65b',
'user_id': 'fred',
'name': 'assembly1',
'description': 'test assembly',
'trigger_id': 'trigger-uuid-1234',
'tags': 'assembly tags',
'plan_id': 'plan_id_1',
'status': 'Building',
'application_uri': 'http://192.168.78.21:5000'}]
self.data_assembly = [
{'project_id': 'project_id_blah',
'uuid': 'ce43e347f0b0422825245b3e5f140a81cef6e65b',
'user_id': 'fred',
'name': 'assembly1',
'description': 'test assembly',
'trigger_id': 'trigger-uuid-1234',
'tags': 'assembly tags',
'plan_id': 'plan_id_1',
'status': 'Building',
'application_uri': 'http://192.168.78.21:5000'}]
utils.create_models_from_data(assembly.Assembly, self.data_assembly,
self.ctx)

View File

@@ -86,8 +86,8 @@ class TestObjectsSqlalchemy(tests.BaseTestCase):
self.assertEqual(component.description, component2.description)
# visible via direct query
query = utils.get_dummy_session().query(component.__class__)\
.filter_by(id=component.id)
dsession = utils.get_dummy_session()
query = dsession.query(component.__class__).filter_by(id=component.id)
component3 = query.first()
self.assertIsNotNone(component3)
self.assertEqual(component3.id, component3.id)

View File

@@ -23,8 +23,9 @@ class TestPlan(base.BaseTestCase):
super(TestPlan, self).setUp()
self.db = self.useFixture(utils.Database())
self.ctx = utils.dummy_context()
raw_content = {'artifacts': [{'content':
{'href': 'http://github.com/some/project'}}]}
raw_content = {'artifacts': [
{'content':
{'href': 'http://github.com/some/project'}}]}
self.data = [{'uuid': 'test-uuid-123',
'project_id': 'bla',
'user_id': 'fred',

View File

@@ -12,10 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
import os.path
import uuid
import mock
from solum.openstack.common.gettextutils import _
from solum.tests import base
from solum.tests import fakes

View File

@@ -15,6 +15,7 @@
"""API for interfacing with Solum Worker."""
from oslo.config import cfg
from solum.common.rpc import service

View File

@@ -18,7 +18,6 @@ import os
import subprocess
import solum
from solum.common import solum_keystoneclient
from solum.conductor import api as conductor_api
from solum.deployer import api as deployer_api
@@ -46,7 +45,7 @@ def job_update_notification(ctxt, build_id, state=None, description=None,
def update_assembly_status(ctxt, assembly_id, status):
#TODO(datsun180b): use conductor to update assembly status
# TODO(datsun180b): use conductor to update assembly status
if assembly_id is None:
return
assem = solum.objects.registry.Assembly.get_by_id(ctxt,