Use central gerrit container factory for gerrit-master tests

The gerrit-master integration tests were configuring and starting
a gerrit-container using its own fixtures.

With this change the gerrit-master-integration tests use the factory
provided by tests/container-images/conftest.py to create a Gerrit
container. The factory-implementation reduces the code duplication,
since several gerrit container runs are needed with slightly different
configuration, which caused boiler-plate code in all test modules
requiring a gerrit-container.

Change-Id: Ic0c379633f30d01cb14ad9f1d6ee87a0971e16e8
diff --git a/tests/container-images/gerrit-master/test_container_integration_gerrit_master.py b/tests/container-images/gerrit-master/test_container_integration_gerrit_master.py
index 30d965b..025d18a 100644
--- a/tests/container-images/gerrit-master/test_container_integration_gerrit_master.py
+++ b/tests/container-images/gerrit-master/test_container_integration_gerrit_master.py
@@ -14,25 +14,28 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import os.path
 import re
 import time
 
 import pytest
 import requests
 
-CONFIG_FILES = ["gerrit.config", "secure.config", "replication.config"]
-
 
 @pytest.fixture(scope="module")
-def config_files(tmp_path_factory):
-    tmp_config_dir = tmp_path_factory.mktemp("gerrit_master_config")
-    configs = {}
-    for config in CONFIG_FILES:
-        gerrit_config_file = os.path.join(tmp_config_dir, config)
-        with open(gerrit_config_file, "w") as config_file:
-            config_file.write(
-                """
+def tmp_dir(tmp_path_factory):
+    return tmp_path_factory.mktemp("gerrit-master-test")
+
+
+@pytest.fixture(scope="class")
+def container_run(
+    docker_client,
+    docker_network,
+    tmp_dir,
+    gerrit_master_image,
+    gerrit_container_factory,
+):
+    configs = {
+        "gerrit.config": """
       [gerrit]
         basePath = git
 
@@ -41,36 +44,27 @@
 
       [test]
         success = True
-      """
-            )
-        configs[config] = gerrit_config_file
-
-    return configs
-
-
-@pytest.fixture(scope="module")
-def container_run(request, docker_client, gerrit_master_image, config_files):
-    container_run = docker_client.containers.run(
-        image=gerrit_master_image.id,
-        user="gerrit",
-        volumes={
-            v: {"bind": "/var/config/%s" % k, "mode": "rw"}
-            for (k, v) in config_files.items()
-        },
-        ports={"8081": "8081"},
-        detach=True,
-        auto_remove=True,
+      """,
+        "secure.config": """
+      [test]
+        success = True
+      """,
+        "replication.config": """
+      [test]
+        success = True
+      """,
+    }
+    test_setup = gerrit_container_factory(
+        docker_client, docker_network, tmp_dir, gerrit_master_image, configs, 8081
     )
+    test_setup.start()
 
-    def stop_container():
-        container_run.stop(timeout=1)
+    yield test_setup.gerrit_container
 
-    request.addfinalizer(stop_container)
-
-    return container_run
+    test_setup.stop()
 
 
-@pytest.fixture(params=CONFIG_FILES)
+@pytest.fixture(params=["gerrit.config", "secure.config", "replication.config"])
 def config_file_to_test(request):
     return request.param