diff --git a/salt/loader.py b/salt/loader.py index 5d3add7a06..ec5b10cd65 100644 --- a/salt/loader.py +++ b/salt/loader.py @@ -158,7 +158,7 @@ def returners(opts, functions, whitelist=None, context=None): Returns the returner modules ''' if context is None: - conext = {} + context = {} return LazyLoader(_module_dirs(opts, 'returners', 'returner'), opts, tag='returner', diff --git a/salt/returners/mysql.py b/salt/returners/mysql.py index a93b750294..cbdb9b7717 100644 --- a/salt/returners/mysql.py +++ b/salt/returners/mysql.py @@ -156,14 +156,26 @@ def _get_serv(ret=None, commit=False): Return a mysql cursor ''' _options = _get_options(ret) - try: - conn = MySQLdb.connect(host=_options.get('host'), - user=_options.get('user'), - passwd=_options.get('pass'), - db=_options.get('db'), - port=_options.get('port')) - except MySQLdb.connections.OperationalError as exc: - raise salt.exceptions.SaltMasterError('MySQL returner could not connect to database: {exc}'.format(exc=exc)) + + if __context__ and 'mysql_returner_conn' in __context__: + log.debug('Reusing MySQL connection pool') + conn = __context__['mysql_returner_conn'] + else: + log.debug('Generating new MySQL connection pool') + try: + conn = MySQLdb.connect(host=_options.get('host'), + user=_options.get('user'), + passwd=_options.get('pass'), + db=_options.get('db'), + port=_options.get('port'), + pool_size=32) + + try: + __context__['mysql_returner_conn'] = conn + except TypeError: + pass + except MySQLdb.connections.OperationalError as exc: + raise salt.exceptions.SaltMasterError('MySQL returner could not connect to database: {exc}'.format(exc=exc)) cursor = conn.cursor() try: yield cursor