Merge "Use package structure for gerrit init scripts"
diff --git a/.gitignore b/.gitignore
index 873bf67..8a09c99 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
 
 __pycache__
 .pytest_cache
+*.pyc
diff --git a/container-images/gerrit-init/Dockerfile b/container-images/gerrit-init/Dockerfile
index 1cfa326..d730b95 100644
--- a/container-images/gerrit-init/Dockerfile
+++ b/container-images/gerrit-init/Dockerfile
@@ -13,10 +13,10 @@
     pip3 install --no-cache --upgrade pip setuptools wheel pipenv && \
     pipenv install --python 3.7.3 --system
 
-COPY tools/* /var/tools/
+COPY tools /var/tools/
 COPY config/* /var/config/
 
 USER gerrit
 
-ENTRYPOINT ["/var/tools/gerrit_init.py", "-s", "/var/gerrit"]
-CMD ["-c", "/var/config/default.config.yaml"]
+ENTRYPOINT ["python3", "/var/tools/gerrit-initializer"]
+CMD ["-s", "/var/gerrit", "-c", "/var/config/default.config.yaml", "init"]
diff --git a/container-images/gerrit-init/README.md b/container-images/gerrit-init/README.md
index 3f92f43..caeb030 100644
--- a/container-images/gerrit-init/README.md
+++ b/container-images/gerrit-init/README.md
@@ -15,22 +15,14 @@
 
 ## Start
 
-* start the container via start script `/var/tools/gerrit_init.py`
+* start the container via start script `python3 /var/tools/gerrit-initializer init`
 
-The `download_plugins.py`-script
-
-* parses required plugins from config file
-* removes unwanted plugins
-* installs and updates plugins not packaged in Gerrit's war-file
-* plugin files are validated using SHA1
-* plugin files may optionally be cached
-
-The `gerrit_init.py`-script
+The `main.py init`-command
 
 * reads configuration from gerrit.config (via `gerrit_config_parser.py`)
 * initializes Gerrit
 
-The `validate_notedb.py`-script
+The `main.py validate_notedb`-command
 
 * validates and waits for the repository `All-Projects.git` with the refs
 `refs/meta/config`.
diff --git a/container-images/gerrit-init/tools/gerrit-initializer/__main__.py b/container-images/gerrit-init/tools/gerrit-initializer/__main__.py
new file mode 100644
index 0000000..e49cc31
--- /dev/null
+++ b/container-images/gerrit-init/tools/gerrit-initializer/__main__.py
@@ -0,0 +1,18 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from main import main
+
+if __name__ == "__main__":
+    main()
diff --git a/container-images/gerrit-init/tools/gerrit-initializer/initializer/__init__.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/__init__.py
new file mode 100644
index 0000000..2230656
--- /dev/null
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/__init__.py
@@ -0,0 +1,13 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/container-images/gerrit-init/tools/gerrit-initializer/initializer/config/__init__.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/config/__init__.py
new file mode 100644
index 0000000..2230656
--- /dev/null
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/config/__init__.py
@@ -0,0 +1,13 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/container-images/gerrit-init/tools/init_config.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/config/init_config.py
similarity index 100%
rename from container-images/gerrit-init/tools/init_config.py
rename to container-images/gerrit-init/tools/gerrit-initializer/initializer/config/init_config.py
diff --git a/container-images/gerrit-init/tools/gerrit-initializer/initializer/helpers/__init__.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/helpers/__init__.py
new file mode 100644
index 0000000..2230656
--- /dev/null
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/helpers/__init__.py
@@ -0,0 +1,13 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/container-images/gerrit-init/tools/git_config_parser.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/helpers/git.py
similarity index 100%
rename from container-images/gerrit-init/tools/git_config_parser.py
rename to container-images/gerrit-init/tools/gerrit-initializer/initializer/helpers/git.py
diff --git a/container-images/gerrit-init/tools/log.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/helpers/log.py
similarity index 100%
rename from container-images/gerrit-init/tools/log.py
rename to container-images/gerrit-init/tools/gerrit-initializer/initializer/helpers/log.py
diff --git a/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/__init__.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/__init__.py
new file mode 100644
index 0000000..2230656
--- /dev/null
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/__init__.py
@@ -0,0 +1,13 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/container-images/gerrit-init/tools/download_plugins.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/download_plugins.py
similarity index 91%
rename from container-images/gerrit-init/tools/download_plugins.py
rename to container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/download_plugins.py
index 9984dc1..d2c8e16 100755
--- a/container-images/gerrit-init/tools/download_plugins.py
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/download_plugins.py
@@ -14,7 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import argparse
 import hashlib
 import os
 import shutil
@@ -24,10 +23,9 @@
 
 import requests
 
-from init_config import InitConfig
-from log import get_logger
+from ..helpers import log
 
-LOG = get_logger("init")
+LOG = log.get_logger("init")
 MAX_LOCK_LIFETIME = 60
 MAX_CACHED_VERSIONS = 5
 
@@ -239,29 +237,3 @@
         CachedPluginInstaller if config.plugin_cache_enabled else PluginInstaller
     )
     return plugin_installer(site, config)
-
-
-# pylint: disable=C0103
-if __name__ == "__main__":
-    parser = argparse.ArgumentParser()
-    parser.add_argument(
-        "-s",
-        "--site",
-        help="Path to Gerrit site",
-        dest="site",
-        action="store",
-        default="/var/gerrit",
-        required=True,
-    )
-    parser.add_argument(
-        "-c",
-        "--config",
-        help="Path to configuration file for init process.",
-        dest="config",
-        action="store",
-        required=True,
-    )
-    args = parser.parse_args()
-
-    config = InitConfig().parse(args.config)
-    get_installer(args.site, config).execute()
diff --git a/container-images/gerrit-init/tools/gerrit_init.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/init.py
similarity index 81%
rename from container-images/gerrit-init/tools/gerrit_init.py
rename to container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/init.py
index f598d55..367d5fe 100755
--- a/container-images/gerrit-init/tools/gerrit_init.py
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/init.py
@@ -1,5 +1,3 @@
-#!/usr/bin/python3
-
 # Copyright (C) 2018 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,17 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import argparse
 import os
 import subprocess
 import sys
 
-from download_plugins import get_installer
-from git_config_parser import GitConfigParser
-from init_config import InitConfig
-from log import get_logger
+from ..helpers import git, log
+from .download_plugins import get_installer
 
-LOG = get_logger("init")
+LOG = log.get_logger("init")
 
 
 class GerritInit:
@@ -41,7 +36,7 @@
         gerrit_config_path = os.path.join(self.site, "etc/gerrit.config")
 
         if os.path.exists(gerrit_config_path):
-            return GitConfigParser(gerrit_config_path)
+            return git.GitConfigParser(gerrit_config_path)
 
         return None
 
@@ -131,31 +126,3 @@
                 init_process.returncode,
             )
             sys.exit(1)
-
-
-# pylint: disable=C0103
-if __name__ == "__main__":
-    parser = argparse.ArgumentParser()
-    parser.add_argument(
-        "-s",
-        "--site",
-        help="Path to Gerrit site",
-        dest="site",
-        action="store",
-        default="/var/gerrit",
-        required=True,
-    )
-    parser.add_argument(
-        "-c",
-        "--config",
-        help="Path to configuration file for init process.",
-        dest="config",
-        action="store",
-        required=True,
-    )
-    args = parser.parse_args()
-
-    config = InitConfig().parse(args.config)
-
-    init = GerritInit(args.site, config)
-    init.execute()
diff --git a/container-images/gerrit-init/tools/gerrit_reindex.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/reindex.py
similarity index 83%
rename from container-images/gerrit-init/tools/gerrit_reindex.py
rename to container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/reindex.py
index 99ac70d..ac4ae9a 100755
--- a/container-images/gerrit-init/tools/gerrit_reindex.py
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/reindex.py
@@ -15,7 +15,6 @@
 # limitations under the License.
 
 import abc
-import argparse
 import enum
 import os.path
 import subprocess
@@ -23,11 +22,9 @@
 
 import requests
 
-from git_config_parser import GitConfigParser
-from init_config import InitConfig
-from log import get_logger
+from ..helpers import git, log
 
-LOG = get_logger("reindex")
+LOG = log.get_logger("reindex")
 
 
 class IndexType(enum.Enum):
@@ -50,7 +47,7 @@
     def _parse_gerrit_index_config(self):
         indices = dict()
         if os.path.exists(self.index_config_path):
-            config = GitConfigParser(self.index_config_path)
+            config = git.GitConfigParser(self.index_config_path)
             options = config.list()
             for opt in options:
                 name, version = opt["subsection"].rsplit("_", 1)
@@ -138,7 +135,7 @@
 class GerritElasticSearchReindexer(GerritAbstractReindexer):
     def _get_elasticsearch_config(self):
         es_config = dict()
-        gerrit_config = GitConfigParser(
+        gerrit_config = git.GitConfigParser(
             os.path.join(self.gerrit_site_path, "etc", "gerrit.config")
         )
         es_config["prefix"] = gerrit_config.get(
@@ -172,7 +169,7 @@
 
 
 def get_reindexer(gerrit_site_path, config):
-    gerrit_config = GitConfigParser(
+    gerrit_config = git.GitConfigParser(
         os.path.join(gerrit_site_path, "etc", "gerrit.config")
     )
     index_type = gerrit_config.get("index.type", default=IndexType.LUCENE.name)
@@ -184,38 +181,3 @@
         return GerritElasticSearchReindexer(gerrit_site_path, config)
 
     raise RuntimeError("Unknown index type %s." % index_type)
-
-
-# pylint: disable=C0103
-if __name__ == "__main__":
-    parser = argparse.ArgumentParser()
-    parser.add_argument(
-        "-s",
-        "--site",
-        help="Path to Gerrit site",
-        dest="site",
-        action="store",
-        default="/var/gerrit",
-        required=True,
-    )
-    parser.add_argument(
-        "-f",
-        "--force",
-        help="Reindex even if indices are ready.",
-        dest="force",
-        action="store_true",
-    )
-    parser.add_argument(
-        "-c",
-        "--config",
-        help="Path to configuration file for init process.",
-        dest="config",
-        action="store",
-        required=True,
-    )
-    args = parser.parse_args()
-
-    config = InitConfig().parse(args.config)
-
-    reindexer = get_reindexer(args.site, config)
-    reindexer.start(args.force)
diff --git a/container-images/gerrit-init/tools/validate_notedb.py b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/validate_notedb.py
old mode 100755
new mode 100644
similarity index 81%
rename from container-images/gerrit-init/tools/validate_notedb.py
rename to container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/validate_notedb.py
index 1d23474..8601fcb
--- a/container-images/gerrit-init/tools/validate_notedb.py
+++ b/container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/validate_notedb.py
@@ -1,5 +1,4 @@
 #!/usr/bin/python3
-
 # Copyright (C) 2018 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,14 +13,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import argparse
 import os
 import subprocess
 import time
 
-from log import get_logger
+from ..helpers import log
 
-LOG = get_logger("init")
+LOG = log.get_logger("init")
 
 
 class NoteDbValidator:
@@ -61,21 +59,3 @@
                 while not self._test_ref_exists(repo, ref):
                     time.sleep(1)
                 LOG.info("Found ref %s in repo %s.", ref, repo)
-
-
-# pylint: disable=C0103
-if __name__ == "__main__":
-    parser = argparse.ArgumentParser()
-    parser.add_argument(
-        "-s",
-        "--site",
-        help="Path to Gerrit site",
-        dest="site",
-        action="store",
-        default="/var/gerrit",
-        required=True,
-    )
-    args = parser.parse_args()
-
-    init = NoteDbValidator(args.site)
-    init.execute()
diff --git a/container-images/gerrit-init/tools/gerrit-initializer/main.py b/container-images/gerrit-init/tools/gerrit-initializer/main.py
new file mode 100755
index 0000000..b4f6726
--- /dev/null
+++ b/container-images/gerrit-init/tools/gerrit-initializer/main.py
@@ -0,0 +1,93 @@
+#!/usr/bin/python3
+
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import argparse
+
+from initializer.tasks import download_plugins, init, reindex, validate_notedb
+from initializer.config.init_config import InitConfig
+
+
+def _run_download_plugins(args):
+    config = InitConfig().parse(args.config)
+    download_plugins.get_installer(args.site, config).execute()
+
+
+def _run_init(args):
+    config = InitConfig().parse(args.config)
+    init.GerritInit(args.site, config).execute()
+
+
+def _run_reindex(args):
+    config = InitConfig().parse(args.config)
+    reindex.get_reindexer(args.site, config).start(args.force)
+
+
+def _run_validate_notedb(args):
+    validate_notedb.NoteDbValidator(args.site).execute()
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument(
+        "-s",
+        "--site",
+        help="Path to Gerrit site",
+        dest="site",
+        action="store",
+        default="/var/gerrit",
+        required=True,
+    )
+    parser.add_argument(
+        "-c",
+        "--config",
+        help="Path to configuration file for init process.",
+        dest="config",
+        action="store",
+        required=True,
+    )
+
+    subparsers = parser.add_subparsers()
+
+    parser_download_plugins = subparsers.add_parser(
+        "download-plugins", help="Download plugins"
+    )
+    parser_download_plugins.set_defaults(func=_run_download_plugins)
+
+    parser_init = subparsers.add_parser("init", help="Initialize Gerrit site")
+    parser_init.set_defaults(func=_run_init)
+
+    parser_reindex = subparsers.add_parser("reindex", help="Reindex Gerrit indexes")
+    parser_reindex.add_argument(
+        "-f",
+        "--force",
+        help="Reindex even if indices are ready.",
+        dest="force",
+        action="store_true",
+    )
+    parser_reindex.set_defaults(func=_run_reindex)
+
+    parser_validate_notedb = subparsers.add_parser(
+        "validate-notedb", help="Validate NoteDB"
+    )
+    parser_validate_notedb.set_defaults(func=_run_validate_notedb)
+
+    args = parser.parse_args()
+    args.func(args)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/helm-charts/gerrit-replica/templates/gerrit-replica.deployment.yaml b/helm-charts/gerrit-replica/templates/gerrit-replica.deployment.yaml
index 5e4beec..a0ab62d 100644
--- a/helm-charts/gerrit-replica/templates/gerrit-replica.deployment.yaml
+++ b/helm-charts/gerrit-replica/templates/gerrit-replica.deployment.yaml
@@ -84,9 +84,10 @@
         - -ce
         args:
         - |
-          /var/tools/gerrit_init.py \
+          python3 /var/tools/gerrit-initializer \
             -c /var/config/gerrit-init.yaml \
-            -s /var/gerrit
+            -s /var/gerrit \
+            init
 
           # The git repositories and logs will be mounted from a volume
           [ -L /var/gerrit/git ] || rm -rf /var/gerrit/git
@@ -132,7 +133,10 @@
             ln -sf /var/mnt/logs /var/gerrit/
           fi
 
-          /var/tools/validate_notedb.py -s /var/gerrit
+          python3 /var/tools/gerrit-initializer \
+            -c /var/config/gerrit-init.yaml \
+            -s /var/gerrit \
+            validate-notedb
         env:
         - name: POD_NAME
           valueFrom:
diff --git a/helm-charts/gerrit-replica/templates/git-repositories-init.job.yaml b/helm-charts/gerrit-replica/templates/git-repositories-init.job.yaml
index 48ace53..e8ed20b 100644
--- a/helm-charts/gerrit-replica/templates/git-repositories-init.job.yaml
+++ b/helm-charts/gerrit-replica/templates/git-repositories-init.job.yaml
@@ -64,9 +64,10 @@
           ln -sf /var/config/gerrit.config /var/gerrit/etc/gerrit.config
           ln -sf /var/mnt/git /var/gerrit/
 
-          /var/tools/gerrit_init.py \
+          python3 /var/tools/gerrit-initializer \
             -c /var/config/gerrit-init.yaml \
-            -s /var/gerrit
+            -s /var/gerrit \
+            init
         env:
         - name: POD_NAME
           valueFrom:
diff --git a/helm-charts/gerrit/templates/gerrit.stateful-set.yaml b/helm-charts/gerrit/templates/gerrit.stateful-set.yaml
index 88f8dc7..e22c71b 100644
--- a/helm-charts/gerrit/templates/gerrit.stateful-set.yaml
+++ b/helm-charts/gerrit/templates/gerrit.stateful-set.yaml
@@ -75,9 +75,10 @@
             fi
           done
 
-          /var/tools/gerrit_init.py \
+          python3 /var/tools/gerrit-initializer \
             -c /var/config/gerrit-init.yaml \
-            -s /var/gerrit
+            -s /var/gerrit \
+            init
 
           {{ if .Values.gerrit.service.ssh.enabled -}}
           rm -f /var/gerrit/etc/ssh_host*key*
@@ -91,9 +92,12 @@
 
           # TODO (Thomas): Do not enforce offline-reindexing, when online-reindexing
           # is configured.
-          /var/tools/gerrit_reindex.py $FLAGS \
+          python3 /var/tools/gerrit-initializer \
             -c /var/config/gerrit-init.yaml \
-            -s /var/gerrit
+            -s /var/gerrit \
+            reindex \
+            $FLAGS
+
         volumeMounts:
         - name: gerrit-site
           mountPath: "/var/gerrit"
diff --git a/tests/container-images/gerrit-init/test_container_integration_gerrit_init.py b/tests/container-images/gerrit-init/test_container_integration_gerrit_init.py
index 9de4043..566f8f7 100644
--- a/tests/container-images/gerrit-init/test_container_integration_gerrit_init.py
+++ b/tests/container-images/gerrit-init/test_container_integration_gerrit_init.py
@@ -128,7 +128,7 @@
         )
 
         exit_code, _ = container_run_endless.exec_run(
-            "/var/tools/gerrit_init.py -s /var/gerrit -c /var/config/init.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/init.yaml init"
         )
         assert exit_code == 0
 
@@ -150,7 +150,7 @@
         )
 
         exit_code, _ = container_run_endless.exec_run(
-            "/var/tools/gerrit_init.py -s /var/gerrit -c /var/config/init.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/init.yaml init"
         )
         assert exit_code == 0
 
diff --git a/tests/container-images/gerrit-init/test_container_integration_gerrit_init_reindexing.py b/tests/container-images/gerrit-init/test_container_integration_gerrit_init_reindexing.py
index cc097dd..8f50e50 100644
--- a/tests/container-images/gerrit-init/test_container_integration_gerrit_init_reindexing.py
+++ b/tests/container-images/gerrit-init/test_container_integration_gerrit_init_reindexing.py
@@ -62,7 +62,7 @@
             os.path.join(temp_site, "index", "gerrit_index.config")
         )
         exit_code, _ = container_run_endless.exec_run(
-            "/var/tools/gerrit_init.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml init"
         )
         assert exit_code == 0
         expected_files = ["gerrit_index.config"] + self._get_indices(
@@ -74,7 +74,7 @@
         timestamp_index_dir = os.path.getctime(os.path.join(temp_site, "index"))
 
         exit_code, _ = container_run_endless.exec_run(
-            "/var/tools/gerrit_reindex.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml reindex"
         )
         assert exit_code == 0
         assert timestamp_index_dir == os.path.getctime(os.path.join(temp_site, "index"))
@@ -83,12 +83,12 @@
         self, container_run_endless, temp_site
     ):
         container_run_endless.exec_run(
-            "/var/tools/gerrit_init.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml init"
         )
         os.remove(os.path.join(temp_site, "index", "gerrit_index.config"))
 
         exit_code, _ = container_run_endless.exec_run(
-            "/var/tools/gerrit_reindex.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml reindex"
         )
         assert exit_code == 0
 
@@ -97,7 +97,7 @@
 
     def test_gerrit_init_fixes_unready_indices(self, container_run_endless):
         container_run_endless.exec_run(
-            "/var/tools/gerrit_init.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml init"
         )
 
         indices = self._get_indices(container_run_endless)
@@ -107,7 +107,7 @@
         )
 
         exit_code, _ = container_run_endless.exec_run(
-            "/var/tools/gerrit_reindex.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml reindex"
         )
         assert exit_code == 0
 
@@ -116,7 +116,7 @@
 
     def test_gerrit_init_fixes_outdated_indices(self, container_run_endless, temp_site):
         container_run_endless.exec_run(
-            "/var/tools/gerrit_init.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml init"
         )
 
         index = self._get_indices(container_run_endless)[0]
@@ -129,7 +129,7 @@
         )
 
         exit_code, _ = container_run_endless.exec_run(
-            "/var/tools/gerrit_reindex.py -s /var/gerrit -c /var/config/default.config.yaml"
+            "python3 /var/tools/gerrit-initializer -s /var/gerrit -c /var/config/default.config.yaml reindex"
         )
         assert exit_code == 0
 
diff --git a/tests/container-images/gerrit-init/test_container_structure_gerrit_init.py b/tests/container-images/gerrit-init/test_container_structure_gerrit_init.py
index 1098c82..ab259c9 100755
--- a/tests/container-images/gerrit-init/test_container_structure_gerrit_init.py
+++ b/tests/container-images/gerrit-init/test_container_structure_gerrit_init.py
@@ -27,11 +27,8 @@
 @pytest.fixture(
     scope="function",
     params=[
-        "/var/tools/download_plugins.py",
-        "/var/tools/gerrit_init.py",
-        "/var/tools/gerrit_reindex.py",
-        "/var/tools/git_config_parser.py",
-        "/var/tools/init_config.py",
+        "/var/tools/gerrit-initializer/__main__.py",
+        "/var/tools/gerrit-initializer/main.py",
     ],
 )
 def expected_script(request):
@@ -74,4 +71,4 @@
 def test_gerrit_init_has_entrypoint(gerrit_init_image):
     entrypoint = gerrit_init_image.attrs["ContainerConfig"]["Entrypoint"]
     assert len(entrypoint) >= 1
-    assert entrypoint == ["/var/tools/gerrit_init.py", "-s", "/var/gerrit"]
+    assert entrypoint == ["python3", "/var/tools/gerrit-initializer"]