Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-199-cli-service-output [created] 79b94e1f9
ARIA-199 Add "services outputs" CLI command Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/79b94e1f Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/79b94e1f Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/79b94e1f Branch: refs/heads/ARIA-199-cli-service-output Commit: 79b94e1f9aed3be3176b96870f7ea472146032c3 Parents: 9174f94 Author: Tal Liron <[email protected]> Authored: Fri Jun 2 14:20:28 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Fri Jun 2 14:20:28 2017 -0500 ---------------------------------------------------------------------- aria/cli/commands/services.py | 22 ++++++++--------- tests/cli/test_services.py | 26 ++++++++++++++++++-- tests/mock/models.py | 4 +++ .../node-cellar/node-cellar.yaml | 12 +++++++++ 4 files changed, 51 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/79b94e1f/aria/cli/commands/services.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py index 476387c..712b6af 100644 --- a/aria/cli/commands/services.py +++ b/aria/cli/commands/services.py @@ -192,17 +192,17 @@ def outputs(service_name, model_storage, logger): """ logger.info('Showing outputs for service {0}...'.format(service_name)) service = model_storage.service.get_by_name(service_name) - #TODO fix this section.. - outputs_def = service.outputs - response = model_storage.service.outputs.get(service_name) - outputs_ = StringIO() - for output_name, output in response.outputs.iteritems(): - outputs_.write(' - "{0}":{1}'.format(output_name, os.linesep)) - description = outputs_def[output_name].get('description', '') - outputs_.write(' Description: {0}{1}'.format(description, - os.linesep)) - outputs_.write(' Value: {0}{1}'.format(output, os.linesep)) - logger.info(outputs_.getvalue()) + + if service.outputs: + outputs_ = StringIO() + for output_name, output in service.outputs.iteritems(): + outputs_.write(' - "{0}":{1}'.format(output_name, os.linesep)) + outputs_.write(' Description: {0}{1}'.format(output.description, + os.linesep)) + outputs_.write(' Value: {0}{1}'.format(output.value, os.linesep)) + logger.info(outputs_.getvalue()) + else: + logger.info('\tNo outputs') @services.command(name='inputs', http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/79b94e1f/tests/cli/test_services.py ---------------------------------------------------------------------- diff --git a/tests/cli/test_services.py b/tests/cli/test_services.py index e5717cc..e514f12 100644 --- a/tests/cli/test_services.py +++ b/tests/cli/test_services.py @@ -174,7 +174,30 @@ class TestServicesDelete(TestCliBase): class TestServicesOutputs(TestCliBase): - pass + + def test_header_string(self, monkeypatch, mock_storage): + monkeypatch.setattr(_Environment, 'model_storage', mock_storage) + self.invoke('services outputs test_s') + assert 'Showing outputs for service test_s...' in self.logger_output_string + + def test_outputs_no_outputs(self, monkeypatch, mock_storage): + monkeypatch.setattr(_Environment, 'model_storage', mock_storage) + self.invoke('services outputs service_with_no_outputs') + + assert 'No outputs' in self.logger_output_string + assert 'output1' not in self.logger_output_string + assert 'value1' not in self.logger_output_string + + def test_outputs_one_output(self, monkeypatch, mock_storage): + monkeypatch.setattr(_Environment, 'model_storage', mock_storage) + s = mock_models.create_service_with_dependencies(include_output=True) + monkeypatch.setattr(mock_storage.service, 'get_by_name', mock.MagicMock(return_value=s)) + + self.invoke('services outputs test_s') + + assert 'output1' in self.logger_output_string + assert 'value1' in self.logger_output_string + assert 'No inputs' not in self.logger_output_string class TestServicesInputs(TestCliBase): @@ -193,7 +216,6 @@ class TestServicesInputs(TestCliBase): assert 'value1' not in self.logger_output_string def test_inputs_one_input(self, monkeypatch, mock_storage): - monkeypatch.setattr(_Environment, 'model_storage', mock_storage) s = mock_models.create_service_with_dependencies(include_input=True) monkeypatch.setattr(mock_storage.service, 'get_by_name', mock.MagicMock(return_value=s)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/79b94e1f/tests/mock/models.py ---------------------------------------------------------------------- diff --git a/tests/mock/models.py b/tests/mock/models.py index 50aa340..725475f 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -86,6 +86,7 @@ def create_service(service_template, name=SERVICE_NAME, inputs=None): def create_service_with_dependencies(include_execution=False, include_input=False, + include_output=False, include_node=False): service_template = create_service_template() service = create_service(service_template=service_template) @@ -96,6 +97,9 @@ def create_service_with_dependencies(include_execution=False, if include_input: input = create_parameter(name='input1', value='value1') service.inputs = {'input1': input} + if include_output: + output = create_parameter(name='output1', value='value1') + service.outputs = {'output1': output} if include_node: node_template = create_node_template(service_template=service_template) node = create_node(node_template, service, state=models.Node.STARTED) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/79b94e1f/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml ---------------------------------------------------------------------- diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml index 4d53f9b..a34301c 100644 --- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml +++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml @@ -144,6 +144,10 @@ topology_template: type: nodejs.Server requirements: - host: application_host + capabilities: + data_endpoint: + properties: + url_path: /app node_filter: # cannot be validated properties: #- flavor_name: { valid_values: [ {concat:[m1,.,small]} ] } # won't work because not validated :/ @@ -302,6 +306,14 @@ topology_template: capabilities: app_endpoint: [ loadbalancer, client ] + outputs: + + endpoint: + description: >- + The application endpoint. + type: string + value: { get_property: [ nodejs, data_endpoint, url_path ] } + policy_types: MaintenanceWorkflow:
