-
Notifications
You must be signed in to change notification settings - Fork 7
Detect AWS and Mac platforms, and automatically set platform #545
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
base: develop
Are you sure you want to change the base?
Changes from 3 commits
da08140
4a95a8c
48ac7c7
d992c1c
d338dd3
072d785
692798a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ | |
| import yaml | ||
| from enum import Enum | ||
| import subprocess | ||
| import platform as pltfrm | ||
| from typing import Self | ||
|
|
||
| from importlib import resources | ||
|
|
||
|
|
@@ -30,22 +32,6 @@ def platform_path() -> str: | |
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def get_platforms() -> list: | ||
|
|
||
| # Get list of supported platforms | ||
| platforms = [dir for dir in os.listdir(platform_path()) | ||
| if os.path.isdir(os.path.join(platform_path(), dir))] | ||
|
|
||
| # If anything in platforms contains '__' remove it from platforms list | ||
| platforms = [platform for platform in platforms if '__' not in platform] | ||
|
|
||
| # List all directories in directory | ||
| return platforms | ||
|
|
||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def login_or_compute(platform) -> str: | ||
|
|
||
| ''' | ||
|
|
@@ -87,36 +73,64 @@ def login_or_compute(platform) -> str: | |
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class SwellPlatform(Enum): | ||
| ''' Store filepaths for platform defaults. ''' | ||
| NCCS_DISCOVER_SLES15 = os.path.join(platform_path(), 'nccs_discover_sles15') | ||
| NCCS_DISCOVER_CASCADE = os.path.join(platform_path(), 'nccs_discover') | ||
| GENERIC = os.path.join(platform_path(), 'generic') | ||
| class SwellPlatforms(Enum): | ||
| ''' Track platforms supported by Swell. ''' | ||
| NCCS_DISCOVER_SLES15 = 'nccs_discover_sles15' | ||
| NCCS_DISCOVER_CASCADE = 'nccs_discover_cascade' | ||
| AWS = 'aws' | ||
| MAC = 'mac' | ||
| GENERIC = 'generic' | ||
|
|
||
| @classmethod | ||
| def detect_platform(cls): | ||
| ''' Detect the current platform, or return generic (NCCS only). ''' | ||
| ''' Detect the current platform, or return generic. ''' | ||
|
|
||
| # Try to get the hostname | ||
| hostname = os.environ.get('HOSTNAME') | ||
| if hostname is None or not any(key in hostname for key in ['discover', 'borg', 'warp']): | ||
| return cls.GENERIC | ||
| os_name = pltfrm.platform() | ||
|
|
||
| if hostname is not None: | ||
|
|
||
| # Check for Discover hostnames | ||
| if any(key in hostname for key in ['discover', 'borg', 'warp']): | ||
|
|
||
| # Try the lscpu shell command, which should be available across NCCS | ||
| try: | ||
| cpu_info = str(subprocess.run('lscpu', capture_output=True).stdout) | ||
| try: | ||
| # Try the lscpu shell command, which should be available across NCCS | ||
| cpu_info = str(subprocess.run('lscpu', capture_output=True).stdout) | ||
|
|
||
| model_name = cpu_info.split('Model name:')[1].strip().split('\n')[0].strip() | ||
| model_name = cpu_info.split('Model name:')[1].strip().split('\n')[0].strip() | ||
|
|
||
| # Match the cpu to the expected platform | ||
| if all(key in model_name for key in ['Intel', 'Xeon']): | ||
| return cls.NCCS_DISCOVER_CASCADE | ||
| elif all(key in model_name for key in ['AMD', 'EPYC']): | ||
| return cls.NCCS_DISCOVER_SLES15 | ||
| else: | ||
| return cls.GENERIC | ||
| # Match the cpu to the expected platform | ||
| if all(key in model_name for key in ['Intel', 'Xeon']): | ||
| return cls.NCCS_DISCOVER_CASCADE | ||
| elif all(key in model_name for key in ['AMD', 'EPYC']): | ||
| return cls.NCCS_DISCOVER_SLES15 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If neither of these conditions is met, suggest raising a |
||
|
|
||
| except (FileNotFoundError, IndexError): | ||
| return cls.GENERIC | ||
|
|
||
| # Check for AWS | ||
| if all(key in os_name for key in ['Linux', 'aws']): | ||
| return cls.AWS | ||
|
|
||
| # Check for Mac | ||
| if all(key in os_name for key in ['macOS', 'arm64']): | ||
| return cls.MAC | ||
|
|
||
| return cls.GENERIC | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my comment above. If we've gotten this far, I suggest we just throw an error. |
||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| @classmethod | ||
| def get_all(cls) -> list: | ||
| return [item.value for item in cls] | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| @classmethod | ||
| def match_name(cls, name: str) -> Self: | ||
| # Return the enum instance based on the name | ||
| return getattr(cls, name.upper()) | ||
|
|
||
| except (FileNotFoundError, IndexError): | ||
| return cls.GENERIC | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure Swell won't actually work with the
GENERICplatform, right? If that's the case, I suggest we don't actually include it as a "supported" platform here and just let any errors in this section get thrown (which would be a noteworthy error --- we're already limiting this section to Discover hostnames).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or would this break
code_testsor other unit tests running on a generic linux machine or something? I.e., Doescode_testsdepend on the platform? If so, it shouldn't!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code tests don't depend on platform, but one quirk of the click interface is that it executes all calls in the driver group regardless of whether the particular command that needs it is called or not. So if we raise an error if the platform was not detected, it will raise that error any time
swellis called for any purposeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, makes sense. Can we work around that with something like this?