This file is indexed.

/usr/lib/python2.7/dist-packages/manila_ui/tests/dashboards/project/shares/share_networks/tests.py is in python-manila-ui 2.5.1-0.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Copyright (c) 2014 NetApp, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, 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.

from django.core.urlresolvers import reverse
import mock

from neutronclient.client import exceptions
from openstack_auth import policy

from manila_ui.api import manila as api_manila
from manila_ui.api import network as api_manila_network
from manila_ui.tests.dashboards.project.shares import test_data
from manila_ui.tests import helpers as test

from openstack_dashboard import api


SHARE_INDEX_URL = reverse('horizon:project:shares:index')


class ShareNetworksViewTests(test.TestCase):

    def test_create_share_network(self):
        share_net = test_data.active_share_network
        url = reverse('horizon:project:shares:create_share_network')
        neutron_net_id = self.networks.first().id
        formData = {
            'name': 'new_share_network',
            'description': 'This is test share network',
            'method': 'CreateForm',
            'neutron_net_id': neutron_net_id,
        }
        for net in self.networks.list():
            formData['subnet-choices-%s' % net.id] = net.subnets[0].id
        self.mock_object(
            api.neutron, "subnet_list",
            mock.Mock(return_value=self.subnets.list()))
        self.mock_object(
            api_manila_network, "network_list",
            mock.Mock(return_value=self.networks.list()))
        self.mock_object(
            api_manila, "share_network_create",
            mock.Mock(return_value=share_net))

        self.client.post(url, formData)

        api_manila.share_network_create.assert_called_with(
            mock.ANY, name=formData['name'], neutron_net_id=neutron_net_id,
            neutron_subnet_id=formData['subnet-choices-%s' % neutron_net_id],
            description=formData['description'])
        api_manila_network.network_list.assert_called_once_with(mock.ANY)
        api.neutron.subnet_list.assert_has_calls([
            mock.call(mock.ANY, network_id=network.id)
            for network in self.networks.list()
        ], any_order=True)

    def test_delete_share_network(self):
        url = reverse('horizon:project:shares:index')
        share_network = test_data.inactive_share_network
        formData = {'action': 'share_networks__delete__%s' % share_network.id}
        self.mock_object(api_manila, "share_network_delete")
        self.mock_object(
            api_manila, "share_network_list",
            mock.Mock(return_value=[
                test_data.active_share_network, share_network]))
        self.mock_object(
            api.neutron, "network_list",
            mock.Mock(return_value=self.networks.list()))
        self.mock_object(
            api.neutron, "subnet_list",
            mock.Mock(return_value=self.subnets.list()))

        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, SHARE_INDEX_URL)
        api_manila.share_network_list.assert_called_once_with(
            mock.ANY, detailed=True)
        api_manila.share_network_delete.assert_called_once_with(
            mock.ANY, share_network.id)
        api.neutron.network_list.assert_called_once_with(mock.ANY)
        api.neutron.subnet_list.assert_called_once_with(mock.ANY)

    def test_detail_view(self):
        share_net = test_data.active_share_network
        sec_service = test_data.sec_service
        self.mock_object(
            api_manila, "share_server_list", mock.Mock(return_value=[]))
        self.mock_object(
            api_manila, "share_network_get", mock.Mock(return_value=share_net))
        self.mock_object(
            api_manila, "share_network_security_service_list",
            mock.Mock(return_value=[sec_service]))
        network = self.networks.first()
        subnet = self.subnets.first()
        self.mock_object(
            api.neutron, "network_get", mock.Mock(return_value=network))
        self.mock_object(
            api.neutron, "subnet_get", mock.Mock(return_value=subnet))
        url = reverse('horizon:project:shares:share_network_detail',
                      args=[share_net.id])

        res = self.client.get(url)

        self.assertContains(res, "<h1>Share Network Details: %s</h1>"
                                 % share_net.name,
                            1, 200)
        self.assertContains(res, "<dd>%s</dd>" % share_net.name, 1, 200)
        self.assertContains(res, "<dd>%s</dd>" % share_net.id, 1, 200)
        self.assertContains(res, "<dd>%s</dd>" % network.name_or_id, 1, 200)
        self.assertContains(res, "<dd>%s</dd>" % subnet.name_or_id, 1, 200)
        self.assertContains(res, "<a href=\"/project/shares/security_services"
                                 "/%s\">%s</a>" % (sec_service.id,
                                                   sec_service.name), 1, 200)
        self.assertNoMessages()
        api_manila.share_network_security_service_list.assert_called_once_with(
            mock.ANY, share_net.id)
        api_manila.share_server_list.assert_called_once_with(
            mock.ANY, search_opts={'share_network_id': share_net.id})
        api_manila.share_network_get.assert_called_once_with(
            mock.ANY, share_net.id)
        api.neutron.network_get.assert_called_once_with(
            mock.ANY, share_net.neutron_net_id)
        api.neutron.subnet_get.assert_called_once_with(
            mock.ANY, share_net.neutron_subnet_id)

    def test_detail_view_network_not_found(self):
        share_net = test_data.active_share_network
        sec_service = test_data.sec_service
        url = reverse('horizon:project:shares:share_network_detail',
                      args=[share_net.id])
        self.mock_object(
            api_manila, "share_server_list", mock.Mock(return_value=[]))
        self.mock_object(
            api_manila, "share_network_get", mock.Mock(return_value=share_net))
        self.mock_object(
            api_manila, "share_network_security_service_list",
            mock.Mock(return_value=[sec_service]))
        self.mock_object(
            api.neutron, "network_get", mock.Mock(
                side_effect=exceptions.NeutronClientException('fake', 500)))
        self.mock_object(
            api.neutron, "subnet_get", mock.Mock(
                side_effect=exceptions.NeutronClientException('fake', 500)))

        res = self.client.get(url)

        self.assertContains(res, "<h1>Share Network Details: %s</h1>"
                                 % share_net.name,
                            1, 200)
        self.assertContains(res, "<dd>%s</dd>" % share_net.name, 1, 200)
        self.assertContains(res, "<dd>%s</dd>" % share_net.id, 1, 200)
        self.assertContains(res, "<dd>Unknown</dd>", 2, 200)
        self.assertNotContains(res, "<dd>%s</dd>" % share_net.neutron_net_id)
        self.assertNotContains(res,
                               "<dd>%s</dd>" % share_net.neutron_subnet_id)
        self.assertContains(res, "<a href=\"/project/shares/security_services"
                                 "/%s\">%s</a>" % (sec_service.id,
                                                   sec_service.name), 1, 200)
        self.assertNoMessages()
        api_manila.share_network_security_service_list.assert_called_once_with(
            mock.ANY, share_net.id)
        api_manila.share_server_list.assert_called_once_with(
            mock.ANY, search_opts={'share_network_id': share_net.id})
        api_manila.share_network_get.assert_called_once_with(
            mock.ANY, share_net.id)
        api.neutron.network_get.assert_called_once_with(
            mock.ANY, share_net.neutron_net_id)
        api.neutron.subnet_get.assert_called_once_with(
            mock.ANY, share_net.neutron_subnet_id)

    def test_update_share_network(self):
        share_net = test_data.inactive_share_network
        formData = {
            'method': 'UpdateForm',
            'name': share_net.name,
            'description': share_net.description,
        }
        url = reverse('horizon:project:shares:update_share_network',
                      args=[share_net.id])
        self.mock_object(api_manila, "share_network_update")
        self.mock_object(
            api_manila, "share_network_get", mock.Mock(return_value=share_net))
        self.mock_object(
            api_manila, "share_network_security_service_list",
            mock.Mock(return_value=[test_data.sec_service]))
        self.mock_object(
            api_manila, "security_service_list",
            mock.Mock(return_value=[test_data.sec_service]))
        self.mock_object(
            policy, 'check',
            mock.Mock(side_effect=(lambda *args, **kwargs: True)))

        res = self.client.post(url, formData)

        self.assertRedirectsNoFollow(res, SHARE_INDEX_URL)
        api_manila.share_network_security_service_list.assert_called_once_with(
            mock.ANY, share_net.id)
        api_manila.security_service_list.assert_has_calls([
            mock.call(mock.ANY),
            mock.call(mock.ANY, search_opts={'share_network_id': share_net.id})
        ])
        api_manila.share_network_get.assert_called_once_with(
            mock.ANY, share_net.id)
        api_manila.share_network_update.assert_called_once_with(
            mock.ANY,
            share_net.id,
            name=formData['name'],
            description=formData['description'])
        self.assertTrue(policy.check.called)