|
 |
a64660 |
From d04bb529dc184470b6de45a1033cd2981838d9f9 Mon Sep 17 00:00:00 2001
|
|
 |
a64660 |
From: Zane Bitter <zbitter@redhat.com>
|
|
 |
a64660 |
Date: Wed, 18 Jul 2018 16:35:03 -0400
|
|
 |
a64660 |
Subject: [PATCH 12/21] Fix pep8 errors with later versions of hacking
|
|
 |
a64660 |
|
|
 |
a64660 |
We are stuck on a very old version of hacking (0.8). In order to move
|
|
 |
a64660 |
forward, we need to fix a bunch of things that flake8 will complain about.
|
|
 |
a64660 |
|
|
 |
a64660 |
Change-Id: If40ac29094b90c5bae63e7423061a190655f50a3
|
|
 |
a64660 |
---
|
|
 |
a64660 |
bin/cfn-push-stats | 4 +-
|
|
 |
a64660 |
heat_cfntools/cfntools/cfn_helper.py | 66 ++++++++++++++------------
|
|
 |
a64660 |
heat_cfntools/tests/test_cfn_helper.py | 16 +++----
|
|
 |
a64660 |
heat_cfntools/tests/test_cfn_hup.py | 3 +-
|
|
 |
a64660 |
4 files changed, 47 insertions(+), 42 deletions(-)
|
|
 |
a64660 |
|
|
 |
a64660 |
diff --git a/bin/cfn-push-stats b/bin/cfn-push-stats
|
|
 |
a64660 |
index d1171ee..29f1fab 100755
|
|
 |
a64660 |
--- a/bin/cfn-push-stats
|
|
 |
a64660 |
+++ b/bin/cfn-push-stats
|
|
 |
a64660 |
@@ -23,7 +23,7 @@ import subprocess
|
|
 |
a64660 |
# Override BOTO_CONFIG, which makes boto look only at the specified
|
|
 |
a64660 |
# config file, instead of the default locations
|
|
 |
a64660 |
os.environ['BOTO_CONFIG'] = '/var/lib/heat-cfntools/cfn-boto-cfg'
|
|
 |
a64660 |
-from boto.ec2 import cloudwatch
|
|
 |
a64660 |
+from boto.ec2 import cloudwatch # noqa
|
|
 |
a64660 |
|
|
 |
a64660 |
|
|
 |
a64660 |
log_format = '%(levelname)s [%(asctime)s] %(message)s'
|
|
 |
a64660 |
@@ -38,7 +38,7 @@ except ImportError:
|
|
 |
a64660 |
LOG.warning("psutil not available. If you want process and memory "
|
|
 |
a64660 |
"statistics, you need to install it.")
|
|
 |
a64660 |
|
|
 |
a64660 |
-from heat_cfntools.cfntools import cfn_helper
|
|
 |
a64660 |
+from heat_cfntools.cfntools import cfn_helper # noqa
|
|
 |
a64660 |
|
|
 |
a64660 |
KILO = 1024
|
|
 |
a64660 |
MEGA = 1048576
|
|
 |
a64660 |
diff --git a/heat_cfntools/cfntools/cfn_helper.py b/heat_cfntools/cfntools/cfn_helper.py
|
|
 |
a64660 |
index e68d8fe..4490e6c 100644
|
|
 |
a64660 |
--- a/heat_cfntools/cfntools/cfn_helper.py
|
|
 |
a64660 |
+++ b/heat_cfntools/cfntools/cfn_helper.py
|
|
 |
a64660 |
@@ -36,16 +36,17 @@ except ImportError:
|
|
 |
a64660 |
rpmutils_present = False
|
|
 |
a64660 |
import re
|
|
 |
a64660 |
import shutil
|
|
 |
a64660 |
-import six
|
|
 |
a64660 |
-import six.moves.configparser as ConfigParser
|
|
 |
a64660 |
import subprocess
|
|
 |
a64660 |
import tempfile
|
|
 |
a64660 |
|
|
 |
a64660 |
+import six
|
|
 |
a64660 |
+import six.moves.configparser as ConfigParser
|
|
 |
a64660 |
+
|
|
 |
a64660 |
|
|
 |
a64660 |
# Override BOTO_CONFIG, which makes boto look only at the specified
|
|
 |
a64660 |
# config file, instead of the default locations
|
|
 |
a64660 |
os.environ['BOTO_CONFIG'] = '/var/lib/heat-cfntools/cfn-boto-cfg'
|
|
 |
a64660 |
-from boto import cloudformation
|
|
 |
a64660 |
+from boto import cloudformation # noqa
|
|
 |
a64660 |
|
|
 |
a64660 |
|
|
 |
a64660 |
LOG = logging.getLogger(__name__)
|
|
 |
a64660 |
@@ -72,6 +73,12 @@ def parse_creds_file(path='/etc/cfn/cfn-credentials'):
|
|
 |
a64660 |
return creds
|
|
 |
a64660 |
|
|
 |
a64660 |
|
|
 |
a64660 |
+class InvalidCredentialsException(Exception):
|
|
 |
a64660 |
+ def __init__(self, credential_file):
|
|
 |
a64660 |
+ super(Exception, self).__init__("invalid credentials file %s" %
|
|
 |
a64660 |
+ credential_file)
|
|
 |
a64660 |
+
|
|
 |
a64660 |
+
|
|
 |
a64660 |
class HupConfig(object):
|
|
 |
a64660 |
def __init__(self, fp_list):
|
|
 |
a64660 |
self.config = ConfigParser.SafeConfigParser()
|
|
 |
a64660 |
@@ -98,8 +105,7 @@ class HupConfig(object):
|
|
 |
a64660 |
with open(self.credential_file) as f:
|
|
 |
a64660 |
self.credentials = f.read()
|
|
 |
a64660 |
except Exception:
|
|
 |
a64660 |
- raise Exception("invalid credentials file %s" %
|
|
 |
a64660 |
- self.credential_file)
|
|
 |
a64660 |
+ raise InvalidCredentialsException(self.credential_file)
|
|
 |
a64660 |
|
|
 |
a64660 |
# optional values
|
|
 |
a64660 |
try:
|
|
 |
a64660 |
@@ -113,8 +119,8 @@ class HupConfig(object):
|
|
 |
a64660 |
self.interval = 10
|
|
 |
a64660 |
|
|
 |
a64660 |
def __str__(self):
|
|
 |
a64660 |
- return '{stack: %s, credential_file: %s, region: %s, interval:%d}' % \
|
|
 |
a64660 |
- (self.stack, self.credential_file, self.region, self.interval)
|
|
 |
a64660 |
+ return ('{stack: %s, credential_file: %s, region: %s, interval:%d}' %
|
|
 |
a64660 |
+ (self.stack, self.credential_file, self.region, self.interval))
|
|
 |
a64660 |
|
|
 |
a64660 |
def unique_resources_get(self):
|
|
 |
a64660 |
resources = []
|
|
 |
a64660 |
@@ -138,20 +144,19 @@ class Hook(object):
|
|
 |
a64660 |
return sp[1]
|
|
 |
a64660 |
|
|
 |
a64660 |
def event(self, ev_name, ev_object, ev_resource):
|
|
 |
a64660 |
- if self.resource_name_get() == ev_resource and \
|
|
 |
a64660 |
- ev_name in self.triggers:
|
|
 |
a64660 |
+ if (self.resource_name_get() == ev_resource and
|
|
 |
a64660 |
+ ev_name in self.triggers):
|
|
 |
a64660 |
CommandRunner(self.action, shell=True).run(user=self.runas)
|
|
 |
a64660 |
else:
|
|
 |
a64660 |
LOG.debug('event: {%s, %s, %s} did not match %s' %
|
|
 |
a64660 |
(ev_name, ev_object, ev_resource, self.__str__()))
|
|
 |
a64660 |
|
|
 |
a64660 |
def __str__(self):
|
|
 |
a64660 |
- return '{%s, %s, %s, %s, %s}' % \
|
|
 |
a64660 |
- (self.name,
|
|
 |
a64660 |
- self.triggers,
|
|
 |
a64660 |
- self.path,
|
|
 |
a64660 |
- self.runas,
|
|
 |
a64660 |
- self.action)
|
|
 |
a64660 |
+ return '{%s, %s, %s, %s, %s}' % (self.name,
|
|
 |
a64660 |
+ self.triggers,
|
|
 |
a64660 |
+ self.path,
|
|
 |
a64660 |
+ self.runas,
|
|
 |
a64660 |
+ self.action)
|
|
 |
a64660 |
|
|
 |
a64660 |
|
|
 |
a64660 |
class ControlledPrivilegesFailureException(Exception):
|
|
 |
a64660 |
@@ -656,7 +661,7 @@ class PackagesHandler(object):
|
|
 |
a64660 |
* if a different version of the package is installed, overwrite it
|
|
 |
a64660 |
* if the package isn't installed, install it
|
|
 |
a64660 |
"""
|
|
 |
a64660 |
- #FIXME: handle rpm installs
|
|
 |
a64660 |
+ # FIXME(asalkeld): handle rpm installs
|
|
 |
a64660 |
pass
|
|
 |
a64660 |
|
|
 |
a64660 |
def _handle_apt_packages(self, packages):
|
|
 |
a64660 |
@@ -738,8 +743,8 @@ class FilesHandler(object):
|
|
 |
a64660 |
f.close()
|
|
 |
a64660 |
else:
|
|
 |
a64660 |
f = open(dest, 'w+')
|
|
 |
a64660 |
- f.write(json.dumps(meta['content'], indent=4)
|
|
 |
a64660 |
- .encode('UTF-8'))
|
|
 |
a64660 |
+ f.write(json.dumps(meta['content'],
|
|
 |
a64660 |
+ indent=4).encode('UTF-8'))
|
|
 |
a64660 |
f.close()
|
|
 |
a64660 |
elif 'source' in meta:
|
|
 |
a64660 |
CommandRunner(['curl', '-o', dest, meta['source']]).run()
|
|
 |
a64660 |
@@ -843,7 +848,7 @@ class SourcesHandler(object):
|
|
 |
a64660 |
|
|
 |
a64660 |
def _apply_source(self, dest, url):
|
|
 |
a64660 |
cmd = self._apply_source_cmd(dest, url)
|
|
 |
a64660 |
- #FIXME bug 1498298
|
|
 |
a64660 |
+ # FIXME bug 1498298
|
|
 |
a64660 |
if cmd != '':
|
|
 |
a64660 |
runner = CommandRunner(cmd, shell=True)
|
|
 |
a64660 |
runner.run()
|
|
 |
a64660 |
@@ -945,7 +950,7 @@ class ServicesHandler(object):
|
|
 |
a64660 |
start_cmd = handler(self, service, "start")
|
|
 |
a64660 |
if start_cmd.status != 0:
|
|
 |
a64660 |
LOG.warning('Service %s did not start. STDERR: %s' %
|
|
 |
a64660 |
- (service, start_cmd.stderr))
|
|
 |
a64660 |
+ (service, start_cmd.stderr))
|
|
 |
a64660 |
for h in self.hooks:
|
|
 |
a64660 |
h.event('service.restarted', service, self.resource)
|
|
 |
a64660 |
|
|
 |
a64660 |
@@ -1124,8 +1129,8 @@ class CommandsHandler(object):
|
|
 |
a64660 |
if command_status == 0:
|
|
 |
a64660 |
LOG.info("%s has been successfully executed" % command_label)
|
|
 |
a64660 |
else:
|
|
 |
a64660 |
- if "ignoreErrors" in properties and \
|
|
 |
a64660 |
- to_boolean(properties["ignoreErrors"]):
|
|
 |
a64660 |
+ if ("ignoreErrors" in properties and
|
|
 |
a64660 |
+ to_boolean(properties["ignoreErrors"])):
|
|
 |
a64660 |
LOG.info("%s has failed (status=%d). Explicit ignoring"
|
|
 |
a64660 |
% (command_label, command_status))
|
|
 |
a64660 |
else:
|
|
 |
a64660 |
@@ -1202,8 +1207,8 @@ class UsersHandler(object):
|
|
 |
a64660 |
groups = ','.join(properties["groups"])
|
|
 |
a64660 |
cmd.extend(['--groups', groups])
|
|
 |
a64660 |
|
|
 |
a64660 |
- #Users are created as non-interactive system users with a shell
|
|
 |
a64660 |
- #of /sbin/nologin. This is by design and cannot be modified.
|
|
 |
a64660 |
+ # Users are created as non-interactive system users with a shell
|
|
 |
a64660 |
+ # of /sbin/nologin. This is by design and cannot be modified.
|
|
 |
a64660 |
cmd.extend(['--shell', '/sbin/nologin'])
|
|
 |
a64660 |
|
|
 |
a64660 |
command = CommandRunner(cmd)
|
|
 |
a64660 |
@@ -1431,9 +1436,10 @@ class Metadata(object):
|
|
 |
a64660 |
return json.dumps(self._metadata)
|
|
 |
a64660 |
|
|
 |
a64660 |
def display(self, key=None):
|
|
 |
a64660 |
- """Print the metadata to the standard output stream. By default the
|
|
 |
a64660 |
- full metadata is displayed but the ouptut can be limited to a specific
|
|
 |
a64660 |
- with the <key> argument.
|
|
 |
a64660 |
+ """Print the metadata to the standard output stream.
|
|
 |
a64660 |
+
|
|
 |
a64660 |
+ By default the full metadata is displayed but the ouptut can be limited
|
|
 |
a64660 |
+ to a specific with the <key> argument.
|
|
 |
a64660 |
|
|
 |
a64660 |
Arguments:
|
|
 |
a64660 |
key -- the metadata's key to display, nested keys can be specified
|
|
 |
a64660 |
@@ -1475,9 +1481,9 @@ class Metadata(object):
|
|
 |
a64660 |
|
|
 |
a64660 |
def _is_valid_metadata(self):
|
|
 |
a64660 |
"""Should find the AWS::CloudFormation::Init json key."""
|
|
 |
a64660 |
- is_valid = self._metadata and \
|
|
 |
a64660 |
- self._init_key in self._metadata and \
|
|
 |
a64660 |
- self._metadata[self._init_key]
|
|
 |
a64660 |
+ is_valid = (self._metadata and
|
|
 |
a64660 |
+ self._init_key in self._metadata and
|
|
 |
a64660 |
+ self._metadata[self._init_key])
|
|
 |
a64660 |
if is_valid:
|
|
 |
a64660 |
self._metadata = self._metadata[self._init_key]
|
|
 |
a64660 |
return is_valid
|
|
 |
a64660 |
diff --git a/heat_cfntools/tests/test_cfn_helper.py b/heat_cfntools/tests/test_cfn_helper.py
|
|
 |
a64660 |
index 83bed76..0255376 100644
|
|
 |
a64660 |
--- a/heat_cfntools/tests/test_cfn_helper.py
|
|
 |
a64660 |
+++ b/heat_cfntools/tests/test_cfn_helper.py
|
|
 |
a64660 |
@@ -14,12 +14,13 @@
|
|
 |
a64660 |
# License for the specific language governing permissions and limitations
|
|
 |
a64660 |
# under the License.
|
|
 |
a64660 |
|
|
 |
a64660 |
-import boto.cloudformation as cfn
|
|
 |
a64660 |
-import fixtures
|
|
 |
a64660 |
import json
|
|
 |
a64660 |
-import mock
|
|
 |
a64660 |
import os
|
|
 |
a64660 |
import tempfile
|
|
 |
a64660 |
+
|
|
 |
a64660 |
+import boto.cloudformation as cfn
|
|
 |
a64660 |
+import fixtures
|
|
 |
a64660 |
+import mock
|
|
 |
a64660 |
import testtools
|
|
 |
a64660 |
import testtools.matchers as ttm
|
|
 |
a64660 |
|
|
 |
a64660 |
@@ -35,7 +36,7 @@ def popen_root_calls(calls, shell=False):
|
|
 |
a64660 |
]
|
|
 |
a64660 |
|
|
 |
a64660 |
|
|
 |
a64660 |
-class FakePOpen():
|
|
 |
a64660 |
+class FakePOpen(object):
|
|
 |
a64660 |
def __init__(self, stdout='', stderr='', returncode=0):
|
|
 |
a64660 |
self.returncode = returncode
|
|
 |
a64660 |
self.stdout = stdout
|
|
 |
a64660 |
@@ -310,8 +311,6 @@ class TestServicesHandler(testtools.TestCase):
|
|
 |
a64660 |
'mysqld.service']]))
|
|
 |
a64660 |
returns.append(FakePOpen())
|
|
 |
a64660 |
|
|
 |
a64660 |
- #calls = popen_root_calls(calls)
|
|
 |
a64660 |
-
|
|
 |
a64660 |
services = {
|
|
 |
a64660 |
"systemd": {
|
|
 |
a64660 |
"mysqld": {"enabled": "true", "ensureRunning": "true"},
|
|
 |
a64660 |
@@ -693,7 +692,8 @@ region=region1
|
|
 |
a64660 |
credential-file=%s-invalid
|
|
 |
a64660 |
interval=120''' % fcreds.name).encode('UTF-8'))
|
|
 |
a64660 |
main_conf.flush()
|
|
 |
a64660 |
- e = self.assertRaises(Exception, cfn_helper.HupConfig,
|
|
 |
a64660 |
+ e = self.assertRaises(cfn_helper.InvalidCredentialsException,
|
|
 |
a64660 |
+ cfn_helper.HupConfig,
|
|
 |
a64660 |
[open(main_conf.name)])
|
|
 |
a64660 |
self.assertIn('invalid credentials file', str(e))
|
|
 |
a64660 |
fcreds.close()
|
|
 |
a64660 |
@@ -778,7 +778,6 @@ interval=120''' % fcreds.name).encode('UTF-8'))
|
|
 |
a64660 |
calls.extend(popen_root_calls(['/bin/hook1'], shell=True))
|
|
 |
a64660 |
calls.extend(popen_root_calls(['/bin/hook2'], shell=True))
|
|
 |
a64660 |
calls.extend(popen_root_calls(['/bin/hook3'], shell=True))
|
|
 |
a64660 |
- #calls = popen_root_calls(calls)
|
|
 |
a64660 |
|
|
 |
a64660 |
with mock.patch('subprocess.Popen') as mock_popen:
|
|
 |
a64660 |
mock_popen.return_value = FakePOpen('All good')
|
|
 |
a64660 |
@@ -1273,7 +1272,6 @@ class TestCfnInit(testtools.TestCase):
|
|
 |
a64660 |
returns.append(FakePOpen('Doing something', 'error', -1))
|
|
 |
a64660 |
calls.extend(popen_root_calls(['/bin/command2'], shell=True))
|
|
 |
a64660 |
returns.append(FakePOpen('All good'))
|
|
 |
a64660 |
- #calls = popen_root_calls(calls)
|
|
 |
a64660 |
|
|
 |
a64660 |
md_data = {"AWS::CloudFormation::Init": {"config": {"commands": {
|
|
 |
a64660 |
"00_foo": {"command": "/bin/command1",
|
|
 |
a64660 |
diff --git a/heat_cfntools/tests/test_cfn_hup.py b/heat_cfntools/tests/test_cfn_hup.py
|
|
 |
a64660 |
index d5cf026..b182f92 100644
|
|
 |
a64660 |
--- a/heat_cfntools/tests/test_cfn_hup.py
|
|
 |
a64660 |
+++ b/heat_cfntools/tests/test_cfn_hup.py
|
|
 |
a64660 |
@@ -13,9 +13,10 @@
|
|
 |
a64660 |
# License for the specific language governing permissions and limitations
|
|
 |
a64660 |
# under the License.
|
|
 |
a64660 |
|
|
 |
a64660 |
+import tempfile
|
|
 |
a64660 |
+
|
|
 |
a64660 |
import fixtures
|
|
 |
a64660 |
import mock
|
|
 |
a64660 |
-import tempfile
|
|
 |
a64660 |
import testtools
|
|
 |
a64660 |
|
|
 |
a64660 |
from heat_cfntools.cfntools import cfn_helper
|
|
 |
a64660 |
--
|
|
 |
a64660 |
2.20.1
|
|
 |
a64660 |
|