fix(pep8): makes python script pep8 compliant

Fixes keystone python script so it is pep8 compliant.

Change-Id: Ib94707996441f35e6ffb32a6d63ab6adbd17a87d
Signed-off-by: Tin <tin@irrational.io>
This commit is contained in:
Tin 2021-05-16 18:38:55 -05:00 committed by Tin Lam
parent d21b00d159
commit 26afeb4cb2
5 changed files with 40 additions and 33 deletions

View File

@ -14,7 +14,7 @@ apiVersion: v1
appVersion: v1.0.0 appVersion: v1.0.0
description: OpenStack-Helm Keystone description: OpenStack-Helm Keystone
name: keystone name: keystone
version: 0.2.1 version: 0.2.2
home: https://docs.openstack.org/keystone/latest/ home: https://docs.openstack.org/keystone/latest/
icon: https://www.openstack.org/themes/openstack/images/project-mascots/Keystone/OpenStack_Project_Keystone_vertical.png icon: https://www.openstack.org/themes/openstack/images/project-mascots/Keystone/OpenStack_Project_Keystone_vertical.png
sources: sources:

View File

@ -36,7 +36,8 @@ logger = logging.getLogger('OpenStack-Helm DB Drop')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler() ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Set the formatter and add the handler # Set the formatter and add the handler
ch.setFormatter(formatter) ch.setFormatter(formatter)
@ -54,7 +55,9 @@ else:
mysql_x509 = os.getenv('MARIADB_X509', "") mysql_x509 = os.getenv('MARIADB_X509', "")
ssl_args = {} ssl_args = {}
if mysql_x509: if mysql_x509:
ssl_args = {'ssl': {'ca': '/etc/mysql/certs/ca.crt', 'key': '/etc/mysql/certs/tls.key', 'cert': '/etc/mysql/certs/tls.crt'}} ssl_args = {'ssl': {'ca': '/etc/mysql/certs/ca.crt',
'key': '/etc/mysql/certs/tls.key',
'cert': '/etc/mysql/certs/tls.crt'}}
# Get the connection string for the service db # Get the connection string for the service db
if "OPENSTACK_CONFIG_FILE" in os.environ: if "OPENSTACK_CONFIG_FILE" in os.environ:
@ -62,7 +65,8 @@ if "OPENSTACK_CONFIG_FILE" in os.environ:
if "OPENSTACK_CONFIG_DB_SECTION" in os.environ: if "OPENSTACK_CONFIG_DB_SECTION" in os.environ:
os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION'] os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION']
else: else:
logger.critical('environment variable OPENSTACK_CONFIG_DB_SECTION not set') logger.critical(
'environment variable OPENSTACK_CONFIG_DB_SECTION not set')
sys.exit(1) sys.exit(1)
if "OPENSTACK_CONFIG_DB_KEY" in os.environ: if "OPENSTACK_CONFIG_DB_KEY" in os.environ:
os_conf_key = os.environ['OPENSTACK_CONFIG_DB_KEY'] os_conf_key = os.environ['OPENSTACK_CONFIG_DB_KEY']
@ -78,13 +82,15 @@ if "OPENSTACK_CONFIG_FILE" in os.environ:
user_db_conn = config.get(os_conf_section, os_conf_key) user_db_conn = config.get(os_conf_section, os_conf_key)
logger.info("Got config from {0}".format(os_conf)) logger.info("Got config from {0}".format(os_conf))
except: except:
logger.critical("Tried to load config from {0} but failed.".format(os_conf)) logger.critical(
"Tried to load config from {0} but failed.".format(os_conf))
raise raise
elif "DB_CONNECTION" in os.environ: elif "DB_CONNECTION" in os.environ:
user_db_conn = os.environ['DB_CONNECTION'] user_db_conn = os.environ['DB_CONNECTION']
logger.info('Got config from DB_CONNECTION env var') logger.info('Got config from DB_CONNECTION env var')
else: else:
logger.critical('Could not get db config, either from config file or env var') logger.critical(
'Could not get db config, either from config file or env var')
sys.exit(1) sys.exit(1)
# Root DB engine # Root DB engine
@ -95,7 +101,8 @@ try:
drivername = root_engine_full.url.drivername drivername = root_engine_full.url.drivername
host = root_engine_full.url.host host = root_engine_full.url.host
port = root_engine_full.url.port port = root_engine_full.url.port
root_engine_url = ''.join([drivername, '://', root_user, ':', root_password, '@', host, ':', str (port)]) root_engine_url = ''.join([drivername, '://', root_user, ':',
root_password, '@', host, ':', str(port)])
root_engine = create_engine(root_engine_url, connect_args=ssl_args) root_engine = create_engine(root_engine_url, connect_args=ssl_args)
connection = root_engine.connect() connection = root_engine.connect()
connection.close() connection.close()

View File

@ -19,7 +19,7 @@ import requests
import sys import sys
def main(args): def main(args):
base_url, token, domainId, domainName, filename = args[1], args[2], args[3], args[4], args[5] base_url, token, domainId, filename = args[1], args[2], args[3], args[5]
url = "%s/domains/%s/config" % (base_url, domainId) url = "%s/domains/%s/config" % (base_url, domainId)
print("Connecting to url: %r" % url) print("Connecting to url: %r" % url)
@ -47,12 +47,12 @@ def main(args):
data=json.dumps(data), data=json.dumps(data),
headers=headers, verify=verify) headers=headers, verify=verify)
print("Response code on action [%s]: %s" % (action, response.status_code)) print("Response code on action [%s]: %s" % (action, response.status_code))
# Put and Patch can return 200 or 201. If it is not a 2XX code, error out. # Put and Patch can return 200 or 201. If it is not a 2XX code, error out.
if (response.status_code // 100) != 2: if (response.status_code // 100) != 2:
sys.exit(1) sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) != 6: if len(sys.argv) != 6:
sys.exit(1) sys.exit(1)

View File

@ -1,35 +1,24 @@
{{/*
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.
*/}}
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import logging
import sys import sys
from sqlalchemy import create_engine
try: try:
import ConfigParser import ConfigParser
PARSER_OPTS = {} PARSER_OPTS = {}
except ImportError: except ImportError:
import configparser as ConfigParser import configparser as ConfigParser
PARSER_OPTS = {"strict": False} PARSER_OPTS = {"strict": False}
import logging
from sqlalchemy import create_engine
# Create logger, console handler and formatter # Create logger, console handler and formatter
logger = logging.getLogger('OpenStack-Helm Keystone Endpoint management') logger = logging.getLogger('OpenStack-Helm Keystone Endpoint management')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler() ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Set the formatter and add the handler # Set the formatter and add the handler
ch.setFormatter(formatter) ch.setFormatter(formatter)
@ -41,7 +30,8 @@ if "OPENSTACK_CONFIG_FILE" in os.environ:
if "OPENSTACK_CONFIG_DB_SECTION" in os.environ: if "OPENSTACK_CONFIG_DB_SECTION" in os.environ:
os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION'] os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION']
else: else:
logger.critical('environment variable OPENSTACK_CONFIG_DB_SECTION not set') logger.critical(
'environment variable OPENSTACK_CONFIG_DB_SECTION not set')
sys.exit(1) sys.exit(1)
if "OPENSTACK_CONFIG_DB_KEY" in os.environ: if "OPENSTACK_CONFIG_DB_KEY" in os.environ:
os_conf_key = os.environ['OPENSTACK_CONFIG_DB_KEY'] os_conf_key = os.environ['OPENSTACK_CONFIG_DB_KEY']
@ -57,13 +47,15 @@ if "OPENSTACK_CONFIG_FILE" in os.environ:
user_db_conn = config.get(os_conf_section, os_conf_key) user_db_conn = config.get(os_conf_section, os_conf_key)
logger.info("Got config from {0}".format(os_conf)) logger.info("Got config from {0}".format(os_conf))
except: except:
logger.critical("Tried to load config from {0} but failed.".format(os_conf)) logger.critical(
"Tried to load config from {0} but failed.".format(os_conf))
raise raise
elif "DB_CONNECTION" in os.environ: elif "DB_CONNECTION" in os.environ:
user_db_conn = os.environ['DB_CONNECTION'] user_db_conn = os.environ['DB_CONNECTION']
logger.info('Got config from DB_CONNECTION env var') logger.info('Got config from DB_CONNECTION env var')
else: else:
logger.critical('Could not get db config, either from config file or env var') logger.critical(
'Could not get db config, either from config file or env var')
sys.exit(1) sys.exit(1)
# User DB engine # User DB engine
@ -76,7 +68,9 @@ except:
# Set Internal Endpoint # Set Internal Endpoint
try: try:
endpoint_url = os.environ['OS_BOOTSTRAP_INTERNAL_URL'] endpoint_url = os.environ['OS_BOOTSTRAP_INTERNAL_URL']
cmd = "update endpoint set url = %s where interface ='internal' and service_id = (select id from service where service.type = 'identity')" cmd = ("update endpoint set url = %s where interface ='internal' and "
"service_id = (select id from service where "
"service.type = 'identity')")
user_engine.execute(cmd, (endpoint_url,)) user_engine.execute(cmd, (endpoint_url,))
except: except:
logger.critical("Could not update internal endpoint") logger.critical("Could not update internal endpoint")
@ -85,7 +79,9 @@ except:
# Set Admin Endpoint # Set Admin Endpoint
try: try:
endpoint_url = os.environ['OS_BOOTSTRAP_ADMIN_URL'] endpoint_url = os.environ['OS_BOOTSTRAP_ADMIN_URL']
cmd = "update endpoint set url = %s where interface ='admin' and service_id = (select id from service where service.type = 'identity')" cmd = ("update endpoint set url = %s where interface ='admin' "
"and service_id = (select id from service where "
"service.type = 'identity')")
user_engine.execute(cmd, (endpoint_url,)) user_engine.execute(cmd, (endpoint_url,))
except: except:
logger.critical("Could not update admin endpoint") logger.critical("Could not update admin endpoint")
@ -94,7 +90,9 @@ except:
# Set Public Endpoint # Set Public Endpoint
try: try:
endpoint_url = os.environ['OS_BOOTSTRAP_PUBLIC_URL'] endpoint_url = os.environ['OS_BOOTSTRAP_PUBLIC_URL']
cmd = "update endpoint set url = %s where interface ='public' and service_id = (select id from service where service.type = 'identity')" cmd = ("update endpoint set url = %s where interface ='public' "
"and service_id = (select id from service where "
"service.type = 'identity')")
user_engine.execute(cmd, (endpoint_url,)) user_engine.execute(cmd, (endpoint_url,))
except: except:
logger.critical("Could not update public endpoint") logger.critical("Could not update public endpoint")
@ -103,7 +101,8 @@ except:
# Print endpoints # Print endpoints
try: try:
endpoints = user_engine.execute( endpoints = user_engine.execute(
"select interface, url from endpoint where service_id = (select id from service where service.type = 'identity')" ("select interface, url from endpoint where service_id = "
"(select id from service where service.type = 'identity')")
).fetchall() ).fetchall()
for row in endpoints: for row in endpoints:
logger.info("endpoint ({0}): {1}".format(row[0], row[1])) logger.info("endpoint ({0}): {1}".format(row[0], row[1]))

View File

@ -17,4 +17,5 @@ keystone:
- 0.1.14 Remove setup helm hooks - 0.1.14 Remove setup helm hooks
- 0.2.0 Remove support for releases before T - 0.2.0 Remove support for releases before T
- 0.2.1 Remove paste ini config settings - 0.2.1 Remove paste ini config settings
- 0.2.2 Make python script PEP8 compliant
... ...