Fix continuation line under/over indented problems

When you are writing a multiple method invocation (or other similar
syntax)

```
obj.method(argument1,
           argument2,
           ...)
```

If you put argument1 in the first line, the following lines should have
the same hanging distance to argument1.

If you put argument1 in the second line, the hanging distance should
always be four.

```
obj.method(
    argument1,
    argument2,
    ...
)
```

Otherwise PEP8 would complain for continuation line under/over indented
problems. See below for more details

https://www.python.org/dev/peps/pep-0008/#indentation

This patch fixes all the continuation line indentation problems and
enables related checks in tox.ini.

Closes-bug: #1459514
Change-Id: I80995c2ae71b817ad78a87ab7c567f0d36112710
changes/88/186388/3
Accela Zhao 7 years ago
parent 433403099a
commit 7344fcf2a7
  1. 67
      magnum/api/controllers/v1/__init__.py
  2. 30
      magnum/api/controllers/v1/bay.py
  3. 76
      magnum/api/controllers/v1/baymodel.py
  4. 4
      magnum/api/controllers/v1/collection.py
  5. 43
      magnum/api/controllers/v1/container.py
  6. 4
      magnum/api/controllers/v1/pod.py
  7. 41
      magnum/api/controllers/v1/replicationcontroller.py
  8. 18
      magnum/api/controllers/v1/service.py
  9. 4
      magnum/api/controllers/v1/types.py
  10. 2
      magnum/api/middleware/parsable_error.py
  11. 2
      magnum/cmd/api.py
  12. 2
      magnum/cmd/conductor.py
  13. 8
      magnum/common/exception.py
  14. 2
      magnum/common/magnum_keystoneclient.py
  15. 8
      magnum/common/utils.py
  16. 30
      magnum/conductor/handlers/bay_conductor.py
  17. 8
      magnum/conductor/handlers/common/kube_utils.py
  18. 26
      magnum/conductor/handlers/docker_conductor.py
  19. 4
      magnum/conductor/handlers/kube.py
  20. 2
      magnum/config.py
  21. 6
      magnum/db/api.py
  22. 13
      magnum/db/sqlalchemy/alembic/versions/592131657ca1_add_coe_column_to_baymodel.py
  23. 4
      magnum/db/sqlalchemy/alembic/versions/59e7664a8ba1_add_container_status.py
  24. 2
      magnum/db/sqlalchemy/alembic/versions/e772b2598d9_add_container_command.py
  25. 23
      magnum/db/sqlalchemy/api.py
  26. 6
      magnum/tests/base.py
  27. 51
      magnum/tests/unit/api/controllers/test_root.py
  28. 30
      magnum/tests/unit/api/controllers/v1/test_bay.py
  29. 86
      magnum/tests/unit/api/controllers/v1/test_baymodel.py
  30. 38
      magnum/tests/unit/api/controllers/v1/test_container.py
  31. 23
      magnum/tests/unit/api/controllers/v1/test_node.py
  32. 32
      magnum/tests/unit/api/controllers/v1/test_pod.py
  33. 63
      magnum/tests/unit/api/controllers/v1/test_replicationcontroller.py
  34. 45
      magnum/tests/unit/api/controllers/v1/test_service.py
  35. 7
      magnum/tests/unit/api/controllers/v1/test_types.py
  36. 4
      magnum/tests/unit/common/test_clients.py
  37. 35
      magnum/tests/unit/common/test_utils.py
  38. 8
      magnum/tests/unit/conductor/handlers/common/test_docker_client.py
  39. 84
      magnum/tests/unit/conductor/handlers/common/test_kube_utils.py
  40. 167
      magnum/tests/unit/conductor/handlers/test_bay_conductor.py
  41. 123
      magnum/tests/unit/conductor/handlers/test_docker_conductor.py
  42. 92
      magnum/tests/unit/conductor/handlers/test_kube.py
  43. 6
      magnum/tests/unit/conductor/test_bay_lock.py
  44. 18
      magnum/tests/unit/conductor/test_template_definition.py
  45. 2
      magnum/tests/unit/db/base.py
  46. 4
      magnum/tests/unit/db/sqlalchemy/test_types.py
  47. 6
      magnum/tests/unit/db/test_bay.py
  48. 14
      magnum/tests/unit/db/test_baymodel.py
  49. 6
      magnum/tests/unit/db/test_container.py
  50. 6
      magnum/tests/unit/db/test_node.py
  51. 6
      magnum/tests/unit/db/test_pod.py
  52. 3
      magnum/tests/unit/db/test_replicationcontroller.py
  53. 9
      magnum/tests/unit/db/test_service.py
  54. 2
      magnum/tests/unit/objects/test_bay.py
  55. 3
      magnum/tests/unit/objects/test_baylock.py
  56. 2
      magnum/tests/unit/objects/test_baymodel.py
  57. 2
      magnum/tests/unit/objects/test_container.py
  58. 2
      magnum/tests/unit/objects/test_node.py
  59. 5
      magnum/tests/unit/objects/test_objects.py
  60. 2
      magnum/tests/unit/objects/test_pod.py
  61. 2
      magnum/tests/unit/objects/test_replicationcontroller.py
  62. 2
      magnum/tests/unit/objects/test_service.py
  63. 2
      tox.ini

@ -116,52 +116,45 @@ class V1(APIBase):
'http://docs.openstack.org',
'developer/magnum/dev',
'api-spec-v1.html',
bookmark=True, type='text/html')
]
bookmark=True, type='text/html')]
v1.media_types = [MediaType('application/json',
'application/vnd.openstack.magnum.v1+json')]
v1.pods = [link.Link.make_link('self', pecan.request.host_url,
'pods', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'pods', '',
bookmark=True)
]
'pods', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'pods', '',
bookmark=True)]
v1.rcs = [link.Link.make_link('self', pecan.request.host_url,
'rcs', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'rcs', '',
bookmark=True)
]
link.Link.make_link('bookmark',
pecan.request.host_url,
'rcs', '',
bookmark=True)]
v1.baymodels = [link.Link.make_link('self', pecan.request.host_url,
'baymodels', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'bays', '',
bookmark=True)
]
'baymodels', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'bays', '',
bookmark=True)]
v1.bays = [link.Link.make_link('self', pecan.request.host_url,
'bays', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'bays', '',
bookmark=True)
]
'bays', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'bays', '',
bookmark=True)]
v1.containers = [link.Link.make_link('self', pecan.request.host_url,
'containers', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'containers', '',
bookmark=True)
]
'containers', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'containers', '',
bookmark=True)]
v1.services = [link.Link.make_link('self', pecan.request.host_url,
'services', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'services', '',
bookmark=True)
]
'services', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'services', '',
bookmark=True)]
return v1

@ -113,15 +113,14 @@ class Bay(base.APIBase):
def _convert_with_links(bay, url, expand=True):
if not expand:
bay.unset_fields_except(['uuid', 'name', 'baymodel_id',
'node_count', 'status',
'bay_create_timeout'])
'node_count', 'status',
'bay_create_timeout'])
bay.links = [link.Link.make_link('self', url,
'bays', bay.uuid),
link.Link.make_link('bookmark', url,
'bays', bay.uuid,
bookmark=True)
]
'bays', bay.uuid),
link.Link.make_link('bookmark', url,
'bays', bay.uuid,
bookmark=True)]
return bay
@classmethod
@ -157,7 +156,7 @@ class BayCollection(collection.Collection):
def convert_with_links(rpc_bays, limit, url=None, expand=False, **kwargs):
collection = BayCollection()
collection.bays = [Bay.convert_with_links(p, expand)
for p in rpc_bays]
for p in rpc_bays]
collection.next = collection.get_next(limit, url=url, **kwargs)
return collection
@ -182,8 +181,8 @@ class BaysController(rest.RestController):
}
def _get_bays_collection(self, marker, limit,
sort_key, sort_dir, expand=False,
resource_url=None):
sort_key, sort_dir, expand=False,
resource_url=None):
limit = api_utils.validate_limit(limit)
sort_dir = api_utils.validate_sort_dir(sort_dir)
@ -191,11 +190,12 @@ class BaysController(rest.RestController):
marker_obj = None
if marker:
marker_obj = objects.Bay.get_by_uuid(pecan.request.context,
marker)
marker)
bays = pecan.request.rpcapi.bay_list(pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
bays = pecan.request.rpcapi.bay_list(
pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
return BayCollection.convert_with_links(bays, limit,
url=resource_url,
@ -220,7 +220,7 @@ class BaysController(rest.RestController):
@wsme_pecan.wsexpose(BayCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text)
def detail(self, bay_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc'):
sort_key='id', sort_dir='asc'):
"""Retrieve a list of bays with detail.
:param bay_uuid: UUID of a bay, to get only bays for that bay.

@ -116,10 +116,10 @@ class BayModel(base.APIBase):
'apiserver_port', 'coe'])
baymodel.links = [link.Link.make_link('self', url,
'baymodels', baymodel.uuid),
link.Link.make_link('bookmark', url,
'baymodels', baymodel.uuid,
bookmark=True)
'baymodels', baymodel.uuid),
link.Link.make_link('bookmark', url,
'baymodels', baymodel.uuid,
bookmark=True)
]
return baymodel
@ -131,22 +131,23 @@ class BayModel(base.APIBase):
@classmethod
def sample(cls, expand=True):
sample = cls(uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
name='example',
image_id='Fedora-k8s',
flavor_id='m1.small',
master_flavor_id='m1.small',
dns_nameserver='8.8.1.1',
keypair_id='keypair1',
external_network_id='ffc44e4a-2319-4062-bce0-9ae1c38b05ba',
fixed_network='private',
apiserver_port=8080,
docker_volume_size=25,
cluster_distro='fedora-atomic',
ssh_authorized_key='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB',
coe='kubernetes',
created_at=datetime.datetime.utcnow(),
updated_at=datetime.datetime.utcnow())
sample = cls(
uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
name='example',
image_id='Fedora-k8s',
flavor_id='m1.small',
master_flavor_id='m1.small',
dns_nameserver='8.8.1.1',
keypair_id='keypair1',
external_network_id='ffc44e4a-2319-4062-bce0-9ae1c38b05ba',
fixed_network='private',
apiserver_port=8080,
docker_volume_size=25,
cluster_distro='fedora-atomic',
ssh_authorized_key='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB',
coe='kubernetes',
created_at=datetime.datetime.utcnow(),
updated_at=datetime.datetime.utcnow())
return cls._convert_with_links(sample, 'http://localhost:9511', expand)
@ -164,7 +165,7 @@ class BayModelCollection(collection.Collection):
**kwargs):
collection = BayModelCollection()
collection.baymodels = [BayModel.convert_with_links(p, expand)
for p in rpc_baymodels]
for p in rpc_baymodels]
collection.next = collection.get_next(limit, url=url, **kwargs)
return collection
@ -187,8 +188,8 @@ class BayModelsController(rest.RestController):
}
def _get_baymodels_collection(self, marker, limit,
sort_key, sort_dir, expand=False,
resource_url=None):
sort_key, sort_dir, expand=False,
resource_url=None):
limit = api_utils.validate_limit(limit)
sort_dir = api_utils.validate_sort_dir(sort_dir)
@ -196,17 +197,17 @@ class BayModelsController(rest.RestController):
marker_obj = None
if marker:
marker_obj = objects.BayModel.get_by_uuid(pecan.request.context,
marker)
marker)
baymodels = objects.BayModel.list(pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
return BayModelCollection.convert_with_links(baymodels, limit,
url=resource_url,
expand=expand,
sort_key=sort_key,
sort_dir=sort_dir)
url=resource_url,
expand=expand,
sort_key=sort_key,
sort_dir=sort_dir)
def _get_image_data(self, context, image_ident):
"""Retrieves os_distro and other metadata from the Glance image.
@ -234,12 +235,12 @@ class BayModelsController(rest.RestController):
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
"""
return self._get_baymodels_collection(marker, limit, sort_key,
sort_dir)
sort_dir)
@wsme_pecan.wsexpose(BayModelCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text)
def detail(self, baymodel_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc'):
sort_key='id', sort_dir='asc'):
"""Retrieve a list of baymodels with detail.
:param baymodel_uuid: UUID of a baymodel, to get only baymodels for
@ -257,8 +258,8 @@ class BayModelsController(rest.RestController):
expand = True
resource_url = '/'.join(['baymodels', 'detail'])
return self._get_baymodels_collection(marker, limit,
sort_key, sort_dir, expand,
resource_url)
sort_key, sort_dir, expand,
resource_url)
@wsme_pecan.wsexpose(BayModel, types.uuid_or_name)
def get_one(self, baymodel_ident):
@ -296,7 +297,7 @@ class BayModelsController(rest.RestController):
new_baymodel.create()
# Set the HTTP Location Header
pecan.response.location = link.build_url('baymodels',
new_baymodel.uuid)
new_baymodel.uuid)
return BayModel.convert_with_links(new_baymodel)
@wsme.validate(types.uuid, [BayModelPatchType])
@ -311,10 +312,11 @@ class BayModelsController(rest.RestController):
raise exception.OperationNotPermitted
rpc_baymodel = objects.BayModel.get_by_uuid(pecan.request.context,
baymodel_uuid)
baymodel_uuid)
try:
baymodel_dict = rpc_baymodel.as_dict()
baymodel = BayModel(**api_utils.apply_jsonpatch(baymodel_dict,
baymodel = BayModel(**api_utils.apply_jsonpatch(
baymodel_dict,
patch))
except api_utils.JSONPATCH_EXCEPTIONS as e:
raise exception.PatchError(patch=patch, reason=e)

@ -41,8 +41,8 @@ class Collection(base.APIBase):
resource_url = url or self._type
q_args = ''.join(['%s=%s&' % (key, kwargs[key]) for key in kwargs])
next_args = '?%(args)slimit=%(limit)d&marker=%(marker)s' % {
'args': q_args, 'limit': limit,
'marker': self.collection[-1].uuid}
'args': q_args, 'limit': limit,
'marker': self.collection[-1].uuid}
return link.Link.make_link('next', pecan.request.host_url,
resource_url, next_args).href

@ -103,12 +103,13 @@ class Container(base.APIBase):
container.unset_fields_except(['uuid', 'name', 'bay_uuid',
'image_id', 'command', 'status'])
container.links = [link.Link.make_link('self', url,
'containers', container.uuid),
link.Link.make_link('bookmark', url,
'containers', container.uuid,
bookmark=True)
]
container.links = [link.Link.make_link(
'self', url,
'containers', container.uuid),
link.Link.make_link(
'bookmark', url,
'containers', container.uuid,
bookmark=True)]
return container
@classmethod
@ -144,7 +145,7 @@ class ContainerCollection(collection.Collection):
expand=False, **kwargs):
collection = ContainerCollection()
collection.containers = [Container.convert_with_links(p, expand)
for p in rpc_containers]
for p in rpc_containers]
collection.next = collection.get_next(limit, url=url, **kwargs)
return collection
@ -230,7 +231,7 @@ class LogsController(object):
container_uuid = api_utils.get_rpc_resource('Container',
container_ident).uuid
LOG.debug('Calling conductor.container_logs with %s' %
container_uuid)
container_uuid)
return pecan.request.rpcapi.container_logs(container_uuid)
@ -270,8 +271,8 @@ class ContainersController(rest.RestController):
}
def _get_containers_collection(self, marker, limit,
sort_key, sort_dir, expand=False,
resource_url=None):
sort_key, sort_dir, expand=False,
resource_url=None):
limit = api_utils.validate_limit(limit)
sort_dir = api_utils.validate_sort_dir(sort_dir)
@ -279,19 +280,19 @@ class ContainersController(rest.RestController):
marker_obj = None
if marker:
marker_obj = objects.Container.get_by_uuid(pecan.request.context,
marker)
marker)
containers = objects.Container.list(pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
containers = [pecan.request.rpcapi.container_show(c.uuid)
for c in containers]
for c in containers]
return ContainerCollection.convert_with_links(containers, limit,
url=resource_url,
expand=expand,
sort_key=sort_key,
sort_dir=sort_dir)
url=resource_url,
expand=expand,
sort_key=sort_key,
sort_dir=sort_dir)
@wsme_pecan.wsexpose(ContainerCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text)
@ -310,7 +311,7 @@ class ContainersController(rest.RestController):
@wsme_pecan.wsexpose(ContainerCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text)
def detail(self, container_uuid=None, marker=None, limit=None,
sort_key='id', sort_dir='asc'):
sort_key='id', sort_dir='asc'):
"""Retrieve a list of containers with detail.
:param container_uuid: UUID of a container, to get only containers
@ -327,8 +328,8 @@ class ContainersController(rest.RestController):
expand = True
resource_url = '/'.join(['containers', 'detail'])
return self._get_containers_collection(marker, limit,
sort_key, sort_dir, expand,
resource_url)
sort_key, sort_dir, expand,
resource_url)
@wsme_pecan.wsexpose(Container, types.uuid_or_name)
def get_one(self, container_ident):
@ -361,8 +362,8 @@ class ContainersController(rest.RestController):
new_container = objects.Container(context, **container_dict)
new_container.create()
res_container = pecan.request.rpcapi.container_create(
new_container.name, new_container.uuid,
new_container)
new_container.name, new_container.uuid,
new_container)
# Set the HTTP Location Header
pecan.response.location = link.build_url('containers',

@ -185,8 +185,8 @@ class PodsController(rest.RestController):
marker)
pods = pecan.request.rpcapi.pod_list(pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
return PodCollection.convert_with_links(pods, limit,
url=resource_url,

@ -76,11 +76,10 @@ class ReplicationController(v1_base.K8sResourceBase):
'labels', 'replicas'])
rc.links = [link.Link.make_link('self', url,
'rcs', rc.uuid),
link.Link.make_link('bookmark', url,
'rcs', rc.uuid,
bookmark=True)
]
'rcs', rc.uuid),
link.Link.make_link('bookmark', url,
'rcs', rc.uuid,
bookmark=True)]
return rc
@classmethod
@ -182,7 +181,7 @@ class ReplicationControllerCollection(collection.Collection):
def convert_with_links(rpc_rcs, limit, url=None, expand=False, **kwargs):
collection = ReplicationControllerCollection()
collection.rcs = [ReplicationController.convert_with_links(p, expand)
for p in rpc_rcs]
for p in rpc_rcs]
collection.next = collection.get_next(limit, url=url, **kwargs)
return collection
@ -208,8 +207,8 @@ class ReplicationControllersController(rest.RestController):
}
def _get_rcs_collection(self, marker, limit,
sort_key, sort_dir, expand=False,
resource_url=None):
sort_key, sort_dir, expand=False,
resource_url=None):
limit = api_utils.validate_limit(limit)
sort_dir = api_utils.validate_sort_dir(sort_dir)
@ -217,18 +216,20 @@ class ReplicationControllersController(rest.RestController):
marker_obj = None
if marker:
marker_obj = objects.ReplicationController.get_by_uuid(
pecan.request.context,
marker)
pecan.request.context,
marker)
rcs = pecan.request.rpcapi.rc_list(pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
rcs = pecan.request.rpcapi.rc_list(
pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
return ReplicationControllerCollection.convert_with_links(rcs, limit,
url=resource_url,
expand=expand,
sort_key=sort_key,
sort_dir=sort_dir)
return ReplicationControllerCollection.convert_with_links(
rcs, limit,
url=resource_url,
expand=expand,
sort_key=sort_key,
sort_dir=sort_dir)
@wsme_pecan.wsexpose(ReplicationControllerCollection, types.uuid,
types.uuid, int, wtypes.text, wtypes.text)
@ -265,8 +266,8 @@ class ReplicationControllersController(rest.RestController):
expand = True
resource_url = '/'.join(['rcs', 'detail'])
return self._get_rcs_collection(marker, limit,
sort_key, sort_dir, expand,
resource_url)
sort_key, sort_dir, expand,
resource_url)
@wsme_pecan.wsexpose(ReplicationController, types.uuid_or_name)
def get_one(self, rc_ident):

@ -95,13 +95,9 @@ class Service(v1_base.K8sResourceBase):
labels={'label1': 'foo'},
selector={'label1': 'foo'},
ip='172.17.2.2',
ports=[
{
"port": 88,
"targetPort": 6379,
"protocol": "TCP"
}
],
ports=[{"port": 88,
"targetPort": 6379,
"protocol": "TCP"}],
manifest_url='file:///tmp/rc.yaml',
manifest='''{
"metadata": {
@ -201,10 +197,10 @@ class ServicesController(rest.RestController):
marker)
services = pecan.request.rpcapi.service_list(pecan.request.context,
limit,
marker_obj,
sort_key=sort_key,
sort_dir=sort_dir)
limit,
marker_obj,
sort_key=sort_key,
sort_dir=sort_dir)
return ServiceCollection.convert_with_links(services, limit,
url=resource_url,

@ -146,8 +146,8 @@ class MultiType(wtypes.UserType):
pass
else:
raise ValueError(
_("Wrong type. Expected '%(type)s', got '%(value)s'")
% {'type': self.types, 'value': type(value)})
_("Wrong type. Expected '%(type)s', got '%(value)s'")
% {'type': self.types, 'value': type(value)})
macaddress = MacAddressType()

@ -66,7 +66,7 @@ class ParsableErrorMiddleware(object):
if (state['status_code'] // 100) not in (2, 3):
req = webob.Request(environ)
if (req.accept.best_match(['application/json', 'application/xml'])
== 'application/xml'):
== 'application/xml'):
try:
# simple check xml is valid
body = [et.ElementTree.tostring(

@ -45,7 +45,7 @@ def main():
if host == '0.0.0.0':
LOG.info(_LI('serving on 0.0.0.0:%(port)s, '
'view at http://127.0.0.1:%(port)s') %
'view at http://127.0.0.1:%(port)s') %
dict(port=port))
else:
LOG.info(_LI('serving on http://%(host)s:%(port)s') %

@ -52,7 +52,7 @@ def main():
]
if (not os.path.isfile(cfg.CONF.bay.k8s_atomic_template_path)
and not os.path.isfile(cfg.CONF.bay.k8s_coreos_template_path)):
and not os.path.isfile(cfg.CONF.bay.k8s_coreos_template_path)):
LOG.error(_LE("The Heat template can not be found for either k8s "
"atomic %(atomic_template)s or coreos "
"(coreos_template)%s. Install template first if you "

@ -41,7 +41,7 @@ CONF = cfg.CONF
try:
CONF.import_opt('fatal_exception_format_errors',
'oslo_versionedobjects.exception')
'oslo_versionedobjects.exception')
except cfg.NoSuchOptError as e:
# Note:work around for magnum run against master branch
# in devstack gate job, as magnum not branched yet
@ -126,8 +126,8 @@ def wrap_controller_exception(func, func_server_error, func_client_error):
# correlation id
log_correlation_id = str(uuid.uuid4())
LOG.error(_LE("%(correlation_id)s:%(excp)s") %
{'correlation_id': log_correlation_id,
'excp': str(excp)})
{'correlation_id': log_correlation_id,
'excp': str(excp)})
# raise a client error with an obfuscated message
func_server_error(log_correlation_id, http_error_code)
else:
@ -216,7 +216,7 @@ class MagnumException(Exception):
LOG.exception(_LE('Exception in string format operation'))
for name, value in kwargs.iteritems():
LOG.error(_LE("%(name)s: %(value)s") %
{'name': name, 'value': value})
{'name': name, 'value': value})
try:
if CONF.fatal_exception_format_errors:
raise e

@ -123,7 +123,7 @@ class KeystoneClientV3(object):
kwargs['project_id'] = self.context.project_id
else:
LOG.error(_LE("Keystone v3 API connection failed, no password "
"trust or auth_token!"))
"trust or auth_token!"))
raise exception.AuthorizationFailure()
client = kc_v3.Client(**kwargs)
if 'auth_ref' not in kwargs:

@ -253,7 +253,7 @@ def is_valid_cidr(address):
ip_segment = address.split('/')
if (len(ip_segment) <= 1 or
ip_segment[1] == ''):
ip_segment[1] == ''):
return False
return True
@ -442,7 +442,7 @@ def unlink_without_raise(path):
return
else:
LOG.warn(_LW("Failed to unlink %(path)s, error: %(e)s"),
{'path': path, 'e': e})
{'path': path, 'e': e})
def rmtree_without_raise(path):
@ -451,7 +451,7 @@ def rmtree_without_raise(path):
shutil.rmtree(path)
except OSError as e:
LOG.warn(_LW("Failed to remove dir %(path)s, error: %(e)s"),
{'path': path, 'e': e})
{'path': path, 'e': e})
def write_to_file(path, contents):
@ -468,7 +468,7 @@ def create_link_without_raise(source, link):
else:
LOG.warn(_LW("Failed to create symlink from %(source)s to %(link)s"
", error: %(e)s"),
{'source': source, 'link': link, 'e': e})
{'source': source, 'link': link, 'e': e})
def safe_rstrip(value, chars=None):

@ -45,7 +45,7 @@ bay_heat_opts = [
cfg.IntOpt('bay_create_timeout',
default=None,
help=('The length of time to let bay creation continue. This '
'interval is in minutes. The default is no timeout.'))
'interval is in minutes. The default is no timeout.'))
]
cfg.CONF.register_opts(bay_heat_opts, group='bay_heat')
@ -148,7 +148,7 @@ class Handler(object):
osc = clients.OpenStackClients(context)
stack = osc.heat().stacks.get(bay.stack_id)
if (stack.stack_status != bay_status.CREATE_COMPLETE and
stack.stack_status != bay_status.UPDATE_COMPLETE):
stack.stack_status != bay_status.UPDATE_COMPLETE):
operation = _('Updating a bay when stack status is '
'"%s"') % stack.stack_status
raise exception.NotSupported(operation=operation)
@ -217,7 +217,7 @@ class HeatPoller(object):
# so another user/client can call delete bay/stack.
if stack.stack_status == bay_status.DELETE_COMPLETE:
LOG.info(_LI('Bay has been deleted, stack_id: %s')
% self.bay.stack_id)
% self.bay.stack_id)
self.bay.destroy()
raise loopingcall.LoopingCallDone()
if (stack.stack_status in [bay_status.CREATE_COMPLETE,
@ -233,20 +233,20 @@ class HeatPoller(object):
if stack.stack_status == bay_status.CREATE_FAILED:
LOG.error(_LE('Unable to create bay, stack_id: %(stack_id)s, '
'reason: %(reason)s') %
{'stack_id': self.bay.stack_id,
'reason': stack.stack_status_reason})
{'stack_id': self.bay.stack_id,
'reason': stack.stack_status_reason})
raise loopingcall.LoopingCallDone()
if stack.stack_status == bay_status.DELETE_FAILED:
LOG.error(_LE('Unable to delete bay, stack_id: %(stack_id)s, '
'reason: %(reason)s') %
{'stack_id': self.bay.stack_id,
'reason': stack.stack_status_reason})
{'stack_id': self.bay.stack_id,
'reason': stack.stack_status_reason})
raise loopingcall.LoopingCallDone()
if stack.stack_status == bay_status.UPDATE_FAILED:
LOG.error(_LE('Unable to update bay, stack_id: %(stack_id)s, '
'reason: %(reason)s') %
{'stack_id': self.bay.stack_id,
'reason': stack.stack_status_reason})
{'stack_id': self.bay.stack_id,
'reason': stack.stack_status_reason})
raise loopingcall.LoopingCallDone()
# only check max attempts when the stack is being created when
# the timeout hasn't been set. If the timeout has been set then
@ -256,15 +256,15 @@ class HeatPoller(object):
self.attempts > cfg.CONF.bay_heat.max_attempts):
LOG.error(_LE('Bay check exit after %(attempts)s attempts,'
'stack_id: %(id)s, stack_status: %(status)s') %
{'attempts': cfg.CONF.bay_heat.max_attempts,
'id': self.bay.stack_id,
'status': stack.stack_status})
{'attempts': cfg.CONF.bay_heat.max_attempts,
'id': self.bay.stack_id,
'status': stack.stack_status})
raise loopingcall.LoopingCallDone()
else:
if self.attempts > cfg.CONF.bay_heat.max_attempts:
LOG.error(_LE('Bay check exit after %(attempts)s attempts,'
'stack_id: %(id)s, stack_status: %(status)s') %
{'attempts': cfg.CONF.bay_heat.max_attempts,
'id': self.bay.stack_id,
'status': stack.stack_status})
{'attempts': cfg.CONF.bay_heat.max_attempts,
'id': self.bay.stack_id,
'status': stack.stack_status})
raise loopingcall.LoopingCallDone()

@ -88,7 +88,7 @@ class KubeClient(object):
except Exception as e:
LOG.error(_LE("Couldn't create service with contents %(content)s "
"due to error %(error)s") %
{'content': service, 'error': e})
{'content': service, 'error': e})
return False
return True
@ -102,7 +102,7 @@ class KubeClient(object):
except Exception as e:
LOG.error(_LE("Couldn't update service with contents %(content)s "
"due to error %(error)s") %
{'content': service, 'error': e})
{'content': service, 'error': e})
return False
return True
@ -130,7 +130,7 @@ class KubeClient(object):
except Exception as e:
LOG.error(_LE("Couldn't create pod with contents %(content)s "
"due to error %(error)s") %
{'content': pod, 'error': e})
{'content': pod, 'error': e})
return False
return True
@ -201,6 +201,6 @@ class KubeClient(object):
return False
except Exception as e:
LOG.error(_LE("Couldn't delete rc %(rc)s due to error %(error)s")
% {'rc': name, 'error': e})
% {'rc': name, 'error': e})
return False
return True

@ -66,7 +66,7 @@ def wrap_container_exception(f):
{'name': container_uuid,
'error': str(e)})
raise exception.ContainerException(
"Docker internal Error: %s" % str(e))
"Docker internal Error: %s" % str(e))
return functools.wraps(f)(wrapped)
@ -92,9 +92,11 @@ class Handler(object):
@staticmethod
def _docker_for_bay(bay):
tcp_url = 'tcp://%s:2376' % bay.api_address
return docker_client.DockerHTTPClient(tcp_url,
CONF.docker.docker_remote_api_version,
CONF.docker.default_timeout)
return docker_client.DockerHTTPClient(
tcp_url,
CONF.docker.docker_remote_api_version,
CONF.docker.default_timeout
)
@classmethod
def _docker_for_container(cls, context, container):
@ -127,7 +129,7 @@ class Handler(object):
except errors.APIError as api_error:
container.status = obj_container.ERROR
raise exception.ContainerException(
"Docker API Error : %s" % str(api_error))
"Docker API Error : %s" % str(api_error))
finally:
container.save()
@ -142,7 +144,7 @@ class Handler(object):
return docker.remove_container(docker_id)
except errors.APIError as api_error:
raise exception.ContainerException(
"Docker API Error : %s" % str(api_error))
"Docker API Error : %s" % str(api_error))
@wrap_container_exception
def container_show(self, context, container_uuid):
@ -171,7 +173,7 @@ class Handler(object):
container.save()
return container
raise exception.ContainerException(
"Docker API Error : %s" % (error_message))
"Docker API Error : %s" % (error_message))
@wrap_container_exception
def _container_action(self, context, container_uuid, status, docker_func):
@ -186,7 +188,7 @@ class Handler(object):
return result
except errors.APIError as api_error:
raise exception.ContainerException(
"Docker API Error : %s" % str(api_error))
"Docker API Error : %s" % str(api_error))
def container_reboot(self, context, container_uuid):
return self._container_action(context, container_uuid,
@ -217,7 +219,7 @@ class Handler(object):
return {'output': docker.get_container_logs(docker_id)}
except errors.APIError as api_error:
raise exception.ContainerException(
"Docker API Error : %s" % str(api_error))
"Docker API Error : %s" % str(api_error))
@wrap_container_exception
def container_execute(self, context, container_uuid, command):
@ -227,9 +229,9 @@ class Handler(object):
try:
docker_id = self._find_container_by_name(docker, container_uuid)
create_res = docker.exec_create(docker_id, command, True,
True, False)
True, False)
return {'output': docker.exec_start(create_res, False,
False, False)}
False, False)}
except errors.APIError as api_error:
raise exception.ContainerException(
"Docker API Error : %s" % str(api_error))
"Docker API Error : %s" % str(api_error))

@ -32,8 +32,8 @@ LOG = logging.getLogger(__name__)
kubernetes_opts = [
cfg.StrOpt('k8s_protocol',
default='http',
help=_('Default protocol of k8s master endpoint'
' (http or https).')),
help=_('Default protocol of k8s master endpoint '
'(http or https).')),
cfg.IntOpt('k8s_port',
default=8080,
help=_('Default port of the k8s master endpoint.')),

@ -61,7 +61,7 @@ logging = {
'()': 'pecan.log.ColorFormatter',
'format': ('%(asctime)s [%(padded_color_levelname)s] [%(name)s]'
'[%(threadName)s] %(message)s'),
'__force_dict__': True
'__force_dict__': True
}
}
}

@ -331,7 +331,7 @@ class Connection(object):
@abc.abstractmethod
def get_node_list(self, context, columns=None, filters=None, limit=None,
marker=None, sort_key=None, sort_dir=None):
marker=None, sort_key=None, sort_dir=None):
"""Get specific columns for matching nodes.
Return a list of the specified columns for all nodes that match the
@ -495,7 +495,7 @@ class Connection(object):
@abc.abstractmethod
def get_service_list(self, context, columns=None, filters=None, limit=None,
marker=None, sort_key=None, sort_dir=None):
marker=None, sort_key=None, sort_dir=None):
"""Get specific columns for matching services.
Return a list of the specified columns for all services that match the
@ -587,7 +587,7 @@ class Connection(object):
@abc.abstractmethod
def get_rc_list(self, context, columns=None, filters=None, limit=None,
marker=None, sort_key=None, sort_dir=None):
marker=None, sort_key=None, sort_dir=None):
"""Get specific columns for matching ReplicationController.
Return a list of the specified columns for all rcs that match the

@ -30,10 +30,10 @@ from magnum.i18n import _
bay_heat_opts = [
cfg.StrOpt('cluster_coe',
default='kubernetes',
help=_('Container Orchestration Environments are '
'kubernetes or swarm. ')),
cfg.StrOpt('cluster_coe',
default='kubernetes',
help=_('Container Orchestration Environments are '
'kubernetes or swarm.'))
]
cfg.CONF.register_opts(bay_heat_opts, group='bay_heat')
@ -46,7 +46,6 @@ def upgrade():
baymodel = sa.sql.table('baymodel',
sa.sql.column('coe', sa.String(length=255)))
op.execute(
baymodel.update().values({'coe':
op.inline_literal(
cfg.CONF.bay_heat.cluster_coe)})
baymodel.update().values({
'coe': op.inline_literal(cfg.CONF.bay_heat.cluster_coe)})
)

@ -28,5 +28,5 @@ import sqlalchemy as sa
def upgrade():
op.add_column('container',
sa.Column('status', sa.String(length=20),
nullable=True))
sa.Column('status', sa.String(length=20),
nullable=True))

@ -28,4 +28,4 @@ import sqlalchemy as sa
def upgrade():
op.add_column('container',
sa.Column('command', sa.String(length=255),
nullable=True))
nullable=True))

@ -138,7 +138,7 @@ class Connection(api.Connection):
return query
def get_bay_list(self, context, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None):
sort_key=None, sort_dir=None):
query = model_query(models.Bay)
query = self._add_tenant_filters(context, query)
query = self._add_bays_filters(query, filters)
@ -292,7 +292,7 @@ class Connection(api.Connection):
query = query.filter_by(flavor_id=filters['flavor_id'])
if 'master_flavor_id' in filters:
query = query.filter_by(
master_flavor_id=filters['master_flavor_id'])
master_flavor_id=filters['master_flavor_id'])
if 'keypair_id' in filters:
query = query.filter_by(keypair_id=filters['keypair_id'])
if 'external_network_id' in filters:
@ -308,7 +308,7 @@ class Connection(api.Connection):
return query
def get_baymodel_list(self, context, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None):
sort_key=None, sort_dir=None):
query = model_query(models.BayModel)
query = self._add_tenant_filters(context, query)
query = self._add_baymodels_filters(query, filters)
@ -599,8 +599,9 @@ class Connection(api.Connection):
# Prevent ironic_node_id overwriting
if values.get("ironic_node_id") and ref.ironic_node_id:
raise exception.NodeAssociated(node=node_id,
instance=ref.ironic_node_id)
raise exception.NodeAssociated(
node=node_id,
instance=ref.ironic_node_id)
ref.update(values)
return ref
@ -619,7 +620,7 @@ class Connection(api.Connection):
return query
def get_pod_list(self, context, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None):
sort_key=None, sort_dir=None):
query = model_query(models.Pod)
query = self._add_tenant_filters(context, query)
query = self._add_pods_filters(query, filters)
@ -723,7 +724,7 @@ class Connection(api.Connection):
return query
def get_service_list(self, context, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None):
sort_key=None, sort_dir=None):
query = model_query(models.Service)
query = self._add_tenant_filters(context, query)
query = self._add_services_filters(query, filters)
@ -827,7 +828,7 @@ class Connection(api.Connection):
return query
def get_rc_list(self, context, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None):
sort_key=None, sort_dir=None):
query = model_query(models.ReplicationController)
query = self._add_tenant_filters(context, query)
query = self._add_rcs_filters(query, filters)
@ -845,7 +846,7 @@ class Connection(api.Connection):
rc.save()
except db_exc.DBDuplicateEntry:
raise exception.ReplicationControllerAlreadyExists(
uuid=values['uuid'])
uuid=values['uuid'])
return rc
def get_rc_by_id(self, context, rc_id):
@ -868,7 +869,7 @@ class Connection(api.Connection):
def get_rcs_by_bay_uuid(self, bay_uuid):
query = model_query(models.ReplicationController).filter_by(
bay_uuid=bay_uuid)
bay_uuid=bay_uuid)
try:
return query.all()
except NoResultFound:
@ -876,7 +877,7 @@ class Connection(api.Connection):
def get_rc_by_name(self, rc_name):
query = model_query(models.ReplicationController).filter_by(
name=rc_name)
name=rc_name)
try:
return query.one()
except MultipleResultsFound:

@ -62,9 +62,9 @@ class TestCase(base.BaseTestCase):
}
}
self.context = magnum_context.RequestContext(
auth_token_info=token_info,
project_id='fake_project',
user_id='fake_user')
auth_token_info=token_info,
project_id='fake_project',
user_id='fake_user')
def make_context(*args, **kwargs):
# If context hasn't been constructed with token_info