Rewrite dictionary creation as a dictionary literal

Do that if it makes sense

Change-Id: I4c53ca90c082faa62d8584f75d5bb0a31bb5131f
This commit is contained in:
Dina Belova 2014-08-20 16:51:26 +04:00
parent 1f3bea3081
commit fa8eaf7a4a
5 changed files with 19 additions and 24 deletions

View File

@ -39,15 +39,14 @@ class ComputeMetricsNotificationBase(notifications.ComputeNotificationBase):
try:
for metric in message['payload']['metrics']:
if name == metric['name']:
info = {}
info['payload'] = metric
info['event_type'] = message['event_type']
info['publisher_id'] = message['publisher_id']
info['resource_id'] = '%s_%s' % (
message['payload']['host'],
message['payload']['nodename'])
info['timestamp'] = str(timeutils.parse_strtime(
metric['timestamp']))
info = {'payload': metric,
'event_type': message['event_type'],
'publisher_id': message['publisher_id'],
'resource_id': '%s_%s' % (
message['payload']['host'],
message['payload']['nodename']),
'timestamp': str(timeutils.parse_strtime(
metric['timestamp']))}
return info
except Exception as err:
LOG.warning(_('An error occurred while building %(m)s '

View File

@ -96,14 +96,13 @@ class SensorNotification(plugin.NotificationBase):
data)
def _package_payload(self, message, payload):
info = {}
info['publisher_id'] = message['publisher_id']
info['timestamp'] = message['payload']['timestamp']
info['event_type'] = message['payload']['event_type']
info['user_id'] = message['payload'].get('user_id')
info['project_id'] = message['payload'].get('project_id')
# NOTE(chdent): How much of the payload should we keep?
info['payload'] = payload
info = {'publisher_id': message['publisher_id'],
'timestamp': message['payload']['timestamp'],
'event_type': message['payload']['event_type'],
'user_id': message['payload'].get('user_id'),
'project_id': message['payload'].get('project_id'),
'payload': payload}
return info
def process_notification(self, message):

View File

@ -53,8 +53,7 @@ class TestDispatcherDB(test.BaseTestCase):
msg = {'counter_name': 'test',
'resource_id': self.id(),
'counter_volume': 1,
}
msg['message_signature'] = 'invalid-signature'
'message_signature': 'invalid-signature'}
class ErrorConnection:

View File

@ -39,10 +39,9 @@ class TestClientHTTPBasicAuth(test.BaseTestCase):
self.parsed_url.netloc,
self.parsed_url.path,
None, None, None))
odl_params = {}
odl_params['auth'] = self.params.get('auth')[0]
odl_params['user'] = self.params.get('user')[0]
odl_params['password'] = self.params.get('password')[0]
odl_params = {'auth': self.params.get('auth')[0],
'user': self.params.get('user')[0],
'password': self.params.get('password')[0]}
self.client = client.Client(self.endpoint, odl_params)
self.resp = mock.MagicMock()

View File

@ -88,7 +88,6 @@ class TestFloatingIPPollster(test.BaseTestCase):
self.assertEqual(set(['ip.floating']), set([s.name for s in samples]))
def test_get_samples_cached(self):
cache = {}
cache['floating_ips'] = self.fake_get_ips()[:2]
cache = {'floating_ips': self.fake_get_ips()[:2]}
samples = list(self.pollster.get_samples(self.manager, cache))
self.assertEqual(2, len(samples))