vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / tests / cli / test_nodes.py
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import pytest
17 import mock
18
19 from aria.cli.env import _Environment
20
21 from .base_test import (  # pylint: disable=unused-import
22     TestCliBase,
23     mock_storage
24 )
25 from ..mock import models as mock_models
26
27
28 class TestNodesShow(TestCliBase):
29
30     def test_header_strings(self, monkeypatch, mock_storage):
31         monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
32         self.invoke('nodes show 1')
33         assert 'Showing node 1' in self.logger_output_string
34         assert 'Node:' in self.logger_output_string
35         assert 'Node attributes:' in self.logger_output_string
36
37     def test_no_attributes(self, monkeypatch, mock_storage):
38
39         monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
40         self.invoke('nodes show 2')
41         assert 'No attributes' in self.logger_output_string
42         assert 'attribute1' not in self.logger_output_string
43         assert 'value1' not in self.logger_output_string
44
45     def test_one_attribute(self, monkeypatch, mock_storage):
46
47         monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
48         m = mock.MagicMock(
49             return_value=mock_models.create_node_with_dependencies(include_attribute=True))
50         monkeypatch.setattr(mock_storage.node, 'get', m)
51         self.invoke('nodes show 3')
52         assert 'No attributes' not in self.logger_output_string
53         assert 'attribute1' in self.logger_output_string
54         assert 'value1' in self.logger_output_string
55
56
57 class TestNodesList(TestCliBase):
58
59     @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
60         ('', '', 'service_name', 'asc'),
61         ('', ' --descending', 'service_name', 'desc'),
62         (' --sort-by name', '', 'name', 'asc'),
63         (' --sort-by name', ' --descending', 'name', 'desc')
64     ])
65     def test_list_specified_service(self, monkeypatch, mock_storage, sort_by, order,
66                                     sort_by_in_output, order_in_output):
67
68         monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
69         self.invoke('nodes list -s test_s{sort_by}{order}'.format(sort_by=sort_by,
70                                                                   order=order))
71         assert 'Listing nodes for service test_s...' in self.logger_output_string
72         assert 'Listing all nodes...' not in self.logger_output_string
73
74         nodes_list = mock_storage.node.list
75         nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
76                                            filters={'service': mock.ANY})
77         assert 'Nodes:' in self.logger_output_string
78         assert 'test_s' in self.logger_output_string
79         assert 'test_n' in self.logger_output_string
80
81     @pytest.mark.parametrize('sort_by, order, sort_by_in_output, order_in_output', [
82         ('', '', 'service_name', 'asc'),
83         ('', ' --descending', 'service_name', 'desc'),
84         (' --sort-by name', '', 'name', 'asc'),
85         (' --sort-by name', ' --descending', 'name', 'desc')
86     ])
87     def test_list_no_specified_service(self, monkeypatch, mock_storage, sort_by, order,
88                                        sort_by_in_output, order_in_output):
89
90         monkeypatch.setattr(_Environment, 'model_storage', mock_storage)
91         self.invoke('nodes list{sort_by}{order}'.format(sort_by=sort_by,
92                                                         order=order))
93         assert 'Listing nodes for service test_s...' not in self.logger_output_string
94         assert 'Listing all nodes...' in self.logger_output_string
95
96         nodes_list = mock_storage.node.list
97         nodes_list.assert_called_once_with(sort={sort_by_in_output: order_in_output},
98                                            filters={})
99         assert 'Nodes:' in self.logger_output_string
100         assert 'test_s' in self.logger_output_string
101         assert 'test_n' in self.logger_output_string