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

RHOAIENG-17251: add a test for the proxy env configuration in RStudio + some other minor changes #870

Merged
merged 3 commits into from
Jan 28, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import json
import logging
import pathlib
import pytest_subtests
import subprocess
import tempfile
import textwrap
from typing import TYPE_CHECKING
from typing import NamedTuple, TYPE_CHECKING

import allure
import pytest
Expand All @@ -21,7 +22,7 @@
class TestRStudioImage:
"""Tests for RStudio Workbench images in this repository."""

APP_ROOT_HOME = "/opt/app-root/src/"
APP_ROOT_HOME = "/opt/app-root/src"

@allure.issue("RHOAIENG-17256")
def test_rmd_to_pdf_rendering(self, image: str) -> None:
Expand Down Expand Up @@ -99,6 +100,43 @@ def test_rmd_to_pdf_rendering(self, image: str) -> None:
finally:
docker_utils.NotebookContainer(container).stop(timeout=0)

@allure.issue("RHOAIENG-16604")
def test_http_proxy_env_propagates(self, image: str, subtests: pytest_subtests.plugin.SubTests) -> None:
"""
This checks that the lowercased proxy configuration is propagated into the RStudio
environment so that the appropriate values are then accepted and followed.
"""
skip_if_not_rstudio_image(image)

class TestCase(NamedTuple):
name: str
name_lc: str
value: str

test_cases: list[TestCase] = [
TestCase("HTTP_PROXY", "http_proxy", "http://localhost:8080"),
TestCase("HTTPS_PROXY", "https_proxy", "https://localhost:8443"),
TestCase("NO_PROXY", "no_proxy", "google.com"),
]

container = WorkbenchContainer(image=image, user=1000, group_add=[0])
for tc in test_cases:
container.with_env(tc.name, tc.value)

try:
# We need to wait for the IDE to be completely loaded so that the envs are processed properly.
container.start(wait_for_readiness=True)

# Once the RStudio IDE is fully up and running, the processed envs should includ also lowercased proxy configs.
for tc in test_cases:
with subtests.test(tc.name):
output = check_output(
container,
f"/usr/bin/R --quiet --no-echo -e 'Sys.getenv(\"{tc.name_lc}\")'")
assert '"' + tc.value + '"' in output
finally:
docker_utils.NotebookContainer(container).stop(timeout=0)


def check_call(container: WorkbenchContainer, cmd: str) -> int:
"""Like subprocess.check_output, but in a container."""
Expand Down
Loading