Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions diracx-core/src/diracx/core/config/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ class BaseGitConfigSource(ConfigSource):
def __init__(self, *, backend_url: ConfigSourceUrl) -> None:
super().__init__(backend_url=backend_url)
self.remote_url = self.extract_remote_url(backend_url)
self.git_branch = self.get_git_branch_from_url(backend_url)
self.git_revision = self.get_git_revision_from_url(backend_url)

def latest_revision(self) -> tuple[str, datetime]:
try:
rev = sh.git(
"rev-parse",
self.git_branch,
self.git_revision,
_cwd=self.repo_location,
_tty_out=False,
_async=is_running_in_async_context(),
Expand Down Expand Up @@ -228,9 +228,9 @@ def extract_remote_url(self, backend_url: ConfigSourceUrl) -> str:
remote_url = urlunparse(parsed_url._replace(query=""))
return remote_url

def get_git_branch_from_url(self, backend_url: ConfigSourceUrl) -> str:
def get_git_revision_from_url(self, backend_url: ConfigSourceUrl) -> str:
"""Extract the branch from the query parameters."""
return dict(backend_url.query_params()).get("branch", DEFAULT_GIT_BRANCH)
return dict(backend_url.query_params()).get("revision", DEFAULT_GIT_BRANCH)


class LocalGitConfigSource(BaseGitConfigSource):
Expand Down Expand Up @@ -259,7 +259,7 @@ def __init__(self, *, backend_url: ConfigSourceUrl) -> None:
raise ValueError(
f"{self.repo_location} is not a valid git repository"
) from e
sh.git.checkout(self.git_branch, _cwd=self.repo_location, _async=False)
sh.git.checkout(self.git_revision, _cwd=self.repo_location, _async=False)

def __hash__(self):
return hash(self.repo_location)
Expand All @@ -277,9 +277,8 @@ def __init__(self, *, backend_url: ConfigSourceUrl) -> None:

self._temp_dir = TemporaryDirectory()
self.repo_location = Path(self._temp_dir.name)
sh.git.clone(
self.remote_url, self.repo_location, branch=self.git_branch, _async=False
)
sh.git.clone(self.remote_url, self.repo_location, _async=False)
sh.git.checkout(self.git_revision, _cwd=self.repo_location, _async=False)

def __hash__(self):
return hash(self.repo_location)
Expand Down
32 changes: 28 additions & 4 deletions diracx-core/tests/test_config_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

# The diracx-chart contains a CS example
TEST_REPO = "git+https://github.com/DIRACGrid/diracx-charts.git"
TEST_REPO_SPECIFIC_BRANCH = TEST_REPO + "?branch=master"
TEST_REPO_SPECIFIC_BRANCH = TEST_REPO + "?revision=master"
Comment thread
natthan-pigoux marked this conversation as resolved.
COMMIT_HASH = "03c5a890d1af4a0a0fb934acea8f538ba08ec68c"
TEST_REPO_SPECIFIC_COMMIT_HASH = TEST_REPO + f"?revision={COMMIT_HASH}"


def github_is_down():
Expand All @@ -21,18 +23,40 @@ def github_is_down():
return True


@pytest.mark.skipif(github_is_down(), reason="Github unavailble")
@pytest.mark.parametrize("repo_url", [TEST_REPO, TEST_REPO_SPECIFIC_BRANCH])
def test_remote_git_config_source(monkeypatch, repo_url):
def default_remote_conf_assertions(monkeypatch, repo_url):
monkeypatch.setattr(
"diracx.core.config.sources.DEFAULT_CONFIG_FILE",
"k3s/examples/cs.yaml",
)

remote_conf = ConfigSource.create_from_url(backend_url=repo_url)
assert isinstance(remote_conf, RemoteGitConfigSource)

hexsha, modified = remote_conf.latest_revision()
assert isinstance(hexsha, str)

assert isinstance(modified, datetime.datetime)
result = remote_conf.read_raw(hexsha, modified)
assert isinstance(result, Config)

return hexsha


@pytest.mark.skipif(github_is_down(), reason="Github unavailble")
def test_remote_git_config_source_default(monkeypatch):
default_remote_conf_assertions(monkeypatch, TEST_REPO)


@pytest.mark.skipif(github_is_down(), reason="Github unavailble")
def test_remote_git_config_source_branch(monkeypatch):
monkeypatch.setattr(
"diracx.core.config.sources.DEFAULT_GIT_BRANCH",
"non_existing_branch",
)
default_remote_conf_assertions(monkeypatch, TEST_REPO_SPECIFIC_BRANCH)


@pytest.mark.skipif(github_is_down(), reason="Github unavailble")
def test_remote_git_config_source_commit(monkeypatch):
hexsha = default_remote_conf_assertions(monkeypatch, TEST_REPO_SPECIFIC_COMMIT_HASH)
assert hexsha == COMMIT_HASH
7 changes: 7 additions & 0 deletions docs/admin/explanations/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ During this time, the DiracX configuration is not intended to be edited directly
The DiracX `default.yml` file differs in structure and contents from the legacy DIRAC Configuration Service.

See [how-to](../how-to/install/convert-cs.md) for how to convert.

## Using specific remote configuration branch or commit

DiracX uses `master` as default branch for configuration git repository. Using remote git repo, one can use the `revision` url query parameters to specify:

- a branch: `git+https://git.repo.url/my_diracx_cs.git?revision=my_branch`
- a commit hash: `git+https://git.repo.url/my_diracx_cs.git?revision=912e0782e96769fecff3941e56fbeeb5`
Loading