summaryrefslogtreecommitdiff
path: root/git_review
diff options
context:
space:
mode:
authorJeremy Stanley <fungi@yuggoth.org>2021-02-23 23:03:49 +0000
committerJeremy Stanley <fungi@yuggoth.org>2021-02-24 00:58:53 +0000
commit95df6748c8f57360e8bb2de00efef5d89b989bac (patch)
tree8643446729f64dd37031e4dc000cff12a1d51362 /git_review
parentdeb6d0864549466fc9144f4f700560629e8e0c28 (diff)
downloadgit-review-95df6748c8f57360e8bb2de00efef5d89b989bac.tar.gz
Test with Gerrit 2.13
More recent OpenSSH/OpenSSL versions no longer want to communicate with the mina-sshd in Gerrit 2.11. In order to pave the way for testing on distros new enough to supply Python 3.9 packages, upgrade the version of Gerrit used in the functional testsuite. Because 2.12 and later moved user SSH keys into Git, we can no longer rely on the same gsql bootstrapping method to inject them into the golden site. However, if we init the server in --dev mode, we can use the default admin/secret test administrator account instead of creating a new administrator account ourselves (we just need to post an SSH public key for it to the REST API at runtime). Also stop precreating host keys and running a reindex, partially reverting I1c5db09c53a56ffd856da24decf29566e86f9d87, which we did to keep 2.11 working on some older (but then newer) platforms. Keep the reindexing in the golden site though, as this remains necessary and likely also provides some performance benefits. Add/improve some code comments around relevant bits, so further updates or rewrites will be less of a struggle for maintainers. Change-Id: I1245519d912a385c4b9bd09da1728d9b7933802b
Diffstat (limited to 'git_review')
-rw-r--r--git_review/tests/__init__.py64
1 files changed, 27 insertions, 37 deletions
diff --git a/git_review/tests/__init__.py b/git_review/tests/__init__.py
index b7ed9d4..8652d42 100644
--- a/git_review/tests/__init__.py
+++ b/git_review/tests/__init__.py
@@ -37,11 +37,10 @@ else:
urlparse = urllib.parse.urlparse
-WAR_URL = 'http://tarballs.openstack.org/' \
- 'ci/gerrit/gerrit-v2.11.4.13.cb9800e.war'
+WAR_URL = 'https://gerrit-releases.storage.googleapis.com/gerrit-2.13.14.war'
# Update GOLDEN_SITE_VER for every change altering golden site, including
# WAR_URL changes. Set new value to something unique (just +1 it for example)
-GOLDEN_SITE_VER = '4'
+GOLDEN_SITE_VER = '5'
# NOTE(yorik-sar): This function needs to be a perfect hash function for
@@ -147,53 +146,32 @@ class GerritHelpers(DirHelpers):
GOLDEN_SITE_VER)
return
- # We write out the ssh host key for gerrit's ssh server which
- # for undocumented reasons forces gerrit init to download the
- # bouncy castle libs which we need for ssh that works on
- # newer distros like ubuntu xenial.
- os.makedirs(self._dir('gsite', 'etc'))
- # create SSH host key
- host_key_file = self._dir('gsite', 'etc', 'ssh_host_rsa_key')
- utils.run_cmd('ssh-keygen', '-t', 'rsa', '-b', '4096', '-m', 'PEM',
- '-f', host_key_file, '-N', '')
-
print("Creating a new golden site of version " + GOLDEN_SITE_VER)
- # initialize Gerrit
+ # initialize Gerrit in developer mode, and include the
+ # download-commands plugin (needed by some tests which try to retrieve
+ # by Change-Id string)
utils.run_cmd('java', '-jar', self.gerrit_war,
- 'init', '-d', self.gsite_dir,
+ 'init', '-d', self.gsite_dir, '--dev',
'--batch', '--no-auto-start', '--install-plugin',
'download-commands')
+
+ # pre-index so that it won't be triggered on start for each copy
utils.run_cmd('java', '-jar', self.gerrit_war, 'reindex',
'-d', self.gsite_dir)
+ # record our site version
with open(golden_ver_file, 'w') as f:
f.write(GOLDEN_SITE_VER)
# create SSH public key
- key_file = self._dir('gsite', 'test_ssh_key')
utils.run_cmd('ssh-keygen', '-t', 'rsa', '-b', '4096', '-m', 'PEM',
- '-f', key_file, '-N', '')
- with open(key_file + '.pub', 'rb') as pub_key_file:
- pub_key = pub_key_file.read()
-
- # create admin user in Gerrit database
- sql_query = """INSERT INTO ACCOUNTS (REGISTERED_ON) VALUES (NOW());
- INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) \
- VALUES (0, 1);
- INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID, PASSWORD) \
- VALUES (0, 'username:test_user', 'test_pass');
- INSERT INTO ACCOUNT_SSH_KEYS (SSH_PUBLIC_KEY, VALID) \
- VALUES ('%s', 'Y')""" % pub_key.decode()
-
- utils.run_cmd('java', '-jar',
- self._dir('gsite', 'bin', 'gerrit.war'),
- 'gsql', '-d', self.gsite_dir, '-c', sql_query)
+ '-f', self._dir('gsite', 'test_ssh_key'), '-N', '')
def _run_gerrit_cli(self, command, *args):
"""SSH to gerrit Gerrit server and run command there."""
return utils.run_cmd('ssh', '-p', str(self.gerrit_port),
- 'test_user@' + self.gerrit_host, 'gerrit',
+ 'admin@' + self.gerrit_host, 'gerrit',
command, *args)
def _run_git_review(self, *args, **kwargs):
@@ -233,15 +211,27 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers):
self.test_dir = self._dir('site', 'tmp', 'test_project')
self.ssh_dir = self._dir('site', 'tmp', 'ssh')
self.project_ssh_uri = (
- 'ssh://test_user@%s:%s/test/test_project.git' % (
+ 'ssh://admin@%s:%s/test/test_project.git' % (
ssh_addr, ssh_port))
self.project_http_uri = (
- 'http://test_user:test_pass@%s:%s/test/test_project.git' % (
+ 'http://admin:secret@%s:%s/test/test_project.git' % (
http_addr, http_port))
self._run_gerrit(ssh_addr, ssh_port, http_addr, http_port)
self._configure_ssh(ssh_addr, ssh_port)
+ # Upload SSH key for test admin user
+ with open(self._dir('gsite', 'test_ssh_key.pub'), 'rb') as pub_key_fd:
+ pub_key = pub_key_fd.read().decode().strip()
+ resp = requests.post(
+ 'http://%s:%s/a/accounts/self/sshkeys' % (http_addr, http_port),
+ auth=requests.auth.HTTPDigestAuth('admin', 'secret'),
+ headers={'Content-Type': 'text/plain'},
+ data=pub_key)
+ if resp.status_code != 201:
+ raise RuntimeError(
+ 'SSH key upload failed: %s "%s"' % (resp, resp.text))
+
# create Gerrit empty project
self._run_gerrit_cli('create-project', 'test/test_project',
'--empty-commit')
@@ -373,7 +363,7 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers):
self._run_git('remote', 'add', self._remote, self.project_uri)
def _configure_gitreview_username(self):
- self._run_git('config', 'gitreview.username', 'test_user')
+ self._run_git('config', 'gitreview.username', 'admin')
def _pick_gerrit_port_and_dir(self):
hash_ = _hash_test_id(self.id())
@@ -408,4 +398,4 @@ class HttpMixin(object):
def _configure_gitreview_username(self):
# trick to set http password
- self._run_git('config', 'gitreview.username', 'test_user:test_pass')
+ self._run_git('config', 'gitreview.username', 'admin:secret')