pylint: fixed conditions
Change-Id: I0e6bcebca55d89bdfb59944bf91f4f9949c95562
This commit is contained in:
parent
5fb9312eda
commit
4db1e72654
@ -21,10 +21,6 @@ disable =
|
||||
missing-class-docstring,
|
||||
missing-function-docstring,
|
||||
missing-module-docstring,
|
||||
no-else-break,
|
||||
no-else-continue,
|
||||
no-else-raise,
|
||||
no-else-return,
|
||||
no-self-use,
|
||||
no-value-for-parameter,
|
||||
protected-access,
|
||||
|
@ -135,7 +135,7 @@ class ConfigFile(object):
|
||||
if not self.optional and not sources:
|
||||
raise MissingRequiredSource('%s file is not found' % self.source)
|
||||
# skip when there is no sources and optional
|
||||
elif self.optional and not sources:
|
||||
if self.optional and not sources:
|
||||
return
|
||||
|
||||
for source in sources:
|
||||
@ -216,7 +216,7 @@ class ConfigFile(object):
|
||||
|
||||
if not sources and not self.optional:
|
||||
raise MissingRequiredSource('%s file is not found' % self.source)
|
||||
elif self.optional and not sources:
|
||||
if self.optional and not sources:
|
||||
return
|
||||
|
||||
for source in sources:
|
||||
@ -261,9 +261,8 @@ def validate_source(data):
|
||||
if data.get('optional'):
|
||||
LOG.info("%s does not exist, but is not required", source)
|
||||
return False
|
||||
else:
|
||||
raise MissingRequiredSource(
|
||||
"The source to copy does not exist: %s" % source)
|
||||
raise MissingRequiredSource(
|
||||
"The source to copy does not exist: %s" % source)
|
||||
|
||||
return True
|
||||
|
||||
@ -395,10 +394,9 @@ def execute_config_strategy(config):
|
||||
raise ImmutableConfig(
|
||||
"The config strategy prevents copying new configs",
|
||||
exit_code=0)
|
||||
else:
|
||||
copy_config(config)
|
||||
handle_permissions(config)
|
||||
os.mknod('/configured')
|
||||
copy_config(config)
|
||||
handle_permissions(config)
|
||||
os.mknod('/configured')
|
||||
else:
|
||||
raise InvalidConfig('KOLLA_CONFIG_STRATEGY is not set properly')
|
||||
|
||||
|
@ -256,7 +256,7 @@ class AnsiblePlaybookAction(base.TripleOAction):
|
||||
if (isinstance(self._inventory, six.string_types) and
|
||||
os.path.exists(self._inventory)):
|
||||
return self._inventory
|
||||
elif not isinstance(self._inventory, six.string_types):
|
||||
if not isinstance(self._inventory, six.string_types):
|
||||
self._inventory = yaml.safe_dump(self._inventory)
|
||||
|
||||
path = os.path.join(self.work_dir, 'inventory.yaml')
|
||||
@ -281,7 +281,7 @@ class AnsiblePlaybookAction(base.TripleOAction):
|
||||
if (isinstance(self._playbook, six.string_types) and
|
||||
os.path.exists(self._playbook)):
|
||||
return self._playbook
|
||||
elif not isinstance(self._playbook, six.string_types):
|
||||
if not isinstance(self._playbook, six.string_types):
|
||||
self._playbook = yaml.safe_dump(self._playbook)
|
||||
|
||||
path = os.path.join(self.work_dir, self.playbook_name)
|
||||
@ -416,9 +416,8 @@ class AnsiblePlaybookAction(base.TripleOAction):
|
||||
if not isinstance(self.extra_env_variables, dict):
|
||||
msg = "extra_env_variables must be a dict"
|
||||
return actions.Result(error=msg)
|
||||
else:
|
||||
for key, value in self.extra_env_variables.items():
|
||||
self.extra_env_variables[key] = six.text_type(value)
|
||||
for key, value in self.extra_env_variables.items():
|
||||
self.extra_env_variables[key] = six.text_type(value)
|
||||
|
||||
if self.gather_facts:
|
||||
command.extend(['--gather-facts', self.gather_facts])
|
||||
|
@ -440,8 +440,7 @@ class GetCandidateNodes(base.TripleOAction):
|
||||
if isinstance(self.ip_addresses, six.string_types):
|
||||
return [str(ip) for ip in
|
||||
netaddr.IPNetwork(self.ip_addresses).iter_hosts()]
|
||||
else:
|
||||
return self.ip_addresses
|
||||
return self.ip_addresses
|
||||
|
||||
def run(self, context):
|
||||
existing = self._existing_ips()
|
||||
|
@ -41,7 +41,6 @@ class TripleOCapabilitiesFilter(filters.BaseHostFilter):
|
||||
LOG.debug('Node tagged %s matches requested node %s', host_node,
|
||||
instance_node[0])
|
||||
return True
|
||||
else:
|
||||
LOG.debug('Node tagged %s does not match requested node %s',
|
||||
host_node, instance_node[0])
|
||||
return False
|
||||
LOG.debug('Node tagged %s does not match requested node %s',
|
||||
host_node, instance_node[0])
|
||||
return False
|
||||
|
@ -844,15 +844,14 @@ class BaseImageUploader(object):
|
||||
if netloc in cls.mirrors:
|
||||
mirror = cls.mirrors[netloc]
|
||||
return '%sv2%s' % (mirror, path)
|
||||
if (cls.is_insecure_registry(registry_host=netloc) and
|
||||
netloc not in cls.no_verify_registries):
|
||||
scheme = 'http'
|
||||
else:
|
||||
if (cls.is_insecure_registry(registry_host=netloc) and
|
||||
netloc not in cls.no_verify_registries):
|
||||
scheme = 'http'
|
||||
else:
|
||||
scheme = 'https'
|
||||
if netloc == 'docker.io':
|
||||
netloc = 'registry-1.docker.io'
|
||||
return '%s://%s/v2%s' % (scheme, netloc, path)
|
||||
scheme = 'https'
|
||||
if netloc == 'docker.io':
|
||||
netloc = 'registry-1.docker.io'
|
||||
return '%s://%s/v2%s' % (scheme, netloc, path)
|
||||
|
||||
@classmethod
|
||||
def _image_tag_from_url(cls, image_url):
|
||||
@ -908,8 +907,7 @@ class BaseImageUploader(object):
|
||||
if e.response.status_code in (403, 404):
|
||||
raise ImageNotFoundException('Not found image: %s' %
|
||||
image_url.geturl())
|
||||
else:
|
||||
raise
|
||||
raise
|
||||
|
||||
manifest_str = cls._get_response_text(manifest_r)
|
||||
|
||||
@ -1546,8 +1544,7 @@ class PythonImageUploader(BaseImageUploader):
|
||||
consolidated_view = cls.uploaded_layers.copy()
|
||||
consolidated_view.update(cls.lock._global_view)
|
||||
return consolidated_view
|
||||
else:
|
||||
return cls.uploaded_layers
|
||||
return cls.uploaded_layers
|
||||
|
||||
@classmethod
|
||||
def _track_uploaded_layers(cls, layer, known_path=None, image_ref=None,
|
||||
@ -1796,8 +1793,7 @@ class PythonImageUploader(BaseImageUploader):
|
||||
if e.response.status_code in (501, 403, 404, 405):
|
||||
cls.export_registries.add(image_url.netloc)
|
||||
return True
|
||||
else:
|
||||
raise
|
||||
raise
|
||||
cls.push_registries.add(image_url.netloc)
|
||||
return False
|
||||
|
||||
@ -1833,8 +1829,7 @@ class PythonImageUploader(BaseImageUploader):
|
||||
except requests.exceptions.HTTPError as e:
|
||||
if e.response.status_code in (403, 404):
|
||||
raise ImageNotFoundException('Not found image: %s' % url)
|
||||
else:
|
||||
raise
|
||||
raise
|
||||
return cls._get_response_text(r)
|
||||
|
||||
def _collect_manifests_layers(self, image_url, session,
|
||||
@ -2179,8 +2174,7 @@ class PythonImageUploader(BaseImageUploader):
|
||||
if e.response.status_code == 400:
|
||||
LOG.error(cls._get_response_text(r))
|
||||
raise ImageUploaderException('Pushing manifest failed')
|
||||
else:
|
||||
raise
|
||||
raise
|
||||
|
||||
@classmethod
|
||||
@tenacity.retry( # Retry up to 5 times with jittered exponential backoff
|
||||
@ -2246,15 +2240,13 @@ class PythonImageUploader(BaseImageUploader):
|
||||
(image, x['digest'], known_path))
|
||||
layer_found = x
|
||||
break
|
||||
else:
|
||||
parts['digest'] = x['digest']
|
||||
blob_url = cls._build_url(
|
||||
target_url, CALL_BLOB % parts)
|
||||
if session.head(blob_url, timeout=30).status_code == 200:
|
||||
LOG.debug('[%s] Layer already exists: %s' %
|
||||
(image, x['digest']))
|
||||
layer_found = x
|
||||
break
|
||||
parts['digest'] = x['digest']
|
||||
blob_url = cls._build_url(target_url, CALL_BLOB % parts)
|
||||
if session.head(blob_url, timeout=30).status_code == 200:
|
||||
LOG.debug('[%s] Layer already exists: %s' %
|
||||
(image, x['digest']))
|
||||
layer_found = x
|
||||
break
|
||||
if layer_found:
|
||||
layer['digest'] = layer_found['digest']
|
||||
if 'size' in layer_found:
|
||||
@ -2645,11 +2637,10 @@ class PythonImageUploader(BaseImageUploader):
|
||||
# workers will scale from 2 to 8 based on the cpu count // 2
|
||||
workers = min(max(2, processutils.get_worker_count() // 2), 8)
|
||||
return futures.ThreadPoolExecutor(max_workers=workers)
|
||||
else:
|
||||
# there really isn't an improvement with > 4 workers due to the
|
||||
# container layer overlaps. The higher the workers, the more
|
||||
# RAM required which can lead to OOMs. It's best to limit to 4
|
||||
return futures.ProcessPoolExecutor(max_workers=4)
|
||||
# there really isn't an improvement with > 4 workers due to the
|
||||
# container layer overlaps. The higher the workers, the more
|
||||
# RAM required which can lead to OOMs. It's best to limit to 4
|
||||
return futures.ProcessPoolExecutor(max_workers=4)
|
||||
|
||||
def run_tasks(self):
|
||||
if not self.upload_tasks:
|
||||
|
@ -144,8 +144,7 @@ class TripleoInventory(object):
|
||||
"""Static yaml inventories reqire a different hosts format?!"""
|
||||
if not dynamic:
|
||||
return {x: {} for x in alist}
|
||||
else:
|
||||
return alist
|
||||
return alist
|
||||
|
||||
def _get_stack(self):
|
||||
if self.plan_name is None:
|
||||
|
@ -60,7 +60,7 @@ class TestConfigureBootAction(base.TestCase):
|
||||
def mock_find(name, disk_format):
|
||||
if name == 'bm-deploy-kernel':
|
||||
return mock.MagicMock(id='k_id')
|
||||
elif name == 'bm-deploy-ramdisk':
|
||||
if name == 'bm-deploy-ramdisk':
|
||||
return mock.MagicMock(id='r_id')
|
||||
self.glance.images.find = mock_find
|
||||
self.context = mock.MagicMock()
|
||||
|
@ -42,14 +42,12 @@ class TestCapabilitiesFilter(base.TestCase):
|
||||
def mock_host_get(key):
|
||||
if key == 'node':
|
||||
return 'compute-0'
|
||||
else:
|
||||
self.fail('Unexpected key requested by filter')
|
||||
self.fail('Unexpected key requested by filter')
|
||||
|
||||
def mock_spec_get(key):
|
||||
if key == 'capabilities:node':
|
||||
return ['compute-0']
|
||||
else:
|
||||
self.fail('Unexpected key requested by filter')
|
||||
self.fail('Unexpected key requested by filter')
|
||||
|
||||
instance = capabilities_filter.TripleOCapabilitiesFilter()
|
||||
host_state = mock.Mock()
|
||||
|
@ -82,7 +82,7 @@ class TestConfig(base.TestCase):
|
||||
for role in fake_role:
|
||||
if 'external' in config:
|
||||
continue
|
||||
elif config == 'step_config':
|
||||
if config == 'step_config':
|
||||
expected_calls += [call('/tmp/tht/%s/%s.pp' %
|
||||
(role, config))]
|
||||
elif config == 'param_config':
|
||||
@ -687,7 +687,7 @@ class TestConfig(base.TestCase):
|
||||
for role in fake_role:
|
||||
if 'external' in config:
|
||||
continue
|
||||
elif config == 'step_config':
|
||||
if config == 'step_config':
|
||||
expected_calls += [call('/tmp/tht/%s/%s.pp' %
|
||||
(role, config))]
|
||||
elif config == 'param_config':
|
||||
|
@ -501,7 +501,7 @@ class StackParametersTest(base.TestCase):
|
||||
def side_effect(args):
|
||||
if args == 123:
|
||||
return bm1
|
||||
elif args == 234:
|
||||
if args == 234:
|
||||
raise ironicexceptions.NotFound
|
||||
|
||||
baremetal_client = mock.MagicMock()
|
||||
@ -520,8 +520,7 @@ class StackParametersTest(base.TestCase):
|
||||
def side_effect2(node, *args):
|
||||
if node == 9876:
|
||||
return [port1, ]
|
||||
else:
|
||||
raise ironicexceptions.NotFound
|
||||
raise ironicexceptions.NotFound
|
||||
|
||||
baremetal_client.port.list = mock.MagicMock(side_effect=side_effect2)
|
||||
|
||||
|
@ -112,8 +112,7 @@ class J2SwiftLoaderTest(base.TestCase):
|
||||
def return_multiple_files(*args):
|
||||
if args[1] == 'bar/foo.yaml':
|
||||
return ['', 'I am foo']
|
||||
else:
|
||||
raise swiftexceptions.ClientException('not found')
|
||||
raise swiftexceptions.ClientException('not found')
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object = mock.MagicMock(side_effect=return_multiple_files)
|
||||
return swift
|
||||
@ -219,9 +218,9 @@ class ProcessTemplatesTest(base.TestCase):
|
||||
return ['', snippet_content]
|
||||
if args[1] == constants.OVERCLOUD_J2_EXCLUDES:
|
||||
return ['', J2_EXCLUDES]
|
||||
elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME:
|
||||
if args[1] == constants.OVERCLOUD_J2_ROLES_NAME:
|
||||
return ['', role_data or ROLE_DATA_YAML]
|
||||
elif args[1] == constants.OVERCLOUD_J2_NETWORKS_NAME:
|
||||
if args[1] == constants.OVERCLOUD_J2_NETWORKS_NAME:
|
||||
return ['', NETWORK_DATA_YAML]
|
||||
|
||||
def return_container_files(*args):
|
||||
|
@ -41,10 +41,9 @@ def search_stack(stack_data, key_name):
|
||||
for k, v in iteritems(stack_data):
|
||||
if k == key_name:
|
||||
return v
|
||||
else:
|
||||
result = search_stack(v, key_name)
|
||||
if result:
|
||||
return result
|
||||
result = search_stack(v, key_name)
|
||||
if result:
|
||||
return result
|
||||
|
||||
|
||||
def get_exclusive_neutron_driver(drivers):
|
||||
|
@ -131,9 +131,8 @@ class Config(object):
|
||||
# If no step is defined, it will be executed for all
|
||||
# steps if strict is false
|
||||
return True
|
||||
else:
|
||||
# We only want the task with the step defined.
|
||||
return False
|
||||
# We only want the task with the step defined.
|
||||
return False
|
||||
if not isinstance(whenexpr, list):
|
||||
whenexpr = [whenexpr]
|
||||
|
||||
@ -148,8 +147,7 @@ class Config(object):
|
||||
if steps_found:
|
||||
if str(step) in steps_found:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return False
|
||||
|
||||
# No step found
|
||||
if strict:
|
||||
@ -258,7 +256,7 @@ class Config(object):
|
||||
if config in constants.EXTERNAL_TASKS:
|
||||
# external tasks are collected globally, not per-role
|
||||
continue
|
||||
elif config == 'step_config':
|
||||
if config == 'step_config':
|
||||
filepath = os.path.join(role_path, 'step_config.pp')
|
||||
with self._open_file(filepath) as step_config:
|
||||
step_config.write(role[config])
|
||||
|
@ -65,6 +65,5 @@ def _check_image(glanceclient, name, disk_format, image_type):
|
||||
|
||||
if image:
|
||||
return image.id
|
||||
else:
|
||||
raise ValueError("%s image %s not found in Glance" % (image_type,
|
||||
name))
|
||||
raise ValueError("%s image %s not found in Glance" % (image_type,
|
||||
name))
|
||||
|
@ -48,10 +48,9 @@ def client(ctx):
|
||||
def _determine_verify(ctx):
|
||||
if ctx.insecure:
|
||||
return False
|
||||
elif ctx.auth_cacert:
|
||||
if ctx.auth_cacert:
|
||||
return ctx.auth_cacert
|
||||
else:
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
def get_session_and_auth(context, **kwargs):
|
||||
@ -163,31 +162,31 @@ def _admin_client(trust_id=None):
|
||||
cl.management_url = auth_url
|
||||
|
||||
return cl
|
||||
else:
|
||||
kwargs = {}
|
||||
|
||||
if trust_id:
|
||||
# Remove project_name and project_id, since we need a trust scoped
|
||||
# auth object
|
||||
kwargs['domain_id'] = None
|
||||
kwargs['domain_name'] = None
|
||||
kwargs['project_name'] = None
|
||||
kwargs['project_domain_name'] = None
|
||||
kwargs['project_id'] = None
|
||||
kwargs['trust_id'] = trust_id
|
||||
kwargs = {}
|
||||
|
||||
auth = loading.load_auth_from_conf_options(
|
||||
CONF,
|
||||
'keystone_authtoken',
|
||||
**kwargs
|
||||
)
|
||||
sess = loading.load_session_from_conf_options(
|
||||
CONF,
|
||||
'keystone',
|
||||
auth=auth
|
||||
)
|
||||
if trust_id:
|
||||
# Remove project_name and project_id, since we need a trust scoped
|
||||
# auth object
|
||||
kwargs['domain_id'] = None
|
||||
kwargs['domain_name'] = None
|
||||
kwargs['project_name'] = None
|
||||
kwargs['project_domain_name'] = None
|
||||
kwargs['project_id'] = None
|
||||
kwargs['trust_id'] = trust_id
|
||||
|
||||
return ks_client.Client(session=sess)
|
||||
auth = loading.load_auth_from_conf_options(
|
||||
CONF,
|
||||
'keystone_authtoken',
|
||||
**kwargs
|
||||
)
|
||||
sess = loading.load_session_from_conf_options(
|
||||
CONF,
|
||||
'keystone',
|
||||
auth=auth
|
||||
)
|
||||
|
||||
return ks_client.Client(session=sess)
|
||||
|
||||
|
||||
def client_for_admin():
|
||||
@ -252,8 +251,7 @@ def get_endpoint_for_project(ctx, service_name=None, service_type=None,
|
||||
" region_name=%s]"
|
||||
% (service_name, service_type, region)
|
||||
)
|
||||
else:
|
||||
return endpoint
|
||||
return endpoint
|
||||
|
||||
|
||||
def obtain_service_catalog(ctx):
|
||||
|
@ -74,14 +74,14 @@ class DriverInfo(object):
|
||||
def convert_key(self, key):
|
||||
if key in self._mapping:
|
||||
return self._mapping[key]
|
||||
elif key in self._deprecated_mapping:
|
||||
if key in self._deprecated_mapping:
|
||||
real = self._deprecated_mapping[key]
|
||||
LOG.warning('Key %s is deprecated, please use %s',
|
||||
key, real)
|
||||
return real
|
||||
elif key.startswith(self._prefix):
|
||||
if key.startswith(self._prefix):
|
||||
return key
|
||||
elif key != 'pm_type' and key.startswith('pm_'):
|
||||
if key != 'pm_type' and key.startswith('pm_'):
|
||||
LOG.warning('Key %s is not supported and will not be passed',
|
||||
key)
|
||||
else:
|
||||
@ -453,7 +453,7 @@ def _get_node_id(node, handler, node_map):
|
||||
raise exception.InvalidNode('Several candidates found for the same '
|
||||
'node data: %s' % candidates,
|
||||
node=node)
|
||||
elif candidates:
|
||||
if candidates:
|
||||
return list(candidates)[0]
|
||||
|
||||
|
||||
@ -722,8 +722,7 @@ def generate_hostmap(baremetal_client, compute_client):
|
||||
|
||||
if hostmap == {}:
|
||||
return None
|
||||
else:
|
||||
return hostmap
|
||||
return hostmap
|
||||
|
||||
|
||||
def run_nova_cell_v2_discovery():
|
||||
|
@ -50,8 +50,7 @@ def get_endpoint(key, stack):
|
||||
endpoint_map = get_endpoint_map(stack)
|
||||
if endpoint_map:
|
||||
return endpoint_map[key]['host']
|
||||
else:
|
||||
return get_service_ips(stack).get(key + 'Vip')
|
||||
return get_service_ips(stack).get(key + 'Vip')
|
||||
|
||||
|
||||
def get_overcloud_endpoint(stack):
|
||||
|
@ -115,14 +115,12 @@ def get_profile_of_flavor(flavor_name, compute_client):
|
||||
profile = flavor.get_keys().get('capabilities:profile', '')
|
||||
if profile:
|
||||
return profile
|
||||
else:
|
||||
raise exception.DeriveParamsError(
|
||||
'Unable to determine profile for flavor (flavor name: '
|
||||
'%s)' % flavor_name)
|
||||
else:
|
||||
raise exception.DeriveParamsError(
|
||||
'Unable to determine flavor for flavor name: '
|
||||
'%s' % flavor_name)
|
||||
'Unable to determine profile for flavor (flavor name: '
|
||||
'%s)' % flavor_name)
|
||||
raise exception.DeriveParamsError(
|
||||
'Unable to determine flavor for flavor name: '
|
||||
'%s' % flavor_name)
|
||||
|
||||
|
||||
def convert_docker_params(stack_env=None):
|
||||
|
@ -134,11 +134,11 @@ def get_snmpd_readonly_user_password(pw_file=None):
|
||||
|
||||
if not os.path.exists(pw_file):
|
||||
return passlib.pwd.genword(length=24)
|
||||
else:
|
||||
with open(pw_file) as f:
|
||||
passwords = yaml.safe_load(f.read())
|
||||
|
||||
return passwords['parameter_defaults']['SnmpdReadonlyUserPassword']
|
||||
with open(pw_file) as f:
|
||||
passwords = yaml.safe_load(f.read())
|
||||
|
||||
return passwords['parameter_defaults']['SnmpdReadonlyUserPassword']
|
||||
|
||||
|
||||
def create_keystone_credential():
|
||||
|
Loading…
Reference in New Issue
Block a user