From 9fc294e196c69a726457fbf9fe791968b8000e5a Mon Sep 17 00:00:00 2001 From: James Page Date: Mon, 3 Mar 2014 09:14:09 +0000 Subject: [PATCH] Pep8 formatting --- hooks/keystone_hooks.py | 5 ++--- hooks/keystone_ssl.py | 7 ++++--- hooks/keystone_utils.py | 34 +++++++++++++++++----------------- hooks/manager.py | 1 + 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/hooks/keystone_hooks.py b/hooks/keystone_hooks.py index 1599e36d..2ab440c1 100755 --- a/hooks/keystone_hooks.py +++ b/hooks/keystone_hooks.py @@ -22,7 +22,6 @@ from charmhelpers.core.hookenv import ( from charmhelpers.core.host import ( mkdir, restart_on_change, - service_restart, ) from charmhelpers.fetch import ( @@ -77,7 +76,7 @@ def config_changed(): unison.ensure_user(user=SSH_USER, group='keystone') homedir = unison.get_homedir(SSH_USER) if not os.path.isdir(homedir): - mkdir(homedir, SSH_USER, 'keystone', 0775) + mkdir(homedir, SSH_USER, 'keystone', 0o775) if openstack_upgrade_available('keystone'): do_openstack_upgrade(configs=CONFIGS) @@ -186,7 +185,7 @@ def ha_changed(): clustered = relation_get('clustered') CONFIGS.write_all() if (clustered is not None and - is_leader(CLUSTER_RES)): + is_leader(CLUSTER_RES)): ensure_initial_admin(config) log('Cluster configured, notifying other services and updating ' 'keystone endpoint configuration') diff --git a/hooks/keystone_ssl.py b/hooks/keystone_ssl.py index b39b227e..45e0029d 100755 --- a/hooks/keystone_ssl.py +++ b/hooks/keystone_ssl.py @@ -113,7 +113,7 @@ def init_ca(ca_dir, common_name, org_name=ORG_NAME, org_unit_name=ORG_UNIT): if not os.path.exists(d): print 'Creating %s.' % d os.mkdir(d) - os.chmod(os.path.join(ca_dir, 'private'), 0710) + os.chmod(os.path.join(ca_dir, 'private'), 0o710) if not os.path.isfile(os.path.join(ca_dir, 'serial')): with open(os.path.join(ca_dir, 'serial'), 'wb') as out: @@ -161,7 +161,7 @@ def intermediate_ca_csr_key(ca_dir): def sign_int_csr(ca_dir, csr, common_name): print 'Signing certificate request %s.' % csr crt = os.path.join(ca_dir, 'certs', - '%s.crt' % os.path.basename(csr).split('.')[0]) + '%s.crt' % os.path.basename(csr).split('.')[0]) subj = '/O=%s/OU=%s/CN=%s' % (ORG_NAME, ORG_UNIT, common_name) cmd = ['openssl', 'ca', '-batch', '-config', os.path.join(ca_dir, 'ca.cnf'), @@ -238,6 +238,7 @@ def tar_directory(path): class JujuCA(object): + def __init__(self, name, ca_dir, root_ca_dir, user, group): root_crt, root_key = init_root_ca(root_ca_dir, '%s Certificate Authority' % name) @@ -288,7 +289,7 @@ class JujuCA(object): key = open(key, 'r').read() except: print 'Could not load ssl private key for %s from %s' %\ - (common_name, key) + (common_name, key) exit(1) return crt, key crt, key = self._create_certificate(common_name, common_name) diff --git a/hooks/keystone_utils.py b/hooks/keystone_utils.py index ab988a32..79eaa6c3 100755 --- a/hooks/keystone_utils.py +++ b/hooks/keystone_utils.py @@ -13,7 +13,7 @@ from charmhelpers.contrib.hahelpers.cluster import( determine_api_port, https, is_clustered - ) +) from charmhelpers.contrib.openstack import context, templating @@ -252,13 +252,13 @@ def migrate_database(): time.sleep(10) -## OLD +# OLD def get_local_endpoint(): """ Returns the URL for the local end-point bypassing haproxy/ssl """ local_endpoint = 'http://localhost:{}/v2.0/'.format( determine_api_port(api_port('keystone-admin')) - ) + ) return local_endpoint @@ -317,7 +317,7 @@ def create_service_entry(service_name, service_type, service_desc, owner=None): log("Created new service entry '%s'" % service_name) -def create_endpoint_template(region, service, publicurl, adminurl, +def create_endpoint_template(region, service, publicurl, adminurl, internalurl): """ Create a new endpoint template for service if one does not already exist matching name *and* region """ @@ -328,7 +328,7 @@ def create_endpoint_template(region, service, publicurl, adminurl, for ep in [e._info for e in manager.api.endpoints.list()]: if ep['service_id'] == service_id and ep['region'] == region: log("Endpoint template already exists for '%s' in '%s'" - % (service, region)) + % (service, region)) up_to_date = True for k in ['publicurl', 'adminurl', 'internalurl']: @@ -405,7 +405,7 @@ def create_role(name, user=None, tenant=None): if None in [user_id, role_id, tenant_id]: error_out("Could not resolve [%s, %s, %s]" % - (user_id, role_id, tenant_id)) + (user_id, role_id, tenant_id)) grant_role(user, name, tenant) @@ -415,7 +415,7 @@ def grant_role(user, role, tenant): import manager manager = manager.KeystoneManager(endpoint=get_local_endpoint(), token=get_admin_token()) - log("Granting user '%s' role '%s' on tenant '%s'" % \ + log("Granting user '%s' role '%s' on tenant '%s'" % (user, role, tenant)) user_id = manager.resolve_user_id(user) role_id = manager.resolve_role_id(role) @@ -426,10 +426,10 @@ def grant_role(user, role, tenant): manager.api.roles.add_user_role(user=user_id, role=role_id, tenant=tenant_id) - log("Granted user '%s' role '%s' on tenant '%s'" % \ + log("Granted user '%s' role '%s' on tenant '%s'" % (user, role, tenant)) else: - log("User '%s' already has role '%s' on tenant '%s'" % \ + log("User '%s' already has role '%s' on tenant '%s'" % (user, role, tenant)) @@ -453,8 +453,8 @@ def ensure_initial_admin(config): log("Loading stored passwd from %s" % STORED_PASSWD) passwd = open(STORED_PASSWD, 'r').readline().strip('\n') if passwd == "": - log("Generating new passwd for user: %s" % \ - config("admin-user")) + log("Generating new passwd for user: %s" % + config("admin-user")) cmd = ['pwgen', '-c', '16', '1'] passwd = str(subprocess.check_output(cmd)).strip() open(STORED_PASSWD, 'w+').writelines("%s\n" % passwd) @@ -506,8 +506,8 @@ def update_user_password(username, password): error_out("Could not resolve user id for '%s'" % username) manager.api.users.update_password(user=user_id, password=password) - log("Successfully updated password for user '%s'" % \ - username) + log("Successfully updated password for user '%s'" % + username) def load_stored_passwords(path=SERVICE_PASSWD_PATH): @@ -545,7 +545,7 @@ def synchronize_service_credentials(): broadcasted by peer, depending on hook context. ''' if (not eligible_leader(CLUSTER_RES) or - not os.path.isfile(SERVICE_PASSWD_PATH)): + not os.path.isfile(SERVICE_PASSWD_PATH)): return log('Synchronizing service passwords to all peers.') if is_clustered(): @@ -569,7 +569,7 @@ def get_ca(user='keystone', group='keystone'): ca_dir=os.path.join(SSL_DIR, '%s_intermediate_ca' % d_name), root_ca_dir=os.path.join(SSL_DIR, - '%s_root_ca' % d_name)) + '%s_root_ca' % d_name)) # SSL_DIR is synchronized via all peers over unison+ssh, need # to ensure permissions. subprocess.check_output(['chown', '-R', '%s.%s' % (user, group), @@ -583,7 +583,7 @@ def relation_list(rid): cmd = [ 'relation-list', '-r', rid, - ] + ] result = str(subprocess.check_output(cmd)).split() if result == "": return None @@ -773,7 +773,7 @@ def add_endpoint(region, service, publicurl, adminurl, internalurl): def get_requested_roles(settings): ''' Retrieve any valid requested_roles from dict settings ''' if ('requested_roles' in settings and - settings['requested_roles'] not in ['None', None]): + settings['requested_roles'] not in ['None', None]): return settings['requested_roles'].split(',') else: return [] diff --git a/hooks/manager.py b/hooks/manager.py index e7058820..8c8968d3 100644 --- a/hooks/manager.py +++ b/hooks/manager.py @@ -3,6 +3,7 @@ from keystoneclient.v2_0 import client class KeystoneManager(object): + def __init__(self, endpoint, token): self.api = client.Client(endpoint=endpoint, token=token)