Skip to content

Commit

Permalink
Fix a few issues with the VMPollerClient class
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Aug 21, 2013
1 parent eb89226 commit ce2c423
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/vmpollerd/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def run(self, config_file="/etc/vm-poller/vm-pollerd-proxy.conf"):
try:
self.backend.bind(self.backend_endpoint)
except zmq.ZMQError as e:
raise VMPollerException, "Cannot bind backend socket: %s" e
raise VMPollerException, "Cannot bind backend socket: %s" % e

# Start the proxy
syslog.syslog("Starting the VMPoller Proxy")
Expand Down Expand Up @@ -438,13 +438,13 @@ class VMPollerClient(object):
"""
def __init__(self, config_file="/etc/vm-poller/vm-pollerd-client.conf"):
if not os.path.exists(config_file):
raise VMPollerException, "Config file %s does not exists" % config
raise VMPollerException, "Config file %s does not exists" % config_file

config = ConfigParser.ConfigParser()
config.read(config_file)

self.timeout = config.get('Default', 'timeout')
self.retries = config.get('Default', 'retries')
self.retries = int(config.get('Default', 'retries'))
self.endpoint = config.get('Default', 'endpoint')

self.zcontext = zmq.Context()
Expand All @@ -469,19 +469,21 @@ def run(self, msg):
socks = dict(self.zpoller.poll(self.timeout))

# Do we have a reply?
if socks[self.zclient] == zmq.POLLIN:
if socks.get(self.zclient) == zmq.POLLIN:
result = self.zclient.recv_json()
break
else:
# We didn't get a reply back from the server, let's retry
self.retries -= 1
syslog.syslog("Didn't get a reply from server, retrying...")
syslog.syslog("Did not receive reply from server, retrying...")

# Socket is confused. Close and remove it.
self.zclient.close()
self.zpoller.unregister(self.zclient)

# Re-establish the connection
self.zclient = self.zcontext.socket(zmq.REQ)
self.zclient.setsockopt(zmq.LINGER, 0)
self.zclient.connect(self.endpoint)
self.zpoller.register(self.zclient, zmq.POLLIN)

Expand All @@ -492,7 +494,7 @@ def run(self, msg):

# Did we have any result reply at all?
if not result:
return "Did not get a reply from the server"
return "Did not receive reply from the server, aborting..."

# Was the request successful?
if result["status"] != 0:
Expand Down

0 comments on commit ce2c423

Please sign in to comment.