Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/xts_core/plugins/xts_allocator_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _send_request(method, url, data=None) -> dict:
except requests.exceptions.RequestException as e:
plugin_utils.error(f'Error during request: {e}')


@staticmethod
def _format_slots_list_to_table(response:list[dict]) -> Table:
'''Format the list of slot dictionaries into a rich table
Expand All @@ -89,15 +90,16 @@ def _format_slots_list_to_table(response:list[dict]) -> Table:
'''
table_headers = map(lambda x: x.capitalize(),response[0].keys())
resp_table = Table(*table_headers)

for entry in response:
row_values = []
for value in entry.values():
if isinstance(value, list):
row_values.append(', '.join(value))
row_values.append(', '.join(map(str, value)))
elif isinstance(value, dict):
row_values.append(str(value))
else:
row_values.append(value)
row_values.append(str(value) if value is not None else "")
resp_table.add_row(*row_values)
return resp_table

Expand Down Expand Up @@ -146,6 +148,11 @@ def _setup_allocate_args(self):
dest='server',
required=True,
help='Allocator server address.')
allocate_parser.add_argument(
'--user-email',
dest='user_email',
required=False,
help='Email of the user performing the allocation')

def _setup_allocator_args(self):
'''Setup the subparsers for the allocator command.
Expand Down Expand Up @@ -262,8 +269,8 @@ def _allocate_slot(self,
server: str,
id: int = None,
platform: str = None,
tags: list = None
):
tags: list = None,
user_email: str = None):
'''
Allocate a test slot and retrieve its rack configuration.

Expand All @@ -275,17 +282,28 @@ def _allocate_slot(self,
'''
if tags and not platform:
plugin_utils.error('[default]--tags[/default] can only be used if [default]--platform[/default] is specified.')
slot_payload = {}
if id:
#ignore --platform and --tags
payload = {'id': id}
slot_payload['id'] = id
plugin_utils.warning('Ignoring [default]--platform[/default] and [default]--tags[/default] because [default]--id[/default] was provided.')
else:
#use --platform (required for allocation)
if not platform:
plugin_utils.error('[default]--platform[/default] is required when [default]--id[/default] is not provided.')
payload = {'platform': platform, 'tags': tags}
slot_payload['platform'] = platform

if tags:
slot_payload['tags'] = tags

user_email = user_email or os.getenv("USER_EMAIL", "[email protected]")

payload = {
"user": {"email": user_email},
"slot": slot_payload
}

response = self._send_request('POST', f'{server}/allocate', payload)
response = self._send_request('POST', f'{server}/allocate_slot', payload)

if response and 'slot_id' in response:
allocated_slot_id = response['slot_id']
Expand Down
Loading