From eb996c27f4d97acba4ad8d21d6bb98e98f6a538b Mon Sep 17 00:00:00 2001 From: Scott Hussey Date: Mon, 9 Jul 2018 14:52:34 -0500 Subject: [PATCH] (format): yapf reformat - Run yapf to correct formatting - Update one variable typo Change-Id: Ic756ce4f9811cdf2726907c54299f4740fca9ce5 --- .../4713e7ebca9_add_task_status_links.py | 1 - drydock_provisioner/config.py | 12 +++++++--- .../drivers/node/maasdriver/actions/node.py | 8 +++++-- .../drivers/node/maasdriver/models/machine.py | 3 ++- .../node/maasdriver/models/node_results.py | 7 +++++- drydock_provisioner/objects/fields.py | 1 + .../validations/bootaction_validity.py | 24 +++++++++---------- drydock_provisioner/statemgmt/db/tables.py | 1 + .../statemgmt/design/resolver.py | 10 +++++--- drydock_provisioner/statemgmt/state.py | 12 +++++----- .../postgres/test_action_config_node_prov.py | 2 +- 11 files changed, 51 insertions(+), 30 deletions(-) diff --git a/alembic/versions/4713e7ebca9_add_task_status_links.py b/alembic/versions/4713e7ebca9_add_task_status_links.py index 5318a55f..cc492e5d 100644 --- a/alembic/versions/4713e7ebca9_add_task_status_links.py +++ b/alembic/versions/4713e7ebca9_add_task_status_links.py @@ -26,4 +26,3 @@ def upgrade(): def downgrade(): for c in tables.Tasks.__add_result_links__: op.drop_column(tables.Tasks.__tablename__, c.name) - diff --git a/drydock_provisioner/config.py b/drydock_provisioner/config.py index 0466cfbc..843e6066 100644 --- a/drydock_provisioner/config.py +++ b/drydock_provisioner/config.py @@ -109,15 +109,21 @@ class DrydockConfig(object): cfg.IntOpt( 'http_client_connect_timeout', default=16, - help='Timeout for initial read of outgoing HTTP calls from Drydock in seconds.'), + help= + 'Timeout for initial read of outgoing HTTP calls from Drydock in seconds.' + ), cfg.IntOpt( 'http_client_read_timeout', default=300, - help='Timeout for initial read of outgoing HTTP calls from Drydock in seconds.'), + help= + 'Timeout for initial read of outgoing HTTP calls from Drydock in seconds.' + ), cfg.IntOpt( 'http_client_retries', default=3, - help='Number of retries for transient errors of outgoing HTTP calls from Drydock.'), + help= + 'Number of retries for transient errors of outgoing HTTP calls from Drydock.' + ), ] # Enabled plugins diff --git a/drydock_provisioner/drivers/node/maasdriver/actions/node.py b/drydock_provisioner/drivers/node/maasdriver/actions/node.py index de72d8ee..995a5211 100644 --- a/drydock_provisioner/drivers/node/maasdriver/actions/node.py +++ b/drydock_provisioner/drivers/node/maasdriver/actions/node.py @@ -941,7 +941,9 @@ class ConfigureHardware(BaseMaasAction): n, update_name=False) if machine is not None: if machine.status_name in [ - 'New', 'Broken', 'Failed commissioning', 'Failed testing']: + 'New', 'Broken', 'Failed commissioning', + 'Failed testing' + ]: self.logger.debug( "Located node %s in MaaS, starting commissioning" % (n.name)) @@ -988,7 +990,9 @@ class ConfigureHardware(BaseMaasAction): self.task.add_status_msg( msg=msg, error=False, ctx=n.name, ctx_type='node') self.task.success(focus=n.get_id()) - elif machine.status_name in ['Ready', 'Deploying', 'Allocated', 'Deployed']: + elif machine.status_name in [ + 'Ready', 'Deploying', 'Allocated', 'Deployed' + ]: msg = "Located node %s in MaaS, node commissioned. Skipping..." % ( n.name) self.logger.info(msg) diff --git a/drydock_provisioner/drivers/node/maasdriver/models/machine.py b/drydock_provisioner/drivers/node/maasdriver/models/machine.py index 7493c08e..69a0294c 100644 --- a/drydock_provisioner/drivers/node/maasdriver/models/machine.py +++ b/drydock_provisioner/drivers/node/maasdriver/models/machine.py @@ -303,7 +303,8 @@ class Machine(model_base.ResourceBase): :param str result_type: the type of results to return. One of ``all``, ``commissioning``, ``testing``, ``deploy`` """ - node_results = maas_nr.NodeResults(system_id_list=[self.resource_id], result_type=result_type) + node_results = maas_nr.NodeResults( + system_id_list=[self.resource_id], result_type=result_type) node_results.refresh() return node_results diff --git a/drydock_provisioner/drivers/node/maasdriver/models/node_results.py b/drydock_provisioner/drivers/node/maasdriver/models/node_results.py index 162b35af..2dd0ef1b 100644 --- a/drydock_provisioner/drivers/node/maasdriver/models/node_results.py +++ b/drydock_provisioner/drivers/node/maasdriver/models/node_results.py @@ -21,7 +21,10 @@ import drydock_provisioner.drivers.node.maasdriver.models.base as model_base class NodeResult(model_base.ResourceBase): resource_url = 'commissioning-results/' - fields = ['resource_id', 'name', 'result_type', 'updated', 'data', 'script_result'] + fields = [ + 'resource_id', 'name', 'result_type', 'updated', 'data', + 'script_result' + ] json_fields = [] type_map = { @@ -57,6 +60,7 @@ class NodeResult(model_base.ResourceBase): def get_type_desc(self): return NodeResult.type_rev_map.get(self.result_type) + class NodeResults(model_base.ResourceCollectionBase): collection_url = 'commissioning-results/' @@ -90,4 +94,5 @@ class NodeResults(model_base.ResourceCollectionBase): if isinstance(o, dict): i = self.collection_resource.from_dict(self.api_client, o) self.resources[i.resource_id] = i + return diff --git a/drydock_provisioner/objects/fields.py b/drydock_provisioner/objects/fields.py index 8f261529..efde1b9c 100644 --- a/drydock_provisioner/objects/fields.py +++ b/drydock_provisioner/objects/fields.py @@ -214,5 +214,6 @@ class BootactionAssetType(BaseDrydockEnum): ALL = (PackageList, Unit, File) + class BootactionAssetTypeField(fields.BaseEnumField): AUTO_TYPE = BootactionAssetType() diff --git a/drydock_provisioner/orchestrator/validations/bootaction_validity.py b/drydock_provisioner/orchestrator/validations/bootaction_validity.py index 68da503f..e11e6dc9 100644 --- a/drydock_provisioner/orchestrator/validations/bootaction_validity.py +++ b/drydock_provisioner/orchestrator/validations/bootaction_validity.py @@ -33,10 +33,10 @@ class BootactionDefined(Validators): for n in nodes_wo_ba: msg = "Node %s is not in scope for any bootactions." % n.name - self.report_warn(msg, [ - n.doc_ref - ], "It is expected all nodes have at least one post-deploy action." - ) + self.report_warn( + msg, [n.doc_ref], + "It is expected all nodes have at least one post-deploy action." + ) return @@ -57,20 +57,20 @@ class BootactionPackageListValid(Validators): if a.type == 'pkg_list': if not a.location and not a.package_list: msg = "Bootaction has asset of type 'pkg_list' but no valid package data" - self.report_error(msg, [ - ba.doc_ref - ], "pkg_list bootaction assets must specify a list of packages." - ) + self.report_error( + msg, [ba.doc_ref], + "pkg_list bootaction assets must specify a list of packages." + ) elif a.package_list: for p, v in a.package_list.items(): try: self.validate_package_version(v) except errors.InvalidPackageListFormat as ex: msg = str(ex) - self.report_error(msg, [ - ba.doc_ref - ], "pkg_list version specifications must be in a valid format." - ) + self.report_error( + msg, [ba.doc_ref], + "pkg_list version specifications must be in a valid format." + ) return def validate_package_version(self, v): diff --git a/drydock_provisioner/statemgmt/db/tables.py b/drydock_provisioner/statemgmt/db/tables.py index 39ce7815..9d551bc1 100644 --- a/drydock_provisioner/statemgmt/db/tables.py +++ b/drydock_provisioner/statemgmt/db/tables.py @@ -62,6 +62,7 @@ class Tasks(ExtendTable): __schema__ = copy.copy(__baseschema__) __schema__.extend(__add_result_links__) + class ResultMessage(ExtendTable): """Table for tracking result/status messages.""" diff --git a/drydock_provisioner/statemgmt/design/resolver.py b/drydock_provisioner/statemgmt/design/resolver.py index 8eea6731..e4ac39cf 100644 --- a/drydock_provisioner/statemgmt/design/resolver.py +++ b/drydock_provisioner/statemgmt/design/resolver.py @@ -34,6 +34,7 @@ cache_opts = { cache = CacheManager(**parse_cache_config_options(cache_opts)) LOG = logging.getLogger(__name__) + class ReferenceResolver(object): """Class for handling different data references to resolve them data.""" @@ -65,8 +66,9 @@ class ReferenceResolver(object): except Exception as ex: tries = tries + 1 if tries < config_mgr.conf.network.http_client_retries: - LOG.debug("Retrying reference after failure: %s" % str(ex)) - time.sleep(5 ** tries) + LOG.debug("Retrying reference after failure: %s" % + str(ex)) + time.sleep(5**tries) except ValueError: raise errors.InvalidDesignReference( "Cannot resolve design reference %s: unable to parse as valid URI." @@ -87,7 +89,8 @@ class ReferenceResolver(object): auth=(design_uri.username, design_uri.password), timeout=get_client_timeouts()) else: - response = requests.get(design_uri.geturl(), timeout=get_client_timeouts()) + response = requests.get( + design_uri.geturl(), timeout=get_client_timeouts()) return response.content @@ -134,6 +137,7 @@ class ReferenceResolver(object): 'promenade+http': resolve_reference_ucp, } + def get_client_timeouts(): """Return a tuple of timeouts for the request library.""" return (config_mgr.conf.network.http_client_connect_timeout, diff --git a/drydock_provisioner/statemgmt/state.py b/drydock_provisioner/statemgmt/state.py index dc785f66..1177883e 100644 --- a/drydock_provisioner/statemgmt/state.py +++ b/drydock_provisioner/statemgmt/state.py @@ -272,8 +272,8 @@ class DrydockState(object): """ try: with self.db_engine.connect() as conn: - query = self.tasks_tbl.insert().values(**( - task.to_db(include_id=True))) + query = self.tasks_tbl.insert().values( + **(task.to_db(include_id=True))) conn.execute(query) return True except Exception as ex: @@ -289,8 +289,8 @@ class DrydockState(object): try: with self.db_engine.connect() as conn: query = self.tasks_tbl.update().where( - self.tasks_tbl.c.task_id == task.task_id.bytes).values(**( - task.to_db(include_id=False))) + self.tasks_tbl.c.task_id == task.task_id.bytes).values( + **(task.to_db(include_id=False))) rs = conn.execute(query) if rs.rowcount == 1: return True @@ -336,8 +336,8 @@ class DrydockState(object): try: with self.db_engine.connect() as conn: query = self.active_instance_tbl.update().where( - self.active_instance_tbl.c.identity == leader_id.bytes).values( - last_ping=datetime.utcnow()) + self.active_instance_tbl.c.identity == + leader_id.bytes).values(last_ping=datetime.utcnow()) rs = conn.execute(query) rc = rs.rowcount diff --git a/tests/integration/postgres/test_action_config_node_prov.py b/tests/integration/postgres/test_action_config_node_prov.py index 53e9e932..1a22fba0 100644 --- a/tests/integration/postgres/test_action_config_node_prov.py +++ b/tests/integration/postgres/test_action_config_node_prov.py @@ -17,7 +17,7 @@ from drydock_provisioner.drivers.node.maasdriver.actions.node import ConfigureNo class TestActionConfigureNodeProvisioner(object): - def test_create_maas_repo(selfi, mocker): + def test_create_maas_repo(self, mocker): distribution_list = ['xenial', 'xenial-updates'] repo_obj = objects.Repository(