Skip to content

Commit

Permalink
Merge pull request #2642 from ClusterHQ/admin-lint-FLOC-4178
Browse files Browse the repository at this point in the history
[FLOC-4178] Add the admin directory to lint checks.
  • Loading branch information
jml committed Feb 16, 2016
2 parents ab094da + 18915ba commit 1563755
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 123 deletions.
2 changes: 1 addition & 1 deletion admin/acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ class CommonOptions(Options):
lambda option_value: _validate_version_option(
option_name=u'flocker-version',
option_value=option_value
)],
)],
['build-server', None, 'http://build.clusterhq.com/',
'Base URL of build server for package downloads'],
['number-of-nodes', None,
Expand Down
6 changes: 3 additions & 3 deletions admin/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,14 @@ def perform_upload_s3_key_recursively(dispatcher, intent):
"""
See :class:`UploadToS3Recursively`.
"""
for file in intent.files:
path = intent.source_path.preauthChild(file)
for child in intent.files:
path = intent.source_path.preauthChild(child)
if path.isfile():
yield Effect(
UploadToS3(
source_path=intent.source_path,
target_bucket=intent.target_bucket,
target_key="%s/%s" % (intent.target_key, file),
target_key="%s/%s" % (intent.target_key, child),
file=path,
))

Expand Down
10 changes: 5 additions & 5 deletions admin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ def script(self):
return self._script


def make_script_file(dir, effects):
def make_script_file(directory, effects):
"""
Create a shell script file from a sequence of effects.
:param bytes dir: The directory in which to create the script.
:param bytes directory: The directory in which to create the script.
:param Effect effects: An effect which contains the commands,
typically a Sequence containing multiple commands.
:return: The base filename of the script.
"""
builder = ScriptBuilder(effects)
fd, filename = tempfile.mkstemp(dir=dir, text=True)
fd, filename = tempfile.mkstemp(dir=directory, text=True)
os.write(fd, builder.script())
os.close(fd)
os.chmod(filename, 0555)
Expand Down Expand Up @@ -201,8 +201,8 @@ class RunOptions(Options):
['distribution', None, None,
'The target distribution. '
'One of {}. With --pip, one of {}'.format(
', '.join(PACKAGED_CLIENT_DISTRIBUTIONS),
', '.join(PIP_DISTRIBUTIONS))],
', '.join(PACKAGED_CLIENT_DISTRIBUTIONS),
', '.join(PIP_DISTRIBUTIONS))],
['branch', None, None, 'Branch to grab packages from'],
['flocker-version', None, None, 'Flocker version to install'],
['build-server', None, 'http://build.clusterhq.com/',
Expand Down
2 changes: 1 addition & 1 deletion admin/cluster_add_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import sys

from eliot import FileDestination, add_destination
from eliot import FileDestination

from twisted.internet.defer import DeferredList, inlineCallbacks
from twisted.python.usage import UsageError
Expand Down
2 changes: 1 addition & 1 deletion admin/cluster_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from itertools import repeat
from pipes import quote as shell_quote

from eliot import FileDestination, add_destination, write_failure
from eliot import FileDestination, write_failure
from pyrsistent import pvector
from txeffect import perform

Expand Down
3 changes: 2 additions & 1 deletion admin/flaky.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def report_test_tree(output, flaky_tests):
"""
reporter = TreeReporter(output)
for (test, flaky) in flaky_tests:
new_test = clone_test_with_new_id(test, '{}({})'.format(test.id(), ', '.join(flaky.jira_keys)))
new_test = clone_test_with_new_id(
test, '{}({})'.format(test.id(), ', '.join(flaky.jira_keys)))
reporter.startTest(new_test)
reporter.addSuccess(new_test)
reporter.stopTest(new_test)
Expand Down
14 changes: 8 additions & 6 deletions admin/homebrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def install
ENV["LDFLAGS"] = "-L#{{opt_prefix}}/openssl/lib"
ENV["CFLAGS"] = "-I#{{opt_prefix}}/openssl/include"
ENV.prepend_create_path "PYTHONPATH", "#{{libexec}}/vendor/lib/python2.7/site-packages"
ENV.prepend_create_path "PYTHONPATH", "#{{libexec}}/vendor/lib/python2.7/\
site-packages"
%w[{dependencies}].each do |r|
resource(r).stage do
system "python", *Language::Python.setup_install_args(libexec/"vendor")
Expand All @@ -197,11 +198,11 @@ def install
end
end
""".format(
sdist_url=sdist_url,
sha1=sha1,
class_name=class_name,
resources=format_resource_stanzas(resources),
dependencies=u' '.join(dependencies))
sdist_url=sdist_url,
sha1=sha1,
class_name=class_name,
resources=format_resource_stanzas(resources),
dependencies=u' '.join(dependencies))


class HomebrewOptions(Options):
Expand Down Expand Up @@ -255,5 +256,6 @@ def main(args, base_path, top_level):


if __name__ == "__main__":
# pylint: disable=relative-import
from _preamble import TOPLEVEL, BASEPATH
main(sys.argv[1:], top_level=TOPLEVEL, base_path=BASEPATH)
4 changes: 2 additions & 2 deletions admin/installer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

__all__ = [
"publish_installer_images_main",
MIN_CLUSTER_SIZE, MAX_CLUSTER_SIZE,
InvalidClusterSizeException
'MIN_CLUSTER_SIZE', 'MAX_CLUSTER_SIZE',
'InvalidClusterSizeException'
]
2 changes: 2 additions & 0 deletions admin/installer/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import troposphere.ec2 as ec2
from troposphere.cloudformation import WaitConditionHandle, WaitCondition

# pylint: disable=relative-import
from _cloudformation_helper import (
MIN_CLUSTER_SIZE, MAX_CLUSTER_SIZE, InvalidClusterSizeException
)
# pylint: enable=relative-import

DEFAULT_CLUSTER_SIZE = MIN_CLUSTER_SIZE
NODE_CONFIGURATION_TIMEOUT = u"900"
Expand Down
55 changes: 30 additions & 25 deletions admin/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _get_current_distribution(klass):
"""
:return: A ``Distribution`` representing the current platform.
"""
name, version, id = (
name, version, _ = (
platform.linux_distribution(full_distribution_name=False))
return klass(name=name.lower(), version=version)

Expand Down Expand Up @@ -663,13 +663,17 @@ def __str__(self):
# Cryptography hazmat bindings
'package-installs-python-pycache-dir opt/flocker/lib/python2.7/site-packages/cryptography/hazmat/bindings/__pycache__/', # noqa

# files included by netaddr - we put the whole python we need in the flocker package, and lint complains.
# See:
# files included by netaddr - we put the whole python we need in the
# flocker package, and lint complains. See:
# https://lintian.debian.org/tags/package-installs-ieee-data.html
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/netaddr/eui/iab.idx",
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/netaddr/eui/iab.txt",
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/netaddr/eui/oui.idx",
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/netaddr/eui/oui.txt",
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/"
"netaddr/eui/iab.idx",
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/"
"netaddr/eui/iab.txt",
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/"
"netaddr/eui/oui.idx",
"package-installs-ieee-data opt/flocker/lib/python2.7/site-packages/"
"netaddr/eui/oui.txt",
"package-contains-timestamped-gzip",
"systemd-service-file-outside-lib",
),
Expand Down Expand Up @@ -753,37 +757,37 @@ class PACKAGE(Values):

class PACKAGE_PYTHON(PACKAGE):
DESCRIPTION = ValueConstant(
'Flocker: a container data volume manager for your '
+ 'Dockerized applications\n'
+ fill('This is the base package of scripts and libraries.', 79)
'Flocker: a container data volume manager for your ' +
'Dockerized applications\n' +
fill('This is the base package of scripts and libraries.', 79)
)


class PACKAGE_CLI(PACKAGE):
DESCRIPTION = ValueConstant(
'Flocker: a container data volume manager for your'
+ ' Dockerized applications\n'
+ fill('This meta-package contains links to the Flocker client '
'utilities, and has only the dependencies required to run '
'those tools', 79)
'Flocker: a container data volume manager for your' +
' Dockerized applications\n' +
fill('This meta-package contains links to the Flocker client '
'utilities, and has only the dependencies required to run '
'those tools', 79)
)


class PACKAGE_NODE(PACKAGE):
DESCRIPTION = ValueConstant(
'Flocker: a container data volume manager for your'
+ ' Dockerized applications\n'
+ fill('This meta-package contains links to the Flocker node '
'utilities, and has only the dependencies required to run '
'those tools', 79)
'Flocker: a container data volume manager for your' +
' Dockerized applications\n' +
fill('This meta-package contains links to the Flocker node '
'utilities, and has only the dependencies required to run '
'those tools', 79)
)


class PACKAGE_DOCKER_PLUGIN(PACKAGE):
DESCRIPTION = ValueConstant(
'Flocker volume plugin for Docker\n'
+ fill('This meta-package contains links to the Flocker Docker plugin',
79)
'Flocker volume plugin for Docker\n' +
fill('This meta-package contains links to the Flocker Docker plugin',
79)
)


Expand Down Expand Up @@ -1089,8 +1093,8 @@ def run(self):
['--volume', '%s:%s' % (host.path, container.path)])

result = call(
['docker', 'run', '--rm']
+ volume_options + [self.tag] + self.command)
['docker', 'run', '--rm'] +
volume_options + [self.tag] + self.command)
if result:
raise SystemExit(result)

Expand All @@ -1114,6 +1118,7 @@ def available_distributions(flocker_source_path):
if path.isdir() and path.child(b"Dockerfile").exists()
)


def build_in_docker(destination_path, distribution, top_level, package_uri):
"""
Build a flocker package for a given ``distribution`` inside a clean docker
Expand Down
35 changes: 18 additions & 17 deletions admin/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
https://clusterhq.atlassian.net/browse/FLOC-397
"""

import json
import yaml
import os
import sys
Expand All @@ -18,7 +17,6 @@
from datetime import datetime
from subprocess import check_call, check_output
from sys import platform as _platform
from urllib import quote

from boto.s3.website import RoutingRules, RoutingRule

Expand Down Expand Up @@ -211,15 +209,16 @@ def publish_docs(flocker_version, doc_version, environment, routing_config):
:param bytes doc_version: The version to publish the documentation as.
:param Environments environment: The environment to publish the
documentation to.
:param dict routing_config: The loaded routing configuration (see ``parse_routing_rules`` for details).
:param dict routing_config: The loaded routing configuration (see
``parse_routing_rules`` for details).
:raises NotARelease: Raised if trying to publish to a version that isn't a
release.
:raises NotTagged: Raised if publishing to production and the version being
published version isn't tagged.
"""
if not (is_release(doc_version)
or is_weekly_release(doc_version)
or is_pre_release(doc_version)):
if not (is_release(doc_version) or
is_weekly_release(doc_version) or
is_pre_release(doc_version)):
raise NotARelease()

if environment == Environments.PRODUCTION:
Expand Down Expand Up @@ -312,7 +311,8 @@ def publish_docs(flocker_version, doc_version, environment, routing_config):

yield Effect(UpdateS3RoutingRules(
bucket=configuration.documentation_bucket,
routing_rules=parse_routing_rules(routing_config, configuration.cloudfront_cname),
routing_rules=parse_routing_rules(
routing_config, configuration.cloudfront_cname),
))

# Invalidate all the changed paths in cloudfront.
Expand Down Expand Up @@ -369,7 +369,7 @@ def publish_docs_main(args, base_path, top_level):
redirects_path = top_level.descendant(['docs', 'redirects.yaml'])
routing_config = yaml.safe_load(redirects_path.getContent())
try:
sync_perform(
sync_perform(
dispatcher=ComposedDispatcher([boto_dispatcher, base_dispatcher]),
effect=publish_docs(
flocker_version=options['flocker-version'],
Expand Down Expand Up @@ -408,9 +408,9 @@ class UploadOptions(Options):
def parseArgs(self):
version = self['flocker-version']

if not (is_release(version)
or is_weekly_release(version)
or is_pre_release(version)):
if not (is_release(version) or
is_weekly_release(version) or
is_pre_release(version)):
raise NotARelease()

if get_doc_version(version) != version:
Expand Down Expand Up @@ -654,7 +654,7 @@ def upload_python_packages(scratch_directory, target_bucket, top_level,
'bdist_wheel', '--dist-dir={}'.format(scratch_directory.path)],
cwd=top_level.path, stdout=output, stderr=error)

files = set([file.basename() for file in scratch_directory.children()])
files = set([f.basename() for f in scratch_directory.children()])
yield Effect(UploadToS3Recursively(
source_path=scratch_directory,
target_bucket=target_bucket,
Expand Down Expand Up @@ -743,9 +743,9 @@ def calculate_base_branch(version, path):
:param bytes path: See :func:`git.Repo.init`.
:returns: The base branch from which the new release branch was created.
"""
if not (is_release(version)
or is_weekly_release(version)
or is_pre_release(version)):
if not (is_release(version) or
is_weekly_release(version) or
is_pre_release(version)):
raise NotARelease()

repo = Repo(path=path, search_parent_directories=True)
Expand Down Expand Up @@ -963,7 +963,7 @@ class TestRedirectsOptions(Options):
["doc-version", None, flocker.__version__,
"The version which the documentation sites are expected to redirect "
"to.\n"
],
],
]

optFlags = [
Expand Down Expand Up @@ -1008,6 +1008,7 @@ def get_expected_redirects(flocker_version):

return expected_redirects


def test_redirects_main(args, base_path, top_level):
"""
Tests redirects to Flocker documentation.
Expand Down Expand Up @@ -1050,7 +1051,7 @@ def test_redirects_main(args, base_path, top_level):
sys.stderr.write(message)

if len(failed_redirects):
raise SystemExit(1)
raise SystemExit(1)
else:
print 'All tested redirects work correctly.'

Expand Down
13 changes: 8 additions & 5 deletions admin/test/test_acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ def test_cluster_id(self):
_PID=32748
_COMM=docker
_EXE=/usr/bin/docker
_CMDLINE=/usr/bin/docker daemon -H fd:// --tlsverify --tlscacert=/etc/flocker/cluster.crt --tlscert=/etc/flocker/node.crt --tlskey=/etc/flocker/node.key -H=0.0.0.0:2376
_CMDLINE=/usr/bin/docker daemon -H fd:// --tlsverify --tlscacert=/etc/flocker/\
c luster.crt --tlscert=/etc/flocker/node.crt --tlskey=/etc/flocker/node.key \
-H=0.0.0.0:2376
_SYSTEMD_CGROUP=/system.slice/docker.service
_SYSTEMD_UNIT=docker.service
MESSAGE=time="2015-10-02T13:33:26.192780138Z" level=info msg="GET /v1.20/containers/json"
MESSAGE=time="2015-10-02T13:33:26.192780138Z" level=info msg="GET /v1.20/\
containers/json"
"""


Expand Down Expand Up @@ -182,13 +185,13 @@ def test_converted(self):
some="json",
_HOSTNAME="some-host-2",
_PROCESS_NAME="flocker-dataset-agent.service",
),
),
dict(
other="values",
_HOSTNAME="some-host-1",
_PROCESS_NAME="flocker-container-agent.service",
),
],
),
],
self._convert(JOURNAL_EXPORT),
)

Expand Down
Loading

0 comments on commit 1563755

Please sign in to comment.