(format): yapf reformat

- Run yapf to correct formatting
- Update one variable typo

Change-Id: Ic756ce4f9811cdf2726907c54299f4740fca9ce5
This commit is contained in:
Scott Hussey 2018-07-09 14:52:34 -05:00
parent b53a3ff0ea
commit eb996c27f4
11 changed files with 51 additions and 30 deletions

View File

@ -26,4 +26,3 @@ def upgrade():
def downgrade():
for c in tables.Tasks.__add_result_links__:
op.drop_column(tables.Tasks.__tablename__, c.name)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -214,5 +214,6 @@ class BootactionAssetType(BaseDrydockEnum):
ALL = (PackageList, Unit, File)
class BootactionAssetTypeField(fields.BaseEnumField):
AUTO_TYPE = BootactionAssetType()

View File

@ -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):

View File

@ -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."""

View File

@ -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,

View File

@ -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

View File

@ -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(