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

migrate video_gridUrl.sh to python #2658

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

KyriosGN0
Copy link
Contributor

@KyriosGN0 KyriosGN0 commented Feb 15, 2025

User description

Signed-off-by: AvivGuiser [email protected]

Thanks for contributing to the Docker-Selenium project!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines, applied for this repository.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

rewrite the video_gridUrl bash script in python

Motivation and Context

solves #2650 partially

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Migrated video_gridUrl.sh script from Bash to Python.

  • Updated references in other scripts to use the new Python script.

  • Adjusted Dockerfile to include the new Python script.

  • Removed the old Bash script video_gridUrl.sh.


Changes walkthrough 📝

Relevant files
Enhancement
video.sh
Updated script reference to Python implementation               

Video/video.sh

  • Updated the reference to video_gridUrl.sh to video_gridUrl.py.
  • Ensured compatibility with the new Python script.
  • +1/-1     
    video_graphQLQuery.sh
    Updated GraphQL script to use Python backend                         

    Video/video_graphQLQuery.sh

  • Replaced video_gridUrl.sh with video_gridUrl.py for endpoint
    resolution.
  • Maintained functionality while transitioning to Python.
  • +1/-1     
    video_gridUrl.sh
    Removed Bash implementation of grid URL script                     

    Video/video_gridUrl.sh

  • Removed the Bash implementation of video_gridUrl.sh.
  • Replaced by a Python script for better scalability.
  • +0/-20   
    video_gridUrl.py
    Added Python implementation for grid URL generation           

    Video/video_gridUrl.py

  • Added a Python implementation for generating the grid URL.
  • Replaced Bash logic with Python for better maintainability.
  • Ensured compatibility with existing environment variables.
  • +34/-0   
    Configuration changes
    Dockerfile
    Updated Dockerfile to include Python script                           

    Video/Dockerfile

  • Updated Dockerfile to include the new Python script.
  • Adjusted file copying to account for .py files.
  • +1/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @KyriosGN0 KyriosGN0 marked this pull request as ready for review February 15, 2025 08:29
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    2650 - PR Code Verified

    Compliant requirements:

    • Successfully migrated video_gridUrl.sh to Python
    • Maintained existing functionality in the Python implementation
    • No changes to user-facing features

    Requires further human verification:

    • Verify that all edge cases and functionality are properly handled in the Python script
    • Test the script in different container configurations to ensure compatibility
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The Python script lacks error handling for network issues, invalid environment variables, or malformed URLs

    def get_grid_url():
        max_time = 3
        se_sub_path = os.getenv('SE_SUB_PATH', '')
    
        # If SE_SUB_PATH is "/", set it to empty string
        if se_sub_path == "/":
            se_sub_path = ""
    
        # Start with default grid URL
        grid_url = os.getenv('SE_NODE_GRID_URL', '')
    
        # Check for hub/router configuration
        se_hub_host = os.getenv('SE_HUB_HOST') or os.getenv('SE_ROUTER_HOST')
        se_hub_port = os.getenv('SE_HUB_PORT') or os.getenv('SE_ROUTER_PORT')
    
        if se_hub_host and se_hub_port:
            grid_url = f"{os.getenv('SE_SERVER_PROTOCOL', 'http')}://{se_hub_host}:{se_hub_port}{se_sub_path}"
        # Check for standalone mode
        elif (os.getenv('DISPLAY_CONTAINER_NAME') and
              os.getenv('SE_VIDEO_RECORD_STANDALONE') == 'true'):
            display_container = os.getenv('DISPLAY_CONTAINER_NAME')
            node_port = os.getenv('SE_NODE_PORT', '4444')
            grid_url = f"{os.getenv('SE_SERVER_PROTOCOL', 'http')}://{display_container}:{node_port}{se_sub_path}"
    
        # Remove trailing slash if present
        grid_url = grid_url.rstrip('/')
    
        return grid_url
    Unused Variable

    The max_time variable is defined but never used in the code

    max_time = 3

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add port number validation

    Add error handling for invalid environment variables, particularly for port
    numbers which could be non-numeric and cause runtime errors.

    Video/video_gridUrl.py [19-20]

     if se_hub_host and se_hub_port:
    -    grid_url = f"{os.getenv('SE_SERVER_PROTOCOL', 'http')}://{se_hub_host}:{se_hub_port}{se_sub_path}"
    +    try:
    +        int(se_hub_port)  # Validate port is numeric
    +        grid_url = f"{os.getenv('SE_SERVER_PROTOCOL', 'http')}://{se_hub_host}:{se_hub_port}{se_sub_path}"
    +    except ValueError:
    +        raise ValueError(f"Invalid port number: {se_hub_port}")
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion adds crucial error handling for port validation, preventing potential runtime errors that could occur if environment variables contain non-numeric port values. This is important for system stability and debugging.

    Medium
    General
    Remove unused variable

    The unused max_time variable should be removed as it's not being used anywhere
    in the code.

    Video/video_gridUrl.py [4-6]

     def get_grid_url():
    -    max_time = 3
         se_sub_path = os.getenv('SE_SUB_PATH', '')
    • Apply this suggestion
    Suggestion importance[1-10]: 2

    __

    Why: While technically correct, removing an unused variable is a minor cleanup that doesn't significantly impact functionality. The change is simple and improves code cleanliness but has minimal impact on the system's operation.

    Low

    @KyriosGN0
    Copy link
    Contributor Author

    hey @VietND96 (don't know if it was u who triggered the workflow) is there some way to re-trigger the CI ? the failures don\t seem related to my change....

    @VietND96
    Copy link
    Member

    I guess something is not working correctly. I will check and let you know

    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