Merge "Remove string concatenation in favor of string formatting"

This commit is contained in:
Jenkins 2015-12-21 10:13:56 +00:00 committed by Gerrit Code Review
commit 853145f4d1
8 changed files with 20 additions and 31 deletions

View File

@ -218,7 +218,7 @@ class JsonPatchType(wtypes.Base):
@staticmethod @staticmethod
def validate(patch): def validate(patch):
_path = '/' + patch.path.split('/')[1] _path = '/{0}'.format(patch.path.split('/')[1])
if _path in patch.internal_attrs(): if _path in patch.internal_attrs():
msg = _("'%s' is an internal attribute and can not be updated") msg = _("'%s' is an internal attribute and can not be updated")
raise wsme.exc.ClientSideError(msg % patch.path) raise wsme.exc.ClientSideError(msg % patch.path)

View File

@ -74,13 +74,13 @@ class ParsableErrorMiddleware(object):
try: try:
# simple check xml is valid # simple check xml is valid
body = [et.ElementTree.tostring( body = [et.ElementTree.tostring(
et.ElementTree.fromstring('<error_message>' et.ElementTree.Element('error_message',
+ '\n'.join(app_iter) text='\n'.join(app_iter)))]
+ '</error_message>'))]
except et.ElementTree.ParseError as err: except et.ElementTree.ParseError as err:
LOG.error(_LE('Error parsing HTTP response: %s'), err) LOG.error(_LE('Error parsing HTTP response: %s'), err)
body = ['<error_message>%s' % state['status_code'] body = [et.ElementTree.tostring(
+ '</error_message>'] et.ElementTree.Element('error_message',
text=state['status_code']))]
state['headers'].append(('Content-Type', 'application/xml')) state['headers'].append(('Content-Type', 'application/xml'))
else: else:
if six.PY3: if six.PY3:

View File

@ -34,7 +34,7 @@ class TriggerActionPlan(object):
action_plan_uuid) action_plan_uuid)
cmd.execute() cmd.execute()
except Exception as e: except Exception as e:
LOG.error("do_launch_action_plan " + unicode(e)) LOG.exception(e)
def launch_action_plan(self, context, action_plan_uuid): def launch_action_plan(self, context, action_plan_uuid):
LOG.debug("Trigger ActionPlan %s" % action_plan_uuid) LOG.debug("Trigger ActionPlan %s" % action_plan_uuid)

View File

@ -33,14 +33,14 @@ from sqlalchemy.types import TypeDecorator, TEXT
from watcher.common import paths from watcher.common import paths
sql_opts = [ sql_opts = [
cfg.StrOpt('mysql_engine', cfg.StrOpt('mysql_engine',
default='InnoDB', default='InnoDB',
help='MySQL engine to use.') help='MySQL engine to use.')
] ]
_DEFAULT_SQL_CONNECTION = 'sqlite:///' + paths.state_path_def('watcher.sqlite') _DEFAULT_SQL_CONNECTION = 'sqlite:///{0}'.format(
paths.state_path_def('watcher.sqlite'))
cfg.CONF.register_opts(sql_opts, 'database') cfg.CONF.register_opts(sql_opts, 'database')
db_options.set_defaults(cfg.CONF, _DEFAULT_SQL_CONNECTION, 'watcher.sqlite') db_options.set_defaults(cfg.CONF, _DEFAULT_SQL_CONNECTION, 'watcher.sqlite')

View File

@ -128,7 +128,7 @@ class TestListAuditTemplate(api_base.FunctionalTest):
audit_template = obj_utils.create_test_audit_template( audit_template = obj_utils.create_test_audit_template(
self.context, id=id_, self.context, id=id_,
uuid=utils.generate_uuid(), uuid=utils.generate_uuid(),
name='My Audit Template ' + str(id_)) name='My Audit Template {0}'.format(id_))
audit_template_list.append(audit_template.uuid) audit_template_list.append(audit_template.uuid)
response = self.get_json('/audit_templates') response = self.get_json('/audit_templates')
self.assertEqual(len(audit_template_list), self.assertEqual(len(audit_template_list),
@ -141,12 +141,12 @@ class TestListAuditTemplate(api_base.FunctionalTest):
for id_ in [1, 2, 3]: for id_ in [1, 2, 3]:
audit_template = obj_utils.create_test_audit_template( audit_template = obj_utils.create_test_audit_template(
self.context, id=id_, uuid=utils.generate_uuid(), self.context, id=id_, uuid=utils.generate_uuid(),
name='My Audit Template ' + str(id_)) name='My Audit Template {0}'.format(id_))
audit_template_list.append(audit_template.uuid) audit_template_list.append(audit_template.uuid)
for id_ in [4, 5]: for id_ in [4, 5]:
audit_template = obj_utils.create_test_audit_template( audit_template = obj_utils.create_test_audit_template(
self.context, id=id_, uuid=utils.generate_uuid(), self.context, id=id_, uuid=utils.generate_uuid(),
name='My Audit Template ' + str(id_)) name='My Audit Template {0}'.format(id_))
audit_template.soft_delete() audit_template.soft_delete()
response = self.get_json('/audit_templates') response = self.get_json('/audit_templates')
self.assertEqual(3, len(response['audit_templates'])) self.assertEqual(3, len(response['audit_templates']))
@ -158,12 +158,12 @@ class TestListAuditTemplate(api_base.FunctionalTest):
for id_ in [1, 2, 3]: for id_ in [1, 2, 3]:
audit_template = obj_utils.create_test_audit_template( audit_template = obj_utils.create_test_audit_template(
self.context, id=id_, uuid=utils.generate_uuid(), self.context, id=id_, uuid=utils.generate_uuid(),
name='My Audit Template ' + str(id_)) name='My Audit Template {0}'.format(id_))
audit_template_list.append(audit_template.uuid) audit_template_list.append(audit_template.uuid)
for id_ in [4, 5]: for id_ in [4, 5]:
audit_template = obj_utils.create_test_audit_template( audit_template = obj_utils.create_test_audit_template(
self.context, id=id_, uuid=utils.generate_uuid(), self.context, id=id_, uuid=utils.generate_uuid(),
name='My Audit Template ' + str(id_)) name='My Audit Template {0}'.format(id_))
audit_template.soft_delete() audit_template.soft_delete()
audit_template_list.append(audit_template.uuid) audit_template_list.append(audit_template.uuid)
response = self.get_json('/audit_templates', response = self.get_json('/audit_templates',
@ -187,7 +187,7 @@ class TestListAuditTemplate(api_base.FunctionalTest):
for id_ in range(5): for id_ in range(5):
obj_utils.create_test_audit_template( obj_utils.create_test_audit_template(
self.context, id=id_, uuid=utils.generate_uuid(), self.context, id=id_, uuid=utils.generate_uuid(),
name='My Audit Template ' + str(id_)) name='My Audit Template {0}'.format(id_))
response = self.get_json('/audit_templates/?limit=3') response = self.get_json('/audit_templates/?limit=3')
self.assertEqual(3, len(response['audit_templates'])) self.assertEqual(3, len(response['audit_templates']))
@ -199,7 +199,7 @@ class TestListAuditTemplate(api_base.FunctionalTest):
for id_ in range(5): for id_ in range(5):
obj_utils.create_test_audit_template( obj_utils.create_test_audit_template(
self.context, id=id_, uuid=utils.generate_uuid(), self.context, id=id_, uuid=utils.generate_uuid(),
name='My Audit Template ' + str(id_)) name='My Audit Template {0}'.format(id_))
response = self.get_json('/audit_templates') response = self.get_json('/audit_templates')
self.assertEqual(3, len(response['audit_templates'])) self.assertEqual(3, len(response['audit_templates']))

View File

@ -169,7 +169,7 @@ class TestListAudit(api_base.FunctionalTest):
for id_ in range(5): for id_ in range(5):
audit_template = obj_utils.create_test_audit_template( audit_template = obj_utils.create_test_audit_template(
self.context, self.context,
name='at' + str(id_), name='at{0}'.format(id_),
uuid=utils.generate_uuid()) uuid=utils.generate_uuid())
obj_utils.create_test_audit( obj_utils.create_test_audit(
self.context, id=id_, uuid=utils.generate_uuid(), self.context, id=id_, uuid=utils.generate_uuid(),

View File

@ -34,7 +34,7 @@ class DbAuditTemplateTestCase(base.DbTestCase):
for i in range(1, 6): for i in range(1, 6):
audit_template = utils.create_test_audit_template( audit_template = utils.create_test_audit_template(
uuid=w_utils.generate_uuid(), uuid=w_utils.generate_uuid(),
name='My Audit Template ' + str(i)) name='My Audit Template {0}'.format(i))
uuids.append(six.text_type(audit_template['uuid'])) uuids.append(six.text_type(audit_template['uuid']))
res = self.dbapi.get_audit_template_list(self.context) res = self.dbapi.get_audit_template_list(self.context)
res_uuids = [r.uuid for r in res] res_uuids = [r.uuid for r in res]

View File

@ -66,14 +66,12 @@ class FakerModelCollector(BaseClusterModelCollector):
mem.set_capacity(hypervisor, 132) mem.set_capacity(hypervisor, 132)
disk.set_capacity(hypervisor, 250) disk.set_capacity(hypervisor, 250)
num_cores.set_capacity(hypervisor, 40) num_cores.set_capacity(hypervisor, 40)
# print("create "+str(hypervisor))
current_state_cluster.add_hypervisor(hypervisor) current_state_cluster.add_hypervisor(hypervisor)
for i in range(0, count_vm): for i in range(0, count_vm):
vm_uuid = "VM_{0}".format(i) vm_uuid = "VM_{0}".format(i)
vm = VM() vm = VM()
vm.uuid = vm_uuid vm.uuid = vm_uuid
# print("create "+str(vm))
mem.set_capacity(vm, 8) mem.set_capacity(vm, 8)
disk.set_capacity(vm, 10) disk.set_capacity(vm, 10)
num_cores.set_capacity(vm, 10) num_cores.set_capacity(vm, 10)
@ -119,14 +117,12 @@ class FakerModelCollector(BaseClusterModelCollector):
mem.set_capacity(node, 132) mem.set_capacity(node, 132)
disk.set_capacity(node, 250) disk.set_capacity(node, 250)
num_cores.set_capacity(node, 40) num_cores.set_capacity(node, 40)
# print("create "+str(node))
current_state_cluster.add_hypervisor(node) current_state_cluster.add_hypervisor(node)
for i in range(0, count_vm): for i in range(0, count_vm):
vm_uuid = "VM_{0}".format(i) vm_uuid = "VM_{0}".format(i)
vm = VM() vm = VM()
vm.uuid = vm_uuid vm.uuid = vm_uuid
# print("create "+str(vm))
mem.set_capacity(vm, 2) mem.set_capacity(vm, 2)
disk.set_capacity(vm, 20) disk.set_capacity(vm, 20)
num_cores.set_capacity(vm, 10) num_cores.set_capacity(vm, 10)
@ -202,14 +198,12 @@ class FakerModelCollector(BaseClusterModelCollector):
mem.set_capacity(node, 132) mem.set_capacity(node, 132)
disk.set_capacity(node, 250) disk.set_capacity(node, 250)
num_cores.set_capacity(node, 40) num_cores.set_capacity(node, 40)
# print("create "+str(node))
current_state_cluster.add_hypervisor(node) current_state_cluster.add_hypervisor(node)
for i in range(0, count_vm): for i in range(0, count_vm):
vm_uuid = "VM_{0}".format(i) vm_uuid = "VM_{0}".format(i)
vm = VM() vm = VM()
vm.uuid = vm_uuid vm.uuid = vm_uuid
# print("create "+str(vm))
mem.set_capacity(vm, 10) mem.set_capacity(vm, 10)
disk.set_capacity(vm, 25) disk.set_capacity(vm, 25)
num_cores.set_capacity(vm, 16) num_cores.set_capacity(vm, 16)
@ -266,14 +260,12 @@ class FakerModelCollector(BaseClusterModelCollector):
mem.set_capacity(node, 132) mem.set_capacity(node, 132)
disk.set_capacity(node, 250) disk.set_capacity(node, 250)
num_cores.set_capacity(node, 40) num_cores.set_capacity(node, 40)
# print("create "+str(node))
current_state_cluster.add_hypervisor(node) current_state_cluster.add_hypervisor(node)
for i in range(0, count_vm): for i in range(0, count_vm):
vm_uuid = "VM_{0}".format(i) vm_uuid = "VM_{0}".format(i)
vm = VM() vm = VM()
vm.uuid = vm_uuid vm.uuid = vm_uuid
# print("create "+str(vm))
mem.set_capacity(vm, 2) mem.set_capacity(vm, 2)
disk.set_capacity(vm, 20) disk.set_capacity(vm, 20)
num_cores.set_capacity(vm, 10) num_cores.set_capacity(vm, 10)
@ -314,7 +306,6 @@ class FakerModelCollector(BaseClusterModelCollector):
mem.set_capacity(node, 1) mem.set_capacity(node, 1)
disk.set_capacity(node, 1) disk.set_capacity(node, 1)
num_cores.set_capacity(node, 1) num_cores.set_capacity(node, 1)
# print("create "+str(node))
current_state_cluster.add_hypervisor(node) current_state_cluster.add_hypervisor(node)
return current_state_cluster return current_state_cluster
@ -338,7 +329,7 @@ class FakerModelCollector(BaseClusterModelCollector):
current_state_cluster.create_resource(disk) current_state_cluster.create_resource(disk)
for i in range(0, count_node): for i in range(0, count_node):
node_uuid = "Node_" + str(i) node_uuid = "Node_{0}".format(i)
node = Hypervisor() node = Hypervisor()
node.uuid = node_uuid node.uuid = node_uuid
node.hostname = "hostname_{0}".format(i) node.hostname = "hostname_{0}".format(i)
@ -346,14 +337,12 @@ class FakerModelCollector(BaseClusterModelCollector):
mem.set_capacity(node, 4) mem.set_capacity(node, 4)
disk.set_capacity(node, 4) disk.set_capacity(node, 4)
num_cores.set_capacity(node, 4) num_cores.set_capacity(node, 4)
# print("create "+str(node))
current_state_cluster.add_hypervisor(node) current_state_cluster.add_hypervisor(node)
for i in range(0, count_vm): for i in range(0, count_vm):
vm_uuid = "VM_" + str(i) vm_uuid = "VM_{0}".format(i)
vm = VM() vm = VM()
vm.uuid = vm_uuid vm.uuid = vm_uuid
# print("create "+str(vm))
mem.set_capacity(vm, 2) mem.set_capacity(vm, 2)
disk.set_capacity(vm, 0) disk.set_capacity(vm, 0)
num_cores.set_capacity(vm, 4) num_cores.set_capacity(vm, 4)