Description:
Procedure to get a new server is ignoring the attempt_delay parameter when fabric returns a server but the server is not reachable. This happens, for example, when server which has failed was not marked as faulty yet.
How to repeat:
Check the function "_connect" function in python23/fabric/connection.py.
Suggested fix:
Suggested fix:
=== modified file 'python23/fabric/connection.py'
--- python23/fabric/connection.py revid:peeyush.x.gupta@oracle.com-20140214120958-ps7sc5x4cji93usi
+++ python23/fabric/connection.py 2014-03-03 07:45:58 +0000
@@ -782,7 +782,7 @@
group = None
if props['tables']:
if props['scope'] == 'LOCAL' and not props['key']:
- raise InterfaceError(
+ raise ValueError(
"Scope 'LOCAL' needs key property to be set")
mysqlserver = self._fabric.get_shard_server(
props['tables'], props['key'],
@@ -793,17 +793,11 @@
mysqlserver = self._fabric.get_group_server(
group, mode=props['mode'])
else:
- raise InterfaceError(
+ raise ValueError(
"Missing group or key and tables properties")
except InterfaceError as err:
- _LOGGER.debug(
- "Trying to get MySQL server (attempt {0}; {1})".format(
- counter, err))
- if counter == attempts:
- raise InterfaceError(
- "Error getting connection: {0}".format(err))
- if attempt_delay > 0:
- time.sleep(attempt_delay)
+ self._check_connect_failure(counter, attempts, attempt_delay,
+ err)
continue
# Make sure we do not change the stored configuration
@@ -815,13 +809,22 @@
self._fabric.set_server_status(mysqlserver.uuid,
_SERVER_STATUS_FAULTY)
self.reset_cache(mysqlserver.group)
- if counter == attempts:
- raise InterfaceError(
- "Reported faulty server to Fabric ({0})".format(err))
+ self._check_connect_failure(counter, attempts, attempt_delay,
+ err)
else:
self._fabric_mysql_server = mysqlserver
break
+ def _check_connect_failure(self, counter, attempts, attempt_delay, error):
+ _LOGGER.debug(
+ "Trying to get MySQL server (attempt {0}; {1})".format(
+ counter, error))
+ if counter == attempts:
+ raise InterfaceError(
+ "Error getting connection: {0}".format(error))
+ if attempt_delay > 0:
+ time.sleep(attempt_delay)
+
def disconnect(self):
"""Close connection to MySQL server"""
try: