-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from lsst/tickets/DM-35144
DM-35144: Add ping subcommand.
- Loading branch information
Showing
12 changed files
with
384 additions
and
13 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
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 @@ | ||
Add ping subcommand to test whether the workflow services are available. |
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
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,59 @@ | ||
# This file is part of ctrl_bps. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
"""Supporting functions for pinging WMS service. | ||
""" | ||
|
||
__all__ = ["ping"] | ||
|
||
import logging | ||
|
||
from lsst.utils import doImport | ||
|
||
_LOG = logging.getLogger(__name__) | ||
|
||
|
||
def ping(wms_service, pass_thru=None): | ||
"""Checks whether WMS services are up, reachable, and any authentication, | ||
if needed, succeeds. | ||
The services to be checked are those needed for submit, report, cancel, | ||
restart, but ping cannot guarantee whether jobs would actually run | ||
successfully. | ||
Parameters | ||
---------- | ||
wms_service : `str` | ||
Name of the class. | ||
pass_thru : `str` | ||
A string to pass directly to the WMS service class. | ||
Returns | ||
------- | ||
status : `int` | ||
Services are available (0) or problems (not 0) | ||
message : `str` | ||
Any message from WMS (e.g., error details). | ||
""" | ||
wms_service_class = doImport(wms_service) | ||
wms_service = wms_service_class({}) | ||
|
||
return wms_service.ping(pass_thru) |
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,78 @@ | ||
# This file is part of ctrl_bps. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
import unittest | ||
|
||
from lsst.ctrl.bps.cli import bps | ||
from lsst.daf.butler.cli.utils import LogCliRunner | ||
|
||
|
||
class TestCommandPing(unittest.TestCase): | ||
"""Test executing the ping subcommand.""" | ||
|
||
def setUp(self): | ||
self.runner = LogCliRunner() | ||
|
||
def testPingNoArgs(self): | ||
with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: | ||
mock_driver.return_value = 0 | ||
result = self.runner.invoke(bps.cli, ["ping"]) | ||
self.assertEqual(result.exit_code, 0) | ||
mock_driver.assert_called_with(wms_service=None, pass_thru="") | ||
|
||
def testPingClass(self): | ||
with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: | ||
mock_driver.return_value = 0 | ||
result = self.runner.invoke( | ||
bps.cli, ["ping", "--wms-service-class", "wms_test_utils.WmsServiceSuccess"] | ||
) | ||
self.assertEqual(result.exit_code, 0) | ||
mock_driver.assert_called_with(wms_service="wms_test_utils.WmsServiceSuccess", pass_thru="") | ||
|
||
def testPingFailure(self): | ||
with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: | ||
mock_driver.return_value = 64 # avoid 1 and 2 as returned when cli problems | ||
result = self.runner.invoke( | ||
bps.cli, ["ping", "--wms-service-class", "wms_test_utils.WmsServiceFailure"] | ||
) | ||
self.assertEqual(result.exit_code, 64) | ||
mock_driver.assert_called_with(wms_service="wms_test_utils.WmsServiceFailure", pass_thru="") | ||
|
||
def testPingPassthru(self): | ||
with unittest.mock.patch("lsst.ctrl.bps.cli.cmd.commands.ping_driver") as mock_driver: | ||
mock_driver.return_value = 0 | ||
result = self.runner.invoke( | ||
bps.cli, | ||
[ | ||
"ping", | ||
"--wms-service-class", | ||
"wms_test_utils.WmsServicePassThru", | ||
"--pass-thru", | ||
"EXTRA_VALUES", | ||
], | ||
) | ||
self.assertEqual(result.exit_code, 0) | ||
mock_driver.assert_called_with( | ||
wms_service="wms_test_utils.WmsServicePassThru", pass_thru="EXTRA_VALUES" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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
Oops, something went wrong.