Commit f53643f6 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Making project names single usage

The various problems with teardown of projects, that can't always
be fixed remotely, have been a pain for a long time.

They are worse in constrained environments, as in CI contexts and
are always a pain point while bumping upstream GitLab versions,
because we always have to pay the price to make project deletion
work first.

By doing this, we lose the ability to easily find the current test
project in logs etc, but it's comparatively acceptable
parent 82f67c127a58
......@@ -2,6 +2,7 @@
import contextlib
import logging
import pytest
import time
from tests.utils.project import Project
from tests.utils.heptapod import (
......@@ -101,7 +102,8 @@ def heptapod(pytestconfig):
@contextlib.contextmanager
def project_fixture(heptapod, name, owner, group=None):
def project_fixture(heptapod, name_prefix, owner, group=None):
name = '%s_%s' % (name_prefix, str(time.time()).replace('.', '_'))
proj = None
try:
proj = Project.api_create(heptapod, owner, name, group=group)
......
......@@ -121,7 +121,7 @@ def test_push_hook_env(test_project, tmpdir, push_proto):
expected_env = [('HEPTAPOD_PROJECT_ID', str(test_project.id)),
('HEPTAPOD_PROJECT_NAMESPACE_FULL_PATH', 'root'),
('HEPTAPOD_PROJECT_PATH', 'test_project'),
('HEPTAPOD_PROJECT_PATH', test_project.name),
('HEPTAPOD_USERINFO_EMAIL', 'admin@example.com'),
# root id, good enough for now:
('HEPTAPOD_USERINFO_ID', '1'),
......
......@@ -4,6 +4,7 @@ import os
import py
import re
import requests
import subprocess
import time
from urllib.parse import urlencode
......@@ -343,10 +344,10 @@ class Project(object):
This should be used right after the project creation.
:param tarball_path: path (relative to DATA_DIR) to an uncompressed tar
archive, containing the Mercurial and Git repos, assumed to have
the correct directory names, according to self.name, with all
archive, containing `test_project.hg` and `test_project.git` (these
will be renamed to according to :attr:`name`, with all
references to each other (mirror-path or whatever is current)
being consistent.
being consistent enough.
"""
if not self.heptapod.fs_access:
raise NotImplementedError(
......@@ -359,17 +360,29 @@ class Project(object):
# does just fail, with an error about the Git repo existence.
tmpdir = py.path.local.mkdtemp()
try:
LocalRepo.clone(self.owner_basic_auth_url, tmpdir)
LocalRepo.clone(self.owner_basic_auth_url, tmpdir.join('clone'))
tartmp = tmpdir.join('tar').ensure(dir=True)
subprocess.check_call(('tar', 'xf', tarball_path),
cwd=str(tartmp))
for ext in ('.hg', '.git'):
tartmp.join('test_project' + ext).rename(
tartmp.join(self.name + ext))
prepared_tarball_path = tmpdir.join('repos.tar')
subprocess.check_call(
('tar', 'cf', str(prepared_tarball_path), '.'),
cwd=str(tartmp))
heptapod = self.heptapod
group_path = '/'.join((heptapod.repositories_root,
self.group.full_path))
heptapod.run_shell(['rm', '-rf', self.fs_path])
heptapod.run_shell(['rm', '-rf', self.fs_common_path + '.git'])
heptapod.put_archive(group_path, prepared_tarball_path)
finally:
tmpdir.remove()
heptapod = self.heptapod
group_path = '/'.join((heptapod.repositories_root,
self.group.full_path))
heptapod.run_shell(['rm', '-rf', self.fs_path])
heptapod.run_shell(['rm', '-rf', self.fs_common_path + '.git'])
heptapod.put_archive(group_path, tarball_path)
def get_hgrc(self, managed=False):
"""Return repo's server-side HGRC, as lines, uid and gid
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment