Bug #71905 Procedure to get a new server is ignoring the attempt_delay parameter
Submitted: 3 Mar 2014 7:49 Modified: 12 Mar 2014 0:55
Reporter: Alfranio Junior Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:1.2 alpha OS:Any
Assigned to: Geert Vanderkelen CPU Architecture:Any

[3 Mar 2014 7:49] Alfranio Junior
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:
[12 Mar 2014 0:55] Paul DuBois
Noted in 1.2.1 changelog.

The delay between attempts when trying to connect to a MySQL
Fabric-managed server was not honored.