Fix broken CI and PyMySQL support

This is a combination of two patches that depend on 
each other to fix a breakage with PyMySQL 0.10.0 and
fixing the up the CI to a working state.

1. Blacklist etcd3gw 0.2.6

etcd3gw 0.2.6 was blacklisted in openstack/requirements [0], because
that version has a bug [1].

tooz does not use openstack/requirements' upper constraints, so the
same blacklisting needs to be introduced here in setup.cfg.

[0] Icb6873d8c5d3a3624c0ac3d76fc9125c5d8134b2
[1] https://github.com/dims/etcd3-gateway/issues/41

Change-Id: I22b955419014dd34c63e406c488e0636ffe9013b
Closes-Bug: #1891314
(cherry picked from commit 3f0759091c)
(cherry picked from commit c8d77ee485)

2. Fix breakage with PyMySQL 0.10.0

In this version a Connection is no longer a context manager. Fix
it by simply getting a Cursor out of it (locks don't seem to
interact with transactions, at least according to MariaDB docs).

Change-Id: I5ea06ebd2b976465ff82f10a74e140f30e9e803f
(cherry picked from commit d59b283440)
This commit is contained in:
Elod Illes 2020-09-29 18:46:25 +02:00 committed by Tobias Urdin
parent b47e687727
commit 667e2ec1f4
3 changed files with 14 additions and 10 deletions

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fixes AttributeError in the ``mysql`` driver with PyMySQL 0.10.0.

View File

@ -51,7 +51,7 @@ etcd3 =
etcd3>=0.12.0 # Apache-2.0
grpcio>=1.18.0
etcd3gw =
etcd3gw>=0.1.0 # Apache-2.0
etcd3gw!=0.2.6,>=0.1.0 # Apache-2.0
zake =
zake>=0.1.6 # Apache-2.0
redis =

View File

@ -61,12 +61,12 @@ class MySQLLock(locking.Lock):
try:
if not self._conn.open:
self._conn.connect()
with self._conn as cur:
cur.execute("SELECT GET_LOCK(%s, 0);", self.name)
# Can return NULL on error
if cur.fetchone()[0] is 1:
self.acquired = True
return True
cur = self._conn.cursor()
cur.execute("SELECT GET_LOCK(%s, 0);", self.name)
# Can return NULL on error
if cur.fetchone()[0] == 1:
self.acquired = True
return True
except pymysql.MySQLError as e:
utils.raise_with_cause(
tooz.ToozError,
@ -90,9 +90,9 @@ class MySQLLock(locking.Lock):
if not self.acquired:
return False
try:
with self._conn as cur:
cur.execute("SELECT RELEASE_LOCK(%s);", self.name)
cur.fetchone()
cur = self._conn.cursor()
cur.execute("SELECT RELEASE_LOCK(%s);", self.name)
cur.fetchone()
self.acquired = False
self._conn.close()
return True