From f47dfe1059fc19995afe0bc9fa3028f65df06f54 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 29 Aug 2019 20:49:40 +0900 Subject: [PATCH] Enforce pep8/pyflakes rule on python codes This change makes sure that we apply pyflake8 checks on all python codes to improve its readability. Note that there are some rules applied for other OpenStack projects, but not yet turned on, which should be enabled in the future. Change-Id: Iaf0299983d3a3fe48e3beb8f47bd33c21deb4972 --- common/container-puppet.py | 46 +-- .../nova_statedir_ownership.py | 3 +- .../nova_wait_for_compute_service.py | 4 +- .../nova_wait_for_placement_service.py | 10 +- .../tests/test_nova_statedir_ownership.py | 13 +- .../undercloud_ctlplane_network.py | 30 +- extraconfig/post_deploy/undercloud_post.py | 23 +- network/endpoints/build_endpoint_map.py | 23 +- tools/merge-new-params-nic-config-script.py | 42 +-- tools/process-templates.py | 36 +- tools/roles-data-generate.py | 1 + tools/yaml-diff.py | 18 +- tools/yaml-nic-config-2-script.py | 103 +++--- tools/yaml-validate.py | 343 +++++++++--------- tox.ini | 29 +- .../tests/test_environment_generator.py | 1 + tripleo_heat_templates/tests/test_yaql.py | 8 - 17 files changed, 412 insertions(+), 321 deletions(-) diff --git a/common/container-puppet.py b/common/container-puppet.py index 8b164667e5..b919fe189e 100755 --- a/common/container-puppet.py +++ b/common/container-puppet.py @@ -1,32 +1,32 @@ #!/usr/bin/env python +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at # -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 # -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # Shell script tool to run puppet inside of the given container image. -# Uses the config file at /var/lib/container-puppet/container-puppet.json as a source for a JSON -# array of [config_volume, puppet_tags, manifest, config_image, [volumes]] settings +# Uses the config file at /var/lib/container-puppet/container-puppet.json +# as a source for a JSON array of +# [config_volume, puppet_tags, manifest, config_image, [volumes]] settings # that can be used to generate config files or run ad-hoc puppet modules # inside of a container. import glob import json import logging +import multiprocessing import os import subprocess import sys import tempfile import time -import multiprocessing from paunch import runner as containers_runner @@ -45,7 +45,7 @@ def get_logger(): if logger is None: logger = logging.getLogger() ch = logging.StreamHandler(sys.stdout) - if os.environ.get('DEBUG') in ['True', 'true'] : + if os.environ.get('DEBUG') in ['True', 'true']: logger.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG) else: @@ -93,6 +93,7 @@ if (os.environ.get('MOUNT_HOST_PUPPET', 'true') == 'true' and PUPPETS not in cli_dcmd): cli_dcmd.extend(['--volume', PUPPETS]) + # this is to match what we do in deployed-server def short_hostname(): subproc = subprocess.Popen(['hostname', '-s'], @@ -188,6 +189,7 @@ def rm_container(name): 'No such container: {}\n'.format(name): log.debug(cmd_stderr) + process_count = int(os.environ.get('PROCESS_COUNT', multiprocessing.cpu_count())) config_file = os.environ.get('CONFIG', '/var/lib/container-puppet/container-puppet.json') @@ -403,12 +405,11 @@ if not os.path.exists(sh_script): """) - def mp_puppet_config(*args): - (config_volume,puppet_tags,manifest,config_image,volumes,privileged,check_mode) = args[0] + (config_volume, puppet_tags, manifest, config_image, volumes, privileged, check_mode) = args[0] log = get_logger() - log.info('Starting configuration of %s using image %s' % (config_volume, - config_image)) + log.info('Starting configuration of %s using image %s' % + (config_volume, config_image)) log.debug('config_volume %s' % config_volume) log.debug('puppet_tags %s' % puppet_tags) log.debug('manifest %s' % manifest) @@ -466,7 +467,6 @@ def mp_puppet_config(*args): for k in filter(lambda k: k.startswith('DOCKER'), os.environ.keys()): env[k] = os.environ.get(k) - common_dcmd += cli_dcmd if check_mode: @@ -483,10 +483,10 @@ def mp_puppet_config(*args): if os.environ.get('NET_HOST', 'false') == 'true': log.debug('NET_HOST enabled') common_dcmd.extend(['--net', 'host', '--volume', - '/etc/hosts:/etc/hosts:ro']) + '/etc/hosts:/etc/hosts:ro']) else: log.debug('running without containers Networking') - dcmd.extend(['--net', 'none']) + common_dcmd.extend(['--net', 'none']) # script injection as the last mount to make sure it's accessible # https://github.com/containers/libpod/issues/1844 @@ -512,7 +512,7 @@ def mp_puppet_config(*args): retval = subproc.returncode # puppet with --detailed-exitcodes will return 0 for success and no changes # and 2 for success and resource changes. Other numbers are failures - if retval in [0,2]: + if retval in [0, 2]: if cmd_stdout: log.debug('%s run succeeded: %s' % (cmd, cmd_stdout)) if cmd_stderr: @@ -534,6 +534,7 @@ def mp_puppet_config(*args): log.info('Finished processing puppet configs for %s' % (config_volume)) return retval + # Holds all the information for each process to consume. # Instead of starting them all linearly we run them using a process # pool. This creates a list of arguments for the above function @@ -608,4 +609,3 @@ for infile in infiles: if not success: sys.exit(1) - diff --git a/container_config_scripts/nova_statedir_ownership.py b/container_config_scripts/nova_statedir_ownership.py index a9bcd3443e..177c48d13a 100644 --- a/container_config_scripts/nova_statedir_ownership.py +++ b/container_config_scripts/nova_statedir_ownership.py @@ -74,7 +74,7 @@ class PathManager(object): try: os.chown(self.path, target_uid, target_gid) self._update() - except Exception as e: + except Exception: LOG.exception('Could not change ownership of %s: ', self.path) else: @@ -172,5 +172,6 @@ class NovaStatedirOwnershipManager(object): LOG.info('Nova statedir ownership complete') + if __name__ == '__main__': NovaStatedirOwnershipManager('/var/lib/nova').run() diff --git a/container_config_scripts/nova_wait_for_compute_service.py b/container_config_scripts/nova_wait_for_compute_service.py index c8596d3702..dd29c6fc92 100644 --- a/container_config_scripts/nova_wait_for_compute_service.py +++ b/container_config_scripts/nova_wait_for_compute_service.py @@ -68,7 +68,7 @@ if __name__ == '__main__': if os.path.isfile(nova_cfg): try: config.read(nova_cfg) - except Exception as e: + except Exception: LOG.exception('Error while reading nova.conf:') else: LOG.error('Nova configuration file %s does not exist', nova_cfg) @@ -107,7 +107,7 @@ if __name__ == '__main__': LOG.info('Nova-compute service registered') sys.exit(0) LOG.info('Waiting for nova-compute service to register') - except Exception as e: + except Exception: LOG.exception( 'Error while waiting for nova-compute service to register') time.sleep(timeout) diff --git a/container_config_scripts/nova_wait_for_placement_service.py b/container_config_scripts/nova_wait_for_placement_service.py index e3bc345a70..0c7da5c0ae 100755 --- a/container_config_scripts/nova_wait_for_placement_service.py +++ b/container_config_scripts/nova_wait_for_placement_service.py @@ -62,7 +62,7 @@ if __name__ == '__main__': if os.path.isfile(nova_cfg): try: config.read(nova_cfg) - except Exception as e: + except Exception: LOG.exception('Error while reading nova.conf:') else: LOG.error('Nova configuration file %s does not exist', nova_cfg) @@ -75,7 +75,7 @@ if __name__ == '__main__': password=config.get('placement', 'password'), project_name=config.get('placement', 'project_name'), project_domain_name=config.get('placement', 'user_domain_name'), - auth_url=config.get('placement', 'auth_url')+'/v3') + auth_url=config.get('placement', 'auth_url') + '/v3') sess = session.Session(auth=auth, verify=False) keystone = client.Client(session=sess, interface='internal') @@ -97,7 +97,7 @@ if __name__ == '__main__': LOG.error('Failed to get placement service endpoint!') else: break - except Exception as e: + except Exception: LOG.exception('Retry - Failed to get placement service endpoint:') time.sleep(timeout) @@ -113,7 +113,7 @@ if __name__ == '__main__': while iterations > 1: iterations -= 1 try: - r = requests.get(placement_endpoint_url+'/', verify=False) + r = requests.get(placement_endpoint_url + '/', verify=False) if r.status_code == 200 and response_reg.match(r.text): LOG.info('Placement service up! - %s', r.text) sys.exit(0) @@ -123,7 +123,7 @@ if __name__ == '__main__': LOG.info('Placement service not up - %s, %s', r.status_code, r.text) - except Exception as e: + except Exception: LOG.exception('Error query the placement endpoint:') time.sleep(timeout) diff --git a/container_config_scripts/tests/test_nova_statedir_ownership.py b/container_config_scripts/tests/test_nova_statedir_ownership.py index 664f5d8481..7004c966af 100644 --- a/container_config_scripts/tests/test_nova_statedir_ownership.py +++ b/container_config_scripts/tests/test_nova_statedir_ownership.py @@ -192,8 +192,8 @@ class PathManagerCase(base.BaseTestCase): with fake_testtree(testtree): pathinfo = PathManager('/var/lib/nova/instances/foo/baz') self.assertTrue(pathinfo.has_owner(current_uid, current_gid)) - pathinfo.chown(current_uid+1, current_gid) - assert_ids(testtree, pathinfo.path, current_uid+1, current_gid) + pathinfo.chown(current_uid + 1, current_gid) + assert_ids(testtree, pathinfo.path, current_uid + 1, current_gid) def test_chgrp(self): testtree = generate_testtree1(current_uid, current_gid) @@ -201,8 +201,8 @@ class PathManagerCase(base.BaseTestCase): with fake_testtree(testtree): pathinfo = PathManager('/var/lib/nova/instances/foo/baz') self.assertTrue(pathinfo.has_owner(current_uid, current_gid)) - pathinfo.chown(current_uid, current_gid+1) - assert_ids(testtree, pathinfo.path, current_uid, current_gid+1) + pathinfo.chown(current_uid, current_gid + 1) + assert_ids(testtree, pathinfo.path, current_uid, current_gid + 1) def test_chown_chgrp(self): testtree = generate_testtree1(current_uid, current_gid) @@ -210,8 +210,9 @@ class PathManagerCase(base.BaseTestCase): with fake_testtree(testtree): pathinfo = PathManager('/var/lib/nova/instances/foo/baz') self.assertTrue(pathinfo.has_owner(current_uid, current_gid)) - pathinfo.chown(current_uid+1, current_gid+1) - assert_ids(testtree, pathinfo.path, current_uid+1, current_gid+1) + pathinfo.chown(current_uid + 1, current_gid + 1) + assert_ids(testtree, pathinfo.path, + current_uid + 1, current_gid + 1) class NovaStatedirOwnershipManagerTestCase(base.BaseTestCase): diff --git a/extraconfig/post_deploy/undercloud_ctlplane_network.py b/extraconfig/post_deploy/undercloud_ctlplane_network.py index 855d321f96..5414885258 100755 --- a/extraconfig/post_deploy/undercloud_ctlplane_network.py +++ b/extraconfig/post_deploy/undercloud_ctlplane_network.py @@ -1,9 +1,19 @@ #!/usr/bin/env python - +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import json import netaddr -import os import openstack +import os import subprocess CTLPLANE_NETWORK_NAME = 'ctlplane' @@ -61,12 +71,15 @@ def _ensure_neutron_network(sdk): return network + def _get_nameservers_for_version(servers, ipversion): """Get list of nameservers for an IP version""" return [s for s in servers if netaddr.IPAddress(s).version == ipversion] + def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes, - allocation_pools, name, segment_id, dns_nameservers): + allocation_pools, name, segment_id, + dns_nameservers): try: if netaddr.IPNetwork(cidr).version == 6: subnet = sdk.network.create_subnet( @@ -137,6 +150,7 @@ def _neutron_add_subnet_segment_association(sdk, subnet_id, segment_id): print('ERROR: Associationg segment with subnet %s failed.' % subnet_id) raise + def _neutron_segment_create(sdk, name, network_id, phynet): try: segment = sdk.network.create_segment( @@ -145,7 +159,7 @@ def _neutron_segment_create(sdk, name, network_id, phynet): physical_network=phynet, network_type='flat') print('INFO: Neutron Segment created %s' % segment) - except Exception as ex: + except Exception: print('ERROR: Neutron Segment %s create failed.' % name) raise @@ -173,7 +187,7 @@ def _ensure_neutron_router(sdk, name, subnet_id): def _get_subnet(sdk, cidr, network_id): try: subnet = list(sdk.network.subnets(cidr=cidr, network_id=network_id)) - except Exception as ex: + except Exception: print('ERROR: Get subnet with cidr %s failed.' % cidr) raise @@ -206,12 +220,13 @@ def _local_neutron_segments_and_subnets(sdk, ctlplane_id, net_cidrs): """Create's and updates the ctlplane subnet on the segment that is local to the underclud. """ + s = CONF['subnets'][CONF['local_subnet']] name = CONF['local_subnet'] subnet = _get_subnet(sdk, s['NetworkCidr'], ctlplane_id) segment = _get_segment(sdk, CONF['physical_network'], ctlplane_id) if subnet: - if CONF['enable_routed_networks'] and subnet.segment_id == None: + if CONF['enable_routed_networks'] and subnet.segment_id is None: # The subnet exists and does not have a segment association. Since # routed networks is enabled in the configuration, we need to # migrate the existing non-routed networks subnet to a routed @@ -239,10 +254,12 @@ def _local_neutron_segments_and_subnets(sdk, ctlplane_id, net_cidrs): return net_cidrs + def _remote_neutron_segments_and_subnets(sdk, ctlplane_id, net_cidrs): """Create's and updates the ctlplane subnet(s) on segments that is not local to the undercloud. """ + for name in CONF['subnets']: s = CONF['subnets'][name] if name == CONF['local_subnet']: @@ -274,6 +291,7 @@ def _remote_neutron_segments_and_subnets(sdk, ctlplane_id, net_cidrs): return net_cidrs + if 'true' not in _run_command(['hiera', 'neutron_api_enabled'], name='hiera').lower(): print('WARNING: UndercloudCtlplaneNetworkDeployment : The Neutron API ' diff --git a/extraconfig/post_deploy/undercloud_post.py b/extraconfig/post_deploy/undercloud_post.py index 1e783068fe..559cf0593b 100755 --- a/extraconfig/post_deploy/undercloud_post.py +++ b/extraconfig/post_deploy/undercloud_post.py @@ -1,13 +1,24 @@ #!/usr/bin/env python +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import json -import os import openstack +import os import subprocess from keystoneauth1 import exceptions as ks_exceptions -from mistralclient.api import client as mistralclient from mistralclient.api import base as mistralclient_exc +from mistralclient.api import client as mistralclient CONF = json.loads(os.environ['config']) @@ -45,7 +56,7 @@ def _run_command(args, env=None, name=None): def _configure_nova(sdk): - """ Disable nova quotas """ + """Disable nova quotas""" sdk.set_compute_quotas('admin', cores='-1', instances='-1', ram='-1') # Configure flavors. @@ -74,7 +85,7 @@ def _configure_nova(sdk): def _create_default_keypair(sdk): - """ Set up a default keypair. """ + """Set up a default keypair.""" ssh_dir = os.path.join(CONF['home_dir'], '.ssh') public_key_file = os.path.join(ssh_dir, 'id_rsa.pub') if (not [True for kp in sdk.compute.keypairs() if kp.name == 'default'] and @@ -105,7 +116,7 @@ def _configure_workbooks_and_workflows(mistral): def _store_passwords_in_mistral_env(mistral): - """ Store required passwords in a mistral environment """ + """Store required passwords in a mistral environment""" env_name = 'tripleo.undercloud-config' config_data = { 'undercloud_ceilometer_snmpd_password': @@ -153,7 +164,7 @@ def _create_default_plan(mistral): nova_api_enabled = 'true' in _run_command( ['hiera', 'nova_api_enabled']).lower() mistral_api_enabled = 'true' in _run_command( - ['hiera','mistral_api_enabled']).lower() + ['hiera', 'mistral_api_enabled']).lower() tripleo_validations_enabled = 'true' in _run_command( ['hiera', 'tripleo_validations_enabled']).lower() diff --git a/network/endpoints/build_endpoint_map.py b/network/endpoints/build_endpoint_map.py index a6483e2376..092e30ddd0 100755 --- a/network/endpoints/build_endpoint_map.py +++ b/network/endpoints/build_endpoint_map.py @@ -1,4 +1,15 @@ #!/usr/bin/env python +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. """ Generate the endpoint_map.yaml template from data in the endpoint_data.yaml @@ -13,12 +24,6 @@ mismatch is detected. """ from __future__ import print_function - - -__all__ = ['load_endpoint_data', 'generate_endpoint_map_template', - 'write_template', 'build_endpoint_map', 'check_up_to_date'] - - import collections import copy import itertools @@ -27,6 +32,9 @@ import sys import yaml +__all__ = ['load_endpoint_data', 'generate_endpoint_map_template', + 'write_template', 'build_endpoint_map', 'check_up_to_date'] + (IN_FILE, OUT_FILE) = ('endpoint_data.yaml', 'endpoint_map.yaml') SUBST = (SUBST_IP_ADDRESS, SUBST_CLOUDNAME) = ('IP_ADDRESS', 'CLOUDNAME') @@ -88,7 +96,8 @@ def make_parameter(ptype, default, description=None): def template_parameters(config): params = collections.OrderedDict() params[PARAM_NETIPMAP] = make_parameter('json', {}, 'The Net IP map') - params[PARAM_SERVICENETMAP] = make_parameter('json', {}, 'The Service Net map') + params[PARAM_SERVICENETMAP] = make_parameter('json', {}, + 'The Service Net map') params[PARAM_ENDPOINTMAP] = make_parameter('json', endpoint_map_default(config), 'Mapping of service endpoint ' diff --git a/tools/merge-new-params-nic-config-script.py b/tools/merge-new-params-nic-config-script.py index 3d764d648f..12f5372c30 100755 --- a/tools/merge-new-params-nic-config-script.py +++ b/tools/merge-new-params-nic-config-script.py @@ -1,15 +1,15 @@ #!/usr/bin/env python -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import argparse import collections @@ -17,6 +17,7 @@ import datetime import os import re import shutil +import six import subprocess import sys import yaml @@ -62,7 +63,7 @@ def parse_opts(argv): # FIXME: This duplicates code from tools/yaml-nic-config-2-script.py, we should # refactor to share the common code def to_commented_yaml(filename): - """ Convert comments into 'comments: ...' YAML """ + """Convert comments into 'comments: ...' YAML""" out_str = '' last_non_comment_spaces = '' @@ -108,7 +109,7 @@ def to_commented_yaml(filename): # FIXME: This duplicates code from tools/yaml-nic-config-2-script.py, we should # refactor to share the common code def to_normal_yaml(filename): - """ Convert back to normal #commented YAML""" + """Convert back to normal #commented YAML""" with open(filename, 'r') as f: data = f.read() @@ -168,14 +169,10 @@ class TemplateLoader(yaml.SafeLoader): return collections.OrderedDict(self.construct_pairs(node)) -if sys.version_info.major >= 3: - TemplateDumper.add_representer(str, TemplateDumper.description_presenter) - TemplateDumper.add_representer(bytes, - TemplateDumper.description_presenter) -else: - TemplateDumper.add_representer(str, TemplateDumper.description_presenter) - TemplateDumper.add_representer(unicode, - TemplateDumper.description_presenter) +TemplateDumper.add_representer(six.text_type, + TemplateDumper.description_presenter) +TemplateDumper.add_representer(six.binary_type, + TemplateDumper.description_presenter) TemplateDumper.add_representer(collections.OrderedDict, TemplateDumper.represent_ordered_dict) @@ -215,9 +212,10 @@ def process_templates_and_get_reference_parameters(): for x in roles_data if x['name'] == OPTS.role_name)) except StopIteration: - raise RuntimeError('The role: {role_name} is not defined in roles ' - 'data file: {roles_data_file}'.format( - role_name=OPTS.role_name, roles_data_file=OPTS.roles_data)) + raise RuntimeError( + 'The role: {role_name} is not defined in roles ' + 'data file: {roles_data_file}'.format( + role_name=OPTS.role_name, roles_data_file=OPTS.roles_data)) refernce_file = '/'.join([temp_dir, 'network/config', NIC_CONFIG_REFERENCE, nic_config_name]) diff --git a/tools/process-templates.py b/tools/process-templates.py index dddaaeb3ee..296dcb6650 100755 --- a/tools/process-templates.py +++ b/tools/process-templates.py @@ -1,15 +1,15 @@ #!/usr/bin/env python -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import argparse import jinja2 @@ -38,6 +38,7 @@ def _shutil_copy_if_not_same(src, dst): else: raise + def parse_opts(argv): parser = argparse.ArgumentParser( description='Configure host network interfaces using a JSON' @@ -49,7 +50,8 @@ def parse_opts(argv): help="""relative path to the roles_data.yaml file.""", default='roles_data.yaml') parser.add_argument('-n', '--network-data', metavar='NETWORK_DATA', - help="""relative path to the network_data.yaml file.""", + help=("""relative path to the network_data.yaml """ + """file."""), default='network_data.yaml') parser.add_argument('--safe', action='store_true', @@ -86,7 +88,8 @@ def _j2_render_to_file(j2_template, j2_data, outfile_name=None, # Search for templates relative to the current template path first template_base = os.path.dirname(yaml_f) - j2_loader = jinja2.loaders.FileSystemLoader([template_base, __tht_root_dir]) + j2_loader = \ + jinja2.loaders.FileSystemLoader([template_base, __tht_root_dir]) try: # Render the j2 template @@ -102,6 +105,7 @@ def _j2_render_to_file(j2_template, j2_data, outfile_name=None, with open(outfile_name, 'w') as out_f: out_f.write(r_template) + def process_templates(template_path, role_data_path, output_dir, network_data_path, overwrite, dry_run): @@ -163,9 +167,9 @@ def process_templates(template_path, role_data_path, output_dir, out_dir = subdir if output_dir: if template_path != '.': - # strip out base path if not default - temp = out_dir.split(template_path)[1] - out_dir = temp[1:] if temp.startswith('/') else temp + # strip out base path if not default + temp = out_dir.split(template_path)[1] + out_dir = temp[1:] if temp.startswith('/') else temp out_dir = os.path.join(output_dir, out_dir) if not os.path.exists(out_dir): os.mkdir(out_dir) @@ -255,7 +259,8 @@ def process_templates(template_path, role_data_path, output_dir, template_data = j2_template.read() j2_data = {'roles': role_data, 'networks': network_data} - out_f = os.path.basename(f).replace('.j2.yaml', '.yaml') + out_f = os.path.basename(f).replace('.j2.yaml', + '.yaml') out_f_path = os.path.join(out_dir, out_f) _j2_render_to_file(template_data, j2_data, out_f_path, overwrite, dry_run) @@ -265,6 +270,7 @@ def process_templates(template_path, role_data_path, output_dir, else: print('Unexpected argument %s' % template_path) + def clean_templates(base_path, role_data_path, network_data_path): def delete(f): diff --git a/tools/roles-data-generate.py b/tools/roles-data-generate.py index 0b7687443e..dcb1fc7e56 100755 --- a/tools/roles-data-generate.py +++ b/tools/roles-data-generate.py @@ -42,6 +42,7 @@ def parse_opts(argv): return opts + opts = parse_opts(sys.argv) roles = collections.OrderedDict.fromkeys(opts.roles) diff --git a/tools/yaml-diff.py b/tools/yaml-diff.py index 6001daf0e1..5acbf48105 100755 --- a/tools/yaml-diff.py +++ b/tools/yaml-diff.py @@ -1,15 +1,15 @@ #!/usr/bin/env python -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import sys import yaml diff --git a/tools/yaml-nic-config-2-script.py b/tools/yaml-nic-config-2-script.py index 031c248172..b681eb50df 100755 --- a/tools/yaml-nic-config-2-script.py +++ b/tools/yaml-nic-config-2-script.py @@ -1,32 +1,32 @@ #!/usr/bin/env python -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import argparse import collections -import copy import datetime import os +import re import shutil +import six import sys import traceback import yaml -import six -import re + def parse_opts(argv): parser = argparse.ArgumentParser( - description='Convert an old style NIC config file into the new format using ' - 'run-os-net-config.sh') + description='Convert an old style NIC config file into the new format ' + 'using run-os-net-config.sh') parser.add_argument('--script-dir', metavar='