lint: tidy up code some more, pylint is enforcing
This commit is contained in:
parent
66b3ccc0f0
commit
61564e8c01
17 changed files with 72 additions and 38 deletions
|
@ -47,5 +47,5 @@ class BaseAutomation(metaclass=ABCMeta):
|
|||
:return: None
|
||||
"""
|
||||
tmpl = jinja2.Template(template)
|
||||
with open(self.working_directory(filename), 'w') as tf:
|
||||
with open(self.working_directory(filename), 'w', encoding="utf-8") as tf:
|
||||
tf.write(tmpl.render(**kwargs))
|
||||
|
|
|
@ -6,6 +6,7 @@ from flask import current_app
|
|||
|
||||
from app import app
|
||||
from app.alarms import get_or_create_alarm
|
||||
from app.brm.brn import BRN
|
||||
from app.extensions import db
|
||||
from app.models.mirrors import Proxy
|
||||
from app.models.alarms import AlarmState
|
||||
|
@ -14,7 +15,7 @@ from app.terraform import BaseAutomation
|
|||
|
||||
def _cloudfront_quota() -> None:
|
||||
alarm = get_or_create_alarm(
|
||||
f"brn:{current_app.config['GLOBAL_NAMESPACE']}:0:mirror:cloudfront:quota/distributions",
|
||||
BRN.from_str(f"brn:{current_app.config['GLOBAL_NAMESPACE']}:0:mirror:cloudfront:quota/distributions"),
|
||||
"quota-usage"
|
||||
)
|
||||
alarm.last_updated = datetime.datetime.utcnow()
|
||||
|
|
|
@ -92,7 +92,7 @@ class BridgeAutomation(TerraformAutomation):
|
|||
if len(parts) < 4:
|
||||
continue
|
||||
bridge = Bridge.query.filter(Bridge.id == output[len('bridge_bridgeline_'):]).first()
|
||||
del(parts[3])
|
||||
del parts[3]
|
||||
bridge.bridgeline = " ".join(parts)
|
||||
bridge.terraform_updated = datetime.datetime.utcnow()
|
||||
db.session.commit()
|
||||
|
|
|
@ -138,7 +138,6 @@ class ProxyAutomation(TerraformAutomation):
|
|||
self.create_missing_proxies()
|
||||
self.deprecate_orphaned_proxies()
|
||||
self.destroy_expired_proxies()
|
||||
return None
|
||||
|
||||
def tf_posthook(self, *, prehook_result: Any = None) -> None:
|
||||
self.import_state(self.tf_show())
|
||||
|
|
|
@ -44,12 +44,12 @@ class TerraformAutomation(BaseAutomation):
|
|||
:param full: include a Terraform refresh in the automation module run
|
||||
:return: success status and Terraform apply logs
|
||||
"""
|
||||
prehook_result = self.tf_prehook()
|
||||
prehook_result = self.tf_prehook() # pylint: disable=assignment-from-no-return
|
||||
self.tf_generate()
|
||||
self.tf_init()
|
||||
returncode, logs = self.tf_apply(refresh=self.always_refresh or full)
|
||||
self.tf_posthook(prehook_result=prehook_result)
|
||||
return True if returncode == 0 else False, logs
|
||||
return returncode == 0, logs
|
||||
|
||||
def tf_apply(self, *,
|
||||
refresh: bool = True,
|
||||
|
@ -60,7 +60,7 @@ class TerraformAutomation(BaseAutomation):
|
|||
# The following subprocess call takes external input, but is providing
|
||||
# the argument list as an array such that argument injection would be
|
||||
# ineffective.
|
||||
tf = subprocess.run( # nosec
|
||||
tfcmd = subprocess.run( # nosec
|
||||
['terraform',
|
||||
'apply',
|
||||
'-auto-approve',
|
||||
|
@ -71,7 +71,7 @@ class TerraformAutomation(BaseAutomation):
|
|||
],
|
||||
cwd=self.working_directory(),
|
||||
stdout=subprocess.PIPE)
|
||||
return tf.returncode, tf.stdout.decode('utf-8')
|
||||
return tfcmd.returncode, tfcmd.stdout.decode('utf-8')
|
||||
|
||||
@abstractmethod
|
||||
def tf_generate(self) -> None:
|
||||
|
@ -92,11 +92,11 @@ class TerraformAutomation(BaseAutomation):
|
|||
|
||||
def tf_output(self) -> Any:
|
||||
# The following subprocess call does not take any user input.
|
||||
tf = subprocess.run( # nosec
|
||||
tfcmd = subprocess.run( # nosec
|
||||
['terraform', 'output', '-json'],
|
||||
cwd=self.working_directory(),
|
||||
stdout=subprocess.PIPE)
|
||||
return json.loads(tf.stdout)
|
||||
return json.loads(tfcmd.stdout)
|
||||
|
||||
def tf_plan(self, *,
|
||||
refresh: bool = True,
|
||||
|
@ -105,7 +105,7 @@ class TerraformAutomation(BaseAutomation):
|
|||
# The following subprocess call takes external input, but is providing
|
||||
# the argument list as an array such that argument injection would be
|
||||
# ineffective.
|
||||
tf = subprocess.run( # nosec
|
||||
tfcmd = subprocess.run( # nosec
|
||||
['terraform',
|
||||
'plan',
|
||||
'-json',
|
||||
|
@ -114,7 +114,7 @@ class TerraformAutomation(BaseAutomation):
|
|||
f'-lock-timeout={str(lock_timeout)}m',
|
||||
],
|
||||
cwd=self.working_directory())
|
||||
return tf.returncode, tf.stdout.decode('utf-8')
|
||||
return tfcmd.returncode, tfcmd.stdout.decode('utf-8')
|
||||
|
||||
def tf_posthook(self, *, prehook_result: Any = None) -> None:
|
||||
"""
|
||||
|
@ -126,7 +126,6 @@ class TerraformAutomation(BaseAutomation):
|
|||
:param prehook_result: the returned value of :func:`tf_prehook`
|
||||
:return: None
|
||||
"""
|
||||
pass
|
||||
|
||||
def tf_prehook(self) -> Optional[Any]:
|
||||
"""
|
||||
|
@ -138,7 +137,6 @@ class TerraformAutomation(BaseAutomation):
|
|||
|
||||
:return: state that is useful to :func:`tf_posthook`, if required
|
||||
"""
|
||||
pass
|
||||
|
||||
def tf_show(self) -> Any:
|
||||
# This subprocess call doesn't take any user input.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue