Skip to content

Conversation

@zghp
Copy link
Contributor

@zghp zghp commented Nov 11, 2025

No description provided.

@zghp zghp requested a review from a team as a code owner November 11, 2025 10:14
Copilot AI review requested due to automatic review settings November 11, 2025 10:14
@github-actions
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


zghp seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link

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 adds support for loading slot configuration from external YAML or JSON files when adding slots to the allocator server.

  • Added a new optional --config argument to the add-slot command that accepts a file path
  • Implemented logic to parse YAML and JSON configuration files and include them in the slot creation payload
  • Removed an unnecessary blank line for code formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


configuration = None
if config:
import json, yaml
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

The yaml module is already imported at the top of the file (line 8), so it doesn't need to be imported again here. Only json needs to be imported locally. Consider moving the json import to the top of the file with other imports, or change this line to import json only.

Copilot uses AI. Check for mistakes.

if configuration:
payload['configuration'] = configuration

Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

Trailing whitespace detected. Please remove the trailing spaces at the end of this line.

Suggested change

Copilot uses AI. Check for mistakes.
Add a new slot to the allocator server.
Args:
args (list): Command-line arguments.
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

The docstring is outdated. It states "Args: args (list): Command-line arguments" but the function signature shows multiple specific parameters. Please update the docstring to document all parameters: server, rack_name, slot_name, platform, owner_email, state, description, tags, and the newly added config.

Suggested change
args (list): Command-line arguments.
server (str): Allocator server URL.
rack_name (str): Name of the rack.
slot_name (str): Name of the slot.
platform (str): Platform type for the slot.
owner_email (str or None): Email address of the slot owner.
state (str, optional): State of the slot. Defaults to ''.
description (str, optional): Description of the slot. Defaults to ''.
tags (list of str, optional): List of tags for the slot. Defaults to [].
config (str or None, optional): Path to a configuration file (YAML or JSON) for the slot. Defaults to None.

Copilot uses AI. Check for mistakes.
plugin_utils.warning(f"Unsupported config format for file: {config}")
except Exception as e:
plugin_utils.error(f"Failed to load configuration file: {e}")
configuration = None
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

This line is unreachable code. The plugin_utils.error() function raises SystemExit(1) and terminates the program, so configuration = None will never be executed. Consider removing this line.

Suggested change
configuration = None

Copilot uses AI. Check for mistakes.
Comment on lines +486 to +488
except Exception as e:
plugin_utils.error(f"Failed to load configuration file: {e}")
configuration = None
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

Consider catching more specific exceptions instead of the broad Exception. For file operations, FileNotFoundError, PermissionError, and IOError are more appropriate. For parsing errors, yaml.YAMLError and json.JSONDecodeError should be caught separately to provide more specific error messages to the user.

Suggested change
except Exception as e:
plugin_utils.error(f"Failed to load configuration file: {e}")
configuration = None
except FileNotFoundError as e:
plugin_utils.error(f"Configuration file not found: {e}")
configuration = None
except PermissionError as e:
plugin_utils.error(f"Permission denied when accessing configuration file: {e}")
configuration = None
except IOError as e:
plugin_utils.error(f"I/O error when accessing configuration file: {e}")
configuration = None
except yaml.YAMLError as e:
plugin_utils.error(f"YAML parsing error in configuration file: {e}")
configuration = None
except json.JSONDecodeError as e:
plugin_utils.error(f"JSON parsing error in configuration file: {e}")
configuration = None

Copilot uses AI. Check for mistakes.
Comment on lines +501 to +502
payload['configuration'] = configuration

Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

Consider validating that the loaded configuration is a dictionary before adding it to the payload. Both yaml.safe_load() and json.load() can return various types (None, lists, strings, etc.) depending on the file content. If the configuration is not a dictionary, it could cause issues with the API endpoint.

Suggested change
payload['configuration'] = configuration
if isinstance(configuration, dict):
payload['configuration'] = configuration
else:
plugin_utils.warning(f"Configuration loaded from {config} is not a dictionary and will be ignored.")

Copilot uses AI. Check for mistakes.
@zghp zghp self-assigned this Nov 11, 2025
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