Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: small fix for dev docker #1786

Merged
merged 14 commits into from
Dec 27, 2023
12 changes: 6 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/ubuntu/.devcontainer/base.Dockerfile
# See here for image contents: https://github.com/devcontainers/images/blob/main/src/base-ubuntu/.devcontainer/Dockerfile

# [Choice] Ubuntu version (use hirsuite or bionic on local arm64/Apple Silicon): hirsute, focal, bionic
ARG VARIANT="hirsute"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
# [Choice] Ubuntu version: https://github.com/devcontainers/images/tree/main/src/base-ubuntu
ARG VARIANT="ubuntu-22.04"
FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends \
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends libkrb5-dev
9 changes: 3 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/ubuntu
// https://mcr.microsoft.com/en-us/product/devcontainers/base/about
{
"name": "Ubuntu",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Ubuntu version: hirsute, focal, bionic
// Use hirsute or bionic on local arm64/Apple Silicon.
// Update 'VARIANT' to pick an Ubuntu version
"args": {
"VARIANT": "focal"
"VARIANT": "ubuntu-22.04"
}
},
// Set *default* container specific settings.json values on container create.
Expand All @@ -30,7 +29,6 @@
"color": "#ff000065"
},
],

"python.defaultInterpreterPath": "/usr/local/python/bin/python",
"mypy-type-checker.args": [
// "--follow-imports=silent",
Expand Down Expand Up @@ -84,7 +82,6 @@
],
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
// The jira server instance we run via docker is exposed on:
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ else
fi

# Install package in editable mode with test dependencies
pip install -e .[test]
pip install -e .[cli,opt,test]
29 changes: 23 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import re
import string
import sys
import time
import unittest
import weakref
from time import sleep
from typing import Any

Expand Down Expand Up @@ -71,6 +73,12 @@ def setUp(self) -> None:
self.user_normal = self.test_manager.user_normal # use this user where possible
self.project_b = self.test_manager.project_b
self.project_a = self.test_manager.project_a
weakref.finalize(
self,
self._cleanup,
test_manager=self.test_manager,
projects=[self.project_a, self.project_b],
)

@property
def identifying_user_property(self) -> str:
Expand All @@ -82,6 +90,14 @@ def is_jira_cloud_ci(self) -> bool:
"""is running on Jira Cloud"""
return self.test_manager._cloud_ci

def _cleanup(self, test_manager: JiraTestManager, projects: list[str]) -> None:
"""This is called when the object is set to be garbage collected."""
for proj in projects:
try:
test_manager._remove_project(proj)
except Exception:
LOGGER.exception(f"Failed to remove project {proj}")


def rndstr():
return "".join(random.sample(string.ascii_lowercase, 6))
Expand All @@ -99,19 +115,19 @@ def rndpassword():


def hashify(some_string, max_len=8):
return hashlib.sha256(some_string.encode("utf-8")).hexdigest()[:8].upper()
return hashlib.sha256(some_string.encode("utf-8")).hexdigest()[:max_len].upper()


def get_unique_project_name():
user = re.sub("[^A-Z_]", "", getpass.getuser().upper())
if "GITHUB_ACTION" in os.environ and "GITHUB_RUN_NUMBER" in os.environ:
run_number = os.environ["GITHUB_RUN_NUMBER"]
# please note that user underline (_) is not supported by
# Jira even if it is documented as supported.
return "GH" + hashify(user + os.environ["GITHUB_RUN_NUMBER"])
identifier = (
user + chr(ord("A") + sys.version_info[0]) + chr(ord("A") + sys.version_info[1])
)
return "Z" + hashify(identifier)
return f"CI{hashify(f'{user}{run_number}',max_len=7)}"
sep = chr(ord("A"))
identifier = f"{user}{sep}{sys.version_info[0]}{sep}{sys.version_info[1]}"
return f"Z{hashify(identifier)}"


class JiraTestManager:
Expand Down Expand Up @@ -259,6 +275,7 @@ def _create_project(
except JIRAError as e:
if "A project with that name already exists" not in str(e):
raise e
time.sleep(1)
return self.jira_admin.project(project_key).id

def create_some_data(self):
Expand Down
20 changes: 7 additions & 13 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,9 @@ def cl_normal(test_manager: JiraTestManager) -> jira.client.JIRA:


@pytest.fixture(scope="function")
def slug(request, cl_admin):
def slug(request: pytest.FixtureRequest, cl_admin: jira.client.JIRA):
"""Project slug."""

def remove_by_slug():
try:
cl_admin.delete_project(slug)
except (ValueError, JIRAError):
# Some tests have project already removed, so we stay silent
pass

slug = get_unique_project_name()

project_name = f"Test user={getpass.getuser()} key={slug} A"

try:
Expand All @@ -52,9 +43,12 @@ def remove_by_slug():
proj = cl_admin.create_project(slug, project_name)
assert proj

request.addfinalizer(remove_by_slug)

return slug
yield slug
try:
cl_admin.delete_project(slug, enable_undo=False)
except (ValueError, JIRAError):
# Some tests have project already removed, so we stay silent
pass


def test_delete_project(cl_admin, cl_normal, slug):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ passenv =
REQUESTS_CA_BUNDLE
SSL_CERT_FILE
TWINE_*
GITHUB_*
XDG_CACHE_HOME
# For Windows users, getpass.get_user() needs USERNAME
USERNAME
Expand Down