From 4f9103d5a7c90b515d3b91437e85a96c110d85b8 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Tue, 17 Dec 2019 14:48:44 +0100 Subject: [PATCH] Prepare to switch to flake8 - 05 Final wave of changes to prepare to migrate to flake8 tests. Change-Id: I75c3acfc8b0ab34b82faf7b500ec9c27aa3efa91 --- pyghmi/cmd/fakebmc.py | 31 ++++---- pyghmi/cmd/pyghmicons.py | 5 +- pyghmi/cmd/virshbmc.py | 14 ++-- pyghmi/ipmi/oem/lenovo/inventory.py | 7 +- pyghmi/ipmi/oem/lenovo/nextscale.py | 36 +++++----- pyghmi/ipmi/oem/lenovo/pci.py | 35 +++++---- pyghmi/ipmi/oem/lenovo/psu.py | 60 +++++++--------- pyghmi/ipmi/oem/lenovo/raid_controller.py | 47 ++++++------- pyghmi/ipmi/oem/lenovo/raid_drive.py | 30 ++++---- pyghmi/ipmi/private/constants.py | 14 ++-- pyghmi/ipmi/private/localsession.py | 86 ++++++++++++----------- pyghmi/ipmi/private/serversession.py | 15 ++-- pyghmi/ipmi/private/session.py | 2 - pyghmi/util/parse.py | 1 + pyghmi/util/webclient.py | 9 ++- 15 files changed, 186 insertions(+), 206 deletions(-) diff --git a/pyghmi/cmd/fakebmc.py b/pyghmi/cmd/fakebmc.py index 14d1ff91..090d8bcf 100755 --- a/pyghmi/cmd/fakebmc.py +++ b/pyghmi/cmd/fakebmc.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # Copyright 2015 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,24 +11,26 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# __author__ = 'jjohnson2@lenovo.com' -# this is a quick sample of how to write something that acts like a bmc -# to play: -# run fakebmc -# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status -# Chassis Power is off -# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power on -# Chassis Power Control: Up/On -# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status -# Chassis Power is on -# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 mc reset cold -# Sent cold reset command to MC -# (fakebmc exits) +"""this is a quick sample of how to write something that acts like a bmc +to play: +run fakebmc +# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status +Chassis Power is off +# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power on +Chassis Power Control: Up/On +# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status +Chassis Power is on +# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 mc reset cold +Sent cold reset command to MC +(fakebmc exits) +""" + import argparse -import pyghmi.ipmi.bmc as bmc import sys +import pyghmi.ipmi.bmc as bmc + class FakeBmc(bmc.Bmc): def __init__(self, authdata, port): diff --git a/pyghmi/cmd/pyghmicons.py b/pyghmi/cmd/pyghmicons.py index 807d819f..e22d9a6d 100755 --- a/pyghmi/cmd/pyghmicons.py +++ b/pyghmi/cmd/pyghmicons.py @@ -22,9 +22,8 @@ import termios import threading import tty -from six import string_types - from pyghmi.ipmi import console +import six def _doinput(sol): @@ -42,7 +41,7 @@ def _doinput(sol): def _print(data): bailout = False - if not isinstance(data, string_types): + if not isinstance(data, six.string_types): bailout = True data = repr(data) sys.stdout.write(data) diff --git a/pyghmi/cmd/virshbmc.py b/pyghmi/cmd/virshbmc.py index 83e5d3bc..0343725c 100755 --- a/pyghmi/cmd/virshbmc.py +++ b/pyghmi/cmd/virshbmc.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -11,18 +10,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Written by pmartini2, but mostly a clone of fakebmc, written by jjohnson2 -# __author__ = 'pmartini2@bloomberg.net' - -# This is a simple, but working proof of concept of using pyghmi.ipmi.bmc to -# control a VM +"""This is a simple, but working proof of concept of using pyghmi.ipmi.bmc to +control a VM +""" import argparse -import libvirt -import pyghmi.ipmi.bmc as bmc import sys import threading +import libvirt +import pyghmi.ipmi.bmc as bmc + def lifecycle_callback(connection, domain, event, detail, console): console.state = console.domain.state(0) diff --git a/pyghmi/ipmi/oem/lenovo/inventory.py b/pyghmi/ipmi/oem/lenovo/inventory.py index 5cd1b4e9..6f246e85 100755 --- a/pyghmi/ipmi/oem/lenovo/inventory.py +++ b/pyghmi/ipmi/oem/lenovo/inventory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2015 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,16 +53,15 @@ class EntryField(object): # General parameter parsing functions def parse_inventory_category(name, info, countable=True): - """Parses every entry in an inventory category (CPU, memory, PCI, drives, - etc). + """Parses every entry in an inventory category + For example: CPU, memory, PCI, drives Expects the first byte to be a count of the number of entries, followed by a list of elements to be parsed by a dedicated parser (below). :param name: the name of the parameter (e.g.: "cpu") :param info: a list of integers with raw data read from an IPMI requests :param countable: whether the data have an entries count field - :returns: dict -- a list of entries in the category. """ raw = info["data"][1:] diff --git a/pyghmi/ipmi/oem/lenovo/nextscale.py b/pyghmi/ipmi/oem/lenovo/nextscale.py index 07d5a3a7..b0a4efa6 100644 --- a/pyghmi/ipmi/oem/lenovo/nextscale.py +++ b/pyghmi/ipmi/oem/lenovo/nextscale.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2016-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,19 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +import struct +import weakref +from xml.etree.ElementTree import fromstring +import zipfile + import pyghmi.constants as pygconst import pyghmi.exceptions as pygexc import pyghmi.ipmi.private.session as ipmisession from pyghmi.ipmi import sdr import pyghmi.util.webclient as webclient -import struct +import six + try: from urllib import urlencode except ImportError: from urllib.parse import urlencode -import weakref -from xml.etree.ElementTree import fromstring -import zipfile try: range = xrange @@ -280,8 +281,9 @@ class SMMClient(object): self.wc.request( 'POST', '/data', ('get=passwordMinLength,passwordForceChange,passwordDurationDays,' - 'passwordExpireWarningDays,passwordChangeInterval,' - 'passwordReuseCheckNum,passwordFailAllowdNum,passwordLockoutTimePeriod')) + 'passwordExpireWarningDays,passwordChangeInterval,' + 'passwordReuseCheckNum,passwordFailAllowdNum,' + 'passwordLockoutTimePeriod')) rsp = self.wc.getresponse() rspbody = rsp.read() accountinfo = fromstring(rspbody) @@ -301,12 +303,10 @@ class SMMClient(object): 'possible': [self.fanmodes[x] for x in self.fanmodes]} return settings - def set_bmc_configuration(self, changeset): rules = [] for key in changeset: - if (isinstance(changeset[key], str) or - isinstance(changeset[key], unicode)): + if isinstance(changeset[key], six.string_types): changeset[key] = {'value': changeset[key]} if key.lower() in self.rulemap: rules.append('{0}:{1}'.format( @@ -321,8 +321,8 @@ class SMMClient(object): break else: raise pygexc.InvalidParameterValue( - '{0} not a valid mode for fanspeed'.format( - changeset[key]['value'])) + '{0} not a valid mode for fanspeed'.format( + changeset[key]['value'])) if rules: rules = 'set={0}'.format(','.join(rules)) self.wc.request('POST', '/data', rules) @@ -352,7 +352,7 @@ class SMMClient(object): rsp['data'] = b'\x01' initpct = 1.0 if progress: - progress({'phase': 'initializing', 'progress': initpct}) + progress({'phase': 'initializing', 'progress': initpct}) while bytearray(rsp['data'])[0] != 0: ipmisession.Session.pause(3) initpct += 3.0 @@ -389,8 +389,12 @@ class SMMClient(object): cv = self.ipmicmd.certverify wc = webclient.SecureHTTPConnection(self.smm, 443, verifycallback=cv) wc.connect() - loginform = urlencode({'user': self.username, - 'password': self.password}) + loginform = urlencode( + { + 'user': self.username, + 'password': self.password + } + ) wc.request('POST', '/data/login', loginform) rsp = wc.getresponse() if rsp.status != 200: diff --git a/pyghmi/ipmi/oem/lenovo/pci.py b/pyghmi/ipmi/oem/lenovo/pci.py index c875107f..e91a411d 100755 --- a/pyghmi/ipmi/oem/lenovo/pci.py +++ b/pyghmi/ipmi/oem/lenovo/pci.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2015 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pyghmi.ipmi.oem.lenovo.inventory import EntryField, \ - parse_inventory_category_entry +from pyghmi.ipmi.oem.lenovo import inventory pci_fields = ( - EntryField("index", "B"), - EntryField("PCIType", "B", mapper={ + inventory.EntryField("index", "B"), + inventory.EntryField("PCIType", "B", mapper={ 0x0: "On board slot", 0x1: "Riser Type 1", 0x2: "Riser Type 2", @@ -31,23 +28,23 @@ pci_fields = ( 0x8: "ROC", 0x9: "Mezz" }), - EntryField("BusNumber", "B"), - EntryField("DeviceFunction", "B"), - EntryField("VendorID", "