This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created health service client that uses a stubbed set of health data. To view health status information, the health status information is included when a user prints an instantiated unity object. * Added print health status method to health service and updated how health statuses are printed to account for service's historical health status information. * Removed uneeded health service unit test fixture. * Updated how health status reports are generated so that the report can be reused in multiple places to improve consistency of the health status report. * Updated CHANGELOG and version number. * Testing different syntax to resolve flake8 linting error. * Updated dictionary references to resolve flake8 linting errors. * Update python-app.yml * Update python-app.yml * Update python-app.yml * Update python-app.yml * Update python-app.yml * Update python-app.yml * Update python-app.yml * updating workflows --------- Co-authored-by: mike-gangl <[email protected]> Co-authored-by: mike-gangl <[email protected]>
- Loading branch information
1 parent
44488b0
commit 99568b4
Showing
7 changed files
with
197 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,34 @@ jobs: | |
UNITY_USER: '${{ secrets.UNITY_TEST_USER }}' | ||
UNITY_PASSWORD: '${{ secrets.UNITY_TEST_PASSWORD }}' | ||
run: | | ||
poetry run pytest --cov=unity_sds_client -m "not regression" | ||
poetry run pytest --cov-report=lcov --cov=unity_sds_client -m "not regression" | ||
- name: Regression Test with pytest | ||
env: | ||
UNITY_USER: '${{ secrets.UNITY_TEST_USER }}' | ||
UNITY_PASSWORD: '${{ secrets.UNITY_TEST_PASSWORD }}' | ||
run: | | ||
poetry run pytest --cov=unity_sds_client -o log_cli=true --log-cli-level=DEBUG | ||
poetry run pytest --cov-report=lcov --cov=unity_sds_client -o log_cli=true --log-cli-level=DEBUG | ||
- name: Coveralls | ||
uses: coverallsapp/github-action@v2 | ||
uses: coverallsapp/[email protected] | ||
version: | ||
if: github.ref == 'refs/heads/develop' && github.event_name == 'push' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
- name: Install Poetry | ||
uses: abatilo/[email protected] | ||
with: | ||
poetry-version: "1.5.1" | ||
- name: version-bump | ||
run: | | ||
poetry version prerelease | ||
- name: Commit Version Bump | ||
run: | | ||
git config --global user.name 'mdps bot' | ||
git config --global user.email '[email protected]' | ||
git commit -am "development version bump. [skip actions]" | ||
git push | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
This module contains a set of tests is to ensure that the | ||
Unity Health Service is functional. | ||
""" | ||
|
||
import pytest | ||
|
||
from unity_sds_client.unity import Unity | ||
from unity_sds_client.unity_services import UnityServices | ||
|
||
|
||
@pytest.mark.regression | ||
def test_health_service_client_creation(): | ||
""" | ||
Test that an instance of the health service can be instantiated. | ||
""" | ||
s = Unity() | ||
health_service = s.client(UnityServices.HEALTH_SERVICE) | ||
|
||
@pytest.mark.regression | ||
def test_health_status_retrieval(): | ||
""" | ||
Test that health statuses can be retrieved using the health service. | ||
""" | ||
print("Example health status check") | ||
s = Unity() | ||
health_service = s.client(UnityServices.HEALTH_SERVICE) | ||
health_statuses = health_service.get_health_status() | ||
assert health_statuses is not None | ||
|
||
@pytest.mark.regression | ||
def test_health_status_printing(): | ||
""" | ||
Test that health statuses can be printed using the health service. | ||
""" | ||
print("Example health status check") | ||
s = Unity() | ||
health_service = s.client(UnityServices.HEALTH_SERVICE) | ||
health_service.print_health_status() | ||
|
||
@pytest.mark.regression | ||
def test_health_service_printing(): | ||
""" | ||
Test that when the health service client is printed, it outputs | ||
the health status information | ||
""" | ||
print("Example health status printing of health service object.") | ||
s = Unity() | ||
health_service = s.client(UnityServices.HEALTH_SERVICE) | ||
print(health_service) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from unity_sds_client.unity_session import UnitySession | ||
|
||
class HealthService(object): | ||
""" | ||
The HealthService class is a wrapper to Unity's Health API endpoints. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
session:UnitySession | ||
): | ||
""" | ||
Initialize the HealthService class. | ||
Parameters | ||
---------- | ||
session : UnitySession | ||
The Unity Session that will be used to facilitate making calls to the Health endpoints. | ||
Returns | ||
------- | ||
List | ||
List of applications and their health statses | ||
""" | ||
|
||
self._health_statuses = None | ||
|
||
def __str__(self): | ||
return self.generate_health_status_report() | ||
|
||
def get_health_status(self): | ||
""" | ||
Returns a list of services and their respective health status | ||
""" | ||
|
||
# Get Health Information | ||
# Stubbed in health data until Health API endpoint is available | ||
self._health_statuses = [ | ||
{ | ||
"service": "airflow", | ||
"landingPage":"https://unity.jpl.nasa.gov/project/venue/processing/ui", | ||
"healthChecks": [ | ||
{ | ||
"status": "HEALTHY", | ||
"date": "2024-04-09T18:01:08Z" | ||
} | ||
] | ||
}, | ||
{ | ||
"service": "jupyter", | ||
"landingPage":"https://unity.jpl.nasa.gov/project/venue/ads/jupyter", | ||
"healthChecks": [ | ||
{ | ||
"status": "HEALTHY", | ||
"date": "2024-04-09T18:01:08Z" | ||
} | ||
] | ||
}, | ||
{ | ||
"service": "other_service", | ||
"landingPage":"https://unity.jpl.nasa.gov/project/venue/other_service", | ||
"healthChecks": [ | ||
{ | ||
"status": "UNHEALTHY", | ||
"date": "2024-04-09T18:01:08Z" | ||
} | ||
] | ||
} | ||
] | ||
|
||
return self._health_statuses | ||
|
||
def generate_health_status_report(self): | ||
""" | ||
Return a generated report of health status information | ||
""" | ||
|
||
if self._health_statuses is None: | ||
self.get_health_status() | ||
|
||
health_status_title = "HEALTH STATUS REPORT" | ||
report = f"\n\n{health_status_title}\n" | ||
report = report + len(health_status_title) * "-" + "\n\n" | ||
for service in self._health_statuses: | ||
service_name = service["service"] | ||
report = report + f"{service_name}\n" | ||
for status in service["healthChecks"]: | ||
service_status = status["status"] | ||
service_status_date = status["date"] | ||
report = report + f"{service_status_date}: {service_status}\n" | ||
report = report + "\n" | ||
|
||
return report | ||
|
||
def print_health_status(self): | ||
""" | ||
Print the health status report | ||
""" | ||
print(f"{self.generate_health_status_report()}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters