diff --git a/.github/workflows/PackageTest.yml b/.github/workflows/PackageTest.yml index 055aa8b..64236bd 100644 --- a/.github/workflows/PackageTest.yml +++ b/.github/workflows/PackageTest.yml @@ -29,9 +29,6 @@ jobs: - name: Setup environment run: /usr/local/bin/entrypoint.sh - - name: Set Up Bank DB Location - run: mkdir -p /ihome/crc/bank - - name: Checkout repository uses: actions/checkout@v4 diff --git a/apps/crc_squeue.py b/apps/crc_squeue.py index 878ee56..5ad48d5 100755 --- a/apps/crc_squeue.py +++ b/apps/crc_squeue.py @@ -1,11 +1,15 @@ """A simple wrapper around the Slurm ``squeue`` command.""" -import getpass +import os +import grp +from getpass import getpass, getuser from argparse import Namespace +from datetime import datetime, date from time import sleep +from .utils.keystone import * +from .utils.system_info import Slurm, Shell from .utils.cli import BaseParser -from .utils.system_info import Shell class CrcSqueue(BaseParser): @@ -40,7 +44,7 @@ def build_slurm_command(cls, args: Namespace) -> str: command_options.append(cls.output_format_all) else: - user = f'-u {getpass.getuser()}' + user = f'-u {getuser()}' command_options.append(user) command_options.append(cls.output_format_user) @@ -53,6 +57,31 @@ def app_logic(self, args: Namespace) -> None: args: Parsed command line arguments """ + default_group = grp.getgrgid(os.getgid()).gr_name + Slurm.check_slurm_account_exists(account_name=default_group) + + auth_header = get_auth_header(KEYSTONE_URL, + {'username': getuser(), + 'password': getpass("Please enter your CRC login password:\n")}) + + keystone_group_id = get_researchgroup_id(KEYSTONE_URL, default_group, auth_header) + + if not keystone_group_id: + print(f"No allocation data found in accounting system for '{default_group}'") + exit() + + requests = get_active_requests(KEYSTONE_URL, keystone_group_id, auth_header) + + if not requests: + print(f"No active resource allocation requests found in accounting system for '{default_group}'") + exit() + + for request in requests: + # Check if proposal will expire within 30 days. If yes, print a message to inform the user + if (date.fromisoformat(request['expire']) - date.today()).days < 30: + print(f"The active proposal for account {default_group} will expire soon on {request['expire']}." + "Please begin working on a new Resource Allocation Request if you want to run jobs beyond that date.") + command = self.build_slurm_command(args) if args.print_command: print(command) diff --git a/tests/test_crc_squeue.py b/tests/test_crc_squeue.py index 080599a..bd70aca 100644 --- a/tests/test_crc_squeue.py +++ b/tests/test_crc_squeue.py @@ -53,7 +53,7 @@ def test_user_option(self) -> None: """Test the ``--all`` argument toggles the slurm ``-u`` option in the returned command""" app = CrcSqueue() - slurm_user_argument = f'-u {getpass.getuser()}' + slurm_user_argument = "-u" # The application should default to showing information for the current user args, _ = app.parse_known_args([])