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

Conversation

jstourac
Copy link
Member

Description

https://issues.redhat.com/browse/RHOAIENG-17251

How Has This Been Tested?

DOCKER_HOST=unix:///run/user/$UID/podman/podman.sock poetry run pytest tests/containers --image quay.io/opendatahub/workbench-images@sha256:e98d19df346e7abb1fa3053f6d41f0d1fa9bab39e49b4cb90b510ca33452c2e4

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

This is to follow the proper filename convention so that the pytest will
be able to find the tests in this file accordingly.
@jstourac jstourac self-assigned this Jan 28, 2025
@openshift-ci openshift-ci bot requested review from caponetto and harshad16 January 28, 2025 10:32
@openshift-ci openshift-ci bot added the size/m label Jan 28, 2025
@jiridanek
Copy link
Member

lgtm, just

here's what I'd do in addition

i'm a big fan of table driven tests (https://dave.cheney.net/2019/05/07/prefer-table-driven-tests#Introducing-table-driven-tests), so

    @allure.issue("RHOAIENG-16604")
    def test_http_proxy_env_propagates(self, subtests, image: str) -> 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 include 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)

one advantage of subtest is that when variable is missing, it will also check all the other variables before failing the test

it also makes things simpler if there's additional variable to be checked, just add it to the test_cases table

@jiridanek
Copy link
Member

/lgtm
in case you discover you aren't fan of table driven tests ;p

@jstourac
Copy link
Member Author

@jiridanek thanks for your review - I updated based on your comment. Please, check again.

Comment on lines 191 to 195
class TestCase():
def __init__(self, name, name_lc, value):
self.name = name
self.name_lc = name_lc
self.value = value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd nest this under def test_, because this only applies for that one test and no other

and using NamedTuple, or @dataclass is better here, imo; avoids having to repeat the field names twice

compared do my version, you dropped the :str type annotations ;p

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, updated

Includes a simple test to check that the variables are propagated
properly so that the proxy configuration can work in RStudio IDE as
expected.

* https://issues.redhat.com/browse/RHOAIENG-17251
Let's not use trailing slash for the directory. When this variable is
used and some value should be append to it, it should be done always as:
`APP_ROOT_HOME/some-path`. So the forward slash is added there and we
avoid having double slash in our outputs that may be misleading (e.g.
empty variable value in the path).
@jiridanek
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jan 28, 2025
@jstourac
Copy link
Member Author

Thank you for your review and tips, @jiridanek !

/approve

Copy link
Contributor

openshift-ci bot commented Jan 28, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jstourac

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jstourac
Copy link
Member Author

/override ci/prow/images

Copy link
Contributor

openshift-ci bot commented Jan 28, 2025

@jstourac: Overrode contexts on behalf of jstourac: ci/prow/images

In response to this:

/override ci/prow/images

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-merge-bot openshift-merge-bot bot merged commit 84de282 into opendatahub-io:main Jan 28, 2025
7 checks passed
@jstourac jstourac deleted the testProxy branch January 28, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants