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

E2E Tests version 1.0 #731

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

iwphonedo
Copy link

This comprehensive commit includes major improvements and enhancements to the OPAL development environment, focusing on debugging, authorization, containerized testing, and project structure optimization. Key highlights include:
1. OPAL Development Enhancements: • Introduced remote debugging capabilities using debugpy and enhanced logging across various components. • Improved OPAL server and client configuration with better container integration and dynamic port management. • Enabled Gitea for local policy management, replacing GitHub for enhanced control and security in testing environments.
2. Refactoring and Streamlining: • Refactored the codebase to improve readability, remove deprecated files, and enhance test fixtures. • Reorganized project structure and consolidated environment setup for consistency. • Simplified session and container management for test execution using pytest and testcontainers.
3. Testing and Configuration Improvements: • Enhanced test automation with new fixtures, logging updates, and RBAC policy improvements. • Improved Docker image handling, session matrix parameterization, and environment variable management for better efficiency and clarity. • Added global exception handling to improve error reporting during tests.
4. Documentation and Cleanup: • Updated README documentation to reflect changes in test organization and container setup. • Removed unused files and components to streamline the project structure.

Fixes Issue

Changes proposed

Check List (Check all the applicable boxes)

  • I sign off on contributing this submission to open-source
  • My code follows the code style of this project.
  • My change requires changes to the documentation.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • This PR does not contain plagiarized content.
  • The title of my pull request is a short description of the requested changes.

Screenshots

Note to reviewers

This comprehensive commit includes major improvements and enhancements to the OPAL development environment, focusing on debugging, authorization, containerized testing, and project structure optimization. Key highlights include:
	1.	OPAL Development Enhancements:
	•	Introduced remote debugging capabilities using debugpy and enhanced logging across various components.
	•	Improved OPAL server and client configuration with better container integration and dynamic port management.
	•	Enabled Gitea for local policy management, replacing GitHub for enhanced control and security in testing environments.
	2.	Refactoring and Streamlining:
	•	Refactored the codebase to improve readability, remove deprecated files, and enhance test fixtures.
	•	Reorganized project structure and consolidated environment setup for consistency.
	•	Simplified session and container management for test execution using pytest and testcontainers.
	3.	Testing and Configuration Improvements:
	•	Enhanced test automation with new fixtures, logging updates, and RBAC policy improvements.
	•	Improved Docker image handling, session matrix parameterization, and environment variable management for better efficiency and clarity.
	•	Added global exception handling to improve error reporting during tests.
	4.	Documentation and Cleanup:
	•	Updated README documentation to reflect changes in test organization and container setup.
	•	Removed unused files and components to streamline the project structure.
@iwphonedo iwphonedo marked this pull request as ready for review January 7, 2025 18:33
Copy link

netlify bot commented Jan 7, 2025

Deploy Preview for opal-docs canceled.

Name Link
🔨 Latest commit 59b3404
🔍 Latest deploy log https://app.netlify.com/sites/opal-docs/deploys/677ee1ee6e573e0008ed6af7

packages/opal-client/opal_client/main.py Outdated Show resolved Hide resolved
packages/opal-client/requires.txt Outdated Show resolved Hide resolved
@@ -86,6 +87,8 @@ async def get_data_sources_config(authorization: Optional[str] = Header(None)):
token = get_token_from_header(authorization)
if data_sources_config.config is not None:
logger.info("Serving source configuration")
logger.info("Source config: {config}", config=data_sources_config.config)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this intentional?

Copy link
Author

Choose a reason for hiding this comment

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

@danyi1212 Can be removed. If needed will be submitted on its own PR.

@@ -1,3 +1,9 @@

import debugpy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this intentional?

Copy link
Author

Choose a reason for hiding this comment

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

Supported now in the dockerfile for local debugging

tests/README.md Outdated
Comment on lines 1 to 3
Got it! If you'd like, I can incorporate code snippets or provide clarifications. Just let me know what specific details or examples you'd like me to include. Here's the README file in Markdown format:

---
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like an incorrect copy-paste from ChatGPT 🙂

Suggested change
Got it! If you'd like, I can incorporate code snippets or provide clarifications. Just let me know what specific details or examples you'd like me to include. Here's the README file in Markdown format:
---

from testcontainers.core.utils import setup_logger


class PostgresBroadcastSettings:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like the settings being decoupled from the container class itself, it's harder to navigate and read.
I would recommend moving the settings to right before the container implementation, same with any other settings implementation.
Also, I think Config is a better term in this context, but I agree with either :)

@@ -0,0 +1,17 @@
FROM permitio/opal-client:latest
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be using a locally built image from the current source code, rather than loading a pre-built image from Docker Hub / Desktop (applied for all Dockerfiles here)

Copy link
Author

Choose a reason for hiding this comment

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

@danyi1212 this and Dockerfile.server are just to support debugging of the opal image. but aren't based on the local code. The local version is in .local dockers. if you think this is not necessary, let me know and I will remove these 2 dockerfiles.

unless an exception is raised during teardown.
"""
try:
with PostgresBroadcastContainer(
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a lot of configurations that may need to be set for each of those objects. Putting them inside fixture might be easy to write, but it hides the complexities inside deep, hard to follow fixtures.

Configuring the containers for each test case will require setting multiple fixtures or global variables (or even environment variables) making it very hard to follow and requires a lot of back and forth to the docs to understand or to write.

I would instead use the containers directly inside the tests logs, making it possible to pass any required configurations directly to the container init. For example, a test setup that requires an OPAL Server, 2 OPAL Clients, Gitea as Policy Store and a Postrges as Broadcaster might look like:

postgres_broadcaster = PostgresContainer()
gitea_store = GiteaContainer()
opal_server = OpalServerContainer(broadcaster=postgres_broadcaster, policy_store=gitea_store)
opal_client_1 = OpalClientContainer(server_url=server.url)
opal_client_2 = OpalClientContainer(server_url=server.url)

with (postgres_broadcaster, opal_sever, opal_client_1, opal_client_2):
    # Test logic here...

Copy link
Author

Choose a reason for hiding this comment

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

You are correct about the need for multiple fixtures, but this is what they are designed for. Putting the setup code inside the test, will prevent us from running sets of tests cases on different setups. So if you want to test scenario1 through N on different setups, you would extract the setup to an outside function and pass it to the tests, that's we do here.

But, in order to somewhat simplify the complexity of the fixtures we added the session_matrix class. It allows to create matrix of setups and then run sets of tests on that setup.

from tests.containers.settings.opal_client_settings import OpalClientSettings


class OpalClientContainer(PermitContainer, DockerContainer):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using multiple inheritance and initializing both parents inside the __init__ is a very complex Python setup that is hard to understand.
I understand it is used for "mixin"-like inheritance, but it would be simpler to have a single base class inherit from DockerContainer then have everything inherited from it

Copy link
Author

Choose a reason for hiding this comment

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

I was looking for mixin, because inheritanc won't work as some containers are already inheriting from DockerContainer. E.g. RedisContainer, PostgresContainer, NginxContainer, KafkaContainer. So mixin was the only sort of OOP approach.


def getEnvVars(self):
env_vars = {
"OPAL_SERVER_URL": self.opal_server_url,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could have used pydantic-settings for this.

Saying that, I don't think we need to be able to configure every little configuration for the tests from environment variables. This would probably just break tests, as they need very specific intentional configurations for each service container.

I would use plain PyDantic models or dataclasses for any complex configurations needed to be passed to Container instances on initiation for autocomplete and self-documenting, easy to read code.

@@ -57,8 +57,13 @@ def build_docker_image(docker_file: str, image_name: str, session_matrix: dict):
image = docker_client.images.get(image_name)

if not image:
# context_path=os.path.join(os.path.dirname(__file__), ".."), # Expands the context
context_path = ".."
if "tests" in os.path.abspath(__file__):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to use pathlib instead, as its clearer and more modern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants