Fixed pep8 issues inside HAS 35/30135/4
authorYing Ruoyu <ruoyu.ying@intel.com>
Fri, 2 Feb 2018 13:56:16 +0000 (21:56 +0800)
committerRuoyu Ying <ruoyu.ying@intel.com>
Tue, 6 Feb 2018 01:01:36 +0000 (01:01 +0000)
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:
conductor/conductor/api/controllers/errors.py
conductor/conductor/api/controllers/v1/__init__.py
conductor/conductor/api/middleware.py
conductor/conductor/cmd/__init__.py
conductor/conductor/conf/__init__.py
conductor/conductor/controller/service.py
conductor/conductor/controller/translator.py
conductor/conductor/data/plugins/__init__.py
conductor/conductor/data/plugins/inventory_provider/__init__.py
conductor/conductor/solver/optimizer/__init__.py
conductor/conductor/solver/optimizer/fit_first.py
conductor/conductor/solver/request/__init__.py
conductor/conductor/solver/request/demand.py
conductor/conductor/solver/request/functions/__init__.py
conductor/conductor/solver/request/parser.py
conductor/conductor/solver/resource/__init__.py
conductor/conductor/solver/resource/region.py
conductor/conductor/solver/resource/service.py
conductor/conductor/solver/service.py
conductor/conductor/solver/simulators/__init__.py
conductor/conductor/solver/simulators/a_and_ai/__init__.py
conductor/conductor/solver/simulators/valet/__init__.py
conductor/conductor/solver/utils/__init__.py
conductor/conductor/tests/data/__init__.py
conductor/conductor/tests/functional/__init__.py
conductor/conductor/tests/integration/__init__.py
conductor/conductor/tests/tempest/__init__.py
conductor/conductor/tests/unit/__init__.py

index 6216721..f54b9c2 100644 (file)
@@ -30,6 +30,7 @@ LOG = log.getLogger(__name__)
 
 def error_wrapper(func):
     """Error decorator."""
+
     def func_wrapper(self, **kw):
         """Wrapper."""
 
index dc0664a..d7686d8 100644 (file)
@@ -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
index f2bbdfd..51efce1 100644 (file)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index f2bbdfd..51efce1 100644 (file)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index d13518c..1ef94bf 100644 (file)
@@ -67,6 +67,7 @@ CONF.register_opts(OPTS)
 
 class ControllerServiceLauncher(object):
     """Launcher for the controller service."""
+
     def __init__(self, conf):
         self.conf = conf
 
index eb467fe..4860deb 100644 (file)
@@ -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()
index f2bbdfd..51efce1 100644 (file)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index f2bbdfd..51efce1 100755 (executable)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index 42d8fed..ea9007f 100755 (executable)
@@ -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
index f2bbdfd..51efce1 100755 (executable)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index 5554cfe..ba9ae98 100755 (executable)
@@ -19,7 +19,6 @@
 #
 
 
-
 class Demand(object):
 
     def __init__(self, _name=None):
index 6e30549..5c422f1 100755 (executable)
@@ -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)
-
index f2bbdfd..51efce1 100755 (executable)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index fc42bd1..436cb64 100755 (executable)
@@ -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
 
index faedb53..9910c05 100755 (executable)
@@ -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
index 60aa092..d0144da 100644 (file)
@@ -98,6 +98,7 @@ CONF.register_opts(OPTS)
 
 class SolverServiceLauncher(object):
     """Launcher for the solver service."""
+
     def __init__(self, conf):
         self.conf = conf
 
index f2bbdfd..51efce1 100755 (executable)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index f2bbdfd..51efce1 100644 (file)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index f2bbdfd..51efce1 100644 (file)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index f2bbdfd..51efce1 100644 (file)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-
index f2bbdfd..51efce1 100644 (file)
@@ -16,4 +16,3 @@
 #
 # -------------------------------------------------------------------------
 #
-