Pylint: fix trivial issues 8

fix: make methods static, if self is not used inside
(call is not changed, backward change is possible without code change,
  if self will be required)
Related-bug: #1556791

Change-Id: I48175c0179e0fde69ed9b527ab570a267b9191a5
This commit is contained in:
Alexey Stepanov 2016-03-15 13:53:13 +03:00
parent 7ba03f6537
commit 235959b861
23 changed files with 99 additions and 51 deletions

View File

@ -208,7 +208,8 @@ class Common(object):
def delete_flavor(self, flavor):
return self.nova.flavors.delete(flavor)
def _get_keystoneclient(self, username, password, tenant_name, auth_url,
@staticmethod
def _get_keystoneclient(username, password, tenant_name, auth_url,
retries=3, ca_cert=None, insecure=False):
exc_type, exc_value, exc_traceback = None, None, None
for i in xrange(retries):

View File

@ -56,7 +56,8 @@ class BaseActions(object):
cmd="systemctl restart {0}".format(service))
return result['exit_code'] == 0
def put_value_to_local_yaml(self, old_file, new_file, element, value):
@staticmethod
def put_value_to_local_yaml(old_file, new_file, element, value):
"""Changes content in old_file at element is given to the new value
and creates new file with changed content
:param old_file: a path to the file content from to be changed
@ -80,7 +81,8 @@ class BaseActions(object):
yaml.dump(origin_yaml, f_new, default_flow_style=False,
default_style='"')
def get_value_from_local_yaml(self, yaml_file, element):
@staticmethod
def get_value_from_local_yaml(yaml_file, element):
"""Get a value of the element from the local yaml file
:param str yaml_file: a path to the yaml file
@ -576,7 +578,8 @@ class FuelBootstrapCliActions(AdminActions):
fuel_settings = self.get_fuel_settings()
return fuel_settings["BOOTSTRAP"]
def parse_uuid(self, message):
@staticmethod
def parse_uuid(message):
uuid_regex = r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-" \
r"[0-9a-f]{4}-[0-9a-f]{12}"

View File

@ -132,7 +132,8 @@ class FuelLibraryModulesProvider(object):
def _request_diff(self, filename):
return self.gerrit_review.get_diff(filename)
def _get_lines_num_changed_from_diff(self, diff):
@staticmethod
def _get_lines_num_changed_from_diff(diff):
lines_changed = []
cursor = 1
for content in diff['content']:
@ -145,7 +146,8 @@ class FuelLibraryModulesProvider(object):
cursor += len(diff_content)
return lines_changed
def _get_modules_line_num_changed_from_content(self, lines, content):
@staticmethod
def _get_modules_line_num_changed_from_content(lines, content):
modules_lines_changed = []
for num in lines:
index = num

View File

@ -29,7 +29,8 @@ class IronicActions(os_actions.OpenStackActions):
user, passwd,
tenant)
def upload_user_image(self, nailgun_node, ssh_manager, img_url):
@staticmethod
def upload_user_image(nailgun_node, ssh_manager, img_url):
disk_info = [{"name": "vda", "extra": [], "free_space": 11000,
"type": "disk", "id": "vda", "size": 11000,
"volumes": [{"mount": "/", "type": "partition",
@ -73,7 +74,8 @@ class IronicActions(os_actions.OpenStackActions):
self.create_ironic_port(address=mac_address,
node_uuid=ironic_node.uuid)
def wait_for_ironic_hypervisors(self, ironic_conn, ironic_slaves):
@staticmethod
def wait_for_ironic_hypervisors(ironic_conn, ironic_slaves):
def _wait_for_ironic_hypervisor():
hypervisors = ironic_conn.get_hypervisors()
@ -96,7 +98,8 @@ class IronicActions(os_actions.OpenStackActions):
wait(lambda: self.get_instance_detail(srv).status == "ACTIVE",
timeout=60 * 15, timeout_msg='Server didn\'t became active')
def verify_vms_connection(self, ironic_conn):
@staticmethod
def verify_vms_connection(ironic_conn):
srv_list = ironic_conn.get_servers()
for srv in srv_list:
wait(lambda: tcp_ping(srv.networks['baremetal'][0], 22),

View File

@ -19,7 +19,8 @@ class NessusClient(object):
self.ssl_verify = ssl_verify
self.login()
def log_request(self, url, method, request_headers, request_body,
@staticmethod
def log_request(url, method, request_headers, request_body,
status_code, response_headers, response_body):
log_fmt = ("Request {method} {url}\n"
"Request - Headers: {request_headers}\n"

View File

@ -319,7 +319,8 @@ class OpenStackActions(common.Common):
controller_ssh, vm_ip, "md5sum {:s}".format(file_path), creds)
return out['stdout']
def execute_through_host(self, ssh, vm_host, cmd, creds=()):
@staticmethod
def execute_through_host(ssh, vm_host, cmd, creds=()):
logger.debug("Making intermediate transport")
intermediate_transport = ssh._ssh.get_transport()
@ -547,8 +548,8 @@ class OpenStackActions(common.Common):
def get_vip(self, vip):
return self.neutron.show_vip(vip)
def get_nova_instance_ip(
self, srv, net_name='novanetwork', addrtype='fixed'):
@staticmethod
def get_nova_instance_ip(srv, net_name='novanetwork', addrtype='fixed'):
for network_label, address_list in srv.addresses.items():
if network_label != net_name:
continue

View File

@ -288,7 +288,8 @@ class CustomRepo(object):
logger.info('Local repository {0} has been updated successfully.'
.format(local_mirror_path))
def assert_msg(self, cmd, err):
@staticmethod
def assert_msg(cmd, err):
return 'Executing \'{0}\' on the admin node has failed with: {1}'\
.format(cmd, err)

View File

@ -56,7 +56,8 @@ class SSHManager(object):
self.login = login
self.__password = password
def _connect(self, remote):
@staticmethod
def _connect(remote):
""" Check if connection is stable and return this one
:param remote:
@ -207,7 +208,8 @@ class SSHManager(object):
remote = self._get_remote(ip=ip, port=port)
return remote.execute_async(cmd)
def _json_deserialize(self, json_string):
@staticmethod
def _json_deserialize(json_string):
""" Deserialize json_string and return object
:param json_string: string or list with json

View File

@ -198,7 +198,8 @@ class EnvironmentModel(object):
) % params
return keys
def get_target_devs(self, devops_nodes):
@staticmethod
def get_target_devs(devops_nodes):
return [
interface.target_dev for interface in [
val for var in map(lambda node: node.interfaces, devops_nodes)
@ -516,11 +517,13 @@ class EnvironmentModel(object):
logger.debug('Offloading settings:\n{0}\n'.format(
''.join(result['stdout'])))
# pylint: disable=no-self-use
@update_rpm_packages
@upload_manifests
def setup_customisation(self):
logger.info('Installing custom packages/manifests '
'before master node bootstrap...')
# pylint: enable=no-self-use
@logwrap
def wait_for_provisioning(self,
@ -722,8 +725,9 @@ class EnvironmentModel(object):
.format(echo_cmd, echo_result['stderr']))
return resolv_conf['stdout']
@staticmethod
@logwrap
def execute_remote_cmd(self, remote, cmd, exit_code=0):
def execute_remote_cmd(remote, cmd, exit_code=0):
result = remote.execute(cmd)
assert_equal(result['exit_code'], exit_code,
'Failed to execute "{0}" on remote host: {1}'.

View File

@ -1580,7 +1580,8 @@ class FuelWebClient(object):
networks=new_settings["networks"]
)
def _get_true_net_name(self, name, net_pools):
@staticmethod
def _get_true_net_name(name, net_pools):
"""Find a devops network name in net_pools"""
for net in net_pools:
if name in net:
@ -1698,7 +1699,8 @@ class FuelWebClient(object):
else:
net_config['ip_ranges'] = self.get_range(ip_network, -1)
def get_range(self, ip_network, ip_range=0):
@staticmethod
def get_range(ip_network, ip_range=0):
net = list(netaddr.IPNetwork(str(ip_network)))
half = len(net) / 2
if ip_range == 0:
@ -2152,11 +2154,13 @@ class FuelWebClient(object):
'Nailgun node status is not ready but {0}'.format(
nailgun_node['status']))
@staticmethod
@logwrap
def modify_python_file(self, remote, modification, filename):
def modify_python_file(remote, modification, filename):
remote.execute('sed -i "{0}" {1}'.format(modification, filename))
def backup_master(self, remote):
@staticmethod
def backup_master(remote):
# FIXME(kozhukalov): This approach is outdated
# due to getting rid of docker containers.
logger.info("Backup of the master node is started.")
@ -2229,8 +2233,9 @@ class FuelWebClient(object):
'Cidr after deployment is not equal'
' to cidr by default')
@staticmethod
@logwrap
def check_fixed_nova_splited_cidr(self, os_conn, nailgun_cidr):
def check_fixed_nova_splited_cidr(os_conn, nailgun_cidr):
logger.debug('Nailgun cidr for nova: {0}'.format(nailgun_cidr))
subnets_list = [net.cidr for net in os_conn.get_nova_network_list()]
@ -2321,13 +2326,12 @@ class FuelWebClient(object):
fqdn, self.environment.d_env.nodes().slaves)
return devops_node
@staticmethod
@logwrap
def get_fqdn_by_hostname(self, hostname):
if DNS_SUFFIX not in hostname:
hostname += DNS_SUFFIX
return hostname
else:
return hostname
def get_fqdn_by_hostname(hostname):
return (
hostname + DNS_SUFFIX if DNS_SUFFIX not in hostname else hostname
)
def get_nodegroup(self, cluster_id, name='default', group_id=None):
ngroups = self.client.get_nodegroups()
@ -2450,8 +2454,9 @@ class FuelWebClient(object):
plugin_data[path[-1]] = value
self.client.update_cluster_attributes(cluster_id, attr)
@staticmethod
@logwrap
def prepare_ceph_to_delete(self, remote_ceph):
def prepare_ceph_to_delete(remote_ceph):
hostname = ''.join(remote_ceph.execute(
"hostname -s")['stdout']).strip()
osd_tree = ceph.get_osd_tree(remote_ceph)

View File

@ -115,7 +115,8 @@ class Build(object):
logger.debug("Request build data from {}".format(build_url))
return json.load(urllib2.urlopen(build_url))
def get_test_data(self, url, result_path=None):
@staticmethod
def get_test_data(url, result_path=None):
if result_path:
test_url = "/".join(
[url.rstrip("/"), 'testReport'] + result_path + ['api/json'])

View File

@ -134,7 +134,8 @@ class ZabbixPlugin(TestBasic):
self.fuel_web.update_plugin_data(
cluster_id, plugin_name, plugin_options)
def check_event_message(self, zabbix_web, zabbix_hostgroup, message):
@staticmethod
def check_event_message(zabbix_web, zabbix_hostgroup, message):
statuses_html = bs4.BeautifulSoup(zabbix_web.get_trigger_statuses())
status_lines = statuses_html.find_all('tr', {'class': 'even_row'})

View File

@ -95,14 +95,16 @@ class TestAdminNode(TestBasic):
@test(groups=["logrotate"])
class TestLogrotateBase(TestBasic):
def generate_file(self, remote, name, path, size):
@staticmethod
def generate_file(remote, name, path, size):
cmd = 'cd {0} && fallocate -l {1} {2}'.format(path, size, name)
result = remote.execute(cmd)
assert_equal(0, result['exit_code'],
'Command {0} execution failed. '
'Execution result is: {1}'.format(cmd, result))
def execute_logrotate_cmd(self, remote, cmd=None, exit_code=None):
@staticmethod
def execute_logrotate_cmd(remote, cmd=None, exit_code=None):
if not cmd:
cmd = 'logrotate -v -f /etc/logrotate.conf'
result = remote.execute(cmd)
@ -140,7 +142,8 @@ class TestLogrotateBase(TestBasic):
'inodes with {0}'. format(result))
return self.bytestogb(int(result['stdout'][0]))
def bytestogb(self, data):
@staticmethod
def bytestogb(data):
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
prefix = {}
for i, s in enumerate(symbols):
@ -151,7 +154,8 @@ class TestLogrotateBase(TestBasic):
return format(value, '.1f'), s
return data, 'B'
def create_old_file(self, remote, name):
@staticmethod
def create_old_file(remote, name):
one_week_old = datetime.datetime.now() - datetime.timedelta(days=7)
res = remote.execute(
'touch {0} -d {1}'.format(name, one_week_old))

View File

@ -36,7 +36,8 @@ class TestOffloading(BondingTest):
'rx-vlan-offload',
'tx-vlan-offload']
def prepare_offloading_modes(self, interfaces, offloading_types, state):
@staticmethod
def prepare_offloading_modes(interfaces, offloading_types, state):
modes = [{'name': name, 'state': state} for name in offloading_types]
return [{'name': interface, 'offloading_modes': deepcopy(modes)}
for interface in interfaces]

View File

@ -104,8 +104,9 @@ class CommandLine(TestBasic):
)
)
@staticmethod
@logwrap
def hiera_floating_ranges(self, node_ip):
def hiera_floating_ranges(node_ip):
"""
1. SSH to controller node

View File

@ -54,25 +54,29 @@ class TestJumboFrames(base_test_case.TestBasic):
return "mtu {0}".format(mtu) in self.get_node_iface(node, iface)
def get_node_iface(self, node, iface):
@staticmethod
def get_node_iface(node, iface):
"""Get environment node network interface."""
command = "sudo ip link show {0}".format(iface)
return ''.join(node.execute(command)['stdout'])
def set_host_iface_mtu(self, iface, mtu):
@staticmethod
def set_host_iface_mtu(iface, mtu):
"""Set devops/fuel-qa host network interface mtu."""
command = "sudo ip link set {0} mtu {1}".format(iface, mtu).split()
return subprocess.call(command, stderr=subprocess.STDOUT)
def get_host_iface(self, iface):
@staticmethod
def get_host_iface(iface):
"""Get devops/fuel-qa host network interface."""
command = "sudo ip link show {0}".format(iface).split()
return subprocess.check_output(command, stderr=subprocess.STDOUT)
def get_host_bridge_ifaces(self, bridge_name):
@staticmethod
def get_host_bridge_ifaces(bridge_name):
"""Get list of devops/fuel-qa host network bridge interfaces."""
command = "sudo brctl show {0}".format(bridge_name).split()

View File

@ -125,7 +125,8 @@ class NodeReinstallationEnv(TestBasic):
class ReadyNodeReinstallation(TestBasic):
"""ReadyNodeReinstallation.""" # TODO documentation
def _check_hostname(self, old_node_nailgun, reinstalled_node_nailgun):
@staticmethod
def _check_hostname(old_node_nailgun, reinstalled_node_nailgun):
"""Check that the hostname is the same on both given nodes."""
assert_equal(old_node_nailgun['hostname'],
reinstalled_node_nailgun['hostname'],

View File

@ -44,7 +44,8 @@ class TestOffloading(TestBasic):
'rx-vlan-offload',
'tx-vlan-offload']
def prepare_offloading_modes(self, interface, types, state):
@staticmethod
def prepare_offloading_modes(interface, types, state):
return [{'name': interface,
'offloading_modes': [{'name': name, 'state': state,
'sub': []} for name in types]}]

View File

@ -77,7 +77,8 @@ class ServicesReconfiguration(TestBasic):
timeout_msg="Timeout exceeded while waiting for "
"node status: {0}".format(status))
def check_response_code(self, expected_code, err_msg,
@staticmethod
def check_response_code(expected_code, err_msg,
func, *args, **kwargs):
try:
func(*args, **kwargs)
@ -89,7 +90,8 @@ class ServicesReconfiguration(TestBasic):
else:
raise Exception(err_msg)
def change_default_range(self, networks, number_excluded_ips,
@staticmethod
def change_default_range(networks, number_excluded_ips,
cut_from_start=True):
"""
Change IP range for public, management, storage network
@ -115,7 +117,8 @@ class ServicesReconfiguration(TestBasic):
default_network["ip_ranges"][0] = [str(ip)
for ip in new_range]
def is_update_dnsmasq_running(self, tasks):
@staticmethod
def is_update_dnsmasq_running(tasks):
for task in tasks:
if task['name'] == "update_dnsmasq" and \
task["status"] == "running":
@ -237,7 +240,8 @@ class ServicesReconfiguration(TestBasic):
"Please, see details: {0}".format(res))
os_conn.delete_instance(instance)
def check_ml2_vlan_range(self, os_conn):
@staticmethod
def check_ml2_vlan_range(os_conn):
"""
:param os_conn: an object of connection to openstack services
:return:
@ -280,7 +284,8 @@ class ServicesReconfiguration(TestBasic):
else:
raise Exception("New configuration was not applied")
def check_token_expiration(self, os_conn, time_expiration):
@staticmethod
def check_token_expiration(os_conn, time_expiration):
"""
:param os_conn: an object of connection to openstack services
:param time_expiration: an integer value of token time expiration

View File

@ -32,7 +32,8 @@ from fuelweb_test.helpers.exceptions import UnexpectedExitCode
@test(groups=["ubuntu_bootstrap_builder", "bvt_ubuntu_bootstrap"])
class UbuntuBootstrapBuild(base_test_case.TestBasic):
def _get_main_repo(self, repos, repo_name, suite_type):
@staticmethod
def _get_main_repo(repos, repo_name, suite_type):
for repo in repos:
if repo_name not in repo["name"]:
continue

View File

@ -36,7 +36,8 @@ class VcenterDeploy(TestBasic):
def node_name(self, name_node):
return self.fuel_web.get_nailgun_node_by_name(name_node)['hostname']
def create_vm(self, os_conn=None, vm_count=None):
@staticmethod
def create_vm(os_conn=None, vm_count=None):
# Get list of available images,flavors and hypervisors
images_list = os_conn.nova.images.list()
flavors_list = os_conn.nova.flavors.list()

View File

@ -60,6 +60,7 @@ class TestCreateMirror(TestBasic):
# TODO(akostrikov) add check that images are present.
self.env.make_snapshot(snapshot_name, is_make=True)
# pylint: disable=no-self-use
@test(groups=['fuel-mirror', 'create-mirror'],
depends_on=[prepare_mirrors_environment])
def no_dependencies_package_install(self):
@ -76,3 +77,4 @@ class TestCreateMirror(TestBasic):
def check_download_with_proxy(self):
# TODO(akostrikov) Wait for https://review.openstack.org/#/c/242533/
raise SkipTest('Not implemented yet')
# pylint: enable=no-self-use

View File

@ -185,6 +185,7 @@ class TestUseMirror(TestBasic):
self.show_step(15)
self.env.make_snapshot('deploy_with_custom_mirror')
# pylint: disable=no-self-use
@test(groups=['fuel-mirror', 'use-mirror'])
def deploy_no_official_access(self):
# TODO(akostrikov) add firewall rules to verify that there is no
@ -196,3 +197,4 @@ class TestUseMirror(TestBasic):
# TODO(akostrikov) add tests to verify that fuel-mirror works with
# proxies too.
raise SkipTest('Not implemented yet')
# pylint: enable=no-self-use