Skip to content

Conversation

adrianlasota
Copy link
Contributor

This pull request introduces a new remote shell (RShell) connection feature, enabling remote command execution via HTTP between a Python client (including UEFI shell support) and a Flask-based server. The implementation includes the RShell connection class, a sample client, and a server for managing command queues and results.

RShell Connection Implementation

  • Added the RShellConnection class to mfd_connect/rshell.py, providing methods to start/connect to the RShell server, execute commands remotely, and manage connection lifecycle. This class includes extensive logging and supports command execution via HTTP requests.

Sample Client and Server

  • Introduced mfd_connect/rshell_client.py, a sample HTTP client designed to run on UEFI shell, which polls for commands, executes them locally, and posts results back to the server. It includes compatibility handling for UEFI shell's limitations.
  • Added mfd_connect/rshell_server.py, a Flask REST server that manages command queues for each client, provides health checks, serves commands for execution, and collects results. The server supports multiple clients and tracks command status.

Usage Example

  • Included examples/rshell_example.py demonstrating how to use the new RShellConnection class to connect to a remote RShell server, execute a command, and disconnect.

@mfd-intel-bot
Copy link

We don't publish DEVs .whl.
To build .whl, run 'pip install git+https://github.com/intel/mfd-connect@MFD-7178'

1 similar comment
@mfd-intel-bot
Copy link

We don't publish DEVs .whl.
To build .whl, run 'pip install git+https://github.com/intel/mfd-connect@MFD-7178'

@mfd-intel-bot
Copy link

We don't publish DEVs .whl.
To build .whl, run 'pip install git+https://github.com/intel/mfd-connect@MFD-7178'

1 similar comment
@mfd-intel-bot
Copy link

We don't publish DEVs .whl.
To build .whl, run 'pip install git+https://github.com/intel/mfd-connect@MFD-7178'

@adrianlasota adrianlasota requested a review from Copilot September 3, 2025 07:51
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a remote shell (RShell) capability that enables HTTP-based command execution between a Python client and Flask server, with specific support for UEFI shell environments.

Key changes:

  • Added RShellConnection class for managing remote command execution via HTTP
  • Implemented Flask-based server for handling command queues and client connections
  • Created UEFI-compatible HTTP client with specialized handling for UEFI shell limitations

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.

File Description
mfd_connect/rshell_server.py Flask REST server managing command queues, health checks, and result collection
mfd_connect/rshell_client.py HTTP client designed for UEFI shell with polling and command execution capabilities
mfd_connect/rshell.py RShellConnection class providing remote command execution interface
examples/rshell_example.py Usage example demonstrating RShellConnection functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

def get_command_to_execute():
"""Get the next command to execute for the connected client."""
ip_address = str(request.remote_addr)
global client_connected
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The variable client_connected is referenced but never defined. This will cause a NameError at runtime.

Suggested change
global client_connected
# global client_connected # Removed: not defined or used

Copilot uses AI. Check for mistakes.

Comment on lines +73 to +74
print(f"Client connected: {ip_address}")
clients.append(ip_address)
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The client IP address is always appended to the clients list, even if it already exists. This will create duplicate entries. The append should be inside the if block.

Suggested change
print(f"Client connected: {ip_address}")
clients.append(ip_address)
clients.append(ip_address)

Copilot uses AI. Check for mistakes.

except Exception as exp:
conn.request(
"POST",
str("Exception"),
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The URL path should be '/post_result' instead of 'Exception' to match the server endpoint.

Suggested change
str("Exception"),
"post_result",

Copilot uses AI. Check for mistakes.

Comment on lines +134 to +138
if env is not None:
logger.log(
level=log_levels.MODULE_DEBUG,
msg="Environment variables are not supported for RShellConnection and will be ignored.",
)
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

This check for env is not None is duplicated. The second occurrence (lines 134-138) should be removed as it's identical to lines 128-132.

Suggested change
if env is not None:
logger.log(
level=log_levels.MODULE_DEBUG,
msg="Environment variables are not supported for RShellConnection and will be ignored.",
)

Copilot uses AI. Check for mistakes.

msg="Skipping logging is not supported for RShellConnection and will be ignored.",
)

if expected_return_codes is not None:
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The parameter expected_return_codes uses ellipsis (...) as default value but is checked against None. This will always be False since ellipsis is not None.

Copilot uses AI. Check for mistakes.

Comment on lines +181 to +182
timeout_string = " " if timeout is None else f" with timeout {timeout} seconds"
logger.log(level=log_levels.CMD, msg=f"Executing >{self._ip}> '{command}', {timeout_string}")
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The log message formatting is incorrect. It should be f\"Executing >{self._ip}> '{command}'{timeout_string}\" to properly concatenate the timeout information.

Suggested change
timeout_string = " " if timeout is None else f" with timeout {timeout} seconds"
logger.log(level=log_levels.CMD, msg=f"Executing >{self._ip}> '{command}', {timeout_string}")
logger.log(level=log_levels.CMD, msg=f"Executing >{self._ip}> '{command}'{timeout_string}")

Copilot uses AI. Check for mistakes.

@mfd-intel-bot
Copy link

We don't publish DEVs .whl.
To build .whl, run 'pip install git+https://github.com/intel/mfd-connect@MFD-7178'

1 similar comment
@mfd-intel-bot
Copy link

We don't publish DEVs .whl.
To build .whl, run 'pip install git+https://github.com/intel/mfd-connect@MFD-7178'

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