Use dictionary literal for dictionary creation
Dictionary creation could be rewritten as a dictionary literal. for example: filters = {} filter['namespace'] = namespace could be rewritten as filters = {'namespace': namespace} Closes-Bug: 1482586 Change-Id: I860483e958296da248a579a6032c14370843d9e4
This commit is contained in:
parent
94cb7020e8
commit
16ab5d7c17
|
@ -663,10 +663,11 @@ class Controller(controller.BaseController):
|
|||
:param image_id: Opaque image identifier
|
||||
:param location_data: Location of where Glance stored this image
|
||||
"""
|
||||
image_meta = {}
|
||||
image_meta['location'] = location_data['url']
|
||||
image_meta['status'] = 'active'
|
||||
image_meta['location_data'] = [location_data]
|
||||
image_meta = {
|
||||
'location': location_data['url'],
|
||||
'status': 'active',
|
||||
'location_data': [location_data]
|
||||
}
|
||||
|
||||
try:
|
||||
s = from_state
|
||||
|
|
|
@ -48,8 +48,7 @@ class ResourceTypeController(object):
|
|||
|
||||
def index(self, req):
|
||||
try:
|
||||
filters = {}
|
||||
filters['namespace'] = None
|
||||
filters = {'namespace': None}
|
||||
rs_type_repo = self.gateway.get_metadef_resource_type_repo(
|
||||
req.context)
|
||||
db_resource_type_list = rs_type_repo.list(filters=filters)
|
||||
|
@ -70,8 +69,7 @@ class ResourceTypeController(object):
|
|||
|
||||
def show(self, req, namespace):
|
||||
try:
|
||||
filters = {}
|
||||
filters['namespace'] = namespace
|
||||
filters = {'namespace': namespace}
|
||||
rs_type_repo = self.gateway.get_metadef_resource_type_repo(
|
||||
req.context)
|
||||
db_resource_type_list = rs_type_repo.list(filters=filters)
|
||||
|
|
|
@ -245,35 +245,37 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
|||
return '/v2/tasks/%s' % task.task_id
|
||||
|
||||
def _format_task(self, schema, task):
|
||||
task_view = {}
|
||||
task_view['id'] = task.task_id
|
||||
task_view['input'] = task.task_input
|
||||
task_view['type'] = task.type
|
||||
task_view['status'] = task.status
|
||||
task_view['owner'] = task.owner
|
||||
task_view['message'] = task.message
|
||||
task_view['result'] = task.result
|
||||
task_view = {
|
||||
'id': task.task_id,
|
||||
'input': task.task_input,
|
||||
'type': task.type,
|
||||
'status': task.status,
|
||||
'owner': task.owner,
|
||||
'message': task.message,
|
||||
'result': task.result,
|
||||
'created_at': timeutils.isotime(task.created_at),
|
||||
'updated_at': timeutils.isotime(task.updated_at),
|
||||
'self': self._get_task_location(task),
|
||||
'schema': '/v2/schemas/task'
|
||||
}
|
||||
if task.expires_at:
|
||||
task_view['expires_at'] = timeutils.isotime(task.expires_at)
|
||||
task_view['created_at'] = timeutils.isotime(task.created_at)
|
||||
task_view['updated_at'] = timeutils.isotime(task.updated_at)
|
||||
task_view['self'] = self._get_task_location(task)
|
||||
task_view['schema'] = '/v2/schemas/task'
|
||||
task_view = schema.filter(task_view) # domain
|
||||
return task_view
|
||||
|
||||
def _format_task_stub(self, schema, task):
|
||||
task_view = {}
|
||||
task_view['id'] = task.task_id
|
||||
task_view['type'] = task.type
|
||||
task_view['status'] = task.status
|
||||
task_view['owner'] = task.owner
|
||||
task_view = {
|
||||
'id': task.task_id,
|
||||
'type': task.type,
|
||||
'status': task.status,
|
||||
'owner': task.owner,
|
||||
'created_at': timeutils.isotime(task.created_at),
|
||||
'updated_at': timeutils.isotime(task.updated_at),
|
||||
'self': self._get_task_location(task),
|
||||
'schema': '/v2/schemas/task'
|
||||
}
|
||||
if task.expires_at:
|
||||
task_view['expires_at'] = timeutils.isotime(task.expires_at)
|
||||
task_view['created_at'] = timeutils.isotime(task.created_at)
|
||||
task_view['updated_at'] = timeutils.isotime(task.updated_at)
|
||||
task_view['self'] = self._get_task_location(task)
|
||||
task_view['schema'] = '/v2/schemas/task'
|
||||
task_view = schema.filter(task_view) # domain
|
||||
return task_view
|
||||
|
||||
|
|
|
@ -150,9 +150,10 @@ class KeystoneStrategy(BaseStrategy):
|
|||
def _v1_auth(self, token_url):
|
||||
creds = self.creds
|
||||
|
||||
headers = {}
|
||||
headers['X-Auth-User'] = creds['username']
|
||||
headers['X-Auth-Key'] = creds['password']
|
||||
headers = {
|
||||
'X-Auth-User': creds['username'],
|
||||
'X-Auth-Key': creds['password']
|
||||
}
|
||||
|
||||
tenant = creds.get('tenant')
|
||||
if tenant:
|
||||
|
@ -202,8 +203,7 @@ class KeystoneStrategy(BaseStrategy):
|
|||
}
|
||||
}
|
||||
|
||||
headers = {}
|
||||
headers['Content-Type'] = 'application/json'
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
req_body = jsonutils.dumps(creds)
|
||||
|
||||
resp, resp_body = self._do_request(
|
||||
|
|
|
@ -228,10 +228,8 @@ class BaseClient(object):
|
|||
self.connect_kwargs = self.get_connect_kwargs()
|
||||
|
||||
def get_connect_kwargs(self):
|
||||
connect_kwargs = {}
|
||||
|
||||
# Both secure and insecure connections have a timeout option
|
||||
connect_kwargs['timeout'] = self.timeout
|
||||
connect_kwargs = {'timeout': self.timeout}
|
||||
|
||||
if self.use_ssl:
|
||||
if self.key_file is None:
|
||||
|
|
|
@ -731,12 +731,13 @@ def stash_conf_values():
|
|||
Allows determining if any of these values have changed
|
||||
when the config is reloaded.
|
||||
"""
|
||||
conf = {}
|
||||
conf['bind_host'] = CONF.bind_host
|
||||
conf['bind_port'] = CONF.bind_port
|
||||
conf['tcp_keepidle'] = CONF.cert_file
|
||||
conf['backlog'] = CONF.backlog
|
||||
conf['key_file'] = CONF.key_file
|
||||
conf['cert_file'] = CONF.cert_file
|
||||
conf = {
|
||||
'bind_host': CONF.bind_host,
|
||||
'bind_port': CONF.bind_port,
|
||||
'tcp_keepidle': CONF.cert_file,
|
||||
'backlog': CONF.backlog,
|
||||
'key_file': CONF.key_file,
|
||||
'cert_file': CONF.cert_file
|
||||
}
|
||||
|
||||
return conf
|
||||
|
|
|
@ -152,9 +152,7 @@ class Driver(base.Driver):
|
|||
for path in get_all_regular_files(self.base_dir):
|
||||
image_id = os.path.basename(path)
|
||||
|
||||
entry = {}
|
||||
entry['image_id'] = image_id
|
||||
|
||||
entry = {'image_id': image_id}
|
||||
file_info = os.stat(path)
|
||||
entry['last_modified'] = file_info[stat.ST_MTIME]
|
||||
entry['last_accessed'] = file_info[stat.ST_ATIME]
|
||||
|
|
|
@ -48,8 +48,7 @@ class ResourceTypeController(object):
|
|||
|
||||
def index(self, req):
|
||||
try:
|
||||
filters = {}
|
||||
filters['namespace'] = None
|
||||
filters = {'namespace': None}
|
||||
rs_type_repo = self.gateway.get_metadef_resource_type_repo(
|
||||
req.context)
|
||||
db_resource_type_list = rs_type_repo.list(filters=filters)
|
||||
|
@ -68,8 +67,7 @@ class ResourceTypeController(object):
|
|||
|
||||
def show(self, req, namespace):
|
||||
try:
|
||||
filters = {}
|
||||
filters['namespace'] = namespace
|
||||
filters = {'namespace': namespace}
|
||||
rs_type_repo = self.gateway.get_metadef_resource_type_repo(
|
||||
req.context)
|
||||
db_resource_type_list = rs_type_repo.list(filters=filters)
|
||||
|
|
|
@ -461,14 +461,12 @@ class TestDeclarativeProperties(test_utils.BaseTestCase):
|
|||
max_value=99)})
|
||||
|
||||
tt = TestType()
|
||||
tt.props = {"foo": "FOO"}
|
||||
tt.props["bar"] = False
|
||||
tt.props = {"foo": "FOO", "bar": False}
|
||||
self.assertRaises(exc.InvalidArtifactPropertyValue,
|
||||
tt.props.__setitem__, "bar", 123)
|
||||
self.assertRaises(exc.InvalidArtifactPropertyValue,
|
||||
tt.props.__setitem__, "extra", "value")
|
||||
tt.fixed = {"name": "Alex"}
|
||||
tt.fixed["age"] = 42
|
||||
tt.fixed = {"name": "Alex", "age": 42}
|
||||
self.assertRaises(exc.InvalidArtifactPropertyValue,
|
||||
tt.fixed.__setitem__, "age", 120)
|
||||
|
||||
|
|
|
@ -211,10 +211,11 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
|
|||
c = glance_replicator.ImageService(FakeHTTPConnection(), 'noauth')
|
||||
|
||||
image_body = 'THISISANIMAGEBODYFORSURE!'
|
||||
image_meta_with_proto = {}
|
||||
image_meta_with_proto['x-auth-token'] = 'noauth'
|
||||
image_meta_with_proto['Content-Type'] = 'application/octet-stream'
|
||||
image_meta_with_proto['Content-Length'] = len(image_body)
|
||||
image_meta_with_proto = {
|
||||
'x-auth-token': 'noauth',
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Length': len(image_body)
|
||||
}
|
||||
|
||||
for key in IMG_RESPONSE_ACTIVE:
|
||||
image_meta_with_proto[
|
||||
|
|
|
@ -229,10 +229,11 @@ class FakeNotifier(object):
|
|||
self.log = []
|
||||
|
||||
def _notify(self, event_type, payload, level):
|
||||
log = {}
|
||||
log['notification_type'] = level
|
||||
log['event_type'] = event_type
|
||||
log['payload'] = payload
|
||||
log = {
|
||||
'notification_type': level,
|
||||
'event_type': event_type,
|
||||
'payload': payload
|
||||
}
|
||||
self.log.append(log)
|
||||
|
||||
def warn(self, event_type, payload):
|
||||
|
|
|
@ -1574,10 +1574,12 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
|||
call_sequence = []
|
||||
# use this to determine if we are within a db session i.e. atomic
|
||||
# operation, that is setting our active state.
|
||||
test_status = {'activate_session_started': False}
|
||||
# We want first status check to be 'queued' so we get past the first
|
||||
# guard.
|
||||
test_status['queued_guard_passed'] = False
|
||||
# We want first status check to be 'queued' so we get past the
|
||||
# first guard.
|
||||
test_status = {
|
||||
'activate_session_started': False,
|
||||
'queued_guard_passed': False
|
||||
}
|
||||
|
||||
state_changes = []
|
||||
|
||||
|
|
Loading…
Reference in New Issue