summaryrefslogtreecommitdiffstats
path: root/events/src
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2018-10-06 09:20:24 +0530
committerAmar Tumballi <amarts@redhat.com>2018-10-08 16:36:31 +0000
commitb5f75e337c19d4fed85d4dcf15cf47f02fea5f6a (patch)
tree9c55fc712fb13b3f672e1dcf011d5b88675fa8b6 /events/src
parentfb6e8d0d0ca21b16d331fa69da9b9dadf6c5c35d (diff)
events: python2 to python3 compat
1. Fix imports 2. Use universal_newlines flag in Popen 3. encode msg used in 'sendto' Updates: #411 Change-Id: Ieacdc2ba86953ff3a2e9d9b9a97157e8e0e36836 Signed-off-by: Kotresh HR <khiremat@redhat.com>
Diffstat (limited to 'events/src')
-rw-r--r--events/src/eventsapiconf.py.in3
-rw-r--r--events/src/gf_event.py18
-rw-r--r--events/src/utils.py4
3 files changed, 13 insertions, 12 deletions
diff --git a/events/src/eventsapiconf.py.in b/events/src/eventsapiconf.py.in
index 003cb981572..76b5954d325 100644
--- a/events/src/eventsapiconf.py.in
+++ b/events/src/eventsapiconf.py.in
@@ -18,7 +18,8 @@ def get_glusterd_workdir():
if glusterd_workdir is not None:
return glusterd_workdir
proc = subprocess.Popen(["gluster", "system::", "getwd"],
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines = True)
out, err = proc.communicate()
if proc.returncode == 0:
glusterd_workdir = out.strip()
diff --git a/events/src/gf_event.py b/events/src/gf_event.py
index 6cde91aad40..0c7b7ec92d7 100644
--- a/events/src/gf_event.py
+++ b/events/src/gf_event.py
@@ -12,10 +12,10 @@
import socket
import time
-from eventsapiconf import SERVER_ADDRESS, EVENTS_ENABLED
-from eventtypes import all_events
+from .eventsapiconf import SERVER_ADDRESS, EVENTS_ENABLED
+from .eventtypes import all_events
-from utils import logger, setup_logger, get_config
+from .utils import logger, setup_logger, get_config
# Run this when this lib loads
setup_logger()
@@ -35,18 +35,18 @@ def gf_event(event_type, **kwargs):
logger.error("Unable to connect to events Server: {0}".format(e))
return
+ port = get_config("port")
+ if port is None:
+ logger.error("Unable to get eventsd port details")
+ return
+
# Convert key value args into KEY1=VALUE1;KEY2=VALUE2;..
msg = ""
for k, v in kwargs.items():
msg += "{0}={1};".format(k, v)
# <TIMESTAMP> <EVENT_TYPE> <MSG>
- msg = "{0} {1} {2}".format(int(time.time()), event_type, msg.strip(";"))
-
- port = get_config("port")
- if port is None:
- logger.error("Unable to get eventsd port details")
- return
+ msg = "{0} {1} {2}".format(int(time.time()), event_type, msg.strip(";")).encode()
try:
sent = client.sendto(msg, (SERVER_ADDRESS, port))
diff --git a/events/src/utils.py b/events/src/utils.py
index 0ec7051ec28..fcdcbd47acc 100644
--- a/events/src/utils.py
+++ b/events/src/utils.py
@@ -26,13 +26,13 @@ import hmac
from hashlib import sha256
from calendar import timegm
-from eventsapiconf import (LOG_FILE,
+from .eventsapiconf import (LOG_FILE,
WEBHOOKS_FILE,
DEFAULT_CONFIG_FILE,
CUSTOM_CONFIG_FILE,
UUID_FILE,
CERTS_DIR)
-import eventtypes
+from . import eventtypes
# Webhooks list