diff --git a/src/bin/shipyard_airflow/tests/unit/control/test_actions_api.py b/src/bin/shipyard_airflow/tests/unit/control/test_actions_api.py index 0ccfc0df..8f2a5373 100644 --- a/src/bin/shipyard_airflow/tests/unit/control/test_actions_api.py +++ b/src/bin/shipyard_airflow/tests/unit/control/test_actions_api.py @@ -23,6 +23,7 @@ from falcon import testing from oslo_config import cfg import pytest import responses +import yaml from shipyard_airflow.common.notes.notes import NotesManager from shipyard_airflow.common.notes.notes_helper import NotesHelper @@ -48,6 +49,23 @@ CONF = cfg.CONF LOG = logging.getLogger(__name__) +def _get_actions_list(): + dir_path = os.path.dirname(os.path.realpath(__file__)) + a_path = dir_path.split('src/bin')[0] + "src/bin/supported_actions.yaml" + with open(a_path, 'r') as stream: + try: + action_list = yaml.safe_load(stream)['actions'] + if not action_list: + raise FileNotFoundError("Action list is empty") + except Exception as e: + print(e) + print("This test requires that the file at '{}' is a valid yaml " + "file containing a list of action names at a key of " + "'actions'".format(a_path)) + assert False + return action_list + + def get_token(): """Stub method to use for NotesHelper/NotesManager""" return "token" @@ -238,6 +256,19 @@ def conf_fixture(request): context = ShipyardRequestContext() +def test_actions_all_in_list(): + """Test that all actions are in alignment with supported list + Compares the action mappings structure with the externalized list of + supported actions, allowing for better alignment with the client + """ + mappings = actions_api._action_mappings() + actions = _get_actions_list() + for action in actions: + assert action in mappings + for action in mappings.keys(): + assert action in actions + + @mock.patch.object(ShipyardPolicy, 'authorize', return_value=True) @mock.patch.object( ActionsResource, diff --git a/src/bin/shipyard_client/shipyard_client/cli/help/output.py b/src/bin/shipyard_client/shipyard_client/cli/help/output.py index 7955c6c3..b6a0d539 100644 --- a/src/bin/shipyard_client/shipyard_client/cli/help/output.py +++ b/src/bin/shipyard_client/shipyard_client/cli/help/output.py @@ -32,23 +32,34 @@ For information of the following topics, run shipyard help def actions(): return '''ACTIONS -The workflow actions that may be invoked using Shipyard +Workflow actions that may be invoked using Shipyard. -deploy_site: Triggers the initial deployment of a site using the latest - committed configuration documents. +deploy_site + Triggers the initial deployment of a site using the latest committed + configdocs. -update_site: Triggers the update to a deployment of a site, using the latest - committed configuration documents. +update_site + Triggers the update to a deployment of a site, using the latest committed + configdocs. -update_software: Starts an update that only exercises the software portion of - the committed configuration documents. +update_software + Starts an update that only exercises the software portion of the committed + configdocs. -redeploy_server: Using parameters to indicate which server(s), triggers a - redeployment of servers to the last committed design and - secrets. +redeploy_server + Using the --param="target_nodes=node1,node2" parameter to target server(s), + triggers a redeployment of servers using the last committed configdocs. -relabel_nodes: Using parameters to indicate which server(s), updates the - labels for those servers. +relabel_nodes + Using the --param="target_nodes=node1,node2" parameter to target server(s), + updates the Kubernetes node labels for the nodes on those servers. + +test_site + Triggers the Helm tests for the site, using parameters to control the + tests: + --param="cleanup=true" to delete the test pods immediately after execution + --param="release=release-name" to target a specific Helm release instead of + all releases (the default if this parameter is not specified). ''' diff --git a/src/bin/shipyard_client/tests/unit/cli/help/test_help_commands.py b/src/bin/shipyard_client/tests/unit/cli/help/test_help_commands.py index 1040dafb..ce2a6f73 100644 --- a/src/bin/shipyard_client/tests/unit/cli/help/test_help_commands.py +++ b/src/bin/shipyard_client/tests/unit/cli/help/test_help_commands.py @@ -11,11 +11,29 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os from click.testing import CliRunner +import yaml from shipyard_client.cli.help.commands import help +def _get_actions_list(): + dir_path = os.path.dirname(os.path.realpath(__file__)) + a_path = dir_path.split('src/bin')[0] + "src/bin/supported_actions.yaml" + with open(a_path, 'r') as stream: + try: + action_list = yaml.safe_load(stream)['actions'] + if not action_list: + raise FileNotFoundError("Action list is empty") + except Exception as e: + print(e) + print("This test requires that the file at '{}' is a valid yaml " + "file containing a list of action names at a key of " + "'actions'".format(a_path)) + assert False + return action_list + def test_help(): """test help with all options""" @@ -27,6 +45,10 @@ def test_help(): topic = 'actions' result = runner.invoke(help, [topic]) assert 'ACTIONS' in result.output + actions = _get_actions_list() + for action in actions: + # Assert that actions each have headers + assert "\n{}\n".format(action) in result.output topic = 'configdocs' result = runner.invoke(help, [topic]) diff --git a/src/bin/supported_actions.yaml b/src/bin/supported_actions.yaml new file mode 100644 index 00000000..a8a5ff11 --- /dev/null +++ b/src/bin/supported_actions.yaml @@ -0,0 +1,14 @@ +# This file contains a list of supported actions that exists outside the +# scope of both the client and API. This is tested in both the client and +# the API to ensure that the actions in the API match the actions supported +# in the help of the client. Because of this, it becomes another place that +# has to be updated, but since it's tied to tests, the reminders to fix it +# should be outweighed by the benefit. +actions: + - deploy_site + - update_site + - update_software + - redeploy_server + - relabel_nodes + - test_site +...