summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Westphahl <simon.westphahl@bmw.de>2021-09-17 12:55:06 +0200
committerJames E. Blair <jim@acmegating.com>2021-09-17 15:52:54 -0700
commitdeb0b692600ea9c3f061055e6af3cffd26e05d70 (patch)
tree10c7aacfe245a884a6fffa5a5cec975f1ed3401c
parent5113fbceb063100d94b2453463c787afe030f869 (diff)
downloadzuul-deb0b692600ea9c3f061055e6af3cffd26e05d70.tar.gz
Simplify Zookeeper change cache API
Move common methods to AbstractChangeCache so that concrete implementations only need to defined the mapping from change type as string to the change class. Change-Id: I78c1bdfad1c0986aa6aef387424ea35b6c2aa71d
-rw-r--r--tests/unit/test_zk.py6
-rw-r--r--zuul/driver/gerrit/gerritconnection.py6
-rw-r--r--zuul/driver/git/gitconnection.py6
-rw-r--r--zuul/driver/github/githubconnection.py6
-rw-r--r--zuul/driver/gitlab/gitlabconnection.py6
-rw-r--r--zuul/driver/pagure/pagureconnection.py6
-rw-r--r--zuul/zk/change_cache.py12
7 files changed, 9 insertions, 39 deletions
diff --git a/tests/unit/test_zk.py b/tests/unit/test_zk.py
index 247466df0..a0bf7972a 100644
--- a/tests/unit/test_zk.py
+++ b/tests/unit/test_zk.py
@@ -1243,12 +1243,6 @@ class DummyChangeCache(AbstractChangeCache):
"DummyChange": DummyChange,
}
- def _getChangeClass(self, change_type):
- return self.CHANGE_TYPE_MAP[change_type]
-
- def _getChangeType(self, change):
- return type(change).__name__
-
class DummySource:
diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py
index dbb2017d1..a5d8f5c17 100644
--- a/zuul/driver/gerrit/gerritconnection.py
+++ b/zuul/driver/gerrit/gerritconnection.py
@@ -63,12 +63,6 @@ class GerritChangeCache(AbstractChangeCache):
"GerritChange": GerritChange,
}
- def _getChangeClass(self, change_type):
- return self.CHANGE_TYPE_MAP[change_type]
-
- def _getChangeType(self, change):
- return type(change).__name__
-
class GerritChangeData(object):
"""Compatability layer for SSH/HTTP
diff --git a/zuul/driver/git/gitconnection.py b/zuul/driver/git/gitconnection.py
index d63ef89fb..83cc14d62 100644
--- a/zuul/driver/git/gitconnection.py
+++ b/zuul/driver/git/gitconnection.py
@@ -34,12 +34,6 @@ class GitChangeCache(AbstractChangeCache):
"Branch": Branch,
}
- def _getChangeClass(self, change_type):
- return self.CHANGE_TYPE_MAP[change_type]
-
- def _getChangeType(self, change):
- return type(change).__name__
-
class GitConnection(ZKChangeCacheMixin, BaseConnection):
driver_name = 'git'
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 6c0b3959e..2ed8ef926 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -103,12 +103,6 @@ class GithubChangeCache(AbstractChangeCache):
"PullRequest": PullRequest,
}
- def _getChangeClass(self, change_type):
- return self.CHANGE_TYPE_MAP[change_type]
-
- def _getChangeType(self, change):
- return type(change).__name__
-
class GithubRequestLogger:
diff --git a/zuul/driver/gitlab/gitlabconnection.py b/zuul/driver/gitlab/gitlabconnection.py
index 8e69140d6..2cd0c807d 100644
--- a/zuul/driver/gitlab/gitlabconnection.py
+++ b/zuul/driver/gitlab/gitlabconnection.py
@@ -51,12 +51,6 @@ class GitlabChangeCache(AbstractChangeCache):
"MergeRequest": MergeRequest,
}
- def _getChangeClass(self, change_type):
- return self.CHANGE_TYPE_MAP[change_type]
-
- def _getChangeType(self, change):
- return type(change).__name__
-
class GitlabEventConnector(threading.Thread):
"""Move events from Gitlab into the scheduler"""
diff --git a/zuul/driver/pagure/pagureconnection.py b/zuul/driver/pagure/pagureconnection.py
index b99598153..3589247b5 100644
--- a/zuul/driver/pagure/pagureconnection.py
+++ b/zuul/driver/pagure/pagureconnection.py
@@ -107,12 +107,6 @@ class PagureChangeCache(AbstractChangeCache):
"PullRequest": PullRequest,
}
- def _getChangeClass(self, change_type):
- return self.CHANGE_TYPE_MAP[change_type]
-
- def _getChangeType(self, change):
- return type(change).__name__
-
class PagureEventConnector(threading.Thread):
"""Move events from Pagure into the scheduler"""
diff --git a/zuul/zk/change_cache.py b/zuul/zk/change_cache.py
index dea69013c..2f77ef395 100644
--- a/zuul/zk/change_cache.py
+++ b/zuul/zk/change_cache.py
@@ -286,12 +286,18 @@ class AbstractChangeCache(ZooKeeperSimpleBase, Iterable, abc.ABC):
def _updateChange(self, change, data):
change.deserialize(data["change_data"])
- @abc.abstractmethod
def _getChangeClass(self, change_type):
"""Return the change class for the given type."""
- pass
+ return self.CHANGE_TYPE_MAP[change_type]
- @abc.abstractmethod
def _getChangeType(self, change):
"""Return the change type as a string for the given type."""
+ return type(change).__name__
+
+ @abc.abstractproperty
+ def CHANGE_TYPE_MAP(self):
+ """Return a mapping of change type as string to change class.
+
+ This property cann also be defined as a class attribute.
+ """
pass