Read list of AZs using manila's API instead of nova's
Manila UI calls Nova API for getting list of availability zones, and it is incorrect for following reasons: - manila can work without nova - list of AZs can differ as nova services may be located in different zones. So, use for such case manila's API 'service list' that provides all required data. Depends-on: Ie7ff8234b5cd4a20d94148c7512b2d5cd621e190 Change-Id: Ib7935ecb24e250d0280e12ee706dbe6f985167e9 Closes-Bug: #1621721
This commit is contained in:
parent
8909d79a96
commit
7c90c46990
|
@ -28,13 +28,12 @@ import six
|
|||
from horizon import exceptions
|
||||
from horizon.utils.memoized import memoized # noqa
|
||||
from openstack_dashboard.api import base
|
||||
from openstack_dashboard.api import nova
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
MANILA_UI_USER_AGENT_REPR = "manila_ui_plugin_for_horizon"
|
||||
MANILA_VERSION = "2.22" # requires manilaclient 1.10.0 or newer
|
||||
MANILA_VERSION = "2.22" # requires manilaclient 1.12.0 or newer
|
||||
MANILA_SERVICE_TYPE = "sharev2"
|
||||
|
||||
# API static values
|
||||
|
@ -405,14 +404,6 @@ def share_replica_resync(request, replica):
|
|||
return manilaclient(request).share_replicas.resync(replica)
|
||||
|
||||
|
||||
def share_valid_availability_zones_for_new_replica(request):
|
||||
availability_zones = (
|
||||
set([az.zoneName
|
||||
for az in nova.availability_zone_list(request)])
|
||||
)
|
||||
return availability_zones
|
||||
|
||||
|
||||
def tenant_absolute_limits(request):
|
||||
limits = manilaclient(request).limits.get().absolute
|
||||
limits_dict = {}
|
||||
|
@ -433,6 +424,10 @@ def share_instance_get(request, share_instance_id):
|
|||
return manilaclient(request).share_instances.get(share_instance_id)
|
||||
|
||||
|
||||
def availability_zone_list(request):
|
||||
return manilaclient(request).availability_zones.list()
|
||||
|
||||
|
||||
@memoized
|
||||
def is_replication_enabled():
|
||||
manila_config = getattr(settings, 'OPENSTACK_MANILA_FEATURES', {})
|
||||
|
|
|
@ -36,11 +36,9 @@ class CreateReplicaForm(forms.SelfHandlingForm):
|
|||
self.fields['share_id'] = forms.CharField(widget=forms.HiddenInput(),
|
||||
initial=share_id)
|
||||
|
||||
availability_zones = (
|
||||
manila.share_valid_availability_zones_for_new_replica(request))
|
||||
|
||||
availability_zones = manila.availability_zone_list(request)
|
||||
self.fields['availability_zone'].choices = (
|
||||
[(az, az) for az in availability_zones])
|
||||
[(az.name, az.name) for az in availability_zones])
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
|
|
|
@ -26,7 +26,6 @@ from horizon.utils.memoized import memoized # noqa
|
|||
|
||||
from manila_ui.api import manila
|
||||
from manila_ui.dashboards import utils
|
||||
from openstack_dashboard.api import nova
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
|
||||
|
@ -52,10 +51,10 @@ class CreateForm(forms.SelfHandlingForm):
|
|||
share_types = manila.share_type_list(request)
|
||||
self.fields['share_type'].choices = (
|
||||
[("", "")] + [(st.name, st.name) for st in share_types])
|
||||
availability_zones = nova.availability_zone_list(request)
|
||||
|
||||
availability_zones = manila.availability_zone_list(request)
|
||||
self.fields['availability_zone'].choices = (
|
||||
[("", "")] +
|
||||
[(az.zoneName, az.zoneName) for az in availability_zones])
|
||||
[("", "")] + [(az.name, az.name) for az in availability_zones])
|
||||
|
||||
self.sn_field_name_prefix = 'share-network-choices-'
|
||||
for st in share_types:
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# under the License.
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
|
||||
from manila_ui.api import manila as api
|
||||
from manila_ui.tests import helpers as base
|
||||
|
@ -200,23 +199,6 @@ class ManilaApiTests(base.APITestCase):
|
|||
mock_reset_state = self.manilaclient.share_replicas.reset_replica_state
|
||||
mock_reset_state.assert_called_once_with(replica, state)
|
||||
|
||||
def test_share_valid_availability_zones_for_new_replica(self):
|
||||
availability_zones = [
|
||||
type("FakeAZ", (object,), {"zoneName": zone_name})
|
||||
for zone_name in ("foo", "bar", "quuz")
|
||||
]
|
||||
self.mock_object(
|
||||
api.nova,
|
||||
"availability_zone_list",
|
||||
mock.Mock(return_value=availability_zones))
|
||||
expected = {"foo", "bar", "quuz"}
|
||||
|
||||
result = api.share_valid_availability_zones_for_new_replica(
|
||||
self.request)
|
||||
|
||||
self.assertEqual(expected, result)
|
||||
api.nova.availability_zone_list.assert_called_once_with(self.request)
|
||||
|
||||
def test_migration_start(self):
|
||||
api.migration_start(self.request, 'fake_share', 'fake_host', False,
|
||||
True, True, False, 'fake_net_id', 'fake_type_id')
|
||||
|
@ -249,3 +231,8 @@ class ManilaApiTests(base.APITestCase):
|
|||
|
||||
(self.manilaclient.shares.migration_get_progress.
|
||||
assert_called_once_with('fake_share'))
|
||||
|
||||
def test_availability_zone_list(self):
|
||||
api.availability_zone_list(self.request)
|
||||
|
||||
self.manilaclient.availability_zones.list.assert_called_once_with()
|
||||
|
|
|
@ -21,16 +21,10 @@ from manila_ui.tests.dashboards.project.shares import test_data
|
|||
from manila_ui.tests import helpers as test
|
||||
|
||||
from openstack_dashboard.api import neutron
|
||||
from openstack_dashboard.api import nova
|
||||
|
||||
SHARE_INDEX_URL = reverse('horizon:admin:shares:index')
|
||||
|
||||
|
||||
class FakeAZ(object):
|
||||
def __init__(self, name):
|
||||
self.zoneName = name
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class ReplicasTests(test.BaseAdminViewTests):
|
||||
|
||||
|
@ -98,12 +92,6 @@ class ReplicasTests(test.BaseAdminViewTests):
|
|||
self.assertFalse(api_manila.share_instance_export_location_list.called)
|
||||
|
||||
def test_list(self):
|
||||
old_az = self.share.availability_zone
|
||||
new_az = old_az + "_new"
|
||||
self.mock_object(
|
||||
nova,
|
||||
"availability_zone_list",
|
||||
mock.Mock(return_value=[FakeAZ(new_az), FakeAZ(old_az)]))
|
||||
self.mock_object(
|
||||
api_manila,
|
||||
"share_replica_list",
|
||||
|
@ -121,12 +109,6 @@ class ReplicasTests(test.BaseAdminViewTests):
|
|||
mock.ANY, self.share.id)
|
||||
|
||||
def test_list_exception(self):
|
||||
old_az = self.share.availability_zone
|
||||
new_az = old_az + "_new"
|
||||
self.mock_object(
|
||||
nova,
|
||||
"availability_zone_list",
|
||||
mock.Mock(return_value=[FakeAZ(new_az), FakeAZ(old_az)]))
|
||||
self.mock_object(
|
||||
api_manila,
|
||||
"share_replica_list",
|
||||
|
|
|
@ -20,14 +20,13 @@ from manila_ui.tests.dashboards.project.shares import test_data
|
|||
from manila_ui.tests import helpers as test
|
||||
|
||||
from openstack_dashboard.api import neutron
|
||||
from openstack_dashboard.api import nova
|
||||
|
||||
SHARE_INDEX_URL = reverse('horizon:project:shares:index')
|
||||
|
||||
|
||||
class FakeAZ(object):
|
||||
def __init__(self, name):
|
||||
self.zoneName = name
|
||||
self.name = name
|
||||
|
||||
|
||||
class ReplicasTests(test.TestCase):
|
||||
|
@ -48,15 +47,14 @@ class ReplicasTests(test.TestCase):
|
|||
new_az = old_az + "_new"
|
||||
self.mock_object(api_manila, "share_replica_create")
|
||||
self.mock_object(
|
||||
nova,
|
||||
"availability_zone_list",
|
||||
api_manila, "availability_zone_list",
|
||||
mock.Mock(return_value=[FakeAZ(new_az), FakeAZ(old_az)]))
|
||||
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertEqual(200, res.status_code)
|
||||
self.assertFalse(api_manila.share_replica_create.called)
|
||||
nova.availability_zone_list.assert_called_once_with(mock.ANY)
|
||||
api_manila.availability_zone_list.assert_called_once_with(mock.ANY)
|
||||
self.assertNoMessages()
|
||||
self.assertTemplateUsed(
|
||||
res, "project/shares/replicas/create_replica.html")
|
||||
|
@ -71,8 +69,7 @@ class ReplicasTests(test.TestCase):
|
|||
"availability_zone": new_az,
|
||||
}
|
||||
self.mock_object(
|
||||
nova,
|
||||
"availability_zone_list",
|
||||
api_manila, "availability_zone_list",
|
||||
mock.Mock(return_value=[FakeAZ(new_az), FakeAZ(old_az)]))
|
||||
self.mock_object(
|
||||
api_manila,
|
||||
|
@ -86,7 +83,7 @@ class ReplicasTests(test.TestCase):
|
|||
mock.ANY, self.share.id, formData["availability_zone"])
|
||||
api_manila.share_replica_create.assert_called_once_with(
|
||||
mock.ANY, formData["share_id"], formData["availability_zone"])
|
||||
nova.availability_zone_list.assert_called_once_with(mock.ANY)
|
||||
api_manila.availability_zone_list.assert_called_once_with(mock.ANY)
|
||||
self.assertRedirectsNoFollow(
|
||||
res,
|
||||
reverse("horizon:project:shares:manage_replicas",
|
||||
|
@ -158,12 +155,6 @@ class ReplicasTests(test.TestCase):
|
|||
self.assertFalse(api_manila.share_instance_export_location_list.called)
|
||||
|
||||
def test_list(self):
|
||||
old_az = self.share.availability_zone
|
||||
new_az = old_az + "_new"
|
||||
self.mock_object(
|
||||
nova,
|
||||
"availability_zone_list",
|
||||
mock.Mock(return_value=[FakeAZ(new_az), FakeAZ(old_az)]))
|
||||
self.mock_object(
|
||||
api_manila,
|
||||
"share_replica_list",
|
||||
|
@ -181,12 +172,6 @@ class ReplicasTests(test.TestCase):
|
|||
mock.ANY, self.share.id)
|
||||
|
||||
def test_list_exception(self):
|
||||
old_az = self.share.availability_zone
|
||||
new_az = old_az + "_new"
|
||||
self.mock_object(
|
||||
nova,
|
||||
"availability_zone_list",
|
||||
mock.Mock(return_value=[FakeAZ(new_az), FakeAZ(old_az)]))
|
||||
self.mock_object(
|
||||
api_manila,
|
||||
"share_replica_list",
|
||||
|
|
|
@ -23,7 +23,6 @@ from manila_ui.tests import helpers as test
|
|||
|
||||
from openstack_dashboard.api import base
|
||||
from openstack_dashboard.api import neutron
|
||||
from openstack_dashboard.api import nova
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
SHARE_INDEX_URL = reverse('horizon:project:shares:index')
|
||||
|
@ -47,7 +46,7 @@ class ShareViewTests(test.TestCase):
|
|||
|
||||
class FakeAZ(object):
|
||||
def __init__(self, name):
|
||||
self.zoneName = name
|
||||
self.name = name
|
||||
|
||||
def setUp(self):
|
||||
super(ShareViewTests, self).setUp()
|
||||
|
@ -60,7 +59,7 @@ class ShareViewTests(test.TestCase):
|
|||
self.mock_object(
|
||||
api_manila, "share_get", mock.Mock(return_value=self.share))
|
||||
|
||||
@mock.patch.object(nova, 'availability_zone_list')
|
||||
@mock.patch.object(api_manila, 'availability_zone_list')
|
||||
def test_create_share(self, az_list):
|
||||
url = reverse('horizon:project:shares:create')
|
||||
share = test_data.share
|
||||
|
@ -102,7 +101,7 @@ class ShareViewTests(test.TestCase):
|
|||
api_manila.share_network_list.assert_called_once_with(mock.ANY)
|
||||
api_manila.share_type_list.assert_called_once_with(mock.ANY)
|
||||
|
||||
@mock.patch.object(nova, 'availability_zone_list')
|
||||
@mock.patch.object(api_manila, 'availability_zone_list')
|
||||
def test_create_share_from_snapshot(self, mock_az_list):
|
||||
share = test_data.share
|
||||
share_net = test_data.active_share_network
|
||||
|
|
Loading…
Reference in New Issue