diff options
author | 2018-02-02 21:56:16 +0800 | |
---|---|---|
committer | 2018-02-06 01:01:36 +0000 | |
commit | d067098d0fbc8718cc56446464e3363755ac04b3 (patch) | |
tree | b74e336cc816a43c473ec8ade33273bd399c7e43 | |
parent | 5eae41a6cbd4a60c72491bdbbce324691a5a929c (diff) |
Fixed pep8 issues inside HAS
Fixed pep8 issues including indentation,
blank lines etc. In translator.py,
errors.py etc.
Change-Id: I73ea2815afded379926acccdc6796391e7540e32
Issue-ID: OPTFRA-61
Signed-off-by: Ying Ruoyu <ruoyu.ying@intel.com>
28 files changed, 25 insertions, 37 deletions
diff --git a/conductor/conductor/api/controllers/errors.py b/conductor/conductor/api/controllers/errors.py index 6216721..f54b9c2 100644 --- a/conductor/conductor/api/controllers/errors.py +++ b/conductor/conductor/api/controllers/errors.py @@ -30,6 +30,7 @@ LOG = log.getLogger(__name__) def error_wrapper(func): """Error decorator.""" + def func_wrapper(self, **kw): """Wrapper.""" diff --git a/conductor/conductor/api/controllers/v1/__init__.py b/conductor/conductor/api/controllers/v1/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/api/controllers/v1/__init__.py +++ b/conductor/conductor/api/controllers/v1/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/api/middleware.py b/conductor/conductor/api/middleware.py index dc0664a..d7686d8 100644 --- a/conductor/conductor/api/middleware.py +++ b/conductor/conductor/api/middleware.py @@ -88,7 +88,7 @@ class ParsableErrorMiddleware(object): error = environ.get('translatable_error') user_locale = self.best_match_language(req.accept_language) if (req.accept.best_match(['application/json', 'application/xml']) - == 'application/xml'): + == 'application/xml'): content_type = 'application/xml' try: # simple check xml is valid diff --git a/conductor/conductor/cmd/__init__.py b/conductor/conductor/cmd/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/cmd/__init__.py +++ b/conductor/conductor/cmd/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/conf/__init__.py b/conductor/conductor/conf/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/conf/__init__.py +++ b/conductor/conductor/conf/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/controller/service.py b/conductor/conductor/controller/service.py index d13518c..1ef94bf 100644 --- a/conductor/conductor/controller/service.py +++ b/conductor/conductor/controller/service.py @@ -67,6 +67,7 @@ CONF.register_opts(OPTS) class ControllerServiceLauncher(object): """Launcher for the controller service.""" + def __init__(self, conf): self.conf = conf diff --git a/conductor/conductor/controller/translator.py b/conductor/conductor/controller/translator.py index eb467fe..4860deb 100644 --- a/conductor/conductor/controller/translator.py +++ b/conductor/conductor/controller/translator.py @@ -143,7 +143,7 @@ class Translator(object): self._optmization = self._template.get("optimization", {}) self._reservations = self._template.get("reservation", {}) - if type(self._version) is datetime.date: + if isinstance(self._version, datetime.date): self._version = str(self._version) def validate_components(self): @@ -193,7 +193,7 @@ class Translator(object): keys = component.get('keys', None) content = component.get('content') - if type(content) is not dict: + if not isinstance(content, dict): raise TranslatorException( "{} section must be a dictionary".format(name)) for content_name, content_def in content.items(): @@ -248,7 +248,7 @@ class Translator(object): path = [path] # Traverse a list - if type(obj) is list: + if isinstance(obj, list): for idx, val in enumerate(obj, start=0): # Add path to the breadcrumb trail new_path = list(path) @@ -258,7 +258,7 @@ class Translator(object): obj[idx] = self._parse_parameters(val, new_path) # Traverse a dict - elif type(obj) is dict: + elif isinstance(obj, dict): # Did we find a "{get_param: ...}" intrinsic? if obj.keys() == ['get_param']: param_name = obj['get_param'] @@ -328,7 +328,7 @@ class Translator(object): def parse_demands(self, demands): """Validate/prepare demands for use by the solver.""" - if type(demands) is not dict: + if not isinstance(demands, dict): raise TranslatorException("Demands must be provided in " "dictionary form") @@ -357,7 +357,7 @@ class Translator(object): # Check each candidate for candidate in requirement.get('candidates'): # Must be a dictionary - if type(candidate) is not dict: + if not isinstance(candidate, dict): raise TranslatorException( "Candidate found in demand {} that is " "not a dictionary".format(name)) @@ -468,9 +468,9 @@ class Translator(object): if (required_candidates and excluded_candidates and set(map(lambda entry: entry['candidate_id'], - required_candidates)) + required_candidates)) & set(map(lambda entry: entry['candidate_id'], - excluded_candidates))): + excluded_candidates))): raise TranslatorException( "Required candidate list and excluded candidate" " list are not mutually exclusive for demand" @@ -516,7 +516,7 @@ class Translator(object): def parse_constraints(self, constraints): """Validate/prepare constraints for use by the solver.""" - if type(constraints) is not dict: + if not isinstance(constraints, dict): raise TranslatorException("Constraints must be provided in " "dictionary form") @@ -637,7 +637,7 @@ class Translator(object): "operands": [], } - if type(optimization_copy) is not dict: + if not isinstance(optimization_copy, dict): raise TranslatorException("Optimization must be a dictionary.") goals = optimization_copy.keys() @@ -652,7 +652,7 @@ class Translator(object): "contain a single function of 'sum'.") operands = optimization_copy['minimize']['sum'] - if type(operands) is not list: + if not isinstance(operands, list): # or len(operands) != 2: raise TranslatorException( "Optimization goal 'minimize', function 'sum' " @@ -660,7 +660,7 @@ class Translator(object): def get_distance_between_args(operand): args = operand.get('distance_between') - if type(args) is not list and len(args) != 2: + if not isinstance(args, list) and len(args) != 2: raise TranslatorException( "Optimization 'distance_between' arguments must " "be a list of length two.") @@ -693,7 +693,7 @@ class Translator(object): for product_op in operand['product']: if threshold.is_number(product_op): weight = product_op - elif type(product_op) is dict: + elif isinstance(product_op, dict): if product_op.keys() == ['distance_between']: function = 'distance_between' args = get_distance_between_args(product_op) @@ -720,7 +720,7 @@ class Translator(object): def parse_reservations(self, reservations): demands = self._demands - if type(reservations) is not dict: + if not isinstance(reservations, dict): raise TranslatorException("Reservations must be provided in " "dictionary form") @@ -818,5 +818,6 @@ def main(): else: print("TESTING - Translator Error: {}".format(trns.error_message)) + if __name__ == '__main__': main() diff --git a/conductor/conductor/data/plugins/__init__.py b/conductor/conductor/data/plugins/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/data/plugins/__init__.py +++ b/conductor/conductor/data/plugins/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/data/plugins/inventory_provider/__init__.py b/conductor/conductor/data/plugins/inventory_provider/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/data/plugins/inventory_provider/__init__.py +++ b/conductor/conductor/data/plugins/inventory_provider/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/optimizer/__init__.py b/conductor/conductor/solver/optimizer/__init__.py index f2bbdfd..51efce1 100755 --- a/conductor/conductor/solver/optimizer/__init__.py +++ b/conductor/conductor/solver/optimizer/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/optimizer/fit_first.py b/conductor/conductor/solver/optimizer/fit_first.py index 42d8fed..ea9007f 100755 --- a/conductor/conductor/solver/optimizer/fit_first.py +++ b/conductor/conductor/solver/optimizer/fit_first.py @@ -89,8 +89,8 @@ class FitFirst(search.Search): .get("cloud_region_version").encode('utf-8') if _decision_path.total_value < bound_value or \ (_decision_path.total_value == bound_value and - self._compare_version(candidate_version, - version_value) > 0): + self._compare_version(candidate_version, + version_value) > 0): bound_value = _decision_path.total_value version_value = candidate_version best_resource = candidate diff --git a/conductor/conductor/solver/request/__init__.py b/conductor/conductor/solver/request/__init__.py index f2bbdfd..51efce1 100755 --- a/conductor/conductor/solver/request/__init__.py +++ b/conductor/conductor/solver/request/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/request/demand.py b/conductor/conductor/solver/request/demand.py index 5554cfe..ba9ae98 100755 --- a/conductor/conductor/solver/request/demand.py +++ b/conductor/conductor/solver/request/demand.py @@ -19,7 +19,6 @@ # - class Demand(object): def __init__(self, _name=None): diff --git a/conductor/conductor/solver/request/functions/__init__.py b/conductor/conductor/solver/request/functions/__init__.py index f2bbdfd..51efce1 100755 --- a/conductor/conductor/solver/request/functions/__init__.py +++ b/conductor/conductor/solver/request/functions/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/request/parser.py b/conductor/conductor/solver/request/parser.py index 6e30549..5c422f1 100755 --- a/conductor/conductor/solver/request/parser.py +++ b/conductor/conductor/solver/request/parser.py @@ -237,4 +237,3 @@ class Parser(object): for d in constraint.demand_list: if d in self.demands.keys(): self.demands[d].constraint_list.append(constraint) - diff --git a/conductor/conductor/solver/resource/__init__.py b/conductor/conductor/solver/resource/__init__.py index f2bbdfd..51efce1 100755 --- a/conductor/conductor/solver/resource/__init__.py +++ b/conductor/conductor/solver/resource/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/resource/region.py b/conductor/conductor/solver/resource/region.py index fc42bd1..436cb64 100755 --- a/conductor/conductor/solver/resource/region.py +++ b/conductor/conductor/solver/resource/region.py @@ -65,10 +65,12 @@ class Region(object): self.last_update = 0 '''update resource capacity after allocating demand''' + def update_capacity(self): pass '''for logging''' + def get_json_summary(self): pass diff --git a/conductor/conductor/solver/resource/service.py b/conductor/conductor/solver/resource/service.py index faedb53..9910c05 100755 --- a/conductor/conductor/solver/resource/service.py +++ b/conductor/conductor/solver/resource/service.py @@ -44,9 +44,11 @@ class Service(object): self.last_update = 0 """update resource capacity after allocating demand""" + def update_capacity(self): pass """for logging""" + def get_json_summary(self): pass diff --git a/conductor/conductor/solver/service.py b/conductor/conductor/solver/service.py index 60aa092..d0144da 100644 --- a/conductor/conductor/solver/service.py +++ b/conductor/conductor/solver/service.py @@ -98,6 +98,7 @@ CONF.register_opts(OPTS) class SolverServiceLauncher(object): """Launcher for the solver service.""" + def __init__(self, conf): self.conf = conf diff --git a/conductor/conductor/solver/simulators/__init__.py b/conductor/conductor/solver/simulators/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/solver/simulators/__init__.py +++ b/conductor/conductor/solver/simulators/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/simulators/a_and_ai/__init__.py b/conductor/conductor/solver/simulators/a_and_ai/__init__.py index f2bbdfd..51efce1 100755 --- a/conductor/conductor/solver/simulators/a_and_ai/__init__.py +++ b/conductor/conductor/solver/simulators/a_and_ai/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/simulators/valet/__init__.py b/conductor/conductor/solver/simulators/valet/__init__.py index f2bbdfd..51efce1 100755 --- a/conductor/conductor/solver/simulators/valet/__init__.py +++ b/conductor/conductor/solver/simulators/valet/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/solver/utils/__init__.py b/conductor/conductor/solver/utils/__init__.py index f2bbdfd..51efce1 100755 --- a/conductor/conductor/solver/utils/__init__.py +++ b/conductor/conductor/solver/utils/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/tests/data/__init__.py b/conductor/conductor/tests/data/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/tests/data/__init__.py +++ b/conductor/conductor/tests/data/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/tests/functional/__init__.py b/conductor/conductor/tests/functional/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/tests/functional/__init__.py +++ b/conductor/conductor/tests/functional/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/tests/integration/__init__.py b/conductor/conductor/tests/integration/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/tests/integration/__init__.py +++ b/conductor/conductor/tests/integration/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/tests/tempest/__init__.py b/conductor/conductor/tests/tempest/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/tests/tempest/__init__.py +++ b/conductor/conductor/tests/tempest/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - diff --git a/conductor/conductor/tests/unit/__init__.py b/conductor/conductor/tests/unit/__init__.py index f2bbdfd..51efce1 100644 --- a/conductor/conductor/tests/unit/__init__.py +++ b/conductor/conductor/tests/unit/__init__.py @@ -16,4 +16,3 @@ # # ------------------------------------------------------------------------- # - |