Fix more PY3 issues in check_rabbitmq_queues.py

Note that, for PY3, the unbuffered IO in the check_rabbitmq.py script
has to be switched off as PY3 doesn't support unbuffered IO for text
(think str) rather than binary byte streams.

Change-Id: I79af54cdbd7381f88732b24f65e94451350b9ab9
Closes-Bug: #1804349
Closes-Bug: #1804348
This commit is contained in:
Alex Kavanagh 2018-11-21 12:32:36 +00:00
parent f30b4ac0c6
commit 065914d696
3 changed files with 25 additions and 5 deletions

View File

@ -79,6 +79,11 @@ from charmhelpers.contrib.hardening.harden import harden
from charmhelpers.fetch import (
add_source,
)
from charmhelpers.fetch import (
apt_install,
apt_update,
filter_installed_packages,
)
from charmhelpers.core.hookenv import (
open_port,
@ -747,6 +752,14 @@ def upgrade_charm():
# Ensure all client connections are up to date on upgrade
update_clients()
# BUG:#1804348
# for the check_rabbitmq.py script, python3-amqplib needs to be installed;
# if previous version was a python2 version of the charm this won't happen
# unless the source is changed. Ensure it is installed here if needed.
apt_update(fatal=True)
if filter_installed_packages(['python3-amqplib']):
apt_install(['python3-amqplib'], fatal=True)
MAN_PLUGIN = 'rabbitmq_management'

View File

@ -181,7 +181,10 @@ def main_loop(conn, exname):
def main(host, port, exname, extype, user, password, vhost, ssl, ssl_ca):
""" setup the connection and the communication channel """
sys.stdout = os.fdopen(os.dup(1), "w", 0)
# BUG:#1804348 - can't have unbuffered text output in PY3 (unlike PY2), and
# this is essentially duping stdout which has to use text (str) and not
# bytes. The only compromise is to lose the unbuffered output.
sys.stdout = os.fdopen(os.dup(1), "w")
host_port = "{}:{}".format(host, port)
conn = get_connection(host_port, user, password, vhost, ssl, ssl_ca)
@ -240,9 +243,13 @@ if __name__ == '__main__':
(options, args) = parser.parse_args()
if options.verbose:
print("""
Using AMQP setup: host:port={}:{} exchange_name={} exchange_type={}
""".format(options.host, options.port, options.exchange, options.type))
print("")
print("Using AMQP setup: host:port={}:{} exchange_name={} "
"exchange_type={} "
.format(options.host,
options.port,
options.exchange,
options.type))
ret = main(options.host, options.port, options.exchange, options.type,
options.user, options.password, options.vhost, options.ssl,
options.ssl_ca)

View File

@ -12,7 +12,7 @@ import sys
def gen_data_lines(filename):
with open(filename, "rb") as fin:
with open(filename, "rt") as fin:
for line in fin:
if not line.startswith("#"):
yield line