From 9625b0d9c9140a2de92da826c1193b25613cf0b6 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Fri, 21 Jul 2023 10:06:22 +0100 Subject: [PATCH] add some documentation to run tests --- .github/workflows/integration_test.yaml | 11 +++++----- tests_integration/README.md | 26 ++++++++++++++++++++++++ tests_integration/deployment_fixtures.py | 23 ++++++++++++--------- 3 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 tests_integration/README.md diff --git a/.github/workflows/integration_test.yaml b/.github/workflows/integration_test.yaml index 89a5a726af..5dc954995f 100644 --- a/.github/workflows/integration_test.yaml +++ b/.github/workflows/integration_test.yaml @@ -1,7 +1,10 @@ -name: "Integration Tests" +name: "Deploy on Digital Ocean" on: - pull_request: + schedule: + - cron: "0 0 * * MON" + workflow_dispatch: + # DISABLE push before merge push: jobs: @@ -21,13 +24,11 @@ jobs: run: | pip install .[dev] conda install --quiet --yes conda-build - - name: Debugging with tmate - uses: mxschmitt/action-tmate@v3.16 - name: Integration Tests run: | pytest --version - pytest tests_integration/ -vvv + pytest tests_integration/ -vvv -s env: NEBARI_K8S_VERSION: 1.24.13-do.0 DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} diff --git a/tests_integration/README.md b/tests_integration/README.md new file mode 100644 index 0000000000..6735ae4eaa --- /dev/null +++ b/tests_integration/README.md @@ -0,0 +1,26 @@ +# Integration Testing via Pytest + +These tests are designed to test things on Nebari deployed +on cloud. At the moment it only deploys on DigitalOcean. + +You need the following environment variables to run these. + +```bash +DIGITALOCEAN_TOKEN +NEBARI_K8S_VERSION +SPACES_ACCESS_KEY_ID +SPACES_SECRET_ACCESS_KEY +CLOUDFLARE_TOKEN +``` + +For instructions on how to get these variables check the documentation +for DigitalOcean deployment. + +Running Tests: + +```bash +pytest tests_integration -vvv -s +``` + +This would deploy on digitalocean, run tests on the deployment +and then teardown the cluster. diff --git a/tests_integration/deployment_fixtures.py b/tests_integration/deployment_fixtures.py index 18da6a1f18..28a1f9124a 100644 --- a/tests_integration/deployment_fixtures.py +++ b/tests_integration/deployment_fixtures.py @@ -28,33 +28,37 @@ def ignore_warnings(): warnings.filterwarnings("ignore", category=InsecureRequestWarning) -def random_letters(length=5): +def _random_letters(length=5): letters = string.ascii_letters return ''.join(random.choice(letters) for _ in range(length)).lower() -def get_or_create_deployment_directory(cloud): +def _get_or_create_deployment_directory(cloud): + """This will create a directory to initialise and deploy + Nebari from. + """ deployment_dirs = list(Path(Path(DEPLOYMENT_DIR) / cloud).glob(f"pytest{cloud}*")) if deployment_dirs: deployment_dir = deployment_dirs[0] else: - project_name = f"pytest{cloud}{random_letters()}" + project_name = f"pytest{cloud}{_random_letters()}" deployment_dir = Path(Path(Path(DEPLOYMENT_DIR) / cloud) / project_name) deployment_dir.mkdir(parents=True) return deployment_dir -def set_do_environment(): +def _set_do_environment(): os.environ['AWS_ACCESS_KEY_ID'] = os.environ['SPACES_ACCESS_KEY_ID'] os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ['SPACES_SECRET_ACCESS_KEY'] @pytest.fixture(scope="session") def deploy(request): + """Deploy Nebari on the given cloud, currently only DigitalOcean""" ignore_warnings() cloud = request.param - set_do_environment() - deployment_dir = get_or_create_deployment_directory(cloud) + _set_do_environment() + deployment_dir = _get_or_create_deployment_directory(cloud) config = render_config_partial( project_name=deployment_dir.name, namespace="dev", @@ -81,12 +85,11 @@ def deploy(request): except Exception as e: logger.info(f"Deploy Failed, Exception: {e}") logger.exception(e) - raise - logger.info("Teardown") - return destroy(config) + logger.info("Tearing down") + return _destroy(config) -def destroy(config): +def _destroy(config): destroy_configuration(config)