1#    (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
2#    All Rights Reserved.
3#
4#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5#    not use this file except in compliance with the License. You may obtain
6#    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, WITHOUT
12#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13#    License for the specific language governing permissions and limitations
14#    under the License.
15#
16
17import sys
18
19from neutronclient.neutron.v2_0.vpn import vpnservice
20from neutronclient.tests.unit import test_cli20
21
22
23class CLITestV20VpnServiceJSON(test_cli20.CLITestV20Base):
24
25    def test_create_vpnservice_all_params(self):
26        # vpn-service-create all params.
27        resource = 'vpnservice'
28        cmd = vpnservice.CreateVPNService(test_cli20.MyApp(sys.stdout), None)
29        subnet = 'mysubnet-id'
30        router = 'myrouter-id'
31        tenant_id = 'mytenant-id'
32        my_id = 'my-id'
33        name = 'myvpnservice'
34        description = 'my-vpn-service'
35        admin_state = True
36
37        args = ['--name', name,
38                '--description', description,
39                router,
40                subnet,
41                '--tenant-id', tenant_id]
42
43        position_names = ['admin_state_up', 'name', 'description',
44                          'subnet_id', 'router_id',
45                          'tenant_id']
46
47        position_values = [admin_state, name, description,
48                           subnet, router, tenant_id]
49
50        self._test_create_resource(resource, cmd, name, my_id, args,
51                                   position_names, position_values)
52
53    def test_create_vpnservice_with_limited_params(self):
54        # vpn-service-create with limited params.
55        resource = 'vpnservice'
56        cmd = vpnservice.CreateVPNService(test_cli20.MyApp(sys.stdout), None)
57        subnet = 'mysubnet-id'
58        router = 'myrouter-id'
59        tenant_id = 'mytenant-id'
60        my_id = 'my-id'
61        admin_state = True
62
63        args = [router,
64                subnet,
65                '--tenant-id', tenant_id]
66
67        position_names = ['admin_state_up',
68                          'subnet_id', 'router_id',
69                          'tenant_id']
70
71        position_values = [admin_state, subnet, router, tenant_id]
72
73        self._test_create_resource(resource, cmd, None, my_id, args,
74                                   position_names, position_values)
75
76    def test_create_vpnservice_without_subnet(self):
77        # vpn-service-create with no subnet provided.
78        resource = 'vpnservice'
79        cmd = vpnservice.CreateVPNService(test_cli20.MyApp(sys.stdout), None)
80        router = 'myrouter-id'
81        tenant_id = 'mytenant-id'
82        my_id = 'my-id'
83        admin_state = True
84
85        args = [router,
86                '--tenant-id', tenant_id]
87
88        position_names = ['admin_state_up',
89                          'subnet_id', 'router_id',
90                          'tenant_id']
91
92        position_values = [admin_state, None, router, tenant_id]
93
94        self._test_create_resource(resource, cmd, None, my_id, args,
95                                   position_names, position_values)
96
97    def test_list_vpnservice(self):
98        # vpn-service-list.
99        resources = "vpnservices"
100        cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
101        self._test_list_resources(resources, cmd, True)
102
103    def test_list_vpnservice_pagination(self):
104        # vpn-service-list.
105        resources = "vpnservices"
106        cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
107        self._test_list_resources_with_pagination(resources, cmd)
108
109    def test_list_vpnservice_sort(self):
110        # vpn-service-list --sort-key name --sort-key id --sort-key asc
111        # --sort-key desc
112        resources = "vpnservices"
113        cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
114        self._test_list_resources(resources, cmd,
115                                  sort_key=["name", "id"],
116                                  sort_dir=["asc", "desc"])
117
118    def test_list_vpnservice_limit(self):
119        # vpn-service-list -P.
120        resources = "vpnservices"
121        cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
122        self._test_list_resources(resources, cmd, page_size=1000)
123
124    def test_show_vpnservice_id(self):
125        # vpn-service-show test_id.
126        resource = 'vpnservice'
127        cmd = vpnservice.ShowVPNService(test_cli20.MyApp(sys.stdout), None)
128        args = ['--fields', 'id', self.test_id]
129        self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
130
131    def test_show_vpnservice_id_name(self):
132        # vpn-service-show."""
133        resource = 'vpnservice'
134        cmd = vpnservice.ShowVPNService(test_cli20.MyApp(sys.stdout), None)
135        args = ['--fields', 'id', '--fields', 'name', self.test_id]
136        self._test_show_resource(resource, cmd, self.test_id,
137                                 args, ['id', 'name'])
138
139    def test_update_vpnservice(self):
140        # vpn-service-update myid --name newname --tags a b.
141        resource = 'vpnservice'
142        cmd = vpnservice.UpdateVPNService(test_cli20.MyApp(sys.stdout), None)
143        self._test_update_resource(resource, cmd, 'myid',
144                                   ['myid', '--name', 'newname'],
145                                   {'name': 'newname', })
146        # vpn-service-update myid --admin-state-up False
147        self._test_update_resource(resource, cmd, 'myid',
148                                   ['myid', '--admin-state-up', 'False'],
149                                   {'admin_state_up': 'False', })
150
151    def test_delete_vpnservice(self):
152        # vpn-service-delete my-id.
153        resource = 'vpnservice'
154        cmd = vpnservice.DeleteVPNService(test_cli20.MyApp(sys.stdout), None)
155        my_id = 'my-id'
156        args = [my_id]
157        self._test_delete_resource(resource, cmd, my_id, args)
158