From efa179d229a1c0de991f5a1cc288aaa3c7c9e2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A1=C2=A1Jing=20Sun?= Date: Thu, 14 Jul 2016 15:14:33 +0800 Subject: [PATCH] remove useless api test files Change-Id: I7b84530de5ef4f69c3e66e0e6dea7694f011abbb --- .../test/api_tests/ceilometer_tests.py | 320 ----- .../test/api_tests/cinder_rest_tests.py | 79 -- .../test/api_tests/cinder_tests.py | 179 --- .../test/api_tests/fwaas_tests.py | 428 ------ .../test/api_tests/glance_rest_tests.py | 94 -- .../test/api_tests/glance_tests.py | 249 ---- .../test/api_tests/heat_tests.py | 213 --- .../test/api_tests/lbaas_tests.py | 376 ------ .../test/api_tests/network_rest_tests.py | 33 - .../test/api_tests/network_tests.py | 778 ----------- .../test/api_tests/neutron_rest_tests.py | 134 -- .../test/api_tests/neutron_tests.py | 428 ------ .../test/api_tests/nova_rest_tests.py | 272 ---- .../test/api_tests/nova_tests.py | 349 ----- .../test/api_tests/swift_tests.py | 229 ---- .../test/api_tests/vpnaas_tests.py | 293 ----- .../test/test_data/ceilometer_data.py | 224 ---- .../test/test_data/cinder_data.py | 316 ----- .../test/test_data/exceptions.py | 36 +- .../test/test_data/glance_data.py | 321 ----- .../test/test_data/heat_data.py | 463 ------- .../test/test_data/neutron_data.py | 1162 ----------------- .../test/test_data/nova_data.py | 803 ------------ .../test/test_data/sahara_data.py | 499 ------- .../test/test_data/swift_data.py | 99 -- .../test/test_data/trove_data.py | 219 ---- .../test/test_data/utils.py | 36 +- 27 files changed, 19 insertions(+), 8613 deletions(-) delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/ceilometer_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/cinder_rest_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/cinder_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/fwaas_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/glance_rest_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/glance_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/heat_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/lbaas_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/network_rest_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/network_tests.py delete mode 100755 code/horizon/openstack_dashboard/test/api_tests/neutron_rest_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/neutron_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/nova_rest_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/nova_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/swift_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/api_tests/vpnaas_tests.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/ceilometer_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/cinder_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/glance_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/heat_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/neutron_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/nova_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/sahara_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/swift_data.py delete mode 100644 code/horizon/openstack_dashboard/test/test_data/trove_data.py diff --git a/code/horizon/openstack_dashboard/test/api_tests/ceilometer_tests.py b/code/horizon/openstack_dashboard/test/api_tests/ceilometer_tests.py deleted file mode 100644 index 5902c006..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/ceilometer_tests.py +++ /dev/null @@ -1,320 +0,0 @@ -# Copyright 2012 Canonical Ltd. -# -# 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 import http - -from mox import IsA # noqa - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test - - -class CeilometerApiTests(test.APITestCase): - def test_sample_list(self): - samples = self.samples.list() - meter_name = "meter_name" - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.samples = self.mox.CreateMockAnything() - ceilometerclient.samples.list(meter_name=meter_name, q=[]).\ - AndReturn(samples) - self.mox.ReplayAll() - - ret_list = api.ceilometer.sample_list(self.request, - meter_name, - query=[]) - for c in ret_list: - self.assertIsInstance(c, api.ceilometer.Sample) - - def test_meter_list(self): - meters = self.meters.list() - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.meters = self.mox.CreateMockAnything() - ceilometerclient.meters.list([]).AndReturn(meters) - self.mox.ReplayAll() - - ret_list = api.ceilometer.meter_list(self.request, []) - for m in ret_list: - self.assertIsInstance(m, api.ceilometer.Meter) - - def test_resource_list(self): - resources = self.resources.list() - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.resources = self.mox.CreateMockAnything() - ceilometerclient.resources.list(q=[]).AndReturn(resources) - self.mox.ReplayAll() - - ret_list = api.ceilometer.resource_list(self.request, query=[]) - for r in ret_list: - self.assertIsInstance(r, api.ceilometer.Resource) - - def test_statistic_list(self): - statistics = self.statistics.list() - meter_name = "meter_name" - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.statistics = self.mox.CreateMockAnything() - ceilometerclient.statistics.list(meter_name=meter_name, - period=None, q=[]).\ - AndReturn(statistics) - self.mox.ReplayAll() - - ret_list = api.ceilometer.statistic_list(self.request, - meter_name, - period=None, - query=[]) - for s in ret_list: - self.assertIsInstance(s, api.ceilometer.Statistic) - - @test.create_stubs({api.nova: ('flavor_list',), - }) - def test_meters_list_all(self): - meters = self.meters.list() - - request = self.mox.CreateMock(http.HttpRequest) - api.nova.flavor_list(request, None).AndReturn([]) - - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.meters = self.mox.CreateMockAnything() - ceilometerclient.meters.list(None).AndReturn(meters) - - self.mox.ReplayAll() - - meters_object = api.ceilometer.Meters(self.request) - - ret_list = meters_object.list_all() - - for m in ret_list: - self.assertIsInstance(m, api.ceilometer.Meter) - - self.assertEqual(3, len(ret_list)) - - names = ["disk.read.bytes", "disk.write.bytes", "instance"] - for ret in ret_list: - self.assertIn(ret.name, names) - names.remove(ret.name) - - @test.create_stubs({api.nova: ('flavor_list',), - }) - def test_meters_list_all_only(self): - meters = self.meters.list() - - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.meters = self.mox.CreateMockAnything() - ceilometerclient.meters.list(None).AndReturn(meters) - - request = self.mox.CreateMock(http.HttpRequest) - api.nova.flavor_list(request, None).AndReturn([]) - self.mox.ReplayAll() - - meters_object = api.ceilometer.Meters(self.request) - ret_list = meters_object.list_all(only_meters=["disk.read.bytes"]) - - self.assertEqual(1, len(ret_list)) - self.assertEqual("disk.read.bytes", ret_list[0].name) - - ret_list = meters_object.list_all(only_meters=["disk.read.bytes", - "instance"]) - - self.assertEqual(2, len(ret_list)) - self.assertEqual("disk.read.bytes", ret_list[0].name) - self.assertEqual("instance", ret_list[1].name) - - @test.create_stubs({api.nova: ('flavor_list',), - }) - def test_meters_list_all_except(self): - meters = self.meters.list() - - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.meters = self.mox.CreateMockAnything() - ceilometerclient.meters.list(None).AndReturn(meters) - - request = self.mox.CreateMock(http.HttpRequest) - api.nova.flavor_list(request, None).AndReturn([]) - self.mox.ReplayAll() - - meters_object = api.ceilometer.Meters(self.request) - ret_list = meters_object.list_all(except_meters=["disk.write.bytes", - "instance"]) - - self.assertEqual(1, len(ret_list)) - self.assertEqual("disk.read.bytes", ret_list[0].name) - - ret_list = meters_object.list_all(except_meters=["disk.write.bytes"]) - - self.assertEqual(len(ret_list), 2) - names = ["disk.read.bytes", "instance"] - - for ret in ret_list: - self.assertIn(ret.name, names) - names.remove(ret.name) - - # TODO(lsmola) Test resource aggregates. - - @test.create_stubs({api.ceilometer.CeilometerUsage: ("get_user", - "get_tenant")}) - def test_global_data_get(self): - class TempUsage(api.base.APIResourceWrapper): - _attrs = ["id", "tenant", "user", "resource", "get_meter"] - - meters = ["fake_meter_1", - "fake_meter_2"] - - default_query = ["Fake query"] - stats_attr = "max" - - resources = self.resources.list() - statistics = self.statistics.list() - user = self.ceilometer_users.list()[0] - tenant = self.ceilometer_tenants.list()[0] - - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.resources = self.mox.CreateMockAnything() - # I am returning only 1 resource - ceilometerclient.resources.list(q=IsA(list)).AndReturn(resources[:1]) - - ceilometerclient.statistics = self.mox.CreateMockAnything() - # check that list is called twice for one resource and 2 meters - ceilometerclient.statistics.list(meter_name=IsA(str), - period=None, q=IsA(list)).\ - AndReturn(statistics) - ceilometerclient.statistics.list(meter_name=IsA(str), - period=None, q=IsA(list)).\ - AndReturn(statistics) - - api.ceilometer.CeilometerUsage\ - .get_user(IsA(str)).AndReturn(user) - api.ceilometer.CeilometerUsage\ - .get_tenant(IsA(str)).AndReturn(tenant) - - self.mox.ReplayAll() - - # getting all resources and with statistics - ceilometer_usage = api.ceilometer.CeilometerUsage(http.HttpRequest) - data = ceilometer_usage.global_data_get( - used_cls=TempUsage, query=["fake_query"], with_statistics=True) - - first = data[0] - self.assertEqual('fake_project_id__fake_user_id__' - 'fake_resource_id', - first.id) - self.assertEqual('user', first.user.name) - self.assertEqual('test_tenant', first.tenant.name) - self.assertEqual('fake_resource_id', first.resource) - self.assertEqual(9, first.get_meter('fake_meter_1'),) - self.assertEqual(9, first.get_meter('fake_meter_2'),) - self.assertEqual(2, len(first.meters)) - # check that only one resource is returned - self.assertEqual(1, len(data)) - - @test.create_stubs({api.ceilometer.CeilometerUsage: ("get_user", - "get_tenant")}) - def test_global_data_get_without_statistic_data(self): - class TempUsage(api.base.APIResourceWrapper): - _attrs = ["id", "tenant", "user", "resource", "fake_meter_1", - "fake_meter_2"] - - meters = ["fake_meter_1", - "fake_meter_2"] - - default_query = ["Fake query"] - stats_attr = "max" - - resources = self.resources.list() - user = self.ceilometer_users.list()[0] - tenant = self.ceilometer_tenants.list()[0] - - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.resources = self.mox.CreateMockAnything() - ceilometerclient.resources.list(q=IsA(list)).AndReturn(resources) - - api.ceilometer.CeilometerUsage\ - .get_user(IsA(str)).MultipleTimes().AndReturn(user) - api.ceilometer.CeilometerUsage\ - .get_tenant(IsA(str)).MultipleTimes().AndReturn(tenant) - - self.mox.ReplayAll() - - # getting all resources and with statistics - ceilometer_usage = api.ceilometer.CeilometerUsage(http.HttpRequest) - data = ceilometer_usage.global_data_get( - used_cls=TempUsage, query=["fake_query"], with_statistics=False) - - first = data[0] - self.assertEqual('fake_project_id__fake_user_id__' - 'fake_resource_id', - first.id) - self.assertEqual('user', first.user.name) - self.assertEqual('test_tenant', first.tenant.name) - self.assertEqual('fake_resource_id', first.resource) - - self.assertRaises(AttributeError, getattr, first, 'fake_meter_1') - self.assertRaises(AttributeError, getattr, first, 'fake_meter_2') - - self.assertEqual(len(resources), len(data)) - - @test.create_stubs({api.ceilometer.CeilometerUsage: ("get_user", - "get_tenant")}) - def test_global_data_get_all_statistic_data(self): - class TempUsage(api.base.APIResourceWrapper): - _attrs = ["id", "tenant", "user", "resource", "get_meter", ] - - meters = ["fake_meter_1", - "fake_meter_2"] - - default_query = ["Fake query"] - stats_attr = None # have to return dictionary with all stats - - resources = self.resources.list() - - statistics = self.statistics.list() - user = self.ceilometer_users.list()[0] - tenant = self.ceilometer_tenants.list()[0] - - ceilometerclient = self.stub_ceilometerclient() - ceilometerclient.resources = self.mox.CreateMockAnything() - ceilometerclient.resources.list(q=IsA(list)).AndReturn(resources) - - ceilometerclient.statistics = self.mox.CreateMockAnything() - ceilometerclient.statistics.list(meter_name=IsA(str), - period=None, q=IsA(list)).\ - MultipleTimes().\ - AndReturn(statistics) - - api.ceilometer.CeilometerUsage\ - .get_user(IsA(str)).MultipleTimes().AndReturn(user) - api.ceilometer.CeilometerUsage\ - .get_tenant(IsA(str)).MultipleTimes().AndReturn(tenant) - - self.mox.ReplayAll() - - # getting all resources and with statistics - ceilometer_usage = api.ceilometer.CeilometerUsage(http.HttpRequest) - data = ceilometer_usage.global_data_get( - used_cls=TempUsage, query=["fake_query"], with_statistics=True) - - first = data[0] - self.assertEqual('fake_project_id__fake_user_id__' - 'fake_resource_id', - first.id) - self.assertEqual('user', first.user.name) - self.assertEqual('test_tenant', first.tenant.name) - self.assertEqual('fake_resource_id', first.resource) - - statistic_obj = api.ceilometer.Statistic(statistics[0]) - # check that it returns whole statistic object - self.assertEqual(vars(first.get_meter('fake_meter_1')[0]), - vars(statistic_obj)) - self.assertEqual(vars(first.get_meter('fake_meter_2')[0]), - vars(statistic_obj)) - - self.assertEqual(len(resources), len(data)) diff --git a/code/horizon/openstack_dashboard/test/api_tests/cinder_rest_tests.py b/code/horizon/openstack_dashboard/test/api_tests/cinder_rest_tests.py deleted file mode 100644 index bbda2695..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/cinder_rest_tests.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright 2015 IBM Corp. -# -# 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. -import mock - -from openstack_dashboard.api.rest import cinder -from openstack_dashboard.test import helpers as test - - -class CinderRestTestCase(test.TestCase): - def test_volumes_get(self): - self._test_volumes_get(False, {}) - - def test_volumes_get_all(self): - self._test_volumes_get(True, {}) - - def test_volumes_get_with_filters(self): - filters = {'status': 'available'} - self._test_volumes_get(False, filters) - - @mock.patch.object(cinder.api, 'cinder') - def _test_volumes_get(self, all, filters, cc): - if all: - request = self.mock_rest_request(GET={'all_projects': 'true'}) - else: - request = self.mock_rest_request(**{'GET': filters}) - cc.volume_list.return_value = [ - mock.Mock(**{'to_dict.return_value': {'id': 'one'}}), - mock.Mock(**{'to_dict.return_value': {'id': 'two'}}), - ] - response = cinder.Volumes().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"id": "one"}, {"id": "two"}]}') - if all: - cc.volume_list.assert_called_once_with(request, - {'all_tenants': 1}) - else: - cc.volume_list.assert_called_once_with(request, - search_opts=filters) - - @mock.patch.object(cinder.api, 'cinder') - def test_volume_snaps_get(self, cc): - request = self.mock_rest_request(**{'GET': {}}) - cc.volume_snapshot_list.return_value = [ - mock.Mock(**{'to_dict.return_value': {'id': 'one'}}), - mock.Mock(**{'to_dict.return_value': {'id': 'two'}}), - ] - response = cinder.VolumeSnapshots().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"id": "one"}, {"id": "two"}]}') - cc.volume_snapshot_list.assert_called_once_with(request, - search_opts={}) - - @mock.patch.object(cinder.api, 'cinder') - def test_volume_snaps_get_with_filters(self, cc): - filters = {'status': 'available'} - request = self.mock_rest_request(**{'GET': dict(filters)}) - cc.volume_snapshot_list.return_value = [ - mock.Mock(**{'to_dict.return_value': {'id': 'one'}}), - mock.Mock(**{'to_dict.return_value': {'id': 'two'}}), - ] - response = cinder.VolumeSnapshots().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"id": "one"}, {"id": "two"}]}') - cc.volume_snapshot_list.assert_called_once_with(request, - search_opts=filters) diff --git a/code/horizon/openstack_dashboard/test/api_tests/cinder_tests.py b/code/horizon/openstack_dashboard/test/api_tests/cinder_tests.py deleted file mode 100644 index abb92c52..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/cinder_tests.py +++ /dev/null @@ -1,179 +0,0 @@ -# Copyright 2012 Red Hat, 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.test.utils import override_settings -import six - -import cinderclient as cinder_client - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test - - -class CinderApiTests(test.APITestCase): - - def test_volume_list(self): - search_opts = {'all_tenants': 1} - detailed = True - volumes = self.cinder_volumes.list() - volume_transfers = self.cinder_volume_transfers.list() - cinderclient = self.stub_cinderclient() - cinderclient.volumes = self.mox.CreateMockAnything() - cinderclient.volumes.list(search_opts=search_opts,).AndReturn(volumes) - cinderclient.transfers = self.mox.CreateMockAnything() - cinderclient.transfers.list( - detailed=detailed, - search_opts=search_opts,).AndReturn(volume_transfers) - self.mox.ReplayAll() - - # No assertions are necessary. Verification is handled by mox. - api.cinder.volume_list(self.request, search_opts=search_opts) - - def test_volume_snapshot_list(self): - search_opts = {'all_tenants': 1} - volume_snapshots = self.cinder_volume_snapshots.list() - cinderclient = self.stub_cinderclient() - cinderclient.volume_snapshots = self.mox.CreateMockAnything() - cinderclient.volume_snapshots.list(search_opts=search_opts).\ - AndReturn(volume_snapshots) - self.mox.ReplayAll() - - api.cinder.volume_snapshot_list(self.request, search_opts=search_opts) - - def test_volume_snapshot_list_no_volume_configured(self): - # remove volume from service catalog - catalog = self.service_catalog - for service in catalog: - if service["type"] == "volume": - self.service_catalog.remove(service) - search_opts = {'all_tenants': 1} - volume_snapshots = self.cinder_volume_snapshots.list() - - cinderclient = self.stub_cinderclient() - cinderclient.volume_snapshots = self.mox.CreateMockAnything() - cinderclient.volume_snapshots.list(search_opts=search_opts).\ - AndReturn(volume_snapshots) - self.mox.ReplayAll() - - api.cinder.volume_snapshot_list(self.request, search_opts=search_opts) - - def test_volume_type_list_with_qos_associations(self): - volume_types = self.cinder_volume_types.list() - # Due to test data limitations, we can only run this test using - # one qos spec, which is associated with one volume type. - # If we use multiple qos specs, the test data will always - # return the same associated volume type, which is invalid - # and prevented by the UI. - qos_specs_full = self.cinder_qos_specs.list() - qos_specs_only_one = [qos_specs_full[0]] - associations = self.cinder_qos_spec_associations.list() - - cinderclient = self.stub_cinderclient() - cinderclient.volume_types = self.mox.CreateMockAnything() - cinderclient.volume_types.list().AndReturn(volume_types) - cinderclient.qos_specs = self.mox.CreateMockAnything() - cinderclient.qos_specs.list().AndReturn(qos_specs_only_one) - cinderclient.qos_specs.get_associations = self.mox.CreateMockAnything() - cinderclient.qos_specs.get_associations(qos_specs_only_one[0].id).\ - AndReturn(associations) - self.mox.ReplayAll() - - assoc_vol_types = \ - api.cinder.volume_type_list_with_qos_associations(self.request) - associate_spec = assoc_vol_types[0].associated_qos_spec - self.assertTrue(associate_spec, qos_specs_only_one[0].name) - - def test_absolute_limits_with_negative_values(self): - values = {"maxTotalVolumes": -1, "totalVolumesUsed": -1} - expected_results = {"maxTotalVolumes": float("inf"), - "totalVolumesUsed": 0} - - limits = self.mox.CreateMockAnything() - limits.absolute = [] - for key, val in six.iteritems(values): - limit = self.mox.CreateMockAnything() - limit.name = key - limit.value = val - limits.absolute.append(limit) - - cinderclient = self.stub_cinderclient() - cinderclient.limits = self.mox.CreateMockAnything() - cinderclient.limits.get().AndReturn(limits) - self.mox.ReplayAll() - - ret_val = api.cinder.tenant_absolute_limits(self.request) - for key in expected_results.keys(): - self.assertEqual(expected_results[key], ret_val[key]) - - -class CinderApiVersionTests(test.TestCase): - - def setUp(self): - super(CinderApiVersionTests, self).setUp() - # The version is set when the module is loaded. Reset the - # active version each time so that we can test with different - # versions. - api.cinder.VERSIONS._active = None - - def test_default_client_is_v2(self): - client = api.cinder.cinderclient(self.request) - self.assertIsInstance(client, cinder_client.v2.client.Client) - - @override_settings(OPENSTACK_API_VERSIONS={'volume': 2}) - def test_v2_setting_returns_v2_client(self): - client = api.cinder.cinderclient(self.request) - self.assertIsInstance(client, cinder_client.v2.client.Client) - - def test_get_v2_volume_attributes(self): - # Get a v2 volume - volume = self.cinder_volumes.get(name="v2_volume") - self.assertTrue(hasattr(volume._apiresource, 'name')) - self.assertFalse(hasattr(volume._apiresource, 'display_name')) - - name = "A v2 test volume name" - description = "A v2 volume description" - setattr(volume._apiresource, 'name', name) - setattr(volume._apiresource, 'description', description) - self.assertEqual(name, volume.name) - self.assertEqual(description, volume.description) - - def test_get_v2_snapshot_attributes(self): - # Get a v2 snapshot - snapshot = self.cinder_volume_snapshots.get( - description="v2 volume snapshot description") - self.assertFalse(hasattr(snapshot._apiresource, 'display_name')) - - name = "A v2 test snapshot name" - description = "A v2 snapshot description" - setattr(snapshot._apiresource, 'name', name) - setattr(snapshot._apiresource, 'description', description) - self.assertEqual(name, snapshot.name) - self.assertEqual(description, snapshot.description) - - def test_get_id_for_nameless_volume(self): - volume = self.cinder_volumes.first() - setattr(volume._apiresource, 'display_name', "") - self.assertEqual(volume.id, volume.name) - - def test_adapt_dictionary_to_v2(self): - volume = self.cinder_volumes.first() - data = {'name': volume.name, - 'description': volume.description, - 'size': volume.size} - - ret_data = api.cinder._replace_v2_parameters(data) - self.assertIn('name', ret_data.keys()) - self.assertIn('description', ret_data.keys()) - self.assertNotIn('display_name', ret_data.keys()) - self.assertNotIn('display_description', ret_data.keys()) diff --git a/code/horizon/openstack_dashboard/test/api_tests/fwaas_tests.py b/code/horizon/openstack_dashboard/test/api_tests/fwaas_tests.py deleted file mode 100644 index 8855bd4a..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/fwaas_tests.py +++ /dev/null @@ -1,428 +0,0 @@ -# Copyright 2013, Big Switch Networks, 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 openstack_dashboard import api -from openstack_dashboard.test import helpers as test - -from neutronclient.v2_0.client import Client as neutronclient # noqa - - -class FwaasApiTests(test.APITestCase): - @test.create_stubs({neutronclient: ('create_firewall_rule',)}) - def test_rule_create(self): - rule1 = self.fw_rules.first() - rule1_dict = self.api_fw_rules.first() - form_data = {'name': rule1.name, - 'description': rule1.description, - 'protocol': rule1.protocol, - 'action': rule1.action, - 'source_ip_address': rule1.source_ip_address, - 'source_port': rule1.source_port, - 'destination_ip_address': rule1.destination_ip_address, - 'destination_port': rule1.destination_port, - 'shared': rule1.shared, - 'enabled': rule1.enabled - } - form_dict = {'firewall_rule': form_data} - ret_dict = {'firewall_rule': rule1_dict} - neutronclient.create_firewall_rule(form_dict).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.rule_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.fwaas.Rule) - self.assertEqual(rule1.name, ret_val.name) - self.assertTrue(ret_val.id) - - def _assert_rule_return_value(self, ret_val, exp_rule): - self.assertIsInstance(ret_val, api.fwaas.Rule) - self.assertEqual(exp_rule.name, ret_val.name) - self.assertTrue(ret_val.id) - if exp_rule.policy: - self.assertEqual(exp_rule.firewall_policy_id, ret_val.policy.id) - self.assertEqual(exp_rule.policy.name, ret_val.policy.name) - else: - self.assertIsNone(ret_val.policy) - - @test.create_stubs({neutronclient: ('list_firewall_rules', - 'list_firewall_policies')}) - def test_rule_list(self): - exp_rules = self.fw_rules.list() - api_rules = {'firewall_rules': self.api_fw_rules.list()} - api_policies = {'firewall_policies': self.api_fw_policies.list()} - - neutronclient.list_firewall_rules().AndReturn(api_rules) - neutronclient.list_firewall_policies().AndReturn(api_policies) - self.mox.ReplayAll() - - ret_val = api.fwaas.rule_list(self.request) - for (v, d) in zip(ret_val, exp_rules): - self._assert_rule_return_value(v, d) - - @test.create_stubs({neutronclient: ('list_firewall_rules', - 'list_firewall_policies')}) - def test_rule_list_for_tenant(self): - tenant_id = self.request.user.project_id - exp_rules = self.fw_rules.list() - api_rules = {'firewall_rules': self.api_fw_rules.list()} - api_policies = {'firewall_policies': self.api_fw_policies.list()} - - neutronclient.list_firewall_rules( - tenant_id=tenant_id, - shared=False).AndReturn({'firewall_rules': []}) - neutronclient.list_firewall_rules(shared=True) \ - .AndReturn(api_rules) - neutronclient.list_firewall_policies().AndReturn(api_policies) - self.mox.ReplayAll() - - ret_val = api.fwaas.rule_list_for_tenant(self.request, tenant_id) - for (v, d) in zip(ret_val, exp_rules): - self._assert_rule_return_value(v, d) - - @test.create_stubs({neutronclient: ('show_firewall_rule', - 'show_firewall_policy')}) - def test_rule_get(self): - exp_rule = self.fw_rules.first() - ret_dict = {'firewall_rule': self.api_fw_rules.first()} - policy_dict = {'firewall_policy': self.api_fw_policies.first()} - - neutronclient.show_firewall_rule(exp_rule.id).AndReturn(ret_dict) - neutronclient.show_firewall_policy( - exp_rule.firewall_policy_id).AndReturn(policy_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.rule_get(self.request, exp_rule.id) - self._assert_rule_return_value(ret_val, exp_rule) - - @test.create_stubs({neutronclient: ('update_firewall_rule',)}) - def test_rule_update(self): - rule = self.fw_rules.first() - rule_dict = self.api_fw_rules.first() - - rule.name = 'new name' - rule.description = 'new desc' - rule.protocol = 'icmp' - rule.action = 'deny' - rule.shared = True - rule.enabled = False - - rule_dict['name'] = 'new name' - rule_dict['description'] = 'new desc' - rule_dict['protocol'] = 'icmp' - rule_dict['action'] = 'deny' - rule_dict['shared'] = True - rule_dict['enabled'] = False - - form_data = {'name': rule.name, - 'description': rule.description, - 'protocol': rule.protocol, - 'action': rule.action, - 'shared': rule.shared, - 'enabled': rule.enabled - } - form_dict = {'firewall_rule': form_data} - ret_dict = {'firewall_rule': rule_dict} - - neutronclient.update_firewall_rule( - rule.id, form_dict).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.rule_update(self.request, - rule.id, **form_data) - self.assertIsInstance(ret_val, api.fwaas.Rule) - self.assertEqual(rule.name, ret_val.name) - self.assertTrue(ret_val.id) - - @test.create_stubs({neutronclient: ('create_firewall_policy', )}) - def test_policy_create(self): - policy1 = self.fw_policies.first() - policy1_dict = self.api_fw_policies.first() - - form_data = {'name': policy1.name, - 'description': policy1.description, - 'firewall_rules': policy1.firewall_rules, - 'shared': policy1.shared, - 'audited': policy1.audited - } - form_dict = {'firewall_policy': form_data} - ret_dict = {'firewall_policy': policy1_dict} - - neutronclient.create_firewall_policy(form_dict).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.fwaas.Policy) - self.assertEqual(policy1.name, ret_val.name) - self.assertTrue(ret_val.id) - - def _assert_policy_return_value(self, ret_val, exp_policy): - self.assertIsInstance(ret_val, api.fwaas.Policy) - self.assertEqual(exp_policy.name, ret_val.name) - self.assertTrue(ret_val.id) - self.assertEqual(len(exp_policy.firewall_rules), len(ret_val.rules)) - self.assertEqual(len(exp_policy.firewall_rules), - len(ret_val.firewall_rules)) - for (r, exp_r) in zip(ret_val.rules, exp_policy.rules): - self.assertEqual(exp_r.id, r.id) - - @test.create_stubs({neutronclient: ('list_firewall_policies', - 'list_firewall_rules')}) - def test_policy_list(self): - exp_policies = self.fw_policies.list() - policies_dict = {'firewall_policies': self.api_fw_policies.list()} - rules_dict = {'firewall_rules': self.api_fw_rules.list()} - - neutronclient.list_firewall_policies().AndReturn(policies_dict) - neutronclient.list_firewall_rules().AndReturn(rules_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_list(self.request) - for (v, d) in zip(ret_val, exp_policies): - self._assert_policy_return_value(v, d) - - @test.create_stubs({neutronclient: ('list_firewall_policies', - 'list_firewall_rules')}) - def test_policy_list_for_tenant(self): - tenant_id = self.request.user.project_id - exp_policies = self.fw_policies.list() - policies_dict = {'firewall_policies': self.api_fw_policies.list()} - rules_dict = {'firewall_rules': self.api_fw_rules.list()} - - neutronclient.list_firewall_policies( - tenant_id=tenant_id, - shared=False).AndReturn({'firewall_policies': []}) - neutronclient.list_firewall_policies( - shared=True).AndReturn(policies_dict) - neutronclient.list_firewall_rules().AndReturn(rules_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_list_for_tenant(self.request, tenant_id) - for (v, d) in zip(ret_val, exp_policies): - self._assert_policy_return_value(v, d) - - @test.create_stubs({neutronclient: ('show_firewall_policy', - 'list_firewall_rules')}) - def test_policy_get(self): - exp_policy = self.fw_policies.first() - policy_dict = self.api_fw_policies.first() - # The first two rules are associated with the first policy. - api_rules = self.api_fw_rules.list()[:2] - - ret_dict = {'firewall_policy': policy_dict} - neutronclient.show_firewall_policy(exp_policy.id).AndReturn(ret_dict) - filters = {'firewall_policy_id': exp_policy.id} - ret_dict = {'firewall_rules': api_rules} - neutronclient.list_firewall_rules(**filters).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_get(self.request, exp_policy.id) - self._assert_policy_return_value(ret_val, exp_policy) - - @test.create_stubs({neutronclient: ('show_firewall_policy',)}) - def test_policy_get_no_rule(self): - # 2nd policy is not associated with any rules. - exp_policy = self.fw_policies.list()[1] - policy_dict = self.api_fw_policies.list()[1] - - ret_dict = {'firewall_policy': policy_dict} - neutronclient.show_firewall_policy(exp_policy.id).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_get(self.request, exp_policy.id) - self.assertIsInstance(ret_val, api.fwaas.Policy) - self.assertEqual(exp_policy.name, ret_val.name) - self.assertTrue(ret_val.id) - self.assertFalse(len(ret_val.rules)) - - @test.create_stubs({neutronclient: ('update_firewall_policy',)}) - def test_policy_update(self): - policy = self.fw_policies.first() - policy_dict = self.api_fw_policies.first() - - policy.name = 'new name' - policy.description = 'new desc' - policy.shared = True - policy.audited = False - - policy_dict['name'] = 'new name' - policy_dict['description'] = 'new desc' - policy_dict['shared'] = True - policy_dict['audited'] = False - - form_data = {'name': policy.name, - 'description': policy.description, - 'shared': policy.shared, - 'audited': policy.audited - } - - form_dict = {'firewall_policy': form_data} - ret_dict = {'firewall_policy': policy_dict} - - neutronclient.update_firewall_policy( - policy.id, form_dict).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_update(self.request, - policy.id, **form_data) - self.assertIsInstance(ret_val, api.fwaas.Policy) - self.assertEqual(policy.name, ret_val.name) - self.assertTrue(ret_val.id) - - @test.create_stubs({neutronclient: ('firewall_policy_insert_rule',)}) - def test_policy_insert_rule(self): - policy = self.fw_policies.first() - policy_dict = self.api_fw_policies.first() - - new_rule_id = 'h0881d38-c3eb-4fee-9763-12de3338041d' - policy.firewall_rules.append(new_rule_id) - policy_dict['firewall_rules'].append(new_rule_id) - - body = {'firewall_rule_id': new_rule_id, - 'insert_before': policy.firewall_rules[1], - 'insert_after': policy.firewall_rules[0]} - - neutronclient.firewall_policy_insert_rule( - policy.id, body).AndReturn(policy_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_insert_rule(self.request, - policy.id, **body) - self.assertIn(new_rule_id, ret_val.firewall_rules) - - @test.create_stubs({neutronclient: ('firewall_policy_remove_rule',)}) - def test_policy_remove_rule(self): - policy = self.fw_policies.first() - policy_dict = self.api_fw_policies.first() - - remove_rule_id = policy.firewall_rules[0] - policy_dict['firewall_rules'].remove(remove_rule_id) - - body = {'firewall_rule_id': remove_rule_id} - - neutronclient.firewall_policy_remove_rule( - policy.id, body).AndReturn(policy_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.policy_remove_rule(self.request, - policy.id, **body) - self.assertNotIn(remove_rule_id, ret_val.firewall_rules) - - @test.create_stubs({neutronclient: ('create_firewall', )}) - def test_firewall_create(self): - firewall = self.firewalls.first() - firewall_dict = self.api_firewalls.first() - - form_data = {'name': firewall.name, - 'description': firewall.description, - 'firewall_policy_id': firewall.firewall_policy_id, - 'shared': firewall.shared, - 'admin_state_up': firewall.admin_state_up - } - - form_dict = {'firewall': form_data} - ret_dict = {'firewall': firewall_dict} - neutronclient.create_firewall(form_dict).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.firewall_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.fwaas.Firewall) - self.assertEqual(firewall.name, ret_val.name) - self.assertTrue(ret_val.id) - - def _assert_firewall_return_value(self, ret_val, exp_firewall): - self.assertIsInstance(ret_val, api.fwaas.Firewall) - self.assertEqual(exp_firewall.name, ret_val.name) - self.assertTrue(ret_val.id) - self.assertEqual(exp_firewall.firewall_policy_id, ret_val.policy.id) - self.assertEqual(exp_firewall.policy.name, ret_val.policy.name) - - # TODO(absubram) : Add API tests for firewall_create with routers, - # add router to firewal and remove router from fw. - - @test.create_stubs({neutronclient: ('list_firewalls', - 'list_firewall_policies')}) - def test_firewall_list(self): - exp_firewalls = self.firewalls.list() - firewalls_dict = {'firewalls': self.api_firewalls.list()} - policies_dict = {'firewall_policies': self.api_fw_policies.list()} - - neutronclient.list_firewalls().AndReturn(firewalls_dict) - neutronclient.list_firewall_policies().AndReturn(policies_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.firewall_list(self.request) - for (v, d) in zip(ret_val, exp_firewalls): - self._assert_firewall_return_value(v, d) - - @test.create_stubs({neutronclient: ('list_firewalls', - 'list_firewall_policies')}) - def test_firewall_list_for_tenant(self): - tenant_id = self.request.user.project_id - exp_firewalls = self.firewalls.list() - firewalls_dict = {'firewalls': self.api_firewalls.list()} - policies_dict = {'firewall_policies': self.api_fw_policies.list()} - - neutronclient.list_firewalls(tenant_id=tenant_id) \ - .AndReturn(firewalls_dict) - neutronclient.list_firewall_policies().AndReturn(policies_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.firewall_list_for_tenant(self.request, tenant_id) - for (v, d) in zip(ret_val, exp_firewalls): - self._assert_firewall_return_value(v, d) - - @test.create_stubs({neutronclient: ('show_firewall', - 'show_firewall_policy')}) - def test_firewall_get(self): - exp_firewall = self.firewalls.first() - ret_dict = {'firewall': self.api_firewalls.first()} - policy_dict = {'firewall_policy': self.api_fw_policies.first()} - - neutronclient.show_firewall(exp_firewall.id).AndReturn(ret_dict) - neutronclient.show_firewall_policy( - exp_firewall.firewall_policy_id).AndReturn(policy_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.firewall_get(self.request, exp_firewall.id) - self._assert_firewall_return_value(ret_val, exp_firewall) - - @test.create_stubs({neutronclient: ('update_firewall',)}) - def test_firewall_update(self): - firewall = self.firewalls.first() - firewall_dict = self.api_firewalls.first() - - firewall.name = 'new name' - firewall.description = 'new desc' - firewall.admin_state_up = False - - firewall_dict['name'] = 'new name' - firewall_dict['description'] = 'new desc' - firewall_dict['admin_state_up'] = False - - form_data = {'name': firewall.name, - 'description': firewall.description, - 'admin_state_up': firewall.admin_state_up - } - - form_dict = {'firewall': form_data} - ret_dict = {'firewall': firewall_dict} - - neutronclient.update_firewall( - firewall.id, form_dict).AndReturn(ret_dict) - self.mox.ReplayAll() - - ret_val = api.fwaas.firewall_update(self.request, - firewall.id, **form_data) - self.assertIsInstance(ret_val, api.fwaas.Firewall) - self.assertEqual(firewall.name, ret_val.name) - self.assertTrue(ret_val.id) diff --git a/code/horizon/openstack_dashboard/test/api_tests/glance_rest_tests.py b/code/horizon/openstack_dashboard/test/api_tests/glance_rest_tests.py deleted file mode 100644 index b8e56b05..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/glance_rest_tests.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright 2015, Rackspace, US, Inc. -# Copyright 2015, Hewlett-Packard Development Company, L.P. -# -# 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. -import mock - -from openstack_dashboard.api.rest import glance -from openstack_dashboard.test import helpers as test - - -class ImagesRestTestCase(test.TestCase): - @mock.patch.object(glance.api, 'glance') - def test_image_get_single(self, gc): - request = self.mock_rest_request() - gc.image_get.return_value.to_dict.return_value = {'name': '1'} - - response = glance.Image().get(request, "1") - self.assertStatusCode(response, 200) - gc.image_get.assert_called_once_with(request, "1") - - @mock.patch.object(glance.api, 'glance') - def test_image_get_list_detailed(self, gc): - kwargs = { - 'sort_dir': 'desc', - 'sort_key': 'namespace', - 'marker': 1, - 'paginate': False, - } - filters = {'name': 'fedora'} - request = self.mock_rest_request( - **{'GET': dict(kwargs, **filters)}) - gc.image_list_detailed.return_value = ([ - mock.Mock(**{'to_dict.return_value': {'name': 'fedora'}}), - mock.Mock(**{'to_dict.return_value': {'name': 'cirros'}}) - ], False, False) - - response = glance.Images().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"name": "fedora"}, {"name": "cirros"}]' - ', "has_more_data": false, "has_prev_data": false}') - gc.image_list_detailed.assert_called_once_with(request, - filters=filters, - **kwargs) - - @mock.patch.object(glance.api, 'glance') - def test_namespace_get_list(self, gc): - request = self.mock_rest_request(**{'GET': {}}) - gc.metadefs_namespace_full_list.return_value = ( - [{'namespace': '1'}, {'namespace': '2'}], False, False - ) - - response = glance.MetadefsNamespaces().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"namespace": "1"}, {"namespace": "2"}]' - ', "has_more_data": false, "has_prev_data": false}') - gc.metadefs_namespace_full_list.assert_called_once_with( - request, filters={} - ) - - @mock.patch.object(glance.api, 'glance') - def test_namespace_get_list_kwargs_and_filters(self, gc): - kwargs = { - 'sort_dir': 'desc', - 'sort_key': 'namespace', - 'marker': 1, - 'paginate': False, - } - filters = {'resource_types': 'type'} - request = self.mock_rest_request( - **{'GET': dict(kwargs, **filters)}) - gc.metadefs_namespace_full_list.return_value = ( - [{'namespace': '1'}, {'namespace': '2'}], False, False - ) - - response = glance.MetadefsNamespaces().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"namespace": "1"}, {"namespace": "2"}]' - ', "has_more_data": false, "has_prev_data": false}') - gc.metadefs_namespace_full_list.assert_called_once_with( - request, filters=filters, **kwargs - ) diff --git a/code/horizon/openstack_dashboard/test/api_tests/glance_tests.py b/code/horizon/openstack_dashboard/test/api_tests/glance_tests.py deleted file mode 100644 index 0a198d5f..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/glance_tests.py +++ /dev/null @@ -1,249 +0,0 @@ -# Copyright 2012 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# Copyright 2012 Nebula, 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.conf import settings -from django.test.utils import override_settings - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test - - -class GlanceApiTests(test.APITestCase): - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_image_list_detailed_no_pagination(self): - # Verify that all images are returned even with a small page size - api_images = self.images.list() - filters = {} - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - glanceclient.images.list(page_size=limit, - limit=limit, - filters=filters, - sort_dir='desc', - sort_key='created_at',) \ - .AndReturn(iter(api_images)) - self.mox.ReplayAll() - - images, has_more, has_prev = api.glance.image_list_detailed( - self.request) - self.assertItemsEqual(images, api_images) - self.assertFalse(has_more) - self.assertFalse(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_image_list_detailed_sort_options(self): - # Verify that sort_dir and sort_key work - api_images = self.images.list() - filters = {} - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - sort_dir = 'asc' - sort_key = 'min_disk' - - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - glanceclient.images.list(page_size=limit, - limit=limit, - filters=filters, - sort_dir=sort_dir, - sort_key=sort_key) \ - .AndReturn(iter(api_images)) - self.mox.ReplayAll() - - images, has_more, has_prev = api.glance.image_list_detailed( - self.request, - sort_dir=sort_dir, - sort_key=sort_key) - self.assertItemsEqual(images, api_images) - self.assertFalse(has_more) - self.assertFalse(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_image_list_detailed_pagination_more_page_size(self): - # The total snapshot count is over page size, should return - # page_size images. - filters = {} - page_size = settings.API_RESULT_PAGE_SIZE - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - - api_images = self.images.list() - images_iter = iter(api_images) - - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - # Pass back all images, ignoring filters - glanceclient.images.list(limit=limit, - page_size=page_size + 1, - filters=filters, - sort_dir='desc', - sort_key='created_at',).AndReturn(images_iter) - self.mox.ReplayAll() - - images, has_more, has_prev = api.glance.image_list_detailed( - self.request, - marker=None, - filters=filters, - paginate=True) - expected_images = api_images[:page_size] - self.assertItemsEqual(images, expected_images) - self.assertTrue(has_more) - self.assertFalse(has_prev) - # Ensure that only the needed number of images are consumed - # from the iterator (page_size + 1). - self.assertEqual(len(list(images_iter)), - len(api_images) - len(expected_images) - 1) - - @override_settings(API_RESULT_PAGE_SIZE=20) - def test_image_list_detailed_pagination_less_page_size(self): - # The total image count is less than page size, should return images - # more, prev should return False. - filters = {} - page_size = settings.API_RESULT_PAGE_SIZE - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - - api_images = self.images.list() - images_iter = iter(api_images) - - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - # Pass back all images, ignoring filters - glanceclient.images.list(limit=limit, - page_size=page_size + 1, - filters=filters, - sort_dir='desc', - sort_key='created_at',).AndReturn(images_iter) - self.mox.ReplayAll() - - images, has_more, has_prev = api.glance.image_list_detailed( - self.request, - filters=filters, - paginate=True) - expected_images = api_images[:page_size] - self.assertItemsEqual(images, expected_images) - self.assertFalse(has_more) - self.assertFalse(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=9) - def test_image_list_detailed_pagination_equal_page_size(self): - # The total image count equals page size, should return - # page_size images. more, prev should return False - filters = {} - page_size = settings.API_RESULT_PAGE_SIZE - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - - api_images = self.images.list() - images_iter = iter(api_images) - - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - glanceclient.images.list(limit=limit, - page_size=page_size + 1, - filters=filters, - sort_dir='desc', - sort_key='created_at',).AndReturn(images_iter) - self.mox.ReplayAll() - - images, has_more, has_prev = api.glance.image_list_detailed( - self.request, - filters=filters, - paginate=True) - expected_images = api_images[:page_size] - self.assertItemsEqual(images, expected_images) - self.assertFalse(has_more) - self.assertFalse(has_prev) - self.assertEqual(len(expected_images), len(images)) - - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_image_list_detailed_pagination_marker(self): - # Tests getting a second page with a marker. - filters = {} - page_size = settings.API_RESULT_PAGE_SIZE - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - marker = 'nonsense' - - api_images = self.images.list()[page_size:] - images_iter = iter(api_images) - - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - # Pass back all images, ignoring filters - glanceclient.images.list(limit=limit, - page_size=page_size + 1, - filters=filters, - marker=marker, - sort_dir='desc', - sort_key='created_at',) \ - .AndReturn(images_iter) - self.mox.ReplayAll() - - images, has_more, has_prev = api.glance.image_list_detailed( - self.request, - marker=marker, - filters=filters, - paginate=True) - expected_images = api_images[:page_size] - self.assertItemsEqual(images, expected_images) - self.assertTrue(has_more) - self.assertTrue(has_prev) - self.assertEqual(len(list(images_iter)), - len(api_images) - len(expected_images) - 1) - - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_image_list_detailed_pagination_marker_prev(self): - # Tests getting previous page with a marker. - filters = {} - page_size = settings.API_RESULT_PAGE_SIZE - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - marker = 'nonsense' - - api_images = self.images.list()[page_size:] - images_iter = iter(api_images) - - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - # Pass back all images, ignoring filters - glanceclient.images.list(limit=limit, - page_size=page_size + 1, - marker=marker, - filters=filters, - sort_dir='asc', - sort_key='created_at',) \ - .AndReturn(images_iter) - self.mox.ReplayAll() - - images, has_more, has_prev = api.glance.image_list_detailed( - self.request, - marker=marker, - filters=filters, - sort_dir='asc', - paginate=True) - expected_images = api_images[:page_size] - self.assertItemsEqual(images, expected_images) - self.assertTrue(has_more) - self.assertTrue(has_prev) - self.assertEqual(len(list(images_iter)), - len(api_images) - len(expected_images) - 1) - - def test_get_image_empty_name(self): - glanceclient = self.stub_glanceclient() - glanceclient.images = self.mox.CreateMockAnything() - glanceclient.images.get('empty').AndReturn(self.empty_name_image) - self.mox.ReplayAll() - image = api.glance.image_get(self.request, 'empty') - self.assertIsNone(image.name) diff --git a/code/horizon/openstack_dashboard/test/api_tests/heat_tests.py b/code/horizon/openstack_dashboard/test/api_tests/heat_tests.py deleted file mode 100644 index 9e99a762..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/heat_tests.py +++ /dev/null @@ -1,213 +0,0 @@ -# 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.conf import settings -from django.test.utils import override_settings # noqa - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test - - -class HeatApiTests(test.APITestCase): - def test_stack_list(self): - api_stacks = self.stacks.list() - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - heatclient.stacks.list(limit=limit, - sort_dir='desc', - sort_key='created_at',) \ - .AndReturn(iter(api_stacks)) - self.mox.ReplayAll() - stacks, has_more, has_prev = api.heat.stacks_list(self.request) - self.assertItemsEqual(stacks, api_stacks) - self.assertFalse(has_more) - self.assertFalse(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_stack_list_sort_options(self): - # Verify that sort_dir and sort_key work - api_stacks = self.stacks.list() - limit = getattr(settings, 'API_RESULT_LIMIT', 1000) - sort_dir = 'asc' - sort_key = 'size' - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - heatclient.stacks.list(limit=limit, - sort_dir=sort_dir, - sort_key=sort_key,) \ - .AndReturn(iter(api_stacks)) - self.mox.ReplayAll() - - stacks, has_more, has_prev = api.heat.stacks_list(self.request, - sort_dir=sort_dir, - sort_key=sort_key) - self.assertItemsEqual(stacks, api_stacks) - self.assertFalse(has_more) - self.assertFalse(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=20) - def test_stack_list_pagination_less_page_size(self): - api_stacks = self.stacks.list() - page_size = settings.API_RESULT_PAGE_SIZE - sort_dir = 'desc' - sort_key = 'created_at' - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - heatclient.stacks.list(limit=page_size + 1, - sort_dir=sort_dir, - sort_key=sort_key,) \ - .AndReturn(iter(api_stacks)) - self.mox.ReplayAll() - - stacks, has_more, has_prev = api.heat.stacks_list(self.request, - sort_dir=sort_dir, - sort_key=sort_key, - paginate=True) - expected_stacks = api_stacks[:page_size] - self.assertItemsEqual(stacks, expected_stacks) - self.assertFalse(has_more) - self.assertFalse(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=10) - def test_stack_list_pagination_equal_page_size(self): - api_stacks = self.stacks.list() - page_size = settings.API_RESULT_PAGE_SIZE - sort_dir = 'desc' - sort_key = 'created_at' - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - heatclient.stacks.list(limit=page_size + 1, - sort_dir=sort_dir, - sort_key=sort_key,) \ - .AndReturn(iter(api_stacks)) - self.mox.ReplayAll() - - stacks, has_more, has_prev = api.heat.stacks_list(self.request, - sort_dir=sort_dir, - sort_key=sort_key, - paginate=True) - expected_stacks = api_stacks[:page_size] - self.assertItemsEqual(stacks, expected_stacks) - self.assertFalse(has_more) - self.assertFalse(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_stack_list_pagination_marker(self): - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20) - sort_dir = 'desc' - sort_key = 'created_at' - marker = 'nonsense' - - api_stacks = self.stacks.list() - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - heatclient.stacks.list(limit=page_size + 1, - marker=marker, - sort_dir=sort_dir, - sort_key=sort_key,) \ - .AndReturn(iter(api_stacks[:page_size + 1])) - self.mox.ReplayAll() - - stacks, has_more, has_prev = api.heat.stacks_list(self.request, - marker=marker, - paginate=True, - sort_dir=sort_dir, - sort_key=sort_key,) - - self.assertEqual(len(stacks), page_size) - self.assertItemsEqual(stacks, api_stacks[:page_size]) - self.assertTrue(has_more) - self.assertTrue(has_prev) - - @override_settings(API_RESULT_PAGE_SIZE=2) - def test_stack_list_pagination_marker_prev(self): - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20) - sort_dir = 'asc' - sort_key = 'created_at' - marker = 'nonsense' - - api_stacks = self.stacks.list() - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - heatclient.stacks.list(limit=page_size + 1, - marker=marker, - sort_dir=sort_dir, - sort_key=sort_key,) \ - .AndReturn(iter(api_stacks[:page_size + 1])) - self.mox.ReplayAll() - - stacks, has_more, has_prev = api.heat.stacks_list(self.request, - marker=marker, - paginate=True, - sort_dir=sort_dir, - sort_key=sort_key,) - - self.assertEqual(len(stacks), page_size) - self.assertItemsEqual(stacks, api_stacks[:page_size]) - self.assertTrue(has_more) - self.assertTrue(has_prev) - - def test_template_get(self): - api_stacks = self.stacks.list() - stack_id = api_stacks[0].id - mock_data_template = self.stack_templates.list()[0] - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - heatclient.stacks.template(stack_id).AndReturn(mock_data_template) - self.mox.ReplayAll() - - template = api.heat.template_get(self.request, stack_id) - self.assertEqual(mock_data_template.data, template.data) - - def test_stack_create(self): - api_stacks = self.stacks.list() - stack = api_stacks[0] - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - form_data = {'timeout_mins': 600} - password = 'secret' - heatclient.stacks.create(**form_data).AndReturn(stack) - self.mox.ReplayAll() - - returned_stack = api.heat.stack_create(self.request, - password, - **form_data) - from heatclient.v1 import stacks - self.assertIsInstance(returned_stack, stacks.Stack) - - def test_stack_update(self): - api_stacks = self.stacks.list() - stack = api_stacks[0] - stack_id = stack.id - - heatclient = self.stub_heatclient() - heatclient.stacks = self.mox.CreateMockAnything() - form_data = {'timeout_mins': 600} - password = 'secret' - heatclient.stacks.update(stack_id, **form_data).AndReturn(stack) - self.mox.ReplayAll() - - returned_stack = api.heat.stack_update(self.request, - stack_id, - password, - **form_data) - from heatclient.v1 import stacks - self.assertIsInstance(returned_stack, stacks.Stack) diff --git a/code/horizon/openstack_dashboard/test/api_tests/lbaas_tests.py b/code/horizon/openstack_dashboard/test/api_tests/lbaas_tests.py deleted file mode 100644 index e0cf6934..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/lbaas_tests.py +++ /dev/null @@ -1,376 +0,0 @@ -# Copyright 2013, Big Switch Networks, 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 openstack_dashboard import api -from openstack_dashboard.test import helpers as test - -from neutronclient.v2_0 import client - -neutronclient = client.Client - - -class LbaasApiTests(test.APITestCase): - @test.create_stubs({neutronclient: ('create_vip',)}) - def test_vip_create(self): - vip1 = self.api_vips.first() - form_data = {'address': vip1['address'], - 'name': vip1['name'], - 'description': vip1['description'], - 'subnet_id': vip1['subnet_id'], - 'protocol_port': vip1['protocol_port'], - 'protocol': vip1['protocol'], - 'pool_id': vip1['pool_id'], - 'session_persistence': vip1['session_persistence'], - 'connection_limit': vip1['connection_limit'], - 'admin_state_up': vip1['admin_state_up'] - } - vip = {'vip': self.api_vips.first()} - neutronclient.create_vip({'vip': form_data}).AndReturn(vip) - self.mox.ReplayAll() - - ret_val = api.lbaas.vip_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.lbaas.Vip) - - @test.create_stubs({neutronclient: ('create_vip',)}) - def test_vip_create_skip_address_if_empty(self): - vip1 = self.api_vips.first() - vipform_data = {'name': vip1['name'], - 'description': vip1['description'], - 'subnet_id': vip1['subnet_id'], - 'protocol_port': vip1['protocol_port'], - 'protocol': vip1['protocol'], - 'pool_id': vip1['pool_id'], - 'session_persistence': vip1['session_persistence'], - 'connection_limit': vip1['connection_limit'], - 'admin_state_up': vip1['admin_state_up'] - } - - neutronclient.create_vip({'vip': vipform_data}).AndReturn( - {'vip': vipform_data}) - self.mox.ReplayAll() - - form_data = dict(vipform_data) - form_data['address'] = "" - ret_val = api.lbaas.vip_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.lbaas.Vip) - - @test.create_stubs({neutronclient: ('list_vips',)}) - def test_vip_list(self): - vips = {'vips': [{'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'address': '10.0.0.100', - 'name': 'vip1name', - 'description': 'vip1description', - 'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e', - 'protocol_port': '80', - 'protocol': 'HTTP', - 'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49', - 'connection_limit': '10', - 'admin_state_up': True - }, ]} - neutronclient.list_vips().AndReturn(vips) - self.mox.ReplayAll() - - ret_val = api.lbaas.vip_list(self.request) - for v in ret_val: - self.assertIsInstance(v, api.lbaas.Vip) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_vip', 'show_pool'), - api.neutron: ('subnet_get', 'port_get')}) - def test_vip_get(self): - vip = self.api_vips.first() - neutronclient.show_vip(vip['id']).AndReturn({'vip': vip}) - api.neutron.subnet_get(self.request, vip['subnet_id'] - ).AndReturn(self.subnets.first()) - api.neutron.port_get(self.request, vip['port_id'] - ).AndReturn(self.ports.first()) - neutronclient.show_pool(vip['pool_id'] - ).AndReturn({'pool': self.api_pools.first()}) - self.mox.ReplayAll() - - ret_val = api.lbaas.vip_get(self.request, vip['id']) - self.assertIsInstance(ret_val, api.lbaas.Vip) - self.assertIsInstance(ret_val.subnet, api.neutron.Subnet) - self.assertEqual(vip['subnet_id'], ret_val.subnet.id) - self.assertIsInstance(ret_val.port, api.neutron.Port) - self.assertEqual(vip['port_id'], ret_val.port.id) - self.assertIsInstance(ret_val.pool, api.lbaas.Pool) - self.assertEqual(self.api_pools.first()['id'], ret_val.pool.id) - - @test.create_stubs({neutronclient: ('update_vip',)}) - def test_vip_update(self): - form_data = {'address': '10.0.0.100', - 'name': 'vip1name', - 'description': 'vip1description', - 'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e', - 'protocol_port': '80', - 'protocol': 'HTTP', - 'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49', - 'connection_limit': '10', - 'admin_state_up': True - } - - vip = {'vip': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'address': '10.0.0.100', - 'name': 'vip1name', - 'description': 'vip1description', - 'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e', - 'protocol_port': '80', - 'protocol': 'HTTP', - 'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49', - 'connection_limit': '10', - 'admin_state_up': True - }} - neutronclient.update_vip(vip['vip']['id'], form_data).AndReturn(vip) - self.mox.ReplayAll() - - ret_val = api.lbaas.vip_update(self.request, - vip['vip']['id'], **form_data) - self.assertIsInstance(ret_val, api.lbaas.Vip) - - @test.create_stubs({neutronclient: ('create_pool',)}) - def test_pool_create(self): - form_data = {'name': 'pool1name', - 'description': 'pool1description', - 'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e', - 'protocol': 'HTTP', - 'lb_method': 'ROUND_ROBIN', - 'admin_state_up': True, - 'provider': 'dummy' - } - - pool = {'pool': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'name': 'pool1name', - 'description': 'pool1description', - 'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e', - 'protocol': 'HTTP', - 'lb_method': 'ROUND_ROBIN', - 'admin_state_up': True, - 'provider': 'dummy' - }} - neutronclient.create_pool({'pool': form_data}).AndReturn(pool) - self.mox.ReplayAll() - - ret_val = api.lbaas.pool_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.lbaas.Pool) - - @test.create_stubs({neutronclient: ('list_pools', 'list_vips'), - api.neutron: ('subnet_list',)}) - def test_pool_list(self): - pools = {'pools': self.api_pools.list()} - subnets = self.subnets.list() - vips = {'vips': self.api_vips.list()} - - neutronclient.list_pools().AndReturn(pools) - api.neutron.subnet_list(self.request).AndReturn(subnets) - neutronclient.list_vips().AndReturn(vips) - self.mox.ReplayAll() - - ret_val = api.lbaas.pool_list(self.request) - for v in ret_val: - self.assertIsInstance(v, api.lbaas.Pool) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_pool', 'show_vip', - 'list_members', - 'list_health_monitors',), - api.neutron: ('subnet_get',)}) - def test_pool_get(self): - pool = self.pools.first() - subnet = self.subnets.first() - pool_dict = {'pool': self.api_pools.first()} - vip_dict = {'vip': self.api_vips.first()} - - neutronclient.show_pool(pool.id).AndReturn(pool_dict) - api.neutron.subnet_get(self.request, subnet.id).AndReturn(subnet) - neutronclient.show_vip(pool.vip_id).AndReturn(vip_dict) - neutronclient.list_members(pool_id=pool.id).AndReturn( - {'members': self.api_members.list()}) - neutronclient.list_health_monitors(id=pool.health_monitors).AndReturn( - {'health_monitors': [self.api_monitors.first()]}) - self.mox.ReplayAll() - - ret_val = api.lbaas.pool_get(self.request, pool.id) - self.assertIsInstance(ret_val, api.lbaas.Pool) - self.assertIsInstance(ret_val.vip, api.lbaas.Vip) - self.assertEqual(ret_val.vip.id, vip_dict['vip']['id']) - self.assertIsInstance(ret_val.subnet, api.neutron.Subnet) - self.assertEqual(ret_val.subnet.id, subnet.id) - self.assertEqual(2, len(ret_val.members)) - self.assertIsInstance(ret_val.members[0], api.lbaas.Member) - self.assertEqual(1, len(ret_val.health_monitors)) - self.assertIsInstance(ret_val.health_monitors[0], - api.lbaas.PoolMonitor) - - @test.create_stubs({neutronclient: ('update_pool',)}) - def test_pool_update(self): - form_data = {'name': 'pool1name', - 'description': 'pool1description', - 'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e', - 'protocol': 'HTTPS', - 'lb_method': 'LEAST_CONNECTION', - 'admin_state_up': True - } - - pool = {'pool': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'name': 'pool1name', - 'description': 'pool1description', - 'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e', - 'protocol': 'HTTPS', - 'lb_method': 'LEAST_CONNECTION', - 'admin_state_up': True - }} - neutronclient.update_pool(pool['pool']['id'], - form_data).AndReturn(pool) - self.mox.ReplayAll() - - ret_val = api.lbaas.pool_update(self.request, - pool['pool']['id'], **form_data) - self.assertIsInstance(ret_val, api.lbaas.Pool) - - @test.create_stubs({neutronclient: ('create_health_monitor',)}) - def test_pool_health_monitor_create(self): - form_data = {'type': 'PING', - 'delay': '10', - 'timeout': '10', - 'max_retries': '10', - 'admin_state_up': True - } - monitor = {'health_monitor': { - 'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'type': 'PING', - 'delay': '10', - 'timeout': '10', - 'max_retries': '10', - 'admin_state_up': True}} - neutronclient.create_health_monitor({ - 'health_monitor': form_data}).AndReturn(monitor) - self.mox.ReplayAll() - - ret_val = api.lbaas.pool_health_monitor_create( - self.request, **form_data) - self.assertIsInstance(ret_val, api.lbaas.PoolMonitor) - - @test.create_stubs({neutronclient: ('list_health_monitors',)}) - def test_pool_health_monitor_list(self): - monitors = {'health_monitors': [ - {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'type': 'PING', - 'delay': '10', - 'timeout': '10', - 'max_retries': '10', - 'http_method': 'GET', - 'url_path': '/monitor', - 'expected_codes': '200', - 'admin_state_up': True}, ]} - - neutronclient.list_health_monitors().AndReturn(monitors) - self.mox.ReplayAll() - - ret_val = api.lbaas.pool_health_monitor_list(self.request) - for v in ret_val: - self.assertIsInstance(v, api.lbaas.PoolMonitor) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_health_monitor', - 'list_pools')}) - def test_pool_health_monitor_get(self): - monitor = self.api_monitors.first() - neutronclient.show_health_monitor( - monitor['id']).AndReturn({'health_monitor': monitor}) - neutronclient.list_pools(id=[p['pool_id'] for p in monitor['pools']] - ).AndReturn({'pools': self.api_pools.list()}) - self.mox.ReplayAll() - - ret_val = api.lbaas.pool_health_monitor_get( - self.request, monitor['id']) - self.assertIsInstance(ret_val, api.lbaas.PoolMonitor) - self.assertEqual(2, len(ret_val.pools)) - self.assertIsInstance(ret_val.pools[0], api.lbaas.Pool) - - @test.create_stubs({neutronclient: ('create_member', )}) - def test_member_create(self): - form_data = {'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'address': '10.0.1.2', - 'protocol_port': '80', - 'weight': '10', - 'admin_state_up': True - } - - member = {'member': - {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'address': '10.0.1.2', - 'protocol_port': '80', - 'weight': '10', - 'admin_state_up': True}} - - neutronclient.create_member({'member': form_data}).AndReturn(member) - self.mox.ReplayAll() - - ret_val = api.lbaas.member_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.lbaas.Member) - - @test.create_stubs({neutronclient: ('list_members', 'list_pools')}) - def test_member_list(self): - members = {'members': self.api_members.list()} - pools = {'pools': self.api_pools.list()} - - neutronclient.list_members().AndReturn(members) - neutronclient.list_pools().AndReturn(pools) - self.mox.ReplayAll() - - ret_val = api.lbaas.member_list(self.request) - for v in ret_val: - self.assertIsInstance(v, api.lbaas.Member) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_member', 'show_pool')}) - def test_member_get(self): - member = self.members.first() - member_dict = {'member': self.api_members.first()} - pool_dict = {'pool': self.api_pools.first()} - - neutronclient.show_member(member.id).AndReturn(member_dict) - neutronclient.show_pool(member.pool_id).AndReturn(pool_dict) - self.mox.ReplayAll() - - ret_val = api.lbaas.member_get(self.request, member.id) - self.assertIsInstance(ret_val, api.lbaas.Member) - - @test.create_stubs({neutronclient: ('update_member',)}) - def test_member_update(self): - form_data = {'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'address': '10.0.1.4', - 'protocol_port': '80', - 'weight': '10', - 'admin_state_up': True - } - - member = {'member': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'address': '10.0.1.2', - 'protocol_port': '80', - 'weight': '10', - 'admin_state_up': True - }} - - neutronclient.update_member(member['member']['id'], - form_data).AndReturn(member) - self.mox.ReplayAll() - - ret_val = api.lbaas.member_update(self.request, - member['member']['id'], **form_data) - self.assertIsInstance(ret_val, api.lbaas.Member) diff --git a/code/horizon/openstack_dashboard/test/api_tests/network_rest_tests.py b/code/horizon/openstack_dashboard/test/api_tests/network_rest_tests.py deleted file mode 100644 index 6d491bf2..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/network_rest_tests.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2015, Hewlett-Packard Development Company, L.P. -# -# 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. -import mock - -from openstack_dashboard.api.rest import network -from openstack_dashboard.test import helpers as test - - -class RestNetworkApiSecurityGroupTests(test.TestCase): - - @mock.patch.object(network.api, 'network') - def test_security_group_detailed(self, client): - request = self.mock_rest_request() - client.security_group_list.return_value = [ - mock.Mock(**{'to_dict.return_value': {'name': 'default'}}), - ] - - response = network.SecurityGroups().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"name": "default"}]}') - client.security_group_list.assert_called_once_with(request) diff --git a/code/horizon/openstack_dashboard/test/api_tests/network_tests.py b/code/horizon/openstack_dashboard/test/api_tests/network_tests.py deleted file mode 100644 index 37b16ba7..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/network_tests.py +++ /dev/null @@ -1,778 +0,0 @@ -# Copyright 2013 NEC Corporation -# -# 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. - -import collections -import copy -import itertools -import uuid - -from django import http -from django.test.utils import override_settings -from mox import IsA # noqa - -from novaclient.v2 import floating_ip_pools - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test - - -class NetworkClientTestCase(test.APITestCase): - def test_networkclient_no_neutron(self): - self.mox.StubOutWithMock(api.base, 'is_service_enabled') - api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \ - .AndReturn(False) - self.mox.ReplayAll() - - nc = api.network.NetworkClient(self.request) - self.assertIsInstance(nc.floating_ips, api.nova.FloatingIpManager) - self.assertIsInstance(nc.secgroups, api.nova.SecurityGroupManager) - - def test_networkclient_neutron(self): - self.mox.StubOutWithMock(api.base, 'is_service_enabled') - api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \ - .AndReturn(True) - self.neutronclient = self.stub_neutronclient() - self.neutronclient.list_extensions() \ - .AndReturn({'extensions': self.api_extensions.list()}) - self.mox.ReplayAll() - - nc = api.network.NetworkClient(self.request) - self.assertIsInstance(nc.floating_ips, api.neutron.FloatingIpManager) - self.assertIsInstance(nc.secgroups, api.neutron.SecurityGroupManager) - - def test_networkclient_neutron_with_nova_security_group(self): - self.mox.StubOutWithMock(api.base, 'is_service_enabled') - api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \ - .AndReturn(True) - self.neutronclient = self.stub_neutronclient() - self.neutronclient.list_extensions().AndReturn({'extensions': []}) - self.mox.ReplayAll() - - nc = api.network.NetworkClient(self.request) - self.assertIsInstance(nc.floating_ips, api.neutron.FloatingIpManager) - self.assertIsInstance(nc.secgroups, api.nova.SecurityGroupManager) - - -class NetworkApiNovaTestBase(test.APITestCase): - def setUp(self): - super(NetworkApiNovaTestBase, self).setUp() - self.mox.StubOutWithMock(api.base, 'is_service_enabled') - api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \ - .AndReturn(False) - - -class NetworkApiNovaSecurityGroupTests(NetworkApiNovaTestBase): - def test_server_update_security_groups(self): - all_secgroups = self.security_groups.list() - added_secgroup = all_secgroups[2] - rm_secgroup = all_secgroups[0] - cur_secgroups_raw = [{'id': sg.id, 'name': sg.name, - 'rules': []} - for sg in all_secgroups[0:2]] - cur_secgroups_ret = {'security_groups': cur_secgroups_raw} - new_sg_ids = [sg.id for sg in all_secgroups[1:3]] - instance_id = self.servers.first().id - - novaclient = self.stub_novaclient() - novaclient.security_groups = self.mox.CreateMockAnything() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.client = self.mox.CreateMockAnything() - novaclient.security_groups.list().AndReturn(all_secgroups) - url = '/servers/%s/os-security-groups' % instance_id - novaclient.client.get(url).AndReturn((200, cur_secgroups_ret)) - novaclient.servers.add_security_group(instance_id, added_secgroup.name) - novaclient.servers.remove_security_group(instance_id, rm_secgroup.name) - self.mox.ReplayAll() - - api.network.server_update_security_groups( - self.request, instance_id, new_sg_ids) - - -class NetworkApiNovaFloatingIpTests(NetworkApiNovaTestBase): - def test_floating_ip_pools_list(self): - pool_names = ['pool1', 'pool2'] - pools = [floating_ip_pools.FloatingIPPool( - None, {'name': pool}) for pool in pool_names] - novaclient = self.stub_novaclient() - novaclient.floating_ip_pools = self.mox.CreateMockAnything() - novaclient.floating_ip_pools.list().AndReturn(pools) - self.mox.ReplayAll() - - ret = api.network.floating_ip_pools_list(self.request) - self.assertEqual(pool_names, [p.name for p in ret]) - - def test_floating_ip_list(self): - fips = self.api_floating_ips.list() - novaclient = self.stub_novaclient() - novaclient.floating_ips = self.mox.CreateMockAnything() - novaclient.floating_ips.list().AndReturn(fips) - self.mox.ReplayAll() - - ret = api.network.tenant_floating_ip_list(self.request) - for r, e in zip(ret, fips): - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'instance_id']: - self.assertEqual(getattr(e, attr), getattr(r, attr)) - self.assertEqual(e.instance_id, r.port_id) - exp_instance_type = 'compute' if e.instance_id else None - self.assertEqual(exp_instance_type, r.instance_type) - - def test_floating_ip_get(self): - fip = self.api_floating_ips.first() - novaclient = self.stub_novaclient() - novaclient.floating_ips = self.mox.CreateMockAnything() - novaclient.floating_ips.get(fip.id).AndReturn(fip) - self.mox.ReplayAll() - - ret = api.network.tenant_floating_ip_get(self.request, fip.id) - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'instance_id']: - self.assertEqual(getattr(fip, attr), getattr(ret, attr)) - self.assertEqual(fip.instance_id, ret.port_id) - self.assertEqual(fip.instance_id, ret.instance_id) - self.assertEqual('compute', ret.instance_type) - - def test_floating_ip_allocate(self): - pool_name = 'fip_pool' - fip = [fip for fip in self.api_floating_ips.list() - if not fip.instance_id][0] - novaclient = self.stub_novaclient() - novaclient.floating_ips = self.mox.CreateMockAnything() - novaclient.floating_ips.create(pool=pool_name).AndReturn(fip) - self.mox.ReplayAll() - - ret = api.network.tenant_floating_ip_allocate(self.request, pool_name) - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'instance_id']: - self.assertEqual(getattr(fip, attr), getattr(ret, attr)) - self.assertIsNone(ret.port_id) - self.assertIsNone(ret.instance_type) - - def test_floating_ip_release(self): - fip = self.api_floating_ips.first() - novaclient = self.stub_novaclient() - novaclient.floating_ips = self.mox.CreateMockAnything() - novaclient.floating_ips.delete(fip.id) - self.mox.ReplayAll() - - api.network.tenant_floating_ip_release(self.request, fip.id) - - def test_floating_ip_associate(self): - server = api.nova.Server(self.servers.first(), self.request) - floating_ip = self.floating_ips.first() - - novaclient = self.stub_novaclient() - novaclient.floating_ips = self.mox.CreateMockAnything() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get(server.id).AndReturn(server) - novaclient.floating_ips.get(floating_ip.id).AndReturn(floating_ip) - novaclient.servers.add_floating_ip(server.id, floating_ip.ip) \ - .AndReturn(server) - self.mox.ReplayAll() - - api.network.floating_ip_associate(self.request, - floating_ip.id, - server.id) - - def test_floating_ip_disassociate(self): - server = api.nova.Server(self.servers.first(), self.request) - floating_ip = self.api_floating_ips.first() - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.floating_ips = self.mox.CreateMockAnything() - novaclient.servers.get(server.id).AndReturn(server) - novaclient.floating_ips.get(floating_ip.id).AndReturn(floating_ip) - novaclient.servers.remove_floating_ip(server.id, floating_ip.ip) \ - .AndReturn(server) - self.mox.ReplayAll() - - api.network.floating_ip_disassociate(self.request, - floating_ip.id) - - def test_floating_ip_target_list(self): - servers = self.servers.list() - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.list().AndReturn(servers) - self.mox.ReplayAll() - - targets = api.network.floating_ip_target_list(self.request) - for target, server in zip(targets, servers): - self.assertEqual(server.id, target.id) - self.assertEqual('%s (%s)' % (server.name, server.id), target.name) - - def test_floating_ip_target_get_by_instance(self): - self.mox.ReplayAll() - instance_id = self.servers.first().id - ret = api.network.floating_ip_target_get_by_instance(self.request, - instance_id) - self.assertEqual(instance_id, ret) - - -class NetworkApiNeutronTestBase(test.APITestCase): - def setUp(self): - super(NetworkApiNeutronTestBase, self).setUp() - self.mox.StubOutWithMock(api.base, 'is_service_enabled') - api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \ - .AndReturn(True) - self.qclient = self.stub_neutronclient() - - -class NetworkApiNeutronTests(NetworkApiNeutronTestBase): - - def _get_expected_addresses(self, server, no_fip_expected=True): - server_ports = self.ports.filter(device_id=server.id) - addresses = collections.defaultdict(list) - for p in server_ports: - net_name = self.networks.get(id=p['network_id']).name - for ip in p.fixed_ips: - addresses[net_name].append( - {'version': 4, - 'addr': ip['ip_address'], - 'OS-EXT-IPS-MAC:mac_addr': p.mac_address, - 'OS-EXT-IPS:type': 'fixed'}) - if no_fip_expected: - continue - fips = self.q_floating_ips.filter(port_id=p['id']) - if not fips: - continue - # Only one FIP should match. - fip = fips[0] - addresses[net_name].append( - {'version': 4, - 'addr': fip.floating_ip_address, - 'OS-EXT-IPS-MAC:mac_addr': p.mac_address, - 'OS-EXT-IPS:type': 'floating'}) - return addresses - - def _check_server_address(self, res_server_data, no_fip_expected=False): - expected_addresses = self._get_expected_addresses(res_server_data, - no_fip_expected) - self.assertEqual(len(expected_addresses), - len(res_server_data.addresses)) - for net, addresses in expected_addresses.items(): - self.assertIn(net, res_server_data.addresses) - self.assertEqual(addresses, res_server_data.addresses[net]) - - def _test_servers_update_addresses(self, router_enabled=True): - tenant_id = self.request.user.tenant_id - - servers = copy.deepcopy(self.servers.list()) - server_ids = [server.id for server in servers] - server_ports = [p for p in self.api_ports.list() - if p['device_id'] in server_ids] - server_port_ids = [p['id'] for p in server_ports] - if router_enabled: - assoc_fips = [fip for fip in self.api_q_floating_ips.list() - if fip['port_id'] in server_port_ids] - server_network_ids = [p['network_id'] for p in server_ports] - server_networks = [net for net in self.api_networks.list() - if net['id'] in server_network_ids] - - self.qclient.list_ports(device_id=server_ids) \ - .AndReturn({'ports': server_ports}) - if router_enabled: - self.qclient.list_floatingips(tenant_id=tenant_id, - port_id=server_port_ids) \ - .AndReturn({'floatingips': assoc_fips}) - self.qclient.list_ports(tenant_id=tenant_id) \ - .AndReturn({'ports': self.api_ports.list()}) - self.qclient.list_networks(id=set(server_network_ids)) \ - .AndReturn({'networks': server_networks}) - self.qclient.list_subnets() \ - .AndReturn({'subnets': self.api_subnets.list()}) - self.mox.ReplayAll() - - api.network.servers_update_addresses(self.request, servers) - - self.assertEqual(self.servers.count(), len(servers)) - self.assertEqual([server.id for server in self.servers.list()], - [server.id for server in servers]) - - no_fip_expected = not router_enabled - - # server[0] has one fixed IP and one floating IP - # if router ext isenabled. - self._check_server_address(servers[0], no_fip_expected) - # The expected is also calculated, we examine the result manually once. - addrs = servers[0].addresses['net1'] - if router_enabled: - self.assertEqual(2, len(addrs)) - self.assertEqual('fixed', addrs[0]['OS-EXT-IPS:type']) - self.assertEqual('floating', addrs[1]['OS-EXT-IPS:type']) - else: - self.assertEqual(1, len(addrs)) - self.assertEqual('fixed', addrs[0]['OS-EXT-IPS:type']) - - # server[1] has one fixed IP. - self._check_server_address(servers[1], no_fip_expected) - # manual check. - addrs = servers[1].addresses['net2'] - self.assertEqual(1, len(addrs)) - self.assertEqual('fixed', addrs[0]['OS-EXT-IPS:type']) - - # server[2] has no corresponding ports in neutron_data, - # so it should be an empty dict. - self.assertFalse(servers[2].addresses) - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_router': True}) - def test_servers_update_addresses(self): - self._test_servers_update_addresses() - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_router': False}) - def test_servers_update_addresses_router_disabled(self): - self._test_servers_update_addresses(router_enabled=False) - - -class NetworkApiNeutronSecurityGroupTests(NetworkApiNeutronTestBase): - - def setUp(self): - super(NetworkApiNeutronSecurityGroupTests, self).setUp() - self.qclient.list_extensions() \ - .AndReturn({'extensions': self.api_extensions.list()}) - self.sg_dict = dict([(sg['id'], sg['name']) for sg - in self.api_q_secgroups.list()]) - - def _cmp_sg_rule(self, exprule, retrule): - self.assertEqual(exprule['id'], retrule.id) - self.assertEqual(exprule['security_group_id'], - retrule.parent_group_id) - self.assertEqual(exprule['direction'], - retrule.direction) - self.assertEqual(exprule['ethertype'], - retrule.ethertype) - self.assertEqual(exprule['port_range_min'], - retrule.from_port) - self.assertEqual(exprule['port_range_max'], - retrule.to_port,) - if (exprule['remote_ip_prefix'] is None and - exprule['remote_group_id'] is None): - expcidr = ('::/0' if exprule['ethertype'] == 'IPv6' - else '0.0.0.0/0') - else: - expcidr = exprule['remote_ip_prefix'] - self.assertEqual(expcidr, retrule.ip_range.get('cidr')) - self.assertEqual(self.sg_dict.get(exprule['remote_group_id']), - retrule.group.get('name')) - - def _cmp_sg(self, exp_sg, ret_sg): - self.assertEqual(exp_sg['id'], ret_sg.id) - self.assertEqual(exp_sg['name'], ret_sg.name) - exp_rules = exp_sg['security_group_rules'] - self.assertEqual(len(exp_rules), len(ret_sg.rules)) - for (exprule, retrule) in itertools.izip(exp_rules, ret_sg.rules): - self._cmp_sg_rule(exprule, retrule) - - def test_security_group_list(self): - sgs = self.api_q_secgroups.list() - tenant_id = self.request.user.tenant_id - # use deepcopy to ensure self.api_q_secgroups is not modified. - self.qclient.list_security_groups(tenant_id=tenant_id) \ - .AndReturn({'security_groups': copy.deepcopy(sgs)}) - self.mox.ReplayAll() - - rets = api.network.security_group_list(self.request) - self.assertEqual(len(sgs), len(rets)) - for (exp, ret) in itertools.izip(sgs, rets): - self._cmp_sg(exp, ret) - - def test_security_group_get(self): - secgroup = self.api_q_secgroups.first() - sg_ids = set([secgroup['id']] + - [rule['remote_group_id'] for rule - in secgroup['security_group_rules'] - if rule['remote_group_id']]) - related_sgs = [sg for sg in self.api_q_secgroups.list() - if sg['id'] in sg_ids] - # use deepcopy to ensure self.api_q_secgroups is not modified. - self.qclient.show_security_group(secgroup['id']) \ - .AndReturn({'security_group': copy.deepcopy(secgroup)}) - self.qclient.list_security_groups(id=sg_ids, fields=['id', 'name']) \ - .AndReturn({'security_groups': related_sgs}) - self.mox.ReplayAll() - ret = api.network.security_group_get(self.request, secgroup['id']) - self._cmp_sg(secgroup, ret) - - def test_security_group_create(self): - secgroup = self.api_q_secgroups.list()[1] - body = {'security_group': - {'name': secgroup['name'], - 'description': secgroup['description'], - 'tenant_id': self.request.user.project_id}} - self.qclient.create_security_group(body) \ - .AndReturn({'security_group': copy.deepcopy(secgroup)}) - self.mox.ReplayAll() - ret = api.network.security_group_create(self.request, secgroup['name'], - secgroup['description']) - self._cmp_sg(secgroup, ret) - - def test_security_group_update(self): - secgroup = self.api_q_secgroups.list()[1] - secgroup = copy.deepcopy(secgroup) - secgroup['name'] = 'newname' - secgroup['description'] = 'new description' - body = {'security_group': - {'name': secgroup['name'], - 'description': secgroup['description']}} - self.qclient.update_security_group(secgroup['id'], body) \ - .AndReturn({'security_group': secgroup}) - self.mox.ReplayAll() - ret = api.network.security_group_update(self.request, - secgroup['id'], - secgroup['name'], - secgroup['description']) - self._cmp_sg(secgroup, ret) - - def test_security_group_delete(self): - secgroup = self.api_q_secgroups.first() - self.qclient.delete_security_group(secgroup['id']) - self.mox.ReplayAll() - api.network.security_group_delete(self.request, secgroup['id']) - - def test_security_group_rule_create(self): - sg_rule = [r for r in self.api_q_secgroup_rules.list() - if r['protocol'] == 'tcp' and r['remote_ip_prefix']][0] - sg_id = sg_rule['security_group_id'] - secgroup = [sg for sg in self.api_q_secgroups.list() - if sg['id'] == sg_id][0] - - post_rule = copy.deepcopy(sg_rule) - del post_rule['id'] - del post_rule['tenant_id'] - post_body = {'security_group_rule': post_rule} - self.qclient.create_security_group_rule(post_body) \ - .AndReturn({'security_group_rule': copy.deepcopy(sg_rule)}) - self.qclient.list_security_groups(id=set([sg_id]), - fields=['id', 'name']) \ - .AndReturn({'security_groups': [copy.deepcopy(secgroup)]}) - self.mox.ReplayAll() - - ret = api.network.security_group_rule_create( - self.request, sg_rule['security_group_id'], - sg_rule['direction'], sg_rule['ethertype'], sg_rule['protocol'], - sg_rule['port_range_min'], sg_rule['port_range_max'], - sg_rule['remote_ip_prefix'], sg_rule['remote_group_id']) - self._cmp_sg_rule(sg_rule, ret) - - def test_security_group_rule_delete(self): - sg_rule = self.api_q_secgroup_rules.first() - self.qclient.delete_security_group_rule(sg_rule['id']) - self.mox.ReplayAll() - api.network.security_group_rule_delete(self.request, sg_rule['id']) - - def _get_instance(self, cur_sg_ids): - instance_port = [p for p in self.api_ports.list() - if p['device_owner'].startswith('compute:')][0] - instance_id = instance_port['device_id'] - # Emulate an intance with two ports - instance_ports = [] - for _i in range(2): - p = copy.deepcopy(instance_port) - p['id'] = str(uuid.uuid4()) - p['security_groups'] = cur_sg_ids - instance_ports.append(p) - return (instance_id, instance_ports) - - def test_server_security_groups(self): - cur_sg_ids = [sg['id'] for sg in self.api_q_secgroups.list()[:2]] - instance_id, instance_ports = self._get_instance(cur_sg_ids) - - self.qclient.list_ports(device_id=instance_id) \ - .AndReturn({'ports': instance_ports}) - secgroups = copy.deepcopy(self.api_q_secgroups.list()) - self.qclient.list_security_groups(id=set(cur_sg_ids)) \ - .AndReturn({'security_groups': secgroups}) - self.mox.ReplayAll() - - api.network.server_security_groups(self.request, instance_id) - - def test_server_update_security_groups(self): - cur_sg_ids = [self.api_q_secgroups.first()['id']] - new_sg_ids = [sg['id'] for sg in self.api_q_secgroups.list()[:2]] - instance_id, instance_ports = self._get_instance(cur_sg_ids) - - self.qclient.list_ports(device_id=instance_id) \ - .AndReturn({'ports': instance_ports}) - for p in instance_ports: - body = {'port': {'security_groups': new_sg_ids}} - self.qclient.update_port(p['id'], body=body).AndReturn({'port': p}) - self.mox.ReplayAll() - api.network.server_update_security_groups( - self.request, instance_id, new_sg_ids) - - def test_security_group_backend(self): - self.mox.ReplayAll() - self.assertEqual('neutron', - api.network.security_group_backend(self.request)) - - -class NetworkApiNeutronFloatingIpTests(NetworkApiNeutronTestBase): - - def setUp(self): - super(NetworkApiNeutronFloatingIpTests, self).setUp() - self.qclient.list_extensions() \ - .AndReturn({'extensions': self.api_extensions.list()}) - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_router': True}) - def test_floating_ip_supported(self): - self.mox.ReplayAll() - self.assertTrue(api.network.floating_ip_supported(self.request)) - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_router': False}) - def test_floating_ip_supported_false(self): - self.mox.ReplayAll() - self.assertFalse(api.network.floating_ip_supported(self.request)) - - def test_floating_ip_pools_list(self): - search_opts = {'router:external': True} - ext_nets = [n for n in self.api_networks.list() - if n['router:external']] - self.qclient.list_networks(**search_opts) \ - .AndReturn({'networks': ext_nets}) - self.mox.ReplayAll() - - rets = api.network.floating_ip_pools_list(self.request) - for attr in ['id', 'name']: - self.assertEqual([p[attr] for p in ext_nets], - [getattr(p, attr) for p in rets]) - - def test_floating_ip_list(self): - fips = self.api_q_floating_ips.list() - filters = {'tenant_id': self.request.user.tenant_id} - self.qclient.list_floatingips(**filters) \ - .AndReturn({'floatingips': fips}) - self.qclient.list_ports(**filters) \ - .AndReturn({'ports': self.api_ports.list()}) - self.mox.ReplayAll() - - rets = api.network.tenant_floating_ip_list(self.request) - assoc_port = self.api_ports.list()[1] - self.assertEqual(len(fips), len(rets)) - for ret, exp in zip(rets, fips): - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'port_id']: - self.assertEqual(exp[attr], getattr(ret, attr)) - if exp['port_id']: - dev_id = assoc_port['device_id'] if exp['port_id'] else None - self.assertEqual(dev_id, ret.instance_id) - self.assertEqual('compute', ret.instance_type) - else: - self.assertIsNone(ret.instance_id) - self.assertIsNone(ret.instance_type) - - def test_floating_ip_list_all_tenants(self): - fips = self.api_q_floating_ips.list() - self.qclient.list_floatingips().AndReturn({'floatingips': fips}) - self.qclient.list_ports().AndReturn({'ports': self.api_ports.list()}) - self.mox.ReplayAll() - - # all_tenants option for floating IP list is api.neutron specific, - # so we call api.neutron.FloatingIpManager directly and - # actually we don't need NetworkClient in this test. - # setUp() in the base class sets up mox to expect - # api.base.is_service_enabled() is called and we need to call - # NetworkClient even if we don't use it so that mox.VerifyAll - # doesn't complain it. - api.network.NetworkClient(self.request) - fip_manager = api.neutron.FloatingIpManager(self.request) - rets = fip_manager.list(all_tenants=True) - assoc_port = self.api_ports.list()[1] - self.assertEqual(len(fips), len(rets)) - for ret, exp in zip(rets, fips): - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'port_id']: - self.assertEqual(getattr(ret, attr), exp[attr]) - if exp['port_id']: - dev_id = assoc_port['device_id'] if exp['port_id'] else None - self.assertEqual(dev_id, ret.instance_id) - self.assertEqual('compute', ret.instance_type) - else: - self.assertIsNone(ret.instance_id) - self.assertIsNone(ret.instance_type) - - def _test_floating_ip_get_associated(self, assoc_port, exp_instance_type): - fip = self.api_q_floating_ips.list()[1] - self.qclient.show_floatingip(fip['id']).AndReturn({'floatingip': fip}) - self.qclient.show_port(assoc_port['id']) \ - .AndReturn({'port': assoc_port}) - self.mox.ReplayAll() - - ret = api.network.tenant_floating_ip_get(self.request, fip['id']) - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'port_id']: - self.assertEqual(fip[attr], getattr(ret, attr)) - self.assertEqual(assoc_port['device_id'], ret.instance_id) - self.assertEqual(exp_instance_type, ret.instance_type) - - def test_floating_ip_get_associated(self): - assoc_port = self.api_ports.list()[1] - self._test_floating_ip_get_associated(assoc_port, 'compute') - - def test_floating_ip_get_associated_with_loadbalancer_vip(self): - assoc_port = copy.deepcopy(self.api_ports.list()[1]) - assoc_port['device_owner'] = 'neutron:LOADBALANCER' - assoc_port['device_id'] = str(uuid.uuid4()) - assoc_port['name'] = 'vip-' + str(uuid.uuid4()) - self._test_floating_ip_get_associated(assoc_port, 'loadbalancer') - - def test_floating_ip_get_unassociated(self): - fip = self.api_q_floating_ips.list()[0] - self.qclient.show_floatingip(fip['id']).AndReturn({'floatingip': fip}) - self.mox.ReplayAll() - - ret = api.network.tenant_floating_ip_get(self.request, fip['id']) - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'port_id']: - self.assertEqual(fip[attr], getattr(ret, attr)) - self.assertIsNone(ret.instance_id) - self.assertIsNone(ret.instance_type) - - def test_floating_ip_allocate(self): - ext_nets = [n for n in self.api_networks.list() - if n['router:external']] - ext_net = ext_nets[0] - fip = self.api_q_floating_ips.first() - self.qclient.create_floatingip( - {'floatingip': {'floating_network_id': ext_net['id'], - 'tenant_id': self.request.user.project_id}}) \ - .AndReturn({'floatingip': fip}) - self.mox.ReplayAll() - - ret = api.network.tenant_floating_ip_allocate(self.request, - ext_net['id']) - for attr in ['id', 'ip', 'pool', 'fixed_ip', 'port_id']: - self.assertEqual(fip[attr], getattr(ret, attr)) - self.assertIsNone(ret.instance_id) - self.assertIsNone(ret.instance_type) - - def test_floating_ip_release(self): - fip = self.api_q_floating_ips.first() - self.qclient.delete_floatingip(fip['id']) - self.mox.ReplayAll() - - api.network.tenant_floating_ip_release(self.request, fip['id']) - - def test_floating_ip_associate(self): - fip = self.api_q_floating_ips.list()[1] - assoc_port = self.api_ports.list()[1] - ip_address = assoc_port['fixed_ips'][0]['ip_address'] - target_id = '%s_%s' % (assoc_port['id'], ip_address) - params = {'port_id': assoc_port['id'], - 'fixed_ip_address': ip_address} - self.qclient.update_floatingip(fip['id'], - {'floatingip': params}) - self.mox.ReplayAll() - - api.network.floating_ip_associate(self.request, fip['id'], target_id) - - def test_floating_ip_disassociate(self): - fip = self.api_q_floating_ips.list()[1] - self.qclient.update_floatingip(fip['id'], - {'floatingip': {'port_id': None}}) - self.mox.ReplayAll() - - api.network.floating_ip_disassociate(self.request, fip['id']) - - def _get_target_id(self, port): - param = {'id': port['id'], - 'addr': port['fixed_ips'][0]['ip_address']} - return '%(id)s_%(addr)s' % param - - def _get_target_name(self, port): - param = {'svrid': port['device_id'], - 'addr': port['fixed_ips'][0]['ip_address']} - return 'server_%(svrid)s: %(addr)s' % param - - def _subs_from_port(self, port): - return [ip['subnet_id'] for ip in port['fixed_ips']] - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_lb': True}) - def test_floating_ip_target_list(self): - ports = self.api_ports.list() - # Port on the first subnet is connected to a router - # attached to external network in neutron_data. - subnet_id = self.subnets.first().id - shared_nets = [n for n in self.api_networks.list() if n['shared']] - shared_subnet_ids = [s for n in shared_nets for s in n['subnets']] - target_ports = [ - (self._get_target_id(p), self._get_target_name(p)) for p in ports - if (not p['device_owner'].startswith('network:') and - (subnet_id in self._subs_from_port(p) or - (set(shared_subnet_ids) & set(self._subs_from_port(p))))) - ] - filters = {'tenant_id': self.request.user.tenant_id} - self.qclient.list_ports(**filters).AndReturn({'ports': ports}) - servers = self.servers.list() - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - search_opts = {'project_id': self.request.user.tenant_id} - novaclient.servers.list(True, search_opts).AndReturn(servers) - - search_opts = {'router:external': True} - ext_nets = [n for n in self.api_networks.list() - if n['router:external']] - self.qclient.list_networks(**search_opts) \ - .AndReturn({'networks': ext_nets}) - self.qclient.list_routers().AndReturn({'routers': - self.api_routers.list()}) - self.qclient.list_networks(shared=True).AndReturn({'networks': - shared_nets}) - shared_subs = [s for s in self.api_subnets.list() - if s['id'] in shared_subnet_ids] - self.qclient.list_subnets().AndReturn({'subnets': shared_subs}) - self.qclient.list_vips().AndReturn({'vips': self.vips.list()}) - - self.mox.ReplayAll() - - rets = api.network.floating_ip_target_list(self.request) - self.assertEqual(len(target_ports), len(rets)) - for ret, exp in zip(rets, target_ports): - self.assertEqual(exp[0], ret.id) - self.assertEqual(exp[1], ret.name) - - def test_floating_ip_target_get_by_instance(self): - ports = self.api_ports.list() - candidates = [p for p in ports if p['device_id'] == '1'] - search_opts = {'device_id': '1'} - self.qclient.list_ports(**search_opts).AndReturn({'ports': candidates}) - self.mox.ReplayAll() - - ret = api.network.floating_ip_target_get_by_instance(self.request, '1') - self.assertEqual(self._get_target_id(candidates[0]), ret) - - def test_target_floating_ip_port_by_instance(self): - ports = self.api_ports.list() - candidates = [p for p in ports if p['device_id'] == '1'] - search_opts = {'device_id': '1'} - self.qclient.list_ports(**search_opts).AndReturn({'ports': candidates}) - self.mox.ReplayAll() - - ret = api.network.floating_ip_target_list_by_instance(self.request, - '1') - self.assertEqual(self._get_target_id(candidates[0]), ret[0]) - self.assertEqual(len(candidates), len(ret)) - - def test_floating_ip_target_get_by_instance_with_preloaded_target(self): - target_list = [{'name': 'name11', 'id': 'id11', 'instance_id': 'vm1'}, - {'name': 'name21', 'id': 'id21', 'instance_id': 'vm2'}, - {'name': 'name22', 'id': 'id22', 'instance_id': 'vm2'}] - self.mox.ReplayAll() - - ret = api.network.floating_ip_target_get_by_instance( - self.request, 'vm2', target_list) - self.assertEqual('id21', ret) - - def test_target_floating_ip_port_by_instance_with_preloaded_target(self): - target_list = [{'name': 'name11', 'id': 'id11', 'instance_id': 'vm1'}, - {'name': 'name21', 'id': 'id21', 'instance_id': 'vm2'}, - {'name': 'name22', 'id': 'id22', 'instance_id': 'vm2'}] - self.mox.ReplayAll() - - ret = api.network.floating_ip_target_list_by_instance( - self.request, 'vm2', target_list) - self.assertEqual(['id21', 'id22'], ret) diff --git a/code/horizon/openstack_dashboard/test/api_tests/neutron_rest_tests.py b/code/horizon/openstack_dashboard/test/api_tests/neutron_rest_tests.py deleted file mode 100755 index cf5ed140..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/neutron_rest_tests.py +++ /dev/null @@ -1,134 +0,0 @@ -# -# (c) Copyright 2015 Hewlett-Packard Development Company, L.P. -# -# 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. -import json - -import mock - -from openstack_dashboard.api.rest import neutron -from openstack_dashboard.test.test_data import neutron_data -from openstack_dashboard.test.test_data.utils import TestData # noqa - -from openstack_dashboard.test import helpers as test - - -TEST = TestData(neutron_data.data) - - -class NeutronNetworksTestCase(test.TestCase): - @classmethod - def setUpClass(cls): - cls._networks = [mock_factory(n) - for n in TEST.api_networks.list()] - - @mock.patch.object(neutron.api, 'neutron') - def test_get_list_for_tenant(self, client): - request = self.mock_rest_request() - networks = self._networks - client.network_list_for_tenant.return_value = networks - response = neutron.Networks().get(request) - self.assertStatusCode(response, 200) - self.assertItemsCollectionEqual(response, TEST.api_networks.list()) - client.network_list_for_tenant.assert_called_once_with( - request, request.user.tenant_id) - - @mock.patch.object(neutron.api, 'neutron') - def test_create(self, client): - self._test_create( - '{"name": "mynetwork"}', - {'name': 'mynetwork'} - ) - - @mock.patch.object(neutron.api, 'neutron') - def test_create_with_bogus_param(self, client): - self._test_create( - '{"name": "mynetwork","bilbo":"baggins"}', - {'name': 'mynetwork'} - ) - - @mock.patch.object(neutron.api, 'neutron') - def _test_create(self, supplied_body, expected_call, client): - request = self.mock_rest_request(body=supplied_body) - client.network_create.return_value = self._networks[0] - response = neutron.Networks().post(request) - self.assertStatusCode(response, 201) - self.assertEqual(response['location'], - '/api/neutron/networks/' + str( - TEST.api_networks.first().get("id"))) - self.assertEqual(response.content, - json.dumps(TEST.api_networks.first())) - - -class NeutronSubnetsTestCase(test.TestCase): - @classmethod - def setUpClass(cls): - cls._networks = [mock_factory(n) - for n in TEST.api_networks.list()] - cls._subnets = [mock_factory(n) - for n in TEST.api_subnets.list()] - - @mock.patch.object(neutron.api, 'neutron') - def test_get(self, client): - request = self.mock_rest_request( - GET={"network_id": self._networks[0].id}) - client.subnet_list.return_value = [self._subnets[0]] - response = neutron.Subnets().get(request) - self.assertStatusCode(response, 200) - client.subnet_list.assert_called_once_with( - request, network_id=TEST.api_networks.first().get("id")) - - @mock.patch.object(neutron.api, 'neutron') - def test_create(self, client): - request = self.mock_rest_request( - body='{"network_id": "%s",' - ' "ip_version": "4",' - ' "cidr": "192.168.199.0/24"}' % self._networks[0].id) - client.subnet_create.return_value = self._subnets[0] - response = neutron.Subnets().post(request) - self.assertStatusCode(response, 201) - self.assertEqual(response['location'], - '/api/neutron/subnets/' + - str(TEST.api_subnets.first().get("id"))) - self.assertEqual(response.content, - json.dumps(TEST.api_subnets.first())) - - -class NeutronPortsTestCase(test.TestCase): - @classmethod - def setUpClass(cls): - cls._networks = [mock_factory(n) - for n in TEST.api_networks.list()] - cls._ports = [mock_factory(n) - for n in TEST.api_ports.list()] - - @mock.patch.object(neutron.api, 'neutron') - def test_get(self, client): - request = self.mock_rest_request( - GET={"network_id": self._networks[0].id}) - client.port_list.return_value = [self._ports[0]] - response = neutron.Ports().get(request) - self.assertStatusCode(response, 200) - client.port_list.assert_called_once_with( - request, network_id=TEST.api_networks.first().get("id")) - - -def mock_obj_to_dict(r): - return mock.Mock(**{'to_dict.return_value': r}) - - -def mock_factory(r): - """mocks all the attributes as well as the to_dict """ - mocked = mock_obj_to_dict(r) - mocked.configure_mock(**r) - return mocked diff --git a/code/horizon/openstack_dashboard/test/api_tests/neutron_tests.py b/code/horizon/openstack_dashboard/test/api_tests/neutron_tests.py deleted file mode 100644 index 5f9940ad..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/neutron_tests.py +++ /dev/null @@ -1,428 +0,0 @@ -# Copyright 2012 NEC Corporation -# -# 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. - -import uuid - -from django.test.utils import override_settings - -from neutronclient.common import exceptions as neutron_exc - -from openstack_dashboard import api -from openstack_dashboard import policy -from openstack_dashboard.test import helpers as test - - -class NeutronApiTests(test.APITestCase): - def test_network_list(self): - networks = {'networks': self.api_networks.list()} - subnets = {'subnets': self.api_subnets.list()} - - neutronclient = self.stub_neutronclient() - neutronclient.list_networks().AndReturn(networks) - neutronclient.list_subnets().AndReturn(subnets) - self.mox.ReplayAll() - - ret_val = api.neutron.network_list(self.request) - for n in ret_val: - self.assertIsInstance(n, api.neutron.Network) - - def test_network_get(self): - network = {'network': self.api_networks.first()} - subnet = {'subnet': self.api_subnets.first()} - network_id = self.api_networks.first()['id'] - subnet_id = self.api_networks.first()['subnets'][0] - - neutronclient = self.stub_neutronclient() - neutronclient.show_network(network_id).AndReturn(network) - neutronclient.show_subnet(subnet_id).AndReturn(subnet) - self.mox.ReplayAll() - - ret_val = api.neutron.network_get(self.request, network_id) - self.assertIsInstance(ret_val, api.neutron.Network) - - def test_network_create(self): - network = {'network': self.api_networks.first()} - - neutronclient = self.stub_neutronclient() - form_data = {'network': {'name': 'net1', - 'tenant_id': self.request.user.project_id}} - neutronclient.create_network(body=form_data).AndReturn(network) - self.mox.ReplayAll() - - ret_val = api.neutron.network_create(self.request, name='net1') - self.assertIsInstance(ret_val, api.neutron.Network) - - def test_network_update(self): - network = {'network': self.api_networks.first()} - network_id = self.api_networks.first()['id'] - - neutronclient = self.stub_neutronclient() - form_data = {'network': {'name': 'net1'}} - neutronclient.update_network(network_id, body=form_data)\ - .AndReturn(network) - self.mox.ReplayAll() - - ret_val = api.neutron.network_update(self.request, network_id, - name='net1') - self.assertIsInstance(ret_val, api.neutron.Network) - - def test_network_delete(self): - network_id = self.api_networks.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.delete_network(network_id) - self.mox.ReplayAll() - - api.neutron.network_delete(self.request, network_id) - - def test_subnet_list(self): - subnets = {'subnets': self.api_subnets.list()} - - neutronclient = self.stub_neutronclient() - neutronclient.list_subnets().AndReturn(subnets) - self.mox.ReplayAll() - - ret_val = api.neutron.subnet_list(self.request) - for n in ret_val: - self.assertIsInstance(n, api.neutron.Subnet) - - def test_subnet_get(self): - subnet = {'subnet': self.api_subnets.first()} - subnet_id = self.api_subnets.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.show_subnet(subnet_id).AndReturn(subnet) - self.mox.ReplayAll() - - ret_val = api.neutron.subnet_get(self.request, subnet_id) - self.assertIsInstance(ret_val, api.neutron.Subnet) - - def test_subnet_create(self): - subnet_data = self.api_subnets.first() - params = {'network_id': subnet_data['network_id'], - 'tenant_id': subnet_data['tenant_id'], - 'name': subnet_data['name'], - 'cidr': subnet_data['cidr'], - 'ip_version': subnet_data['ip_version'], - 'gateway_ip': subnet_data['gateway_ip']} - - neutronclient = self.stub_neutronclient() - neutronclient.create_subnet(body={'subnet': params})\ - .AndReturn({'subnet': subnet_data}) - self.mox.ReplayAll() - - ret_val = api.neutron.subnet_create(self.request, **params) - self.assertIsInstance(ret_val, api.neutron.Subnet) - - def test_subnet_update(self): - subnet_data = self.api_subnets.first() - subnet_id = subnet_data['id'] - params = {'name': subnet_data['name'], - 'gateway_ip': subnet_data['gateway_ip']} - - neutronclient = self.stub_neutronclient() - neutronclient.update_subnet(subnet_id, body={'subnet': params})\ - .AndReturn({'subnet': subnet_data}) - self.mox.ReplayAll() - - ret_val = api.neutron.subnet_update(self.request, subnet_id, **params) - self.assertIsInstance(ret_val, api.neutron.Subnet) - - def test_subnet_delete(self): - subnet_id = self.api_subnets.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.delete_subnet(subnet_id) - self.mox.ReplayAll() - - api.neutron.subnet_delete(self.request, subnet_id) - - def test_port_list(self): - ports = {'ports': self.api_ports.list()} - - neutronclient = self.stub_neutronclient() - neutronclient.list_ports().AndReturn(ports) - self.mox.ReplayAll() - - ret_val = api.neutron.port_list(self.request) - for p in ret_val: - self.assertIsInstance(p, api.neutron.Port) - - def test_port_get(self): - port = {'port': self.api_ports.first()} - port_id = self.api_ports.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.show_port(port_id).AndReturn(port) - self.mox.ReplayAll() - - ret_val = api.neutron.port_get(self.request, port_id) - self.assertIsInstance(ret_val, api.neutron.Port) - - def test_port_create(self): - port_data = self.api_ports.first() - params = {'network_id': port_data['network_id'], - 'tenant_id': port_data['tenant_id'], - 'name': port_data['name'], - 'device_id': port_data['device_id']} - - neutronclient = self.stub_neutronclient() - neutronclient.create_port(body={'port': params})\ - .AndReturn({'port': port_data}) - self.mox.ReplayAll() - - ret_val = api.neutron.port_create(self.request, **params) - self.assertIsInstance(ret_val, api.neutron.Port) - self.assertEqual(api.neutron.Port(port_data).id, ret_val.id) - - def test_port_update(self): - port_data = self.api_ports.first() - port_id = port_data['id'] - params = {'name': port_data['name'], - 'device_id': port_data['device_id']} - - neutronclient = self.stub_neutronclient() - neutronclient.update_port(port_id, body={'port': params})\ - .AndReturn({'port': port_data}) - self.mox.ReplayAll() - - ret_val = api.neutron.port_update(self.request, port_id, **params) - self.assertIsInstance(ret_val, api.neutron.Port) - self.assertEqual(api.neutron.Port(port_data).id, ret_val.id) - - def test_port_delete(self): - port_id = self.api_ports.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.delete_port(port_id) - self.mox.ReplayAll() - - api.neutron.port_delete(self.request, port_id) - - def test_router_list(self): - routers = {'routers': self.api_routers.list()} - - neutronclient = self.stub_neutronclient() - neutronclient.list_routers().AndReturn(routers) - self.mox.ReplayAll() - - ret_val = api.neutron.router_list(self.request) - for n in ret_val: - self.assertIsInstance(n, api.neutron.Router) - - def test_router_get(self): - router = {'router': self.api_routers.first()} - router_id = self.api_routers.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.show_router(router_id).AndReturn(router) - self.mox.ReplayAll() - - ret_val = api.neutron.router_get(self.request, router_id) - self.assertIsInstance(ret_val, api.neutron.Router) - - def test_router_create(self): - router = {'router': self.api_routers.first()} - - neutronclient = self.stub_neutronclient() - form_data = {'router': {'name': 'router1', - 'tenant_id': self.request.user.project_id}} - neutronclient.create_router(body=form_data).AndReturn(router) - self.mox.ReplayAll() - - ret_val = api.neutron.router_create(self.request, name='router1') - self.assertIsInstance(ret_val, api.neutron.Router) - - def test_router_delete(self): - router_id = self.api_routers.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.delete_router(router_id) - self.mox.ReplayAll() - - api.neutron.router_delete(self.request, router_id) - - def test_router_add_interface(self): - subnet_id = self.api_subnets.first()['id'] - router_id = self.api_routers.first()['id'] - - neutronclient = self.stub_neutronclient() - form_data = {'subnet_id': subnet_id} - neutronclient.add_interface_router( - router_id, form_data).AndReturn(None) - self.mox.ReplayAll() - - api.neutron.router_add_interface( - self.request, router_id, subnet_id=subnet_id) - - def test_router_remove_interface(self): - router_id = self.api_routers.first()['id'] - fake_port = self.api_ports.first()['id'] - - neutronclient = self.stub_neutronclient() - neutronclient.remove_interface_router( - router_id, {'port_id': fake_port}) - self.mox.ReplayAll() - - api.neutron.router_remove_interface( - self.request, router_id, port_id=fake_port) - - def test_is_extension_supported(self): - neutronclient = self.stub_neutronclient() - neutronclient.list_extensions().MultipleTimes() \ - .AndReturn({'extensions': self.api_extensions.list()}) - self.mox.ReplayAll() - - self.assertTrue( - api.neutron.is_extension_supported(self.request, 'quotas')) - self.assertFalse( - api.neutron.is_extension_supported(self.request, 'doesntexist')) - - # NOTE(amotoki): "dvr" permission tests check most of - # get_feature_permission features. - # These tests are not specific to "dvr" extension. - # Please be careful if you drop "dvr" extension in future. - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_distributed_router': - True}, - POLICY_CHECK_FUNCTION=None) - def _test_get_dvr_permission_dvr_supported(self, dvr_enabled): - neutronclient = self.stub_neutronclient() - extensions = self.api_extensions.list() - if not dvr_enabled: - extensions = [ext for ext in extensions if ext['alias'] != 'dvr'] - neutronclient.list_extensions() \ - .AndReturn({'extensions': extensions}) - self.mox.ReplayAll() - self.assertEqual(dvr_enabled, - api.neutron.get_feature_permission(self.request, - 'dvr', 'get')) - - def test_get_dvr_permission_dvr_supported(self): - self._test_get_dvr_permission_dvr_supported(dvr_enabled=True) - - def test_get_dvr_permission_dvr_not_supported(self): - self._test_get_dvr_permission_dvr_supported(dvr_enabled=False) - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_distributed_router': - True}, - POLICY_CHECK_FUNCTION=policy.check) - def _test_get_dvr_permission_with_policy_check(self, policy_check_allowed, - operation): - self.mox.StubOutWithMock(policy, 'check') - if operation == "create": - role = (("network", "create_router:distributed"),) - elif operation == "get": - role = (("network", "get_router:distributed"),) - policy.check(role, self.request).AndReturn(policy_check_allowed) - if policy_check_allowed: - neutronclient = self.stub_neutronclient() - neutronclient.list_extensions() \ - .AndReturn({'extensions': self.api_extensions.list()}) - self.mox.ReplayAll() - self.assertEqual(policy_check_allowed, - api.neutron.get_feature_permission(self.request, - 'dvr', operation)) - - def test_get_dvr_permission_with_policy_check_allowed(self): - self._test_get_dvr_permission_with_policy_check(True, "get") - - def test_get_dvr_permission_with_policy_check_disallowed(self): - self._test_get_dvr_permission_with_policy_check(False, "get") - - def test_get_dvr_permission_create_with_policy_check_allowed(self): - self._test_get_dvr_permission_with_policy_check(True, "create") - - def test_get_dvr_permission_create_with_policy_check_disallowed(self): - self._test_get_dvr_permission_with_policy_check(False, "create") - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_distributed_router': - False}) - def test_get_dvr_permission_dvr_disabled_by_config(self): - self.assertFalse(api.neutron.get_feature_permission(self.request, - 'dvr', 'get')) - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_distributed_router': - True}, - POLICY_CHECK_FUNCTION=policy.check) - def test_get_dvr_permission_dvr_unsupported_operation(self): - self.assertRaises(ValueError, - api.neutron.get_feature_permission, - self.request, 'dvr', 'unSupported') - - @override_settings(OPENSTACK_NEUTRON_NETWORK={}) - def test_get_dvr_permission_dvr_default_config(self): - self.assertFalse(api.neutron.get_feature_permission(self.request, - 'dvr', 'get')) - - @override_settings(OPENSTACK_NEUTRON_NETWORK={}) - def test_get_dvr_permission_router_ha_default_config(self): - self.assertFalse(api.neutron.get_feature_permission(self.request, - 'l3-ha', 'get')) - - # NOTE(amotoki): Most of get_feature_permission are checked by "dvr" check - # above. l3-ha check only checks l3-ha specific code. - - @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_ha_router': True}, - POLICY_CHECK_FUNCTION=policy.check) - def _test_get_router_ha_permission_with_policy_check(self, ha_enabled): - self.mox.StubOutWithMock(policy, 'check') - role = (("network", "create_router:ha"),) - policy.check(role, self.request).AndReturn(True) - neutronclient = self.stub_neutronclient() - if ha_enabled: - extensions = self.api_extensions.list() - else: - extensions = {} - neutronclient.list_extensions().AndReturn({'extensions': extensions}) - self.mox.ReplayAll() - self.assertEqual(ha_enabled, - api.neutron.get_feature_permission(self.request, - 'l3-ha', 'create')) - - def test_get_router_ha_permission_with_l3_ha_extension(self): - self._test_get_router_ha_permission_with_policy_check(True) - - def test_get_router_ha_permission_without_l3_ha_extension(self): - self._test_get_router_ha_permission_with_policy_check(False) - - def test_list_resources_with_long_filters(self): - # In this tests, port_list is called with id=[10 port ID] - # filter. It generates about 40*10 char length URI. - # Each port ID is converted to "id=&" in URI and - # it means 40 chars (len(UUID)=36). - # If excess length is 220, it means 400-220=180 chars - # can be sent in the first request. - # As a result three API calls with 4, 4, 2 port ID - # are expected. - - ports = [{'id': str(uuid.uuid4()), - 'name': 'port%s' % i, - 'admin_state_up': True} - for i in range(10)] - port_ids = [port['id'] for port in ports] - - neutronclient = self.stub_neutronclient() - uri_len_exc = neutron_exc.RequestURITooLong(excess=220) - neutronclient.list_ports(id=port_ids).AndRaise(uri_len_exc) - for i in range(0, 10, 4): - neutronclient.list_ports(id=port_ids[i:i + 4]) \ - .AndReturn({'ports': ports[i:i + 4]}) - self.mox.ReplayAll() - - ret_val = api.neutron.list_resources_with_long_filters( - api.neutron.port_list, 'id', port_ids, - request=self.request) - self.assertEqual(10, len(ret_val)) - self.assertEqual(port_ids, [p.id for p in ret_val]) diff --git a/code/horizon/openstack_dashboard/test/api_tests/nova_rest_tests.py b/code/horizon/openstack_dashboard/test/api_tests/nova_rest_tests.py deleted file mode 100644 index f7035edc..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/nova_rest_tests.py +++ /dev/null @@ -1,272 +0,0 @@ -# Copyright 2014, Rackspace, US, 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. -import mock - -from django.conf import settings - -from openstack_dashboard.api.rest import nova -from openstack_dashboard.test import helpers as test - - -class NovaRestTestCase(test.TestCase): - # - # Keypairs - # - @mock.patch.object(nova.api, 'nova') - def test_keypair_get(self, nc): - request = self.mock_rest_request() - nc.keypair_list.return_value = [ - mock.Mock(**{'to_dict.return_value': {'id': 'one'}}), - mock.Mock(**{'to_dict.return_value': {'id': 'two'}}), - ] - response = nova.Keypairs().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"id": "one"}, {"id": "two"}]}') - nc.keypair_list.assert_called_once_with(request) - - @mock.patch.object(nova.api, 'nova') - def test_keypair_create(self, nc): - request = self.mock_rest_request(body='''{"name": "Ni!"}''') - new = nc.keypair_create.return_value - new.to_dict.return_value = {'name': 'Ni!', 'public_key': 'sekrit'} - new.name = 'Ni!' - with mock.patch.object(settings, 'DEBUG', True): - response = nova.Keypairs().post(request) - self.assertStatusCode(response, 201) - self.assertEqual(response.content, - '{"name": "Ni!", "public_key": "sekrit"}') - self.assertEqual(response['location'], '/api/nova/keypairs/Ni%21') - nc.keypair_create.assert_called_once_with(request, 'Ni!') - - @mock.patch.object(nova.api, 'nova') - def test_keypair_import(self, nc): - request = self.mock_rest_request(body=''' - {"name": "Ni!", "public_key": "hi"} - ''') - new = nc.keypair_import.return_value - new.to_dict.return_value = {'name': 'Ni!', 'public_key': 'hi'} - new.name = 'Ni!' - with mock.patch.object(settings, 'DEBUG', True): - response = nova.Keypairs().post(request) - self.assertStatusCode(response, 201) - self.assertEqual(response.content, - '{"name": "Ni!", "public_key": "hi"}') - self.assertEqual(response['location'], '/api/nova/keypairs/Ni%21') - nc.keypair_import.assert_called_once_with(request, 'Ni!', 'hi') - - # - # Availability Zones - # - def test_availzone_get_brief(self): - self._test_availzone_get(False) - - def test_availzone_get_detailed(self): - self._test_availzone_get(True) - - @mock.patch.object(nova.api, 'nova') - def _test_availzone_get(self, detail, nc): - if detail: - request = self.mock_rest_request(GET={'detailed': 'true'}) - else: - request = self.mock_rest_request(GET={}) - nc.availability_zone_list.return_value = [ - mock.Mock(**{'to_dict.return_value': {'id': 'one'}}), - mock.Mock(**{'to_dict.return_value': {'id': 'two'}}), - ] - response = nova.AvailabilityZones().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"id": "one"}, {"id": "two"}]}') - nc.availability_zone_list.assert_called_once_with(request, detail) - - # - # Limits - # - def test_limits_get_not_reserved(self): - self._test_limits_get(False) - - def test_limits_get_reserved(self): - self._test_limits_get(True) - - @mock.patch.object(nova.api, 'nova') - def _test_limits_get(self, reserved, nc): - if reserved: - request = self.mock_rest_request(GET={'reserved': 'true'}) - else: - request = self.mock_rest_request(GET={}) - nc.tenant_absolute_limits.return_value = {'id': 'one'} - response = nova.Limits().get(request) - self.assertStatusCode(response, 200) - nc.tenant_absolute_limits.assert_called_once_with(request, reserved) - self.assertEqual(response.content, '{"id": "one"}') - - # - # Servers - # - @mock.patch.object(nova.api, 'nova') - def test_server_create_missing(self, nc): - request = self.mock_rest_request(body='''{"name": "hi"}''') - response = nova.Servers().post(request) - self.assertStatusCode(response, 400) - self.assertEqual(response.content, - '"missing required parameter \'source_id\'"') - nc.server_create.assert_not_called() - - @mock.patch.object(nova.api, 'nova') - def test_server_create_basic(self, nc): - request = self.mock_rest_request(body='''{"name": "Ni!", - "source_id": "image123", "flavor_id": "flavor123", - "key_name": "sekrit", "user_data": "base64 yes", - "security_groups": [{"name": "root"}]} - ''') - new = nc.server_create.return_value - new.to_dict.return_value = {'id': 'server123'} - new.id = 'server123' - response = nova.Servers().post(request) - self.assertStatusCode(response, 201) - self.assertEqual(response.content, '{"id": "server123"}') - self.assertEqual(response['location'], '/api/nova/servers/server123') - nc.server_create.assert_called_once_with( - request, 'Ni!', 'image123', 'flavor123', 'sekrit', 'base64 yes', - [{'name': 'root'}] - ) - - @mock.patch.object(nova.api, 'nova') - def test_server_get_single(self, nc): - request = self.mock_rest_request() - nc.server_get.return_value.to_dict.return_value = {'name': '1'} - - response = nova.Server().get(request, "1") - self.assertStatusCode(response, 200) - nc.server_get.assert_called_once_with(request, "1") - - # - # Extensions - # - @mock.patch.object(nova.api, 'nova') - def _test_extension_list(self, nc): - request = self.mock_rest_request() - nc.list_extensions.return_value = [ - mock.Mock(**{'to_dict.return_value': {'name': 'foo'}}), - mock.Mock(**{'to_dict.return_value': {'name': 'bar'}}), - ] - response = nova.Extensions().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"name": "foo"}, {"name": "bar"}]}') - nc.list_extensions.assert_called_once_with(request) - - # - # Flavors - # - def test_get_extras_no(self): - self._test_flavor_get_single(get_extras=False) - - def test_get_extras_yes(self): - self._test_flavor_get_single(get_extras=True) - - def test_get_extras_default(self): - self._test_flavor_get_single(get_extras=None) - - @mock.patch.object(nova.api, 'nova') - def _test_flavor_get_single(self, nc, get_extras): - if get_extras: - request = self.mock_rest_request(GET={'get_extras': 'tRuE'}) - elif get_extras is None: - request = self.mock_rest_request() - get_extras = False - else: - request = self.mock_rest_request(GET={'get_extras': 'fAlsE'}) - nc.flavor_get.return_value.to_dict.return_value = {'name': '1'} - - response = nova.Flavor().get(request, "1") - self.assertStatusCode(response, 200) - if get_extras: - self.assertEqual(response.content, '{"extras": {}, "name": "1"}') - else: - self.assertEqual(response.content, '{"name": "1"}') - nc.flavor_get.assert_called_once_with(request, "1", - get_extras=get_extras) - - @mock.patch.object(nova.api, 'nova') - def _test_flavor_list_public(self, nc, is_public=None): - if is_public: - request = self.mock_rest_request(GET={'is_public': 'tRuE'}) - elif is_public is None: - request = self.mock_rest_request(GET={}) - else: - request = self.mock_rest_request(GET={'is_public': 'fAlsE'}) - nc.flavor_list.return_value = [ - mock.Mock(**{'to_dict.return_value': {'id': '1'}}), - mock.Mock(**{'to_dict.return_value': {'id': '2'}}), - ] - response = nova.Flavors().get(request) - self.assertStatusCode(response, 200) - self.assertEqual(response.content, - '{"items": [{"id": "1"}, {"id": "2"}]}') - nc.flavor_list.assert_called_once_with(request, is_public=is_public, - get_extras=False) - - def test_flavor_list_private(self): - self._test_flavor_list_public(is_public=False) - - def test_flavor_list_public(self): - self._test_flavor_list_public(is_public=True) - - def test_flavor_list_public_none(self): - self._test_flavor_list_public(is_public=None) - - @mock.patch.object(nova.api, 'nova') - def _test_flavor_list_extras(self, nc, get_extras=None): - if get_extras: - request = self.mock_rest_request(GET={'get_extras': 'tRuE'}) - elif get_extras is None: - request = self.mock_rest_request(GET={}) - get_extras = False - else: - request = self.mock_rest_request(GET={'get_extras': 'fAlsE'}) - nc.flavor_list.return_value = [ - mock.Mock(**{'extras': {}, 'to_dict.return_value': {'id': '1'}}), - mock.Mock(**{'extras': {}, 'to_dict.return_value': {'id': '2'}}), - ] - response = nova.Flavors().get(request) - self.assertStatusCode(response, 200) - if get_extras: - self.assertEqual(response.content, - '{"items": [{"extras": {}, "id": "1"}, ' - '{"extras": {}, "id": "2"}]}') - else: - self.assertEqual(response.content, - '{"items": [{"id": "1"}, {"id": "2"}]}') - nc.flavor_list.assert_called_once_with(request, is_public=None, - get_extras=get_extras) - - def test_flavor_list_extras_no(self): - self._test_flavor_list_extras(get_extras=False) - - def test_flavor_list_extras_yes(self): - self._test_flavor_list_extras(get_extras=True) - - def test_flavor_list_extras_absent(self): - self._test_flavor_list_extras(get_extras=None) - - @mock.patch.object(nova.api, 'nova') - def test_flavor_extra_specs(self, nc): - request = self.mock_rest_request() - nc.flavor_get_extras.return_value.to_dict.return_value = {'foo': '1'} - - response = nova.FlavorExtraSpecs().get(request, "1") - self.assertStatusCode(response, 200) - nc.flavor_get_extras.assert_called_once_with(request, "1", raw=True) diff --git a/code/horizon/openstack_dashboard/test/api_tests/nova_tests.py b/code/horizon/openstack_dashboard/test/api_tests/nova_tests.py deleted file mode 100644 index 7b360ef2..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/nova_tests.py +++ /dev/null @@ -1,349 +0,0 @@ -# Copyright 2012 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# Copyright 2012 Nebula, Inc. -# Copyright (c) 2012 X.commerce, a business unit of eBay 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 __future__ import absolute_import - -from django.conf import settings -from django import http -from django.test.utils import override_settings - -from mox import IsA # noqa -from novaclient import exceptions as nova_exceptions -from novaclient.v2 import servers -import six - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test - - -class ServerWrapperTests(test.TestCase): - - def test_get_base_attribute(self): - server = api.nova.Server(self.servers.first(), self.request) - self.assertEqual(self.servers.first().id, server.id) - - def test_image_name(self): - image = self.images.first() - self.mox.StubOutWithMock(api.glance, 'image_get') - api.glance.image_get(IsA(http.HttpRequest), - image.id).AndReturn(image) - self.mox.ReplayAll() - - server = api.nova.Server(self.servers.first(), self.request) - self.assertEqual(image.name, server.image_name) - - -class ComputeApiTests(test.APITestCase): - - def test_server_reboot(self): - server = self.servers.first() - HARDNESS = servers.REBOOT_HARD - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.reboot(server.id, HARDNESS) - self.mox.ReplayAll() - - ret_val = api.nova.server_reboot(self.request, server.id) - self.assertIsNone(ret_val) - - def test_server_soft_reboot(self): - server = self.servers.first() - HARDNESS = servers.REBOOT_SOFT - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.reboot(server.id, HARDNESS) - self.mox.ReplayAll() - - ret_val = api.nova.server_reboot(self.request, server.id, HARDNESS) - self.assertIsNone(ret_val) - - def test_server_vnc_console(self): - server = self.servers.first() - console = self.servers.vnc_console_data - console_type = console["console"]["type"] - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get_vnc_console(server.id, - console_type).AndReturn(console) - self.mox.ReplayAll() - - ret_val = api.nova.server_vnc_console(self.request, - server.id, - console_type) - self.assertIsInstance(ret_val, api.nova.VNCConsole) - - def test_server_spice_console(self): - server = self.servers.first() - console = self.servers.spice_console_data - console_type = console["console"]["type"] - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get_spice_console(server.id, - console_type).AndReturn(console) - self.mox.ReplayAll() - - ret_val = api.nova.server_spice_console(self.request, - server.id, - console_type) - self.assertIsInstance(ret_val, api.nova.SPICEConsole) - - def test_server_rdp_console(self): - server = self.servers.first() - console = self.servers.rdp_console_data - console_type = console["console"]["type"] - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get_rdp_console(server.id, - console_type).AndReturn(console) - self.mox.ReplayAll() - - ret_val = api.nova.server_rdp_console(self.request, - server.id, - console_type) - self.assertIsInstance(ret_val, api.nova.RDPConsole) - - def test_server_list(self): - servers = self.servers.list() - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.list(True, {'all_tenants': True}).AndReturn(servers) - self.mox.ReplayAll() - - ret_val, has_more = api.nova.server_list(self.request, - all_tenants=True) - for server in ret_val: - self.assertIsInstance(server, api.nova.Server) - - def test_server_list_pagination(self): - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20) - servers = self.servers.list() - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.list(True, - {'all_tenants': True, - 'marker': None, - 'limit': page_size + 1}).AndReturn(servers) - self.mox.ReplayAll() - - ret_val, has_more = api.nova.server_list(self.request, - {'marker': None, - 'paginate': True}, - all_tenants=True) - for server in ret_val: - self.assertIsInstance(server, api.nova.Server) - self.assertFalse(has_more) - - @override_settings(API_RESULT_PAGE_SIZE=1) - def test_server_list_pagination_more(self): - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 1) - servers = self.servers.list() - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.list(True, - {'all_tenants': True, - 'marker': None, - 'limit': page_size + 1}) \ - .AndReturn(servers[:page_size + 1]) - self.mox.ReplayAll() - - ret_val, has_more = api.nova.server_list(self.request, - {'marker': None, - 'paginate': True}, - all_tenants=True) - for server in ret_val: - self.assertIsInstance(server, api.nova.Server) - self.assertEqual(page_size, len(ret_val)) - self.assertTrue(has_more) - - def test_usage_get(self): - novaclient = self.stub_novaclient() - novaclient.usage = self.mox.CreateMockAnything() - novaclient.usage.get(self.tenant.id, - 'start', - 'end').AndReturn(self.usages.first()) - self.mox.ReplayAll() - - ret_val = api.nova.usage_get(self.request, self.tenant.id, - 'start', 'end') - self.assertIsInstance(ret_val, api.nova.NovaUsage) - - def test_usage_list(self): - usages = self.usages.list() - - novaclient = self.stub_novaclient() - novaclient.usage = self.mox.CreateMockAnything() - novaclient.usage.list('start', 'end', True).AndReturn(usages) - self.mox.ReplayAll() - - ret_val = api.nova.usage_list(self.request, 'start', 'end') - for usage in ret_val: - self.assertIsInstance(usage, api.nova.NovaUsage) - - def test_server_get(self): - server = self.servers.first() - - novaclient = self.stub_novaclient() - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get(server.id).AndReturn(server) - self.mox.ReplayAll() - - ret_val = api.nova.server_get(self.request, server.id) - self.assertIsInstance(ret_val, api.nova.Server) - - def _test_absolute_limits(self, values, expected_results): - limits = self.mox.CreateMockAnything() - limits.absolute = [] - for key, val in six.iteritems(values): - limit = self.mox.CreateMockAnything() - limit.name = key - limit.value = val - limits.absolute.append(limit) - - novaclient = self.stub_novaclient() - novaclient.limits = self.mox.CreateMockAnything() - novaclient.limits.get(reserved=True).AndReturn(limits) - self.mox.ReplayAll() - - ret_val = api.nova.tenant_absolute_limits(self.request, reserved=True) - for key in expected_results.keys(): - self.assertEqual(expected_results[key], ret_val[key]) - - def test_absolute_limits_handle_unlimited(self): - values = {"maxTotalCores": -1, "maxTotalInstances": 10} - expected_results = {"maxTotalCores": float("inf"), - "maxTotalInstances": 10} - self._test_absolute_limits(values, expected_results) - - def test_absolute_limits_negative_used_workaround(self): - values = {"maxTotalCores": -1, - "maxTotalInstances": 10, - "totalInstancesUsed": -1, - "totalCoresUsed": -1, - "totalRAMUsed": -2048, - "totalSecurityGroupsUsed": 1, - "totalFloatingIpsUsed": 0, - } - expected_results = {"maxTotalCores": float("inf"), - "maxTotalInstances": 10, - "totalInstancesUsed": 0, - "totalCoresUsed": 0, - "totalRAMUsed": 0, - "totalSecurityGroupsUsed": 1, - "totalFloatingIpsUsed": 0, - } - self._test_absolute_limits(values, expected_results) - - def test_cold_migrate_host_succeed(self): - hypervisor = self.hypervisors.first() - novaclient = self.stub_novaclient() - - novaclient.hypervisors = self.mox.CreateMockAnything() - novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) - - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.migrate("test_uuid") - - self.mox.ReplayAll() - - ret_val = api.nova.migrate_host(self.request, "host", False, True, - True) - - self.assertTrue(ret_val) - - def test_cold_migrate_host_fails(self): - hypervisor = self.hypervisors.first() - novaclient = self.stub_novaclient() - - novaclient.hypervisors = self.mox.CreateMockAnything() - novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) - - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.migrate("test_uuid").AndRaise( - nova_exceptions.ClientException(404)) - - self.mox.ReplayAll() - - self.assertRaises(nova_exceptions.ClientException, - api.nova.migrate_host, - self.request, "host", False, True, True) - - def test_live_migrate_host_with_active_vm(self): - hypervisor = self.hypervisors.first() - server = self.servers.first() - novaclient = self.stub_novaclient() - server_uuid = hypervisor.servers[0]["uuid"] - - novaclient.hypervisors = self.mox.CreateMockAnything() - novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) - - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get(server_uuid).AndReturn(server) - novaclient.servers.live_migrate(server_uuid, None, True, True) - - self.mox.ReplayAll() - - ret_val = api.nova.migrate_host(self.request, "host", True, True, - True) - - self.assertTrue(ret_val) - - def test_live_migrate_host_with_paused_vm(self): - hypervisor = self.hypervisors.first() - server = self.servers.list()[3] - novaclient = self.stub_novaclient() - server_uuid = hypervisor.servers[0]["uuid"] - - novaclient.hypervisors = self.mox.CreateMockAnything() - novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) - - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get(server_uuid).AndReturn(server) - novaclient.servers.live_migrate(server_uuid, None, True, True) - - self.mox.ReplayAll() - - ret_val = api.nova.migrate_host(self.request, "host", True, True, - True) - - self.assertTrue(ret_val) - - def test_live_migrate_host_without_running_vm(self): - hypervisor = self.hypervisors.first() - server = self.servers.list()[1] - novaclient = self.stub_novaclient() - server_uuid = hypervisor.servers[0]["uuid"] - - novaclient.hypervisors = self.mox.CreateMockAnything() - novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) - - novaclient.servers = self.mox.CreateMockAnything() - novaclient.servers.get(server_uuid).AndReturn(server) - novaclient.servers.migrate(server_uuid) - - self.mox.ReplayAll() - - ret_val = api.nova.migrate_host(self.request, "host", True, True, - True) - self.assertTrue(ret_val) diff --git a/code/horizon/openstack_dashboard/test/api_tests/swift_tests.py b/code/horizon/openstack_dashboard/test/api_tests/swift_tests.py deleted file mode 100644 index 9bba7c80..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/swift_tests.py +++ /dev/null @@ -1,229 +0,0 @@ -# Copyright 2012 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# Copyright 2012 Nebula, 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 __future__ import absolute_import - -from mox import IsA # noqa - -from horizon import exceptions - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test - - -class SwiftApiTests(test.APITestCase): - def test_swift_get_containers(self): - containers = self.containers.list() - cont_data = [c._apidict for c in containers] - swift_api = self.stub_swiftclient() - swift_api.get_account(limit=1001, - marker=None, - full_listing=True).AndReturn([{}, cont_data]) - self.mox.ReplayAll() - - (conts, more) = api.swift.swift_get_containers(self.request) - self.assertEqual(len(containers), len(conts)) - self.assertFalse(more) - - def test_swift_get_container_with_data(self): - container = self.containers.first() - objects = self.objects.list() - swift_api = self.stub_swiftclient() - swift_api.get_object(container.name, "") \ - .AndReturn((container, objects)) - self.mox.ReplayAll() - - cont = api.swift.swift_get_container(self.request, container.name) - self.assertEqual(container.name, cont.name) - self.assertEqual(len(objects), len(cont.data)) - - def test_swift_get_container_without_data(self): - container = self.containers.first() - swift_api = self.stub_swiftclient() - swift_api.head_container(container.name).AndReturn(container) - self.mox.ReplayAll() - - cont = api.swift.swift_get_container(self.request, - container.name, - with_data=False) - self.assertEqual(cont.name, container.name) - self.assertIsNone(cont.data) - - def test_swift_create_duplicate_container(self): - metadata = {'is_public': False} - container = self.containers.first() - headers = api.swift._metadata_to_header(metadata=(metadata)) - swift_api = self.stub_swiftclient() - # Check for existence, then create - exc = self.exceptions.swift - swift_api.head_container(container.name).AndRaise(exc) - swift_api.put_container(container.name, headers=headers) \ - .AndReturn(container) - self.mox.ReplayAll() - # Verification handled by mox, no assertions needed. - api.swift.swift_create_container(self.request, - container.name, - metadata=(metadata)) - - def test_swift_create_container(self): - metadata = {'is_public': True} - container = self.containers.first() - swift_api = self.stub_swiftclient() - swift_api.head_container(container.name).AndReturn(container) - self.mox.ReplayAll() - # Verification handled by mox, no assertions needed. - with self.assertRaises(exceptions.AlreadyExists): - api.swift.swift_create_container(self.request, - container.name, - metadata=(metadata)) - - def test_swift_update_container(self): - metadata = {'is_public': True} - container = self.containers.first() - swift_api = self.stub_swiftclient() - headers = api.swift._metadata_to_header(metadata=(metadata)) - swift_api.post_container(container.name, headers=headers)\ - .AndReturn(container) - self.mox.ReplayAll() - # Verification handled by mox, no assertions needed. - api.swift.swift_update_container(self.request, - container.name, - metadata=(metadata)) - - def test_swift_get_objects(self): - container = self.containers.first() - objects = self.objects.list() - - swift_api = self.stub_swiftclient() - swift_api.get_container(container.name, - limit=1001, - marker=None, - prefix=None, - delimiter='/', - full_listing=True).AndReturn([{}, objects]) - self.mox.ReplayAll() - - (objs, more) = api.swift.swift_get_objects(self.request, - container.name) - self.assertEqual(len(objects), len(objs)) - self.assertFalse(more) - - def test_swift_get_object_with_data_non_chunked(self): - container = self.containers.first() - object = self.objects.first() - - swift_api = self.stub_swiftclient() - swift_api.get_object( - container.name, object.name, resp_chunk_size=None - ).AndReturn([object, object.data]) - - self.mox.ReplayAll() - - obj = api.swift.swift_get_object(self.request, container.name, - object.name, resp_chunk_size=None) - self.assertEqual(object.name, obj.name) - - def test_swift_get_object_with_data_chunked(self): - container = self.containers.first() - object = self.objects.first() - - swift_api = self.stub_swiftclient() - swift_api.get_object( - container.name, object.name, resp_chunk_size=api.swift.CHUNK_SIZE - ).AndReturn([object, object.data]) - - self.mox.ReplayAll() - - obj = api.swift.swift_get_object( - self.request, container.name, object.name) - self.assertEqual(object.name, obj.name) - - def test_swift_get_object_without_data(self): - container = self.containers.first() - object = self.objects.first() - - swift_api = self.stub_swiftclient() - swift_api.head_object(container.name, object.name) \ - .AndReturn(object) - - self.mox.ReplayAll() - - obj = api.swift.swift_get_object(self.request, - container.name, - object.name, - with_data=False) - self.assertEqual(object.name, obj.name) - self.assertIsNone(obj.data) - - def test_swift_upload_object(self): - container = self.containers.first() - obj = self.objects.first() - fake_name = 'fake_object.jpg' - - class FakeFile(object): - def __init__(self): - self.name = fake_name - self.data = obj.data - self.size = len(obj.data) - - headers = {'X-Object-Meta-Orig-Filename': fake_name} - - swift_api = self.stub_swiftclient() - swift_api.put_object(container.name, - obj.name, - IsA(FakeFile), - headers=headers) - self.mox.ReplayAll() - - api.swift.swift_upload_object(self.request, - container.name, - obj.name, - FakeFile()) - - def test_swift_upload_object_without_file(self): - container = self.containers.first() - obj = self.objects.first() - - swift_api = self.stub_swiftclient() - swift_api.put_object(container.name, - obj.name, - None, - headers={}) - self.mox.ReplayAll() - - response = api.swift.swift_upload_object(self.request, - container.name, - obj.name, - None) - self.assertEqual(0, response['bytes']) - - def test_swift_object_exists(self): - container = self.containers.first() - obj = self.objects.first() - - swift_api = self.stub_swiftclient() - swift_api.head_object(container.name, obj.name).AndReturn(container) - - exc = self.exceptions.swift - swift_api.head_object(container.name, obj.name).AndRaise(exc) - self.mox.ReplayAll() - - args = self.request, container.name, obj.name - self.assertTrue(api.swift.swift_object_exists(*args)) - # Again, for a "non-existent" object - self.assertFalse(api.swift.swift_object_exists(*args)) diff --git a/code/horizon/openstack_dashboard/test/api_tests/vpnaas_tests.py b/code/horizon/openstack_dashboard/test/api_tests/vpnaas_tests.py deleted file mode 100644 index ad6f070c..00000000 --- a/code/horizon/openstack_dashboard/test/api_tests/vpnaas_tests.py +++ /dev/null @@ -1,293 +0,0 @@ -# Copyright 2013, Mirantis 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 openstack_dashboard import api -from openstack_dashboard.test import helpers as test - -from neutronclient.v2_0 import client - -neutronclient = client.Client - - -class VPNaasApiTests(test.APITestCase): - @test.create_stubs({neutronclient: ('create_vpnservice',)}) - def test_vpnservice_create(self): - vpnservice1 = self.api_vpnservices.first() - form_data = { - 'name': vpnservice1['name'], - 'description': vpnservice1['description'], - 'subnet_id': vpnservice1['subnet_id'], - 'router_id': vpnservice1['router_id'], - 'admin_state_up': vpnservice1['admin_state_up'] - } - - vpnservice = {'vpnservice': self.api_vpnservices.first()} - neutronclient.create_vpnservice( - {'vpnservice': form_data}).AndReturn(vpnservice) - self.mox.ReplayAll() - - ret_val = api.vpn.vpnservice_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.vpn.VPNService) - - @test.create_stubs({neutronclient: ('list_vpnservices', - 'list_ipsec_site_connections'), - api.neutron: ('subnet_list', 'router_list')}) - def test_vpnservice_list(self): - vpnservices = {'vpnservices': self.vpnservices.list()} - vpnservices_dict = {'vpnservices': self.api_vpnservices.list()} - subnets = self.subnets.list() - routers = self.routers.list() - ipsecsiteconnections_dict = { - 'ipsec_site_connections': self.api_ipsecsiteconnections.list()} - - neutronclient.list_vpnservices().AndReturn(vpnservices_dict) - api.neutron.subnet_list(self.request).AndReturn(subnets) - api.neutron.router_list(self.request).AndReturn(routers) - neutronclient.list_ipsec_site_connections().AndReturn( - ipsecsiteconnections_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.vpnservice_list(self.request) - for (v, d) in zip(ret_val, vpnservices['vpnservices']): - self.assertIsInstance(v, api.vpn.VPNService) - self.assertTrue(v.name, d.name) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_vpnservice', - 'list_ipsec_site_connections'), - api.neutron: ('subnet_get', 'router_get')}) - def test_vpnservice_get(self): - vpnservice = self.vpnservices.first() - vpnservice_dict = {'vpnservice': self.api_vpnservices.first()} - subnet = self.subnets.first() - router = self.routers.first() - ipsecsiteconnections_dict = { - 'ipsec_site_connections': self.api_ipsecsiteconnections.list()} - - neutronclient.show_vpnservice( - vpnservice.id).AndReturn(vpnservice_dict) - api.neutron.subnet_get(self.request, subnet.id).AndReturn(subnet) - api.neutron.router_get(self.request, router.id).AndReturn(router) - neutronclient.list_ipsec_site_connections().AndReturn( - ipsecsiteconnections_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.vpnservice_get(self.request, vpnservice.id) - self.assertIsInstance(ret_val, api.vpn.VPNService) - - @test.create_stubs({neutronclient: ('create_ikepolicy',)}) - def test_ikepolicy_create(self): - ikepolicy1 = self.api_ikepolicies.first() - form_data = { - 'name': ikepolicy1['name'], - 'description': ikepolicy1['description'], - 'auth_algorithm': ikepolicy1['auth_algorithm'], - 'encryption_algorithm': ikepolicy1['encryption_algorithm'], - 'ike_version': ikepolicy1['ike_version'], - 'lifetime': ikepolicy1['lifetime'], - 'phase1_negotiation_mode': ikepolicy1['phase1_negotiation_mode'], - 'pfs': ikepolicy1['pfs'] - } - - ikepolicy = {'ikepolicy': self.api_ikepolicies.first()} - neutronclient.create_ikepolicy( - {'ikepolicy': form_data}).AndReturn(ikepolicy) - self.mox.ReplayAll() - - ret_val = api.vpn.ikepolicy_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.vpn.IKEPolicy) - - @test.create_stubs({neutronclient: ('list_ikepolicies', - 'list_ipsec_site_connections')}) - def test_ikepolicy_list(self): - ikepolicies = {'ikepolicies': self.ikepolicies.list()} - ikepolicies_dict = {'ikepolicies': self.api_ikepolicies.list()} - ipsecsiteconnections_dict = { - 'ipsec_site_connections': self.api_ipsecsiteconnections.list()} - - neutronclient.list_ikepolicies().AndReturn(ikepolicies_dict) - neutronclient.list_ipsec_site_connections().AndReturn( - ipsecsiteconnections_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.ikepolicy_list(self.request) - for (v, d) in zip(ret_val, ikepolicies['ikepolicies']): - self.assertIsInstance(v, api.vpn.IKEPolicy) - self.assertTrue(v.name, d.name) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_ikepolicy', - 'list_ipsec_site_connections')}) - def test_ikepolicy_get(self): - ikepolicy = self.ikepolicies.first() - ikepolicy_dict = {'ikepolicy': self.api_ikepolicies.first()} - ipsecsiteconnections_dict = { - 'ipsec_site_connections': self.api_ipsecsiteconnections.list()} - - neutronclient.show_ikepolicy( - ikepolicy.id).AndReturn(ikepolicy_dict) - neutronclient.list_ipsec_site_connections().AndReturn( - ipsecsiteconnections_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.ikepolicy_get(self.request, ikepolicy.id) - self.assertIsInstance(ret_val, api.vpn.IKEPolicy) - - @test.create_stubs({neutronclient: ('create_ipsecpolicy',)}) - def test_ipsecpolicy_create(self): - ipsecpolicy1 = self.api_ipsecpolicies.first() - form_data = { - 'name': ipsecpolicy1['name'], - 'description': ipsecpolicy1['description'], - 'auth_algorithm': ipsecpolicy1['auth_algorithm'], - 'encryption_algorithm': ipsecpolicy1['encryption_algorithm'], - 'encapsulation_mode': ipsecpolicy1['encapsulation_mode'], - 'lifetime': ipsecpolicy1['lifetime'], - 'pfs': ipsecpolicy1['pfs'], - 'transform_protocol': ipsecpolicy1['transform_protocol'] - } - - ipsecpolicy = {'ipsecpolicy': self.api_ipsecpolicies.first()} - neutronclient.create_ipsecpolicy( - {'ipsecpolicy': form_data}).AndReturn(ipsecpolicy) - self.mox.ReplayAll() - - ret_val = api.vpn.ipsecpolicy_create(self.request, **form_data) - self.assertIsInstance(ret_val, api.vpn.IPSecPolicy) - - @test.create_stubs({neutronclient: ('list_ipsecpolicies', - 'list_ipsec_site_connections')}) - def test_ipsecpolicy_list(self): - ipsecpolicies = {'ipsecpolicies': self.ipsecpolicies.list()} - ipsecpolicies_dict = {'ipsecpolicies': self.api_ipsecpolicies.list()} - ipsecsiteconnections_dict = { - 'ipsec_site_connections': self.api_ipsecsiteconnections.list()} - - neutronclient.list_ipsecpolicies().AndReturn(ipsecpolicies_dict) - neutronclient.list_ipsec_site_connections().AndReturn( - ipsecsiteconnections_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.ipsecpolicy_list(self.request) - for (v, d) in zip(ret_val, ipsecpolicies['ipsecpolicies']): - self.assertIsInstance(v, api.vpn.IPSecPolicy) - self.assertTrue(v.name, d.name) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_ipsecpolicy', - 'list_ipsec_site_connections')}) - def test_ipsecpolicy_get(self): - ipsecpolicy = self.ipsecpolicies.first() - ipsecpolicy_dict = {'ipsecpolicy': self.api_ipsecpolicies.first()} - ipsecsiteconnections_dict = { - 'ipsec_site_connections': self.api_ipsecsiteconnections.list()} - - neutronclient.show_ipsecpolicy( - ipsecpolicy.id).AndReturn(ipsecpolicy_dict) - neutronclient.list_ipsec_site_connections().AndReturn( - ipsecsiteconnections_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.ipsecpolicy_get(self.request, ipsecpolicy.id) - self.assertIsInstance(ret_val, api.vpn.IPSecPolicy) - - @test.create_stubs({neutronclient: ('create_ipsec_site_connection',)}) - def test_ipsecsiteconnection_create(self): - ipsecsiteconnection1 = self.api_ipsecsiteconnections.first() - form_data = { - 'name': ipsecsiteconnection1['name'], - 'description': ipsecsiteconnection1['description'], - 'dpd': ipsecsiteconnection1['dpd'], - 'ikepolicy_id': ipsecsiteconnection1['ikepolicy_id'], - 'initiator': ipsecsiteconnection1['initiator'], - 'ipsecpolicy_id': ipsecsiteconnection1['ipsecpolicy_id'], - 'mtu': ipsecsiteconnection1['mtu'], - 'peer_address': ipsecsiteconnection1['peer_address'], - 'peer_cidrs': ipsecsiteconnection1['peer_cidrs'], - 'peer_id': ipsecsiteconnection1['peer_id'], - 'psk': ipsecsiteconnection1['psk'], - 'vpnservice_id': ipsecsiteconnection1['vpnservice_id'], - 'admin_state_up': ipsecsiteconnection1['admin_state_up'] - } - - ipsecsiteconnection = {'ipsec_site_connection': - self.api_ipsecsiteconnections.first()} - neutronclient.create_ipsec_site_connection( - {'ipsec_site_connection': - form_data}).AndReturn(ipsecsiteconnection) - self.mox.ReplayAll() - - ret_val = api.vpn.ipsecsiteconnection_create( - self.request, **form_data) - self.assertIsInstance(ret_val, api.vpn.IPSecSiteConnection) - - @test.create_stubs({neutronclient: ('list_ipsec_site_connections', - 'list_ikepolicies', - 'list_ipsecpolicies', - 'list_vpnservices')}) - def test_ipsecsiteconnection_list(self): - ipsecsiteconnections = { - 'ipsec_site_connections': self.ipsecsiteconnections.list()} - ipsecsiteconnections_dict = { - 'ipsec_site_connections': self.api_ipsecsiteconnections.list()} - ikepolicies_dict = {'ikepolicies': self.api_ikepolicies.list()} - ipsecpolicies_dict = {'ipsecpolicies': self.api_ipsecpolicies.list()} - vpnservices_dict = {'vpnservices': self.api_vpnservices.list()} - - neutronclient.list_ipsec_site_connections().AndReturn( - ipsecsiteconnections_dict) - neutronclient.list_ikepolicies().AndReturn(ikepolicies_dict) - neutronclient.list_ipsecpolicies().AndReturn(ipsecpolicies_dict) - neutronclient.list_vpnservices().AndReturn(vpnservices_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.ipsecsiteconnection_list(self.request) - for (v, d) in zip(ret_val, - ipsecsiteconnections['ipsec_site_connections']): - self.assertIsInstance(v, api.vpn.IPSecSiteConnection) - self.assertTrue(v.name, d.name) - self.assertTrue(v.id) - - @test.create_stubs({neutronclient: ('show_ipsec_site_connection', - 'show_ikepolicy', 'show_ipsecpolicy', - 'show_vpnservice')}) - def test_ipsecsiteconnection_get(self): - ipsecsiteconnection = self.ipsecsiteconnections.first() - connection_dict = {'ipsec_site_connection': - self.api_ipsecsiteconnections.first()} - ikepolicy_dict = {'ikepolicy': self.api_ikepolicies.first()} - ipsecpolicy_dict = {'ipsecpolicy': self.api_ipsecpolicies.first()} - vpnservice_dict = {'vpnservice': self.api_vpnservices.first()} - - neutronclient.show_ipsec_site_connection( - ipsecsiteconnection.id).AndReturn(connection_dict) - neutronclient.show_ikepolicy( - ipsecsiteconnection.ikepolicy_id).AndReturn(ikepolicy_dict) - neutronclient.show_ipsecpolicy( - ipsecsiteconnection.ipsecpolicy_id).AndReturn(ipsecpolicy_dict) - neutronclient.show_vpnservice( - ipsecsiteconnection.vpnservice_id).AndReturn(vpnservice_dict) - - self.mox.ReplayAll() - - ret_val = api.vpn.ipsecsiteconnection_get(self.request, - ipsecsiteconnection.id) - self.assertIsInstance(ret_val, api.vpn.IPSecSiteConnection) diff --git a/code/horizon/openstack_dashboard/test/test_data/ceilometer_data.py b/code/horizon/openstack_dashboard/test/test_data/ceilometer_data.py deleted file mode 100644 index e2937bcc..00000000 --- a/code/horizon/openstack_dashboard/test/test_data/ceilometer_data.py +++ /dev/null @@ -1,224 +0,0 @@ -# Copyright 2012 Canonical Ltd. -# -# 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 ceilometerclient.v2 import meters -from ceilometerclient.v2 import resources -from ceilometerclient.v2 import samples -from ceilometerclient.v2 import statistics - -from keystoneclient.v2_0 import tenants -from keystoneclient.v2_0 import users - -from openstack_dashboard.api import ceilometer -from openstack_dashboard.test.test_data import utils - - -def data(TEST): - TEST.ceilometer_users = utils.TestDataContainer() - TEST.ceilometer_tenants = utils.TestDataContainer() - TEST.resources = utils.TestDataContainer() - TEST.api_resources = utils.TestDataContainer() - TEST.samples = utils.TestDataContainer() - TEST.meters = utils.TestDataContainer() - TEST.statistics = utils.TestDataContainer() - TEST.global_disk_usages = utils.TestDataContainer() - TEST.global_network_usages = utils.TestDataContainer() - TEST.global_network_traffic_usages = utils.TestDataContainer() - TEST.global_object_store_usages = utils.TestDataContainer() - TEST.statistics_array = utils.TestDataContainer() - - # users - ceilometer_user_dict1 = {'id': "1", - 'name': 'user', - 'email': 'test@example.com', - 'password': 'password', - 'token': 'test_token', - 'project_id': '1', - 'enabled': True, - 'domain_id': "1"} - ceilometer_user_dict2 = {'id': "2", - 'name': 'user2', - 'email': 'test2@example.com', - 'password': 'password', - 'token': 'test_token', - 'project_id': '2', - 'enabled': True, - 'domain_id': "2"} - TEST.ceilometer_users.add(users.User(None, - ceilometer_user_dict1)) - TEST.ceilometer_users.add(users.User(None, - ceilometer_user_dict2)) - - # Tenants. - tenant_dict = {'id': "1", - 'name': 'test_tenant', - 'description': "a test tenant.", - 'enabled': True, - 'domain_id': '1'} - tenant_dict_2 = {'id': "2", - 'name': 'disabled_tenant', - 'description': "a disabled test tenant.", - 'enabled': False, - 'domain_id': '2'} - tenant_dict_3 = {'id': "3", - 'name': u'\u4e91\u89c4\u5219', - 'description': "an unicode-named tenant.", - 'enabled': True, - 'domain_id': '2'} - ceilometer_tenant = tenants.Tenant(tenants.TenantManager, - tenant_dict) - ceilometer_disabled_tenant = tenants.Tenant(tenants.TenantManager, - tenant_dict_2) - ceilometer_tenant_unicode = tenants.Tenant(tenants.TenantManager, - tenant_dict_3) - - TEST.ceilometer_tenants.add(ceilometer_tenant, - ceilometer_disabled_tenant, - ceilometer_tenant_unicode) - - # resources - resource_dict_1 = dict( - resource_id='fake_resource_id', - project_id='fake_project_id', - user_id="fake_user_id", - timestamp='2012-07-02T10:42:00.000000', - metadata={'tag': 'self.counter3', 'display_name': 'test-server'}, - links=[{'url': 'test_url', 'rel': 'storage.objects'}], - ) - resource_dict_2 = dict( - resource_id='fake_resource_id2', - project_id='fake_project_id', - user_id="fake_user_id", - timestamp='2012-07-02T10:42:00.000000', - metadata={'tag': 'self.counter3', 'display_name': 'test-server'}, - links=[{'url': 'test_url', 'rel': 'storage.objects'}], - ) - resource_dict_3 = dict( - resource_id='fake_resource_id3', - project_id='fake_project_id', - user_id="fake_user_id", - timestamp='2012-07-02T10:42:00.000000', - metadata={'tag': 'self.counter3', 'display_name': 'test-server'}, - links=[{'url': 'test_url', 'rel': 'instance'}], - ) - resource_dict_4 = dict( - resource_id='fake_resource_id3', - project_id='fake_project_id', - user_id="fake_user_id", - timestamp='2012-07-02T10:42:00.000000', - metadata={'tag': 'self.counter3', 'display_name': 'test-server'}, - links=[{'url': 'test_url', 'rel': 'memory'}], - ) - - resource_1 = resources.Resource(resources.ResourceManager(None), - resource_dict_1) - resource_2 = resources.Resource(resources.ResourceManager(None), - resource_dict_2) - resource_3 = resources.Resource(resources.ResourceManager(None), - resource_dict_3) - resource_4 = resources.Resource(resources.ResourceManager(None), - resource_dict_4) - - TEST.resources.add(resource_1) - TEST.resources.add(resource_2) - TEST.resources.add(resource_3) - - # Having a separate set of fake objects for openstack_dashboard - # api Resource class. This is required because of additional methods - # defined in openstack_dashboard.api.ceilometer.Resource - - api_resource_1 = ceilometer.Resource(resource_1) - api_resource_2 = ceilometer.Resource(resource_2) - api_resource_3 = ceilometer.Resource(resource_3) - api_resource_4 = ceilometer.Resource(resource_4) - - TEST.api_resources.add(api_resource_1) - TEST.api_resources.add(api_resource_2) - TEST.api_resources.add(api_resource_3) - TEST.api_resources.add(api_resource_4) - - # samples - sample_dict_1 = {'resource_id': 'fake_resource_id', - 'project_id': 'fake_project_id', - 'user_id': 'fake_user_id', - 'counter_name': 'image', - 'counter_type': 'gauge', - 'counter_unit': 'image', - 'counter_volume': 1, - 'timestamp': '2012-12-21T11:00:55.000000', - 'metadata': {'name1': 'value1', 'name2': 'value2'}, - 'message_id': 'fake_message_id'} - sample_dict_2 = {'resource_id': 'fake_resource_id2', - 'project_id': 'fake_project_id', - 'user_id': 'fake_user_id', - 'counter_name': 'image', - 'counter_type': 'gauge', - 'counter_unit': 'image', - 'counter_volume': 1, - 'timestamp': '2012-12-21T11:00:55.000000', - 'metadata': {'name1': 'value1', 'name2': 'value2'}, - 'message_id': 'fake_message_id'} - sample_1 = samples.Sample(samples.SampleManager(None), sample_dict_1) - sample_2 = samples.Sample(samples.SampleManager(None), sample_dict_2) - TEST.samples.add(sample_1) - TEST.samples.add(sample_2) - - # meters - meter_dict_1 = {'name': 'instance', - 'type': 'gauge', - 'unit': 'instance', - 'resource_id': 'fake_resource_id', - 'project_id': 'fake_project_id', - 'user_id': 'fake_user_id'} - meter_dict_2 = {'name': 'instance', - 'type': 'gauge', - 'unit': 'instance', - 'resource_id': 'fake_resource_id', - 'project_id': 'fake_project_id', - 'user_id': 'fake_user_id'} - meter_dict_3 = {'name': 'disk.read.bytes', - 'type': 'gauge', - 'unit': 'instance', - 'resource_id': 'fake_resource_id', - 'project_id': 'fake_project_id', - 'user_id': 'fake_user_id'} - meter_dict_4 = {'name': 'disk.write.bytes', - 'type': 'gauge', - 'unit': 'instance', - 'resource_id': 'fake_resource_id', - 'project_id': 'fake_project_id', - 'user_id': 'fake_user_id'} - meter_1 = meters.Meter(meters.MeterManager(None), meter_dict_1) - meter_2 = meters.Meter(meters.MeterManager(None), meter_dict_2) - meter_3 = meters.Meter(meters.MeterManager(None), meter_dict_3) - meter_4 = meters.Meter(meters.MeterManager(None), meter_dict_4) - TEST.meters.add(meter_1) - TEST.meters.add(meter_2) - TEST.meters.add(meter_3) - TEST.meters.add(meter_4) - - # statistic - statistic_dict_1 = {'min': 1, - 'max': 9, - 'avg': 4.55, - 'sum': 45, - 'count': 10, - 'duration_start': '2012-12-21T11:00:55.000000', - 'duration_end': '2012-12-21T11:00:55.000000', - 'period': 7200, - 'period_start': '2012-12-21T11:00:55.000000', - 'period_end': '2012-12-21T11:00:55.000000'} - statistic_1 = statistics.Statistics(statistics.StatisticsManager(None), - statistic_dict_1) - TEST.statistics.add(statistic_1) diff --git a/code/horizon/openstack_dashboard/test/test_data/cinder_data.py b/code/horizon/openstack_dashboard/test/test_data/cinder_data.py deleted file mode 100644 index b99696a6..00000000 --- a/code/horizon/openstack_dashboard/test/test_data/cinder_data.py +++ /dev/null @@ -1,316 +0,0 @@ -# Copyright 2012 Nebula, 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 cinderclient.v2 import availability_zones -from cinderclient.v2 import qos_specs -from cinderclient.v2 import quotas -from cinderclient.v2 import services -from cinderclient.v2 import volume_backups as vol_backups -from cinderclient.v2 import volume_encryption_types as vol_enc_types -from cinderclient.v2 import volume_snapshots as vol_snaps -from cinderclient.v2 import volume_transfers -from cinderclient.v2 import volume_types -from cinderclient.v2 import volumes - -from openstack_dashboard import api -from openstack_dashboard.usage import quotas as usage_quotas - -from openstack_dashboard.test.test_data import utils - - -def data(TEST): - TEST.cinder_services = utils.TestDataContainer() - TEST.cinder_volumes = utils.TestDataContainer() - TEST.cinder_volume_backups = utils.TestDataContainer() - TEST.cinder_volume_encryption_types = utils.TestDataContainer() - TEST.cinder_volume_types = utils.TestDataContainer() - TEST.cinder_volume_encryption = utils.TestDataContainer() - TEST.cinder_bootable_volumes = utils.TestDataContainer() - TEST.cinder_qos_specs = utils.TestDataContainer() - TEST.cinder_qos_spec_associations = utils.TestDataContainer() - TEST.cinder_volume_snapshots = utils.TestDataContainer() - TEST.cinder_quotas = utils.TestDataContainer() - TEST.cinder_quota_usages = utils.TestDataContainer() - TEST.cinder_availability_zones = utils.TestDataContainer() - TEST.cinder_volume_transfers = utils.TestDataContainer() - - # Services - service_1 = services.Service(services.ServiceManager(None), { - "service": "cinder-scheduler", - "status": "enabled", - "binary": "cinder-scheduler", - "zone": "internal", - "state": "up", - "updated_at": "2013-07-08T05:21:00.000000", - "host": "devstack001", - "disabled_reason": None - }) - - service_2 = services.Service(services.ServiceManager(None), { - "service": "cinder-volume", - "status": "enabled", - "binary": "cinder-volume", - "zone": "nova", - "state": "up", - "updated_at": "2013-07-08T05:20:51.000000", - "host": "devstack001", - "disabled_reason": None - }) - TEST.cinder_services.add(service_1) - TEST.cinder_services.add(service_2) - - # Volumes - Cinder v1 - volume = volumes.Volume( - volumes.VolumeManager(None), - {'id': "11023e92-8008-4c8b-8059-7f2293ff3887", - 'status': 'available', - 'size': 40, - 'display_name': 'Volume name', - 'display_description': 'Volume description', - 'created_at': '2014-01-27 10:30:00', - 'volume_type': None, - 'attachments': []}) - nameless_volume = volumes.Volume( - volumes.VolumeManager(None), - {"id": "4b069dd0-6eaa-4272-8abc-5448a68f1cce", - "status": 'available', - "size": 10, - "display_name": '', - "display_description": '', - "device": "/dev/hda", - "created_at": '2010-11-21 18:34:25', - "volume_type": 'vol_type_1', - "attachments": []}) - other_volume = volumes.Volume( - volumes.VolumeManager(None), - {'id': "21023e92-8008-1234-8059-7f2293ff3889", - 'status': 'in-use', - 'size': 10, - 'display_name': u'my_volume', - 'display_description': '', - 'created_at': '2013-04-01 10:30:00', - 'volume_type': None, - 'attachments': [{"id": "1", "server_id": '1', - "device": "/dev/hda"}]}) - volume_with_type = volumes.Volume( - volumes.VolumeManager(None), - {'id': "7dcb47fd-07d9-42c2-9647-be5eab799ebe", - 'name': 'my_volume2', - 'status': 'in-use', - 'size': 10, - 'display_name': u'my_volume2', - 'display_description': '', - 'created_at': '2013-04-01 10:30:00', - 'volume_type': 'vol_type_2', - 'attachments': [{"id": "2", "server_id": '2', - "device": "/dev/hdb"}]}) - non_bootable_volume = volumes.Volume( - volumes.VolumeManager(None), - {'id': "21023e92-8008-1234-8059-7f2293ff3890", - 'status': 'in-use', - 'size': 10, - 'display_name': u'my_volume', - 'display_description': '', - 'created_at': '2013-04-01 10:30:00', - 'volume_type': None, - 'bootable': False, - 'attachments': [{"id": "1", "server_id": '1', - "device": "/dev/hda"}]}) - - volume.bootable = 'true' - nameless_volume.bootable = 'true' - other_volume.bootable = 'true' - - TEST.cinder_volumes.add(api.cinder.Volume(volume)) - TEST.cinder_volumes.add(api.cinder.Volume(nameless_volume)) - TEST.cinder_volumes.add(api.cinder.Volume(other_volume)) - TEST.cinder_volumes.add(api.cinder.Volume(volume_with_type)) - - TEST.cinder_bootable_volumes.add(api.cinder.Volume(non_bootable_volume)) - - vol_type1 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), - {'id': u'1', - 'name': u'vol_type_1', - 'extra_specs': {'foo': 'bar'}}) - vol_type2 = volume_types.VolumeType(volume_types.VolumeTypeManager(None), - {'id': u'2', - 'name': u'vol_type_2'}) - TEST.cinder_volume_types.add(vol_type1, vol_type2) - - # Volumes - Cinder v2 - volume_v2 = volumes.Volume( - volumes.VolumeManager(None), - {'id': "31023e92-8008-4c8b-8059-7f2293ff1234", - 'name': 'v2_volume', - 'description': "v2 Volume Description", - 'status': 'available', - 'size': 20, - 'created_at': '2014-01-27 10:30:00', - 'volume_type': None, - 'os-vol-host-attr:host': 'host@backend-name#pool', - 'bootable': 'true', - 'attachments': []}) - volume_v2.bootable = 'true' - - TEST.cinder_volumes.add(api.cinder.Volume(volume_v2)) - - snapshot = vol_snaps.Snapshot( - vol_snaps.SnapshotManager(None), - {'id': '5f3d1c33-7d00-4511-99df-a2def31f3b5d', - 'display_name': 'test snapshot', - 'display_description': 'volume snapshot', - 'size': 40, - 'status': 'available', - 'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'}) - snapshot2 = vol_snaps.Snapshot( - vol_snaps.SnapshotManager(None), - {'id': 'c9d0881a-4c0b-4158-a212-ad27e11c2b0f', - 'name': '', - 'description': 'v2 volume snapshot description', - 'size': 80, - 'status': 'available', - 'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'}) - - snapshot.bootable = 'true' - snapshot2.bootable = 'true' - - TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot)) - TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot2)) - TEST.cinder_volume_snapshots.first()._volume = volume - - # Volume Type Encryption - vol_enc_type1 = vol_enc_types.VolumeEncryptionType( - vol_enc_types.VolumeEncryptionTypeManager(None), - {'volume_type_id': u'1', - 'control_location': "front-end", - 'key_size': 512, - 'provider': "a-provider", - 'cipher': "a-cipher"}) - vol_enc_type2 = vol_enc_types.VolumeEncryptionType( - vol_enc_types.VolumeEncryptionTypeManager(None), - {'volume_type_id': u'2', - 'control_location': "front-end", - 'key_size': 256, - 'provider': "a-provider", - 'cipher': "a-cipher"}) - vol_unenc_type1 = vol_enc_types.VolumeEncryptionType( - vol_enc_types.VolumeEncryptionTypeManager(None), {}) - TEST.cinder_volume_encryption_types.add(vol_enc_type1, vol_enc_type2, - vol_unenc_type1) - - volume_backup1 = vol_backups.VolumeBackup( - vol_backups.VolumeBackupManager(None), - {'id': 'a374cbb8-3f99-4c3f-a2ef-3edbec842e31', - 'name': 'backup1', - 'description': 'volume backup 1', - 'size': 10, - 'status': 'available', - 'container_name': 'volumebackups', - 'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'}) - - volume_backup2 = vol_backups.VolumeBackup( - vol_backups.VolumeBackupManager(None), - {'id': 'c321cbb8-3f99-4c3f-a2ef-3edbec842e52', - 'name': 'backup2', - 'description': 'volume backup 2', - 'size': 20, - 'status': 'available', - 'container_name': 'volumebackups', - 'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'}) - - TEST.cinder_volume_backups.add(volume_backup1) - TEST.cinder_volume_backups.add(volume_backup2) - - # Volume Encryption - vol_enc_metadata1 = volumes.Volume( - volumes.VolumeManager(None), - {'cipher': 'test-cipher', - 'key_size': 512, - 'provider': 'test-provider', - 'control_location': 'front-end'}) - vol_unenc_metadata1 = volumes.Volume( - volumes.VolumeManager(None), - {}) - TEST.cinder_volume_encryption.add(vol_enc_metadata1) - TEST.cinder_volume_encryption.add(vol_unenc_metadata1) - - # Quota Sets - quota_data = dict(volumes='1', - snapshots='1', - gigabytes='1000') - quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data) - TEST.cinder_quotas.add(api.base.QuotaSet(quota)) - - # Quota Usages - quota_usage_data = {'gigabytes': {'used': 0, - 'quota': 1000}, - 'instances': {'used': 0, - 'quota': 10}, - 'snapshots': {'used': 0, - 'quota': 10}} - quota_usage = usage_quotas.QuotaUsage() - for k, v in quota_usage_data.items(): - quota_usage.add_quota(api.base.Quota(k, v['quota'])) - quota_usage.tally(k, v['used']) - - TEST.cinder_quota_usages.add(quota_usage) - - # Availability Zones - # Cinder returns the following structure from os-availability-zone - # {"availabilityZoneInfo": - # [{"zoneState": {"available": true}, "zoneName": "nova"}]} - # Note that the default zone is still "nova" even though this is cinder - TEST.cinder_availability_zones.add( - availability_zones.AvailabilityZone( - availability_zones.AvailabilityZoneManager(None), - { - 'zoneName': 'nova', - 'zoneState': {'available': True} - } - ) - ) - # Cinder Limits - limits = {"absolute": {"totalVolumesUsed": 1, - "totalGigabytesUsed": 5, - "maxTotalVolumeGigabytes": 1000, - "maxTotalVolumes": 10}} - TEST.cinder_limits = limits - - # QOS Specs - qos_spec1 = qos_specs.QoSSpecs( - qos_specs.QoSSpecsManager(None), - {"id": "418db45d-6992-4674-b226-80aacad2073c", - "name": "high_iops", - "consumer": "back-end", - "specs": {"minIOPS": "1000", "maxIOPS": '100000'}}) - qos_spec2 = qos_specs.QoSSpecs( - qos_specs.QoSSpecsManager(None), - {"id": "6ed7035f-992e-4075-8ed6-6eff19b3192d", - "name": "high_bws", - "consumer": "back-end", - "specs": {"maxBWS": '5000'}}) - - TEST.cinder_qos_specs.add(qos_spec1, qos_spec2) - vol_type1.associated_qos_spec = qos_spec1.name - TEST.cinder_qos_spec_associations.add(vol_type1) - - # volume_transfers - transfer_1 = volume_transfers.VolumeTransfer( - volume_transfers.VolumeTransferManager(None), { - 'id': '99999999-8888-7777-6666-555555555555', - 'name': 'test transfer', - 'volume_id': volume.id, - 'auth_key': 'blah', - 'created_at': ''}) - TEST.cinder_volume_transfers.add(transfer_1) diff --git a/code/horizon/openstack_dashboard/test/test_data/exceptions.py b/code/horizon/openstack_dashboard/test/test_data/exceptions.py index ad582515..751190df 100644 --- a/code/horizon/openstack_dashboard/test/test_data/exceptions.py +++ b/code/horizon/openstack_dashboard/test/test_data/exceptions.py @@ -12,14 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import ceilometerclient.exc as ceilometer_exceptions -from cinderclient import exceptions as cinder_exceptions -import glanceclient.exc as glance_exceptions + from keystoneclient import exceptions as keystone_exceptions -from neutronclient.common import exceptions as neutron_exceptions -from novaclient import exceptions as nova_exceptions -from swiftclient import client as swift_exceptions -from troveclient import exceptions as trove_exceptions from openstack_dashboard.test.test_data import utils @@ -63,31 +57,3 @@ def data(TEST): keystone_exception = keystone_exceptions.ClientException TEST.exceptions.keystone = create_stubbed_exception(keystone_exception) - - nova_exception = nova_exceptions.ClientException - TEST.exceptions.nova = create_stubbed_exception(nova_exception) - - nova_unauth = nova_exceptions.Unauthorized - TEST.exceptions.nova_unauthorized = create_stubbed_exception(nova_unauth) - - glance_exception = glance_exceptions.ClientException - TEST.exceptions.glance = create_stubbed_exception(glance_exception) - - ceilometer_exception = ceilometer_exceptions.HTTPException - TEST.exceptions.ceilometer = create_stubbed_exception(ceilometer_exception) - - neutron_exception = neutron_exceptions.NeutronClientException - TEST.exceptions.neutron = create_stubbed_exception(neutron_exception) - - swift_exception = swift_exceptions.ClientException - TEST.exceptions.swift = create_stubbed_exception(swift_exception) - - cinder_exception = cinder_exceptions.BadRequest - TEST.exceptions.cinder = create_stubbed_exception(cinder_exception) - - trove_exception = trove_exceptions.ClientException - TEST.exceptions.trove = create_stubbed_exception(trove_exception) - - trove_auth = trove_exceptions.Unauthorized - TEST.exceptions.trove_unauthorized = \ - create_stubbed_exception(trove_auth) diff --git a/code/horizon/openstack_dashboard/test/test_data/glance_data.py b/code/horizon/openstack_dashboard/test/test_data/glance_data.py deleted file mode 100644 index 190e27c3..00000000 --- a/code/horizon/openstack_dashboard/test/test_data/glance_data.py +++ /dev/null @@ -1,321 +0,0 @@ -# Copyright 2012 Nebula, 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 glanceclient.v1 import images - -from openstack_dashboard.test.test_data import utils - - -class Namespace(dict): - def __repr__(self): - return "" % self._info - - def __init__(self, info): - super(Namespace, self).__init__() - self.__dict__.update(info) - self.update(info) - self._info = info - - def as_json(self, indent=4): - return self.__dict__ - - -def data(TEST): - TEST.images = utils.TestDataContainer() - TEST.snapshots = utils.TestDataContainer() - TEST.metadata_defs = utils.TestDataContainer() - - # Snapshots - snapshot_dict = {'name': u'snapshot', - 'container_format': u'ami', - 'id': 3, - 'status': "active", - 'owner': TEST.tenant.id, - 'properties': {'image_type': u'snapshot'}, - 'is_public': False, - 'protected': False} - snapshot_dict_no_owner = {'name': u'snapshot 2', - 'container_format': u'ami', - 'id': 4, - 'status': "active", - 'owner': None, - 'properties': {'image_type': u'snapshot'}, - 'is_public': False, - 'protected': False} - snapshot_dict_queued = {'name': u'snapshot 2', - 'container_format': u'ami', - 'id': 5, - 'status': "queued", - 'owner': TEST.tenant.id, - 'properties': {'image_type': u'snapshot'}, - 'is_public': False, - 'protected': False} - snapshot = images.Image(images.ImageManager(None), snapshot_dict) - TEST.snapshots.add(snapshot) - snapshot = images.Image(images.ImageManager(None), snapshot_dict_no_owner) - TEST.snapshots.add(snapshot) - snapshot = images.Image(images.ImageManager(None), snapshot_dict_queued) - TEST.snapshots.add(snapshot) - - # Images - image_dict = {'id': '007e7d55-fe1e-4c5c-bf08-44b4a4964822', - 'name': 'public_image', - 'disk_format': u'qcow2', - 'status': "active", - 'size': 20 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': TEST.tenant.id, - 'container_format': 'novaImage', - 'properties': {'image_type': u'image'}, - 'is_public': True, - 'protected': False, - 'min_ram': 0, - 'created_at': '2014-02-14T20:56:53'} - public_image = images.Image(images.ImageManager(None), image_dict) - - image_dict = {'id': 'a001c047-22f8-47d0-80a1-8ec94a9524fe', - 'name': 'private_image', - 'status': "active", - 'size': 10 * 1024 ** 2, - 'virtual_size': 20 * 1024 ** 2, - 'min_disk': 0, - 'owner': TEST.tenant.id, - 'container_format': 'aki', - 'is_public': False, - 'protected': False, - 'min_ram': 0, - 'created_at': '2014-03-14T12:56:53'} - private_image = images.Image(images.ImageManager(None), image_dict) - - image_dict = {'id': 'd6936c86-7fec-474a-85c5-5e467b371c3c', - 'name': 'protected_images', - 'status': "active", - 'owner': TEST.tenant.id, - 'size': 2 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 30, - 'container_format': 'novaImage', - 'properties': {'image_type': u'image'}, - 'is_public': True, - 'protected': True, - 'min_ram': 0, - 'created_at': '2014-03-16T06:22:14'} - protected_image = images.Image(images.ImageManager(None), image_dict) - - image_dict = {'id': '278905a6-4b52-4d1e-98f9-8c57bb25ba32', - 'name': None, - 'status': "active", - 'size': 5 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': TEST.tenant.id, - 'container_format': 'novaImage', - 'properties': {'image_type': u'image'}, - 'is_public': True, - 'protected': False, - 'min_ram': 0} - public_image2 = images.Image(images.ImageManager(None), image_dict) - - image_dict = {'id': '710a1acf-a3e3-41dd-a32d-5d6b6c86ea10', - 'name': 'private_image 2', - 'status': "active", - 'size': 30 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': TEST.tenant.id, - 'container_format': 'aki', - 'is_public': False, - 'protected': False, - 'min_ram': 0} - private_image2 = images.Image(images.ImageManager(None), image_dict) - - image_dict = {'id': '7cd892fd-5652-40f3-a450-547615680132', - 'name': 'private_image 3', - 'status': "active", - 'size': 2 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': TEST.tenant.id, - 'container_format': 'aki', - 'is_public': False, - 'protected': False, - 'min_ram': 0} - private_image3 = images.Image(images.ImageManager(None), image_dict) - - # A shared image. Not public and not local tenant. - image_dict = {'id': 'c8756975-7a3b-4e43-b7f7-433576112849', - 'name': 'shared_image 1', - 'status': "active", - 'size': 8 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': 'someothertenant', - 'container_format': 'aki', - 'is_public': False, - 'protected': False, - 'min_ram': 0} - shared_image1 = images.Image(images.ImageManager(None), image_dict) - - # "Official" image. Public and tenant matches an entry - # in IMAGES_LIST_FILTER_TENANTS. - image_dict = {'id': 'f448704f-0ce5-4d34-8441-11b6581c6619', - 'name': 'official_image 1', - 'status': "active", - 'size': 2 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': 'officialtenant', - 'container_format': 'aki', - 'is_public': True, - 'protected': False, - 'min_ram': 0} - official_image1 = images.Image(images.ImageManager(None), image_dict) - - image_dict = {'id': 'a67e7d45-fe1e-4c5c-bf08-44b4a4964822', - 'name': 'multi_prop_image', - 'status': "active", - 'size': 20 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': TEST.tenant.id, - 'container_format': 'novaImage', - 'properties': {'description': u'a multi prop image', - 'foo': u'foo val', - 'bar': u'bar val'}, - 'is_public': True, - 'protected': False} - multi_prop_image = images.Image(images.ImageManager(None), image_dict) - - # An image without name being returned based on current api - image_dict = {'id': 'c8756975-7a3b-4e43-b7f7-433576112849', - 'status': "active", - 'size': 8 * 1024 ** 3, - 'virtual_size': None, - 'min_disk': 0, - 'owner': 'someothertenant', - 'container_format': 'aki', - 'is_public': False, - 'protected': False} - no_name_image = images.Image(images.ImageManager(None), image_dict) - - TEST.images.add(public_image, private_image, protected_image, - public_image2, private_image2, private_image3, - shared_image1, official_image1, multi_prop_image) - - TEST.empty_name_image = no_name_image - - metadef_dict = { - 'namespace': 'namespace_1', - 'display_name': 'Namespace 1', - 'description': 'Mock desc 1', - 'resource_type_associations': [ - { - 'created_at': '2014-08-21T08:39:43Z', - 'prefix': 'mock', - 'name': 'mock name' - } - ], - 'visibility': 'public', - 'protected': True, - 'created_at': '2014-08-21T08:39:43Z', - 'properties': { - 'cpu_mock:mock': { - 'default': '1', - 'type': 'integer', - 'description': 'Number of mocks.', - 'title': 'mocks' - } - } - } - metadef = Namespace(metadef_dict) - TEST.metadata_defs.add(metadef) - - metadef_dict = { - 'namespace': 'namespace_2', - 'display_name': 'Namespace 2', - 'description': 'Mock desc 2', - 'resource_type_associations': [ - { - 'created_at': '2014-08-21T08:39:43Z', - 'prefix': 'mock', - 'name': 'mock name' - } - ], - 'visibility': 'private', - 'protected': False, - 'created_at': '2014-08-21T08:39:43Z', - 'properties': { - 'hdd_mock:mock': { - 'default': '2', - 'type': 'integer', - 'description': 'Number of mocks.', - 'title': 'mocks' - } - } - } - metadef = Namespace(metadef_dict) - TEST.metadata_defs.add(metadef) - - metadef_dict = { - 'namespace': 'namespace_3', - 'display_name': 'Namespace 3', - 'description': 'Mock desc 3', - 'resource_type_associations': [ - { - 'created_at': '2014-08-21T08:39:43Z', - 'prefix': 'mock', - 'name': 'mock name' - } - ], - 'visibility': 'public', - 'protected': False, - 'created_at': '2014-08-21T08:39:43Z', - 'properties': { - 'gpu_mock:mock': { - 'default': '2', - 'type': 'integer', - 'description': 'Number of mocks.', - 'title': 'mocks' - } - } - } - metadef = Namespace(metadef_dict) - TEST.metadata_defs.add(metadef) - - metadef_dict = { - 'namespace': 'namespace_4', - 'display_name': 'Namespace 4', - 'description': 'Mock desc 4', - 'resource_type_associations': [ - { - 'created_at': '2014-08-21T08:39:43Z', - 'prefix': 'mock', - 'name': 'mock name' - } - ], - 'visibility': 'public', - 'protected': True, - 'created_at': '2014-08-21T08:39:43Z', - 'properties': { - 'ram_mock:mock': { - 'default': '2', - 'type': 'integer', - 'description': 'Number of mocks.', - 'title': 'mocks' - } - } - } - metadef = Namespace(metadef_dict) - TEST.metadata_defs.add(metadef) diff --git a/code/horizon/openstack_dashboard/test/test_data/heat_data.py b/code/horizon/openstack_dashboard/test/test_data/heat_data.py deleted file mode 100644 index 110b8196..00000000 --- a/code/horizon/openstack_dashboard/test/test_data/heat_data.py +++ /dev/null @@ -1,463 +0,0 @@ -# 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 heatclient.v1 import resource_types -from heatclient.v1 import services -from heatclient.v1 import stacks - -from openstack_dashboard.test.test_data import utils - - -# A slightly hacked up copy of a sample cloudformation template for testing. -TEMPLATE = """ -{ -"AWSTemplateFormatVersion": "2010-09-09", -"Description": "AWS CloudFormation Sample Template.", -"Parameters": { -"KeyName": { -"Description": "Name of an EC2 Key Pair to enable SSH access to the instances", -"Type": "String" -}, -"InstanceType": { -"Description": "WebServer EC2 instance type", -"Type": "String", -"Default": "m1.small", -"AllowedValues": [ -"m1.tiny", -"m1.small", -"m1.medium", -"m1.large", -"m1.xlarge" -], -"ConstraintDescription": "must be a valid EC2 instance type." -}, -"DBName": { -"Default": "wordpress", -"Description": "The WordPress database name", -"Type": "String", -"MinLength": "1", -"MaxLength": "64", -"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", -"ConstraintDescription": "must begin with a letter and..." -}, -"DBUsername": { -"Default": "admin", -"NoEcho": "true", -"Description": "The WordPress database admin account username", -"Type": "String", -"MinLength": "1", -"MaxLength": "16", -"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", -"ConstraintDescription": "must begin with a letter and..." -}, -"DBPassword": { -"Default": "admin", -"NoEcho": "true", -"Description": "The WordPress database admin account password", -"Type": "String", -"MinLength": "1", -"MaxLength": "41", -"AllowedPattern": "[a-zA-Z0-9]*", -"ConstraintDescription": "must contain only alphanumeric characters." -}, -"DBRootPassword": { -"Default": "admin", -"NoEcho": "true", -"Description": "Root password for MySQL", -"Type": "String", -"MinLength": "1", -"MaxLength": "41", -"AllowedPattern": "[a-zA-Z0-9]*", -"ConstraintDescription": "must contain only alphanumeric characters." -}, -"LinuxDistribution": { -"Default": "F17", -"Description": "Distribution of choice", -"Type": "String", -"AllowedValues": [ -"F18", -"F17", -"U10", -"RHEL-6.1", -"RHEL-6.2", -"RHEL-6.3" -] -}, -"Network": { -"Type": "String", -"CustomConstraint": "neutron.network" -} -}, -"Mappings": { -"AWSInstanceType2Arch": { -"m1.tiny": { -"Arch": "32" -}, -"m1.small": { -"Arch": "64" -}, -"m1.medium": { -"Arch": "64" -}, -"m1.large": { -"Arch": "64" -}, -"m1.xlarge": { -"Arch": "64" -} -}, -"DistroArch2AMI": { -"F18": { -"32": "F18-i386-cfntools", -"64": "F18-x86_64-cfntools" -}, -"F17": { -"32": "F17-i386-cfntools", -"64": "F17-x86_64-cfntools" -}, -"U10": { -"32": "U10-i386-cfntools", -"64": "U10-x86_64-cfntools" -}, -"RHEL-6.1": { -"32": "rhel61-i386-cfntools", -"64": "rhel61-x86_64-cfntools" -}, -"RHEL-6.2": { -"32": "rhel62-i386-cfntools", -"64": "rhel62-x86_64-cfntools" -}, -"RHEL-6.3": { -"32": "rhel63-i386-cfntools", -"64": "rhel63-x86_64-cfntools" -} -} -}, -"Resources": { -"WikiDatabase": { -"Type": "AWS::EC2::Instance", -"Metadata": { -"AWS::CloudFormation::Init": { -"config": { -"packages": { -"yum": { -"mysql": [], -"mysql-server": [], -"httpd": [], -"wordpress": [] -} -}, -"services": { -"systemd": { -"mysqld": { -"enabled": "true", -"ensureRunning": "true" -}, -"httpd": { -"enabled": "true", -"ensureRunning": "true" -} -} -} -} -} -}, -"Properties": { -"ImageId": { -"Fn::FindInMap": [ -"DistroArch2AMI", -{ -"Ref": "LinuxDistribution" -}, -{ -"Fn::FindInMap": [ -"AWSInstanceType2Arch", -{ -"Ref": "InstanceType" -}, -"Arch" -] -} -] -}, -"InstanceType": { -"Ref": "InstanceType" -}, -"KeyName": { -"Ref": "KeyName" -}, -"UserData": { -"Fn::Base64": { -"Fn::Join": [ -"", -[ -"#!/bin/bash -v\n", -"/opt/aws/bin/cfn-init\n" -] -] -} -} -} -} -}, -"Outputs": { -"WebsiteURL": { -"Value": { -"Fn::Join": [ -"", -[ -"http://", -{ -"Fn::GetAtt": [ -"WikiDatabase", -"PublicIp" -] -}, -"/wordpress" -] -] -}, -"Description": "URL for Wordpress wiki" -} -} -} -""" - -VALIDATE = """ -{ -"Description": "AWS CloudFormation Sample Template.", -"Parameters": { -"DBUsername": { -"Type": "String", -"Description": "The WordPress database admin account username", -"Default": "admin", -"MinLength": "1", -"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", -"NoEcho": "true", -"MaxLength": "16", -"ConstraintDescription": "must begin with a letter and..." -}, -"LinuxDistribution": { -"Default": "F17", -"Type": "String", -"Description": "Distribution of choice", -"AllowedValues": [ -"F18", -"F17", -"U10", -"RHEL-6.1", -"RHEL-6.2", -"RHEL-6.3" -] -}, -"DBRootPassword": { -"Type": "String", -"Description": "Root password for MySQL", -"Default": "admin", -"MinLength": "1", -"AllowedPattern": "[a-zA-Z0-9]*", -"NoEcho": "true", -"MaxLength": "41", -"ConstraintDescription": "must contain only alphanumeric characters." -}, -"KeyName": { -"Type": "String", -"Description": "Name of an EC2 Key Pair to enable SSH access to the instances" -}, -"DBName": { -"Type": "String", -"Description": "The WordPress database name", -"Default": "wordpress", -"MinLength": "1", -"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*", -"MaxLength": "64", -"ConstraintDescription": "must begin with a letter and..." -}, -"DBPassword": { -"Type": "String", -"Description": "The WordPress database admin account password", -"Default": "admin", -"MinLength": "1", -"AllowedPattern": "[a-zA-Z0-9]*", -"NoEcho": "true", -"MaxLength": "41", -"ConstraintDescription": "must contain only alphanumeric characters." -}, -"InstanceType": { -"Default": "m1.small", -"Type": "String", -"ConstraintDescription": "must be a valid EC2 instance type.", -"Description": "WebServer EC2 instance type", -"AllowedValues": [ -"m1.tiny", -"m1.small", -"m1.medium", -"m1.large", -"m1.xlarge" -] -}, -"Network": { -"Type": "String", -"CustomConstraint": "neutron.network" -} -} -} -""" - -ENVIRONMENT = """ -parameters: - InstanceType: m1.xsmall - db_password: verybadpass - KeyName: heat_key -""" - - -class Environment(object): - def __init__(self, data): - self.data = data - - -class Template(object): - def __init__(self, data, validate): - self.data = data - self.validate = validate - - -def data(TEST): - TEST.stacks = utils.TestDataContainer() - TEST.stack_templates = utils.TestDataContainer() - TEST.stack_environments = utils.TestDataContainer() - TEST.resource_types = utils.TestDataContainer() - TEST.heat_services = utils.TestDataContainer() - - # Services - service_1 = services.Service(services.ServiceManager(None), { - "status": "up", - "binary": "heat-engine", - "report_interval": 60, - "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d1", - "created_at": "2015-02-06T03:23:32.000000", - "hostname": "mrkanag", - "updated_at": "2015-02-20T09:49:52.000000", - "topic": "engine", - "host": "engine-1", - "deleted_at": None, - "id": "1efd7015-5016-4caa-b5c8-12438af7b100" - }) - - service_2 = services.Service(services.ServiceManager(None), { - "status": "up", - "binary": "heat-engine", - "report_interval": 60, - "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d2", - "created_at": "2015-02-06T03:23:32.000000", - "hostname": "mrkanag", - "updated_at": "2015-02-20T09:49:52.000000", - "topic": "engine", - "host": "engine-2", - "deleted_at": None, - "id": "1efd7015-5016-4caa-b5c8-12438af7b100" - }) - - TEST.heat_services.add(service_1) - TEST.heat_services.add(service_2) - - # Data return by heatclient. - TEST.api_resource_types = utils.TestDataContainer() - - for i in range(10): - stack_data = { - "description": "No description", - "links": [{ - "href": "http://192.168.1.70:8004/v1/" - "051c727ee67040d6a7b7812708485a97/" - "stacks/stack-1211-38/" - "05b4f39f-ea96-4d91-910c-e758c078a089", - "rel": "self" - }], - "parameters": { - 'DBUsername': '******', - 'InstanceType': 'm1.small', - 'AWS::StackId': ( - 'arn:openstack:heat::2ce287:stacks/teststack/88553ec'), - 'DBRootPassword': '******', - 'AWS::StackName': "teststack{0}".format(i), - 'DBPassword': '******', - 'AWS::Region': 'ap-southeast-1', - 'DBName': u'wordpress' - }, - "stack_status_reason": "Stack successfully created", - "stack_name": "stack-test{0}".format(i), - "creation_time": "2013-04-22T00:11:39Z", - "updated_time": "2013-04-22T00:11:39Z", - "stack_status": "CREATE_COMPLETE", - "id": "05b4f39f-ea96-4d91-910c-e758c078a089{0}".format(i) - } - stack = stacks.Stack(stacks.StackManager(None), stack_data) - TEST.stacks.add(stack) - - TEST.stack_templates.add(Template(TEMPLATE, VALIDATE)) - TEST.stack_environments.add(Environment(ENVIRONMENT)) - - # Resource types list - r_type_1 = { - "resource_type": "AWS::CloudFormation::Stack", - "attributes": {}, - "properties": { - "Parameters": { - "description": - "The set of parameters passed to this nested stack.", - "immutable": False, - "required": False, - "type": "map", - "update_allowed": True}, - "TemplateURL": { - "description": "The URL of a template that specifies" - " the stack to be created as a resource.", - "immutable": False, - "required": True, - "type": "string", - "update_allowed": True}, - "TimeoutInMinutes": { - "description": "The length of time, in minutes," - " to wait for the nested stack creation.", - "immutable": False, - "required": False, - "type": "number", - "update_allowed": True} - } - } - - r_type_2 = { - "resource_type": "OS::Heat::CloudConfig", - "attributes": { - "config": { - "description": "The config value of the software config."} - }, - "properties": { - "cloud_config": { - "description": "Map representing the cloud-config data" - " structure which will be formatted as YAML.", - "immutable": False, - "required": False, - "type": "map", - "update_allowed": False} - } - } - - r_types_list = [r_type_1, r_type_2] - - for rt in r_types_list: - r_type = resource_types.ResourceType( - resource_types.ResourceTypeManager(None), rt['resource_type']) - TEST.resource_types.add(r_type) - TEST.api_resource_types.add(rt) diff --git a/code/horizon/openstack_dashboard/test/test_data/neutron_data.py b/code/horizon/openstack_dashboard/test/test_data/neutron_data.py deleted file mode 100644 index 0bc646e6..00000000 --- a/code/horizon/openstack_dashboard/test/test_data/neutron_data.py +++ /dev/null @@ -1,1162 +0,0 @@ -# Copyright 2012 Nebula, 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. - -import copy -import uuid - -from openstack_dashboard.api import base -from openstack_dashboard.api import fwaas -from openstack_dashboard.api import lbaas -from openstack_dashboard.api import neutron -from openstack_dashboard.api import vpn -from openstack_dashboard.test.test_data import utils - - -def data(TEST): - # Data returned by openstack_dashboard.api.neutron wrapper. - TEST.agents = utils.TestDataContainer() - TEST.networks = utils.TestDataContainer() - TEST.subnets = utils.TestDataContainer() - TEST.ports = utils.TestDataContainer() - TEST.routers = utils.TestDataContainer() - TEST.routers_with_rules = utils.TestDataContainer() - TEST.q_floating_ips = utils.TestDataContainer() - TEST.q_secgroups = utils.TestDataContainer() - TEST.q_secgroup_rules = utils.TestDataContainer() - TEST.providers = utils.TestDataContainer() - TEST.pools = utils.TestDataContainer() - TEST.vips = utils.TestDataContainer() - TEST.members = utils.TestDataContainer() - TEST.monitors = utils.TestDataContainer() - TEST.neutron_quotas = utils.TestDataContainer() - TEST.net_profiles = utils.TestDataContainer() - TEST.policy_profiles = utils.TestDataContainer() - TEST.network_profile_binding = utils.TestDataContainer() - TEST.policy_profile_binding = utils.TestDataContainer() - TEST.vpnservices = utils.TestDataContainer() - TEST.ikepolicies = utils.TestDataContainer() - TEST.ipsecpolicies = utils.TestDataContainer() - TEST.ipsecsiteconnections = utils.TestDataContainer() - TEST.firewalls = utils.TestDataContainer() - TEST.fw_policies = utils.TestDataContainer() - TEST.fw_rules = utils.TestDataContainer() - - # Data return by neutronclient. - TEST.api_agents = utils.TestDataContainer() - TEST.api_networks = utils.TestDataContainer() - TEST.api_subnets = utils.TestDataContainer() - TEST.api_ports = utils.TestDataContainer() - TEST.api_routers = utils.TestDataContainer() - TEST.api_q_floating_ips = utils.TestDataContainer() - TEST.api_q_secgroups = utils.TestDataContainer() - TEST.api_q_secgroup_rules = utils.TestDataContainer() - TEST.api_pools = utils.TestDataContainer() - TEST.api_vips = utils.TestDataContainer() - TEST.api_members = utils.TestDataContainer() - TEST.api_monitors = utils.TestDataContainer() - TEST.api_extensions = utils.TestDataContainer() - TEST.api_net_profiles = utils.TestDataContainer() - TEST.api_policy_profiles = utils.TestDataContainer() - TEST.api_network_profile_binding = utils.TestDataContainer() - TEST.api_policy_profile_binding = utils.TestDataContainer() - TEST.api_vpnservices = utils.TestDataContainer() - TEST.api_ikepolicies = utils.TestDataContainer() - TEST.api_ipsecpolicies = utils.TestDataContainer() - TEST.api_ipsecsiteconnections = utils.TestDataContainer() - TEST.api_firewalls = utils.TestDataContainer() - TEST.api_fw_policies = utils.TestDataContainer() - TEST.api_fw_rules = utils.TestDataContainer() - - # 1st network. - network_dict = {'admin_state_up': True, - 'id': '82288d84-e0a5-42ac-95be-e6af08727e42', - 'name': 'net1', - 'status': 'ACTIVE', - 'subnets': ['e8abc972-eb0c-41f1-9edd-4bc6e3bcd8c9'], - 'tenant_id': '1', - 'router:external': False, - 'shared': False} - subnet_dict = {'allocation_pools': [{'end': '10.0.0.254', - 'start': '10.0.0.2'}], - 'dns_nameservers': [], - 'host_routes': [], - 'cidr': '10.0.0.0/24', - 'enable_dhcp': True, - 'gateway_ip': '10.0.0.1', - 'id': network_dict['subnets'][0], - 'ip_version': 4, - 'name': 'mysubnet1', - 'network_id': network_dict['id'], - 'tenant_id': network_dict['tenant_id']} - - TEST.api_networks.add(network_dict) - TEST.api_subnets.add(subnet_dict) - - network = copy.deepcopy(network_dict) - subnet = neutron.Subnet(subnet_dict) - network['subnets'] = [subnet] - TEST.networks.add(neutron.Network(network)) - TEST.subnets.add(subnet) - - # Network profile for network when using the cisco n1k plugin. - net_profile_dict = {'name': 'net_profile_test1', - 'segment_type': 'vlan', - 'physical_network': 'phys1', - 'segment_range': '3000-3100', - 'id': - '00000000-1111-1111-1111-000000000000', - 'project': TEST.networks.get(name="net1")['tenant_id'], - # vlan profiles have no sub_type or multicast_ip_range - 'multicast_ip_range': None, - 'sub_type': None} - - TEST.api_net_profiles.add(net_profile_dict) - TEST.net_profiles.add(neutron.Profile(net_profile_dict)) - - # Policy profile for port when using the cisco n1k plugin. - policy_profile_dict = {'name': 'policy_profile_test1', - 'id': - '00000000-9999-9999-9999-000000000000'} - - TEST.api_policy_profiles.add(policy_profile_dict) - TEST.policy_profiles.add(neutron.Profile(policy_profile_dict)) - - # Network profile binding. - network_profile_binding_dict = {'profile_id': - '00000000-1111-1111-1111-000000000000', - 'tenant_id': network_dict['tenant_id']} - - TEST.api_network_profile_binding.add(network_profile_binding_dict) - TEST.network_profile_binding.add(neutron.Profile( - network_profile_binding_dict)) - - # Policy profile binding. - policy_profile_binding_dict = {'profile_id': - '00000000-9999-9999-9999-000000000000', - 'tenant_id': network_dict['tenant_id']} - - TEST.api_policy_profile_binding.add(policy_profile_binding_dict) - TEST.policy_profile_binding.add(neutron.Profile( - policy_profile_binding_dict)) - - # Ports on 1st network. - port_dict = {'admin_state_up': True, - 'device_id': 'af75c8e5-a1cc-4567-8d04-44fcd6922890', - 'device_owner': 'network:dhcp', - 'fixed_ips': [{'ip_address': '10.0.0.3', - 'subnet_id': subnet_dict['id']}], - 'id': '063cf7f3-ded1-4297-bc4c-31eae876cc91', - 'mac_address': 'fa:16:3e:9c:d5:7e', - 'name': '', - 'network_id': network_dict['id'], - 'status': 'ACTIVE', - 'tenant_id': network_dict['tenant_id'], - 'binding:vnic_type': 'normal', - 'binding:host_id': 'host'} - - TEST.api_ports.add(port_dict) - TEST.ports.add(neutron.Port(port_dict)) - - port_dict = {'admin_state_up': True, - 'device_id': '1', - 'device_owner': 'compute:nova', - 'fixed_ips': [{'ip_address': '10.0.0.4', - 'subnet_id': subnet_dict['id']}], - 'id': '7e6ce62c-7ea2-44f8-b6b4-769af90a8406', - 'mac_address': 'fa:16:3e:9d:e6:2f', - 'name': '', - 'network_id': network_dict['id'], - 'status': 'ACTIVE', - 'tenant_id': network_dict['tenant_id'], - 'binding:vnic_type': 'normal', - 'binding:host_id': 'host'} - TEST.api_ports.add(port_dict) - TEST.ports.add(neutron.Port(port_dict)) - assoc_port = port_dict - - port_dict = {'admin_state_up': True, - 'device_id': '279989f7-54bb-41d9-ba42-0d61f12fda61', - 'device_owner': 'network:router_interface', - 'fixed_ips': [{'ip_address': '10.0.0.1', - 'subnet_id': subnet_dict['id']}], - 'id': '9036eedb-e7fa-458e-bc6e-d9d06d9d1bc4', - 'mac_address': 'fa:16:3e:9c:d5:7f', - 'name': '', - 'network_id': network_dict['id'], - 'status': 'ACTIVE', - 'tenant_id': network_dict['tenant_id'], - 'binding:vnic_type': 'normal', - 'binding:host_id': 'host'} - TEST.api_ports.add(port_dict) - TEST.ports.add(neutron.Port(port_dict)) - - # 2nd network. - network_dict = {'admin_state_up': True, - 'id': '72c3ab6c-c80f-4341-9dc5-210fa31ac6c2', - 'name': 'net2', - 'status': 'ACTIVE', - 'subnets': ['3f7c5d79-ee55-47b0-9213-8e669fb03009'], - 'tenant_id': '2', - 'router:external': False, - 'shared': True} - subnet_dict = {'allocation_pools': [{'end': '172.16.88.254', - 'start': '172.16.88.2'}], - 'dns_nameservers': ['10.56.1.20', '10.56.1.21'], - 'host_routes': [{'destination': '192.168.20.0/24', - 'nexthop': '172.16.88.253'}, - {'destination': '192.168.21.0/24', - 'nexthop': '172.16.88.252'}], - 'cidr': '172.16.88.0/24', - 'enable_dhcp': True, - 'gateway_ip': '172.16.88.1', - 'id': '3f7c5d79-ee55-47b0-9213-8e669fb03009', - 'ip_version': 4, - 'name': 'aaaa', - 'network_id': network_dict['id'], - 'tenant_id': network_dict['tenant_id']} - - TEST.api_networks.add(network_dict) - TEST.api_subnets.add(subnet_dict) - - network = copy.deepcopy(network_dict) - subnet = neutron.Subnet(subnet_dict) - network['subnets'] = [subnet] - TEST.networks.add(neutron.Network(network)) - TEST.subnets.add(subnet) - - port_dict = {'admin_state_up': True, - 'device_id': '2', - 'device_owner': 'compute:nova', - 'fixed_ips': [{'ip_address': '172.16.88.3', - 'subnet_id': subnet_dict['id']}], - 'id': '1db2cc37-3553-43fa-b7e2-3fc4eb4f9905', - 'mac_address': 'fa:16:3e:56:e6:2f', - 'name': '', - 'network_id': network_dict['id'], - 'status': 'ACTIVE', - 'tenant_id': network_dict['tenant_id'], - 'binding:vnic_type': 'normal', - 'binding:host_id': 'host'} - - TEST.api_ports.add(port_dict) - TEST.ports.add(neutron.Port(port_dict)) - - # External network. - network_dict = {'admin_state_up': True, - 'id': '9b466b94-213a-4cda-badf-72c102a874da', - 'name': 'ext_net', - 'status': 'ACTIVE', - 'subnets': ['d6bdc71c-7566-4d32-b3ff-36441ce746e8'], - 'tenant_id': '3', - 'router:external': True, - 'shared': False} - subnet_dict = {'allocation_pools': [{'start': '172.24.4.226.', - 'end': '172.24.4.238'}], - 'dns_nameservers': [], - 'host_routes': [], - 'cidr': '172.24.4.0/28', - 'enable_dhcp': False, - 'gateway_ip': '172.24.4.225', - 'id': 'd6bdc71c-7566-4d32-b3ff-36441ce746e8', - 'ip_version': 4, - 'name': 'ext_subnet', - 'network_id': network_dict['id'], - 'tenant_id': network_dict['tenant_id']} - ext_net = network_dict - - TEST.api_networks.add(network_dict) - TEST.api_subnets.add(subnet_dict) - - network = copy.deepcopy(network_dict) - subnet = neutron.Subnet(subnet_dict) - network['subnets'] = [subnet] - TEST.networks.add(neutron.Network(network)) - TEST.subnets.add(subnet) - - # 1st v6 network. - network_dict = {'admin_state_up': True, - 'id': '96688ea1-ffa5-78ec-22ca-33aaabfaf775', - 'name': 'v6_net1', - 'status': 'ACTIVE', - 'subnets': ['88ddd443-4377-ab1f-87dd-4bc4a662dbb6'], - 'tenant_id': '1', - 'router:external': False, - 'shared': False} - subnet_dict = {'allocation_pools': [{'end': 'ff09::ff', - 'start': 'ff09::02'}], - 'dns_nameservers': [], - 'host_routes': [], - 'cidr': 'ff09::/64', - 'enable_dhcp': True, - 'gateway_ip': 'ff09::1', - 'id': network_dict['subnets'][0], - 'ip_version': 6, - 'name': 'v6_subnet1', - 'network_id': network_dict['id'], - 'tenant_id': network_dict['tenant_id'], - 'ipv6_modes': 'none/none'} - - TEST.api_networks.add(network_dict) - TEST.api_subnets.add(subnet_dict) - - network = copy.deepcopy(network_dict) - subnet = neutron.Subnet(subnet_dict) - network['subnets'] = [subnet] - TEST.networks.add(neutron.Network(network)) - TEST.subnets.add(subnet) - - # 2nd v6 network - slaac. - network_dict = {'admin_state_up': True, - 'id': 'c62e4bb3-296a-4cd1-8f6b-aaa7a0092326', - 'name': 'v6_net2', - 'status': 'ACTIVE', - 'subnets': ['5d736a21-0036-4779-8f8b-eed5f98077ec'], - 'tenant_id': '1', - 'router:external': False, - 'shared': False} - subnet_dict = {'allocation_pools': [{'end': 'ff09::ff', - 'start': 'ff09::02'}], - 'dns_nameservers': [], - 'host_routes': [], - 'cidr': 'ff09::/64', - 'enable_dhcp': True, - 'gateway_ip': 'ff09::1', - 'id': network_dict['subnets'][0], - 'ip_version': 6, - 'name': 'v6_subnet2', - 'network_id': network_dict['id'], - 'tenant_id': network_dict['tenant_id'], - 'ipv6_modes': 'slaac/slaac'} - - TEST.api_networks.add(network_dict) - TEST.api_subnets.add(subnet_dict) - - network = copy.deepcopy(network_dict) - subnet = neutron.Subnet(subnet_dict) - network['subnets'] = [subnet] - TEST.networks.add(neutron.Network(network)) - TEST.subnets.add(subnet) - - # Set up router data. - port_dict = {'admin_state_up': True, - 'device_id': '7180cede-bcd8-4334-b19f-f7ef2f331f53', - 'device_owner': 'network:router_gateway', - 'fixed_ips': [{'ip_address': '10.0.0.3', - 'subnet_id': subnet_dict['id']}], - 'id': '44ec6726-4bdc-48c5-94d4-df8d1fbf613b', - 'mac_address': 'fa:16:3e:9c:d5:7e', - 'name': '', - 'network_id': TEST.networks.get(name="ext_net")['id'], - 'status': 'ACTIVE', - 'tenant_id': '1', - 'binding:vnic_type': 'normal', - 'binding:host_id': 'host'} - TEST.api_ports.add(port_dict) - TEST.ports.add(neutron.Port(port_dict)) - - router_dict = {'id': '279989f7-54bb-41d9-ba42-0d61f12fda61', - 'name': 'router1', - 'status': 'ACTIVE', - 'admin_state_up': True, - 'distributed': True, - 'external_gateway_info': - {'network_id': ext_net['id']}, - 'tenant_id': '1'} - TEST.api_routers.add(router_dict) - TEST.routers.add(neutron.Router(router_dict)) - router_dict = {'id': '10e3dc42-1ce1-4d48-87cf-7fc333055d6c', - 'name': 'router2', - 'status': 'ACTIVE', - 'admin_state_up': False, - 'distributed': False, - 'external_gateway_info': None, - 'tenant_id': '1'} - TEST.api_routers.add(router_dict) - TEST.routers.add(neutron.Router(router_dict)) - router_dict = {'id': '7180cede-bcd8-4334-b19f-f7ef2f331f53', - 'name': 'rulerouter', - 'status': 'ACTIVE', - 'admin_state_up': True, - 'distributed': False, - 'external_gateway_info': - {'network_id': ext_net['id']}, - 'tenant_id': '1', - 'router_rules': [{'id': '101', - 'action': 'deny', - 'source': 'any', - 'destination': 'any', - 'nexthops': []}, - {'id': '102', - 'action': 'permit', - 'source': 'any', - 'destination': '8.8.8.8/32', - 'nexthops': ['1.0.0.2', '1.0.0.1']}]} - TEST.api_routers.add(router_dict) - TEST.routers_with_rules.add(neutron.Router(router_dict)) - - # Floating IP. - # Unassociated. - fip_dict = {'tenant_id': '1', - 'floating_ip_address': '172.16.88.227', - 'floating_network_id': ext_net['id'], - 'id': '9012cd70-cfae-4e46-b71e-6a409e9e0063', - 'fixed_ip_address': None, - 'port_id': None, - 'router_id': None} - TEST.api_q_floating_ips.add(fip_dict) - TEST.q_floating_ips.add(neutron.FloatingIp(fip_dict)) - - # Associated (with compute port on 1st network). - fip_dict = {'tenant_id': '1', - 'floating_ip_address': '172.16.88.228', - 'floating_network_id': ext_net['id'], - 'id': 'a97af8f2-3149-4b97-abbd-e49ad19510f7', - 'fixed_ip_address': assoc_port['fixed_ips'][0]['ip_address'], - 'port_id': assoc_port['id'], - 'router_id': router_dict['id']} - TEST.api_q_floating_ips.add(fip_dict) - TEST.q_floating_ips.add(neutron.FloatingIp(fip_dict)) - - # Security group. - - sec_group_1 = {'tenant_id': '1', - 'description': 'default', - 'id': 'faad7c80-3b62-4440-967c-13808c37131d', - 'name': 'default'} - sec_group_2 = {'tenant_id': '1', - 'description': 'NotDefault', - 'id': '27a5c9a1-bdbb-48ac-833a-2e4b5f54b31d', - 'name': 'other_group'} - sec_group_3 = {'tenant_id': '1', - 'description': 'NotDefault', - 'id': '443a4d7a-4bd2-4474-9a77-02b35c9f8c95', - 'name': 'another_group'} - - def add_rule_to_group(secgroup, default_only=True): - rule_egress_ipv4 = { - 'id': str(uuid.uuid4()), - 'direction': u'egress', 'ethertype': u'IPv4', - 'port_range_min': None, 'port_range_max': None, - 'protocol': None, 'remote_group_id': None, - 'remote_ip_prefix': None, - 'security_group_id': secgroup['id'], - 'tenant_id': secgroup['tenant_id']} - rule_egress_ipv6 = { - 'id': str(uuid.uuid4()), - 'direction': u'egress', 'ethertype': u'IPv6', - 'port_range_min': None, 'port_range_max': None, - 'protocol': None, 'remote_group_id': None, - 'remote_ip_prefix': None, - 'security_group_id': secgroup['id'], - 'tenant_id': secgroup['tenant_id']} - - rule_tcp_80 = { - 'id': str(uuid.uuid4()), - 'direction': u'ingress', 'ethertype': u'IPv4', - 'port_range_min': 80, 'port_range_max': 80, - 'protocol': u'tcp', 'remote_group_id': None, - 'remote_ip_prefix': u'0.0.0.0/0', - 'security_group_id': secgroup['id'], - 'tenant_id': secgroup['tenant_id']} - rule_icmp = { - 'id': str(uuid.uuid4()), - 'direction': u'ingress', 'ethertype': u'IPv4', - 'port_range_min': 5, 'port_range_max': 8, - 'protocol': u'icmp', 'remote_group_id': None, - 'remote_ip_prefix': u'0.0.0.0/0', - 'security_group_id': secgroup['id'], - 'tenant_id': secgroup['tenant_id']} - rule_group = { - 'id': str(uuid.uuid4()), - 'direction': u'ingress', 'ethertype': u'IPv4', - 'port_range_min': 80, 'port_range_max': 80, - 'protocol': u'tcp', 'remote_group_id': sec_group_1['id'], - 'remote_ip_prefix': None, - 'security_group_id': secgroup['id'], - 'tenant_id': secgroup['tenant_id']} - rule_all_tcp = { - 'id': str(uuid.uuid4()), - 'direction': u'egress', 'ethertype': u'IPv4', - 'port_range_min': 1, 'port_range_max': 65535, - 'protocol': u'tcp', 'remote_group_id': None, - 'remote_ip_prefix': u'0.0.0.0/24', - 'security_group_id': secgroup['id'], - 'tenant_id': secgroup['tenant_id']} - - rules = [] - if not default_only: - rules += [rule_tcp_80, rule_icmp, rule_group, rule_all_tcp] - rules += [rule_egress_ipv4, rule_egress_ipv6] - secgroup['security_group_rules'] = rules - - add_rule_to_group(sec_group_1, default_only=False) - add_rule_to_group(sec_group_2) - add_rule_to_group(sec_group_3) - - groups = [sec_group_1, sec_group_2, sec_group_3] - sg_name_dict = dict([(sg['id'], sg['name']) for sg in groups]) - for sg in groups: - # Neutron API. - TEST.api_q_secgroups.add(sg) - for rule in sg['security_group_rules']: - TEST.api_q_secgroup_rules.add(copy.copy(rule)) - # OpenStack Dashboard internaly API. - TEST.q_secgroups.add( - neutron.SecurityGroup(copy.deepcopy(sg), sg_name_dict)) - for rule in sg['security_group_rules']: - TEST.q_secgroup_rules.add( - neutron.SecurityGroupRule(copy.copy(rule), sg_name_dict)) - - # LBaaS. - - # 1st pool. - pool_dict = {'id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49', - 'tenant_id': '1', - 'vip_id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'name': 'pool1', - 'description': 'pool description', - 'subnet_id': TEST.subnets.first().id, - 'protocol': 'HTTP', - 'lb_method': 'ROUND_ROBIN', - 'health_monitors': TEST.monitors.list(), - 'members': ['78a46e5e-eb1a-418a-88c7-0e3f5968b08'], - 'admin_state_up': True, - 'status': 'ACTIVE', - 'provider': 'haproxy'} - TEST.api_pools.add(pool_dict) - TEST.pools.add(lbaas.Pool(pool_dict)) - - # 2nd pool. - pool_dict = {'id': '8913dde8-4915-4b90-8d3e-b95eeedb0d50', - 'tenant_id': '1', - 'vip_id': 'f0881d38-c3eb-4fee-9763-12de3338041d', - 'name': 'pool2', - 'description': 'pool description', - 'subnet_id': TEST.subnets.first().id, - 'protocol': 'HTTPS', - 'lb_method': 'ROUND_ROBIN', - 'health_monitors': TEST.monitors.list()[0:1], - 'members': [], - 'status': 'PENDING_CREATE', - 'admin_state_up': True} - TEST.api_pools.add(pool_dict) - TEST.pools.add(lbaas.Pool(pool_dict)) - - # 1st vip. - vip_dict = {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'name': 'vip1', - 'address': '10.0.0.100', - 'description': 'vip description', - 'subnet_id': TEST.subnets.first().id, - 'port_id': TEST.ports.first().id, - 'subnet': TEST.subnets.first().cidr, - 'protocol_port': 80, - 'protocol': pool_dict['protocol'], - 'pool_id': pool_dict['id'], - 'session_persistence': {'type': 'APP_COOKIE', - 'cookie_name': 'jssessionid'}, - 'connection_limit': 10, - 'admin_state_up': True} - TEST.api_vips.add(vip_dict) - TEST.vips.add(lbaas.Vip(vip_dict)) - - # 2nd vip. - vip_dict = {'id': 'f0881d38-c3eb-4fee-9763-12de3338041d', - 'name': 'vip2', - 'address': '10.0.0.110', - 'description': 'vip description', - 'subnet_id': TEST.subnets.first().id, - 'port_id': TEST.ports.list()[0].id, - 'subnet': TEST.subnets.first().cidr, - 'protocol_port': 80, - 'protocol': pool_dict['protocol'], - 'pool_id': pool_dict['id'], - 'session_persistence': {'type': 'APP_COOKIE', - 'cookie_name': 'jssessionid'}, - 'connection_limit': 10, - 'admin_state_up': True} - TEST.api_vips.add(vip_dict) - TEST.vips.add(lbaas.Vip(vip_dict)) - - # 1st member. - member_dict = {'id': '78a46e5e-eb1a-418a-88c7-0e3f5968b08', - 'tenant_id': '1', - 'pool_id': pool_dict['id'], - 'address': '10.0.0.11', - 'protocol_port': 80, - 'weight': 10, - 'status': 'ACTIVE', - 'admin_state_up': True} - TEST.api_members.add(member_dict) - TEST.members.add(lbaas.Member(member_dict)) - - # 2nd member. - member_dict = {'id': '41ac1f8d-6d9c-49a4-a1bf-41955e651f91', - 'tenant_id': '1', - 'pool_id': pool_dict['id'], - 'address': '10.0.0.12', - 'protocol_port': 80, - 'weight': 10, - 'status': 'ACTIVE', - 'admin_state_up': True} - TEST.api_members.add(member_dict) - TEST.members.add(lbaas.Member(member_dict)) - - # 1st monitor. - monitor_dict = {'id': 'd4a0500f-db2b-4cc4-afcf-ec026febff96', - 'type': 'http', - 'delay': 10, - 'timeout': 10, - 'max_retries': 10, - 'http_method': 'GET', - 'url_path': '/', - 'expected_codes': '200', - 'admin_state_up': True, - "pools": [{"pool_id": TEST.pools.list()[0].id}, - {"pool_id": TEST.pools.list()[1].id}], - } - TEST.api_monitors.add(monitor_dict) - TEST.monitors.add(lbaas.PoolMonitor(monitor_dict)) - - # 2nd monitor. - monitor_dict = {'id': 'd4a0500f-db2b-4cc4-afcf-ec026febff97', - 'type': 'ping', - 'delay': 10, - 'timeout': 10, - 'max_retries': 10, - 'admin_state_up': True, - 'pools': [], - } - TEST.api_monitors.add(monitor_dict) - TEST.monitors.add(lbaas.PoolMonitor(monitor_dict)) - - # Quotas. - quota_data = {'network': '10', - 'subnet': '10', - 'port': '50', - 'router': '10', - 'floatingip': '50', - 'security_group': '20', - 'security_group_rule': '100', - } - TEST.neutron_quotas.add(base.QuotaSet(quota_data)) - - # Extensions. - extension_1 = {"name": "security-group", - "alias": "security-group", - "description": "The security groups extension."} - extension_2 = {"name": "Quota management support", - "alias": "quotas", - "description": "Expose functions for quotas management"} - extension_3 = {"name": "Provider network", - "alias": "provider", - "description": "Provider network extension"} - extension_4 = {"name": "Distributed Virtual Router", - "alias": "dvr", - "description": - "Enables configuration of Distributed Virtual Routers."} - extension_5 = {"name": "HA Router extension", - "alias": "l3-ha", - "description": "Add HA capability to routers."} - extension_6 = {"name": "LoadBalancing service", - "alias": "lbaas", - "description": "Extension for LoadBalancing service"} - TEST.api_extensions.add(extension_1) - TEST.api_extensions.add(extension_2) - TEST.api_extensions.add(extension_3) - TEST.api_extensions.add(extension_4) - TEST.api_extensions.add(extension_5) - TEST.api_extensions.add(extension_6) - - # 1st agent. - agent_dict = {"binary": "neutron-openvswitch-agent", - "description": None, - "admin_state_up": True, - "heartbeat_timestamp": "2013-07-26 06:51:47", - "alive": True, - "id": "c876ff05-f440-443e-808c-1d34cda3e88a", - "topic": "N/A", - "host": "devstack001", - "agent_type": "Open vSwitch agent", - "started_at": "2013-07-26 05:23:28", - "created_at": "2013-07-26 05:23:28", - "configurations": {"devices": 2}} - TEST.api_agents.add(agent_dict) - TEST.agents.add(neutron.Agent(agent_dict)) - - # 2nd agent. - agent_dict = {"binary": "neutron-dhcp-agent", - "description": None, - "admin_state_up": True, - "heartbeat_timestamp": "2013-07-26 06:51:48", - "alive": True, - "id": "f0d12e3d-1973-41a2-b977-b95693f9a8aa", - "topic": "dhcp_agent", - "host": "devstack001", - "agent_type": "DHCP agent", - "started_at": "2013-07-26 05:23:30", - "created_at": "2013-07-26 05:23:30", - "configurations": { - "subnets": 1, - "use_namespaces": True, - "dhcp_lease_duration": 120, - "dhcp_driver": "neutron.agent.linux.dhcp.Dnsmasq", - "networks": 1, - "ports": 1}} - TEST.api_agents.add(agent_dict) - TEST.agents.add(neutron.Agent(agent_dict)) - - # Service providers. - provider_1 = {"service_type": "LOADBALANCER", - "name": "haproxy", - "default": True} - TEST.providers.add(provider_1) - - # VPNaaS. - - # 1st VPNService. - vpnservice_dict = {'id': '09a26949-6231-4f72-942a-0c8c0ddd4d61', - 'tenant_id': '1', - 'name': 'cloud_vpn1', - 'description': 'vpn description', - 'subnet_id': TEST.subnets.first().id, - 'router_id': TEST.routers.first().id, - 'vpn_type': 'ipsec', - 'ipsecsiteconnections': [], - 'admin_state_up': True, - 'status': 'Active', - 'ipsecsiteconns': TEST.ipsecsiteconnections.list()} - TEST.api_vpnservices.add(vpnservice_dict) - TEST.vpnservices.add(vpn.VPNService(vpnservice_dict)) - - # 2nd VPNService. - vpnservice_dict = {'id': '09a26949-6231-4f72-942a-0c8c0ddd4d62', - 'tenant_id': '1', - 'name': 'cloud_vpn2', - 'description': 'vpn description', - 'subnet_id': TEST.subnets.first().id, - 'router_id': TEST.routers.first().id, - 'vpn_type': 'ipsec', - 'ipsecsiteconnections': [], - 'admin_state_up': True, - 'status': 'Active', - 'ipsecsiteconns': []} - TEST.api_vpnservices.add(vpnservice_dict) - TEST.vpnservices.add(vpn.VPNService(vpnservice_dict)) - - # 1st IKEPolicy - ikepolicy_dict = {'id': 'a1f009b7-0ffa-43a7-ba19-dcabb0b4c981', - 'tenant_id': '1', - 'name': 'ikepolicy_1', - 'description': 'ikepolicy description', - 'auth_algorithm': 'sha1', - 'encryption_algorithm': 'aes-256', - 'ike_version': 'v1', - 'lifetime': {'units': 'seconds', 'value': 3600}, - 'phase1_negotiation_mode': 'main', - 'pfs': 'group5', - 'ipsecsiteconns': TEST.ipsecsiteconnections.list()} - TEST.api_ikepolicies.add(ikepolicy_dict) - TEST.ikepolicies.add(vpn.IKEPolicy(ikepolicy_dict)) - - # 2nd IKEPolicy - ikepolicy_dict = {'id': 'a1f009b7-0ffa-43a7-ba19-dcabb0b4c982', - 'tenant_id': '1', - 'name': 'ikepolicy_2', - 'description': 'ikepolicy description', - 'auth_algorithm': 'sha1', - 'encryption_algorithm': 'aes-256', - 'ike_version': 'v1', - 'lifetime': {'units': 'seconds', 'value': 3600}, - 'phase1_negotiation_mode': 'main', - 'pfs': 'group5', - 'ipsecsiteconns': []} - TEST.api_ikepolicies.add(ikepolicy_dict) - TEST.ikepolicies.add(vpn.IKEPolicy(ikepolicy_dict)) - - # 1st IPSecPolicy - ipsecpolicy_dict = {'id': '8376e1dd-2b1c-4346-b23c-6989e75ecdb8', - 'tenant_id': '1', - 'name': 'ipsecpolicy_1', - 'description': 'ipsecpolicy description', - 'auth_algorithm': 'sha1', - 'encapsulation_mode': 'tunnel', - 'encryption_algorithm': '3des', - 'lifetime': {'units': 'seconds', 'value': 3600}, - 'pfs': 'group5', - 'transform_protocol': 'esp', - 'ipsecsiteconns': TEST.ipsecsiteconnections.list()} - TEST.api_ipsecpolicies.add(ipsecpolicy_dict) - TEST.ipsecpolicies.add(vpn.IPSecPolicy(ipsecpolicy_dict)) - - # 2nd IPSecPolicy - ipsecpolicy_dict = {'id': '8376e1dd-2b1c-4346-b23c-6989e75ecdb9', - 'tenant_id': '1', - 'name': 'ipsecpolicy_2', - 'description': 'ipsecpolicy description', - 'auth_algorithm': 'sha1', - 'encapsulation_mode': 'tunnel', - 'encryption_algorithm': '3des', - 'lifetime': {'units': 'seconds', 'value': 3600}, - 'pfs': 'group5', - 'transform_protocol': 'esp', - 'ipsecsiteconns': []} - TEST.api_ipsecpolicies.add(ipsecpolicy_dict) - TEST.ipsecpolicies.add(vpn.IPSecPolicy(ipsecpolicy_dict)) - - # 1st IPSecSiteConnection - ipsecsiteconnection_dict = {'id': 'dd1dd3a0-f349-49be-b013-245e147763d6', - 'tenant_id': '1', - 'name': 'ipsec_connection_1', - 'description': 'vpn connection description', - 'dpd': {'action': 'hold', - 'interval': 30, - 'timeout': 120}, - 'ikepolicy_id': ikepolicy_dict['id'], - 'initiator': 'bi-directional', - 'ipsecpolicy_id': ipsecpolicy_dict['id'], - 'mtu': 1500, - 'peer_address': - '2607:f0d0:4545:3:200:f8ff:fe21:67cf', - 'peer_cidrs': ['20.1.0.0/24', '21.1.0.0/24'], - 'peer_id': - '2607:f0d0:4545:3:200:f8ff:fe21:67cf', - 'psk': 'secret', - 'vpnservice_id': vpnservice_dict['id'], - 'admin_state_up': True, - 'status': 'Active'} - TEST.api_ipsecsiteconnections.add(ipsecsiteconnection_dict) - TEST.ipsecsiteconnections.add( - vpn.IPSecSiteConnection(ipsecsiteconnection_dict)) - - # 2nd IPSecSiteConnection - ipsecsiteconnection_dict = {'id': 'dd1dd3a0-f349-49be-b013-245e147763d7', - 'tenant_id': '1', - 'name': 'ipsec_connection_2', - 'description': 'vpn connection description', - 'dpd': {'action': 'hold', - 'interval': 30, - 'timeout': 120}, - 'ikepolicy_id': ikepolicy_dict['id'], - 'initiator': 'bi-directional', - 'ipsecpolicy_id': ipsecpolicy_dict['id'], - 'mtu': 1500, - 'peer_address': '172.0.0.2', - 'peer_cidrs': ['20.1.0.0/24'], - 'peer_id': '172.0.0.2', - 'psk': 'secret', - 'vpnservice_id': vpnservice_dict['id'], - 'admin_state_up': True, - 'status': 'Active'} - TEST.api_ipsecsiteconnections.add(ipsecsiteconnection_dict) - TEST.ipsecsiteconnections.add( - vpn.IPSecSiteConnection(ipsecsiteconnection_dict)) - - # FWaaS - - # 1st rule (used by 1st policy) - rule1_dict = {'id': 'f0881d38-c3eb-4fee-9763-12de3338041d', - 'tenant_id': '1', - 'name': 'rule1', - 'description': 'rule1 description', - 'protocol': 'tcp', - 'action': 'allow', - 'source_ip_address': '1.2.3.0/24', - 'source_port': '80', - 'destination_ip_address': '4.5.6.7/32', - 'destination_port': '1:65535', - 'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'position': 1, - 'shared': True, - 'enabled': True} - TEST.api_fw_rules.add(rule1_dict) - - rule1 = fwaas.Rule(copy.deepcopy(rule1_dict)) - # NOTE: rule1['policy'] is set below - TEST.fw_rules.add(rule1) - - # 2nd rule (used by 2nd policy; no name) - rule2_dict = {'id': 'c6298a93-850f-4f64-b78a-959fd4f1e5df', - 'tenant_id': '1', - 'name': '', - 'description': '', - 'protocol': 'udp', - 'action': 'deny', - 'source_ip_address': '1.2.3.0/24', - 'source_port': '80', - 'destination_ip_address': '4.5.6.7/32', - 'destination_port': '1:65535', - 'firewall_policy_id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'position': 2, - 'shared': True, - 'enabled': True} - TEST.api_fw_rules.add(rule2_dict) - - rule2 = fwaas.Rule(copy.deepcopy(rule2_dict)) - # NOTE: rule2['policy'] is set below - TEST.fw_rules.add(rule2) - - # 3rd rule (not used by any policy) - rule3_dict = {'id': 'h0881d38-c3eb-4fee-9763-12de3338041d', - 'tenant_id': '1', - 'name': 'rule3', - 'description': 'rule3 description', - 'protocol': None, - 'action': 'allow', - 'source_ip_address': '1.2.3.0/24', - 'source_port': '80', - 'destination_ip_address': '4.5.6.7/32', - 'destination_port': '1:65535', - 'firewall_policy_id': None, - 'position': None, - 'shared': True, - 'enabled': True} - TEST.api_fw_rules.add(rule3_dict) - - rule3 = fwaas.Rule(copy.deepcopy(rule3_dict)) - # rule3 is not associated with any rules - rule3._apidict['policy'] = None - TEST.fw_rules.add(rule3) - - # 1st policy (associated with 2 rules) - policy1_dict = {'id': 'abcdef-c3eb-4fee-9763-12de3338041e', - 'tenant_id': '1', - 'name': 'policy1', - 'description': 'policy with two rules', - 'firewall_rules': [rule1_dict['id'], rule2_dict['id']], - 'audited': True, - 'shared': True} - TEST.api_fw_policies.add(policy1_dict) - - policy1 = fwaas.Policy(copy.deepcopy(policy1_dict)) - policy1._apidict['rules'] = [rule1, rule2] - TEST.fw_policies.add(policy1) - - # Reverse relations (rule -> policy) - rule1._apidict['policy'] = policy1 - rule2._apidict['policy'] = policy1 - - # 2nd policy (associated with no rules; no name) - policy2_dict = {'id': 'cf50b331-787a-4623-825e-da794c918d6a', - 'tenant_id': '1', - 'name': '', - 'description': '', - 'firewall_rules': [], - 'audited': False, - 'shared': False} - TEST.api_fw_policies.add(policy2_dict) - - policy2 = fwaas.Policy(copy.deepcopy(policy2_dict)) - policy2._apidict['rules'] = [] - TEST.fw_policies.add(policy2) - - # 1st firewall - fw1_dict = {'id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49', - 'tenant_id': '1', - 'firewall_policy_id': - 'abcdef-c3eb-4fee-9763-12de3338041e', - 'name': 'firewall1', - 'router_ids': [TEST.routers.first().id], - 'description': 'firewall description', - 'status': 'PENDING_CREATE', - 'shared': True, - 'admin_state_up': True} - TEST.api_firewalls.add(fw1_dict) - - fw1 = fwaas.Firewall(copy.deepcopy(fw1_dict)) - fw1._apidict['policy'] = policy1 - fw1._apidict['routers'] = [TEST.routers.first()] - TEST.firewalls.add(fw1) - - # 2nd firewall (no name) - fw2_dict = {'id': '1aa75150-415f-458e-bae5-5a362a4fb1f7', - 'tenant_id': '1', - 'firewall_policy_id': - 'abcdef-c3eb-4fee-9763-12de3338041e', - 'name': '', - 'description': '', - 'status': 'PENDING_CREATE', - 'shared': True, - 'admin_state_up': True} - TEST.api_firewalls.add(fw1_dict) - - fw2 = fwaas.Firewall(copy.deepcopy(fw2_dict)) - fw2._apidict['policy'] = policy1 - TEST.firewalls.add(fw1) - - # Additional Cisco N1K profiles. - - # 2nd network profile for network when using the cisco n1k plugin. - # Profile applied on 1st network. - net_profile_dict = {'name': 'net_profile_test2', - 'segment_type': 'overlay', - 'sub_type': 'native_vxlan', - 'segment_range': '10000-10100', - 'multicast_ip_range': '144.0.0.0-144.0.0.100', - 'id': - '00000000-2222-2222-2222-000000000000', - 'project': '1', - # overlay profiles have no physical_network - 'physical_network': None} - - TEST.api_net_profiles.add(net_profile_dict) - TEST.net_profiles.add(neutron.Profile(net_profile_dict)) - - # 2nd network profile binding. - network_profile_binding_dict = {'profile_id': - '00000000-2222-2222-2222-000000000000', - 'tenant_id': '1'} - - TEST.api_network_profile_binding.add(network_profile_binding_dict) - TEST.network_profile_binding.add(neutron.Profile( - network_profile_binding_dict)) - - # 3rd network profile for network when using the cisco n1k plugin - # Profile applied on 1st network - net_profile_dict = {'name': 'net_profile_test3', - 'segment_type': 'overlay', - 'sub_type': 'other', - 'other_subtype': 'GRE', - 'segment_range': '11000-11100', - 'id': - '00000000-3333-3333-3333-000000000000', - 'project': '1'} - - TEST.api_net_profiles.add(net_profile_dict) - TEST.net_profiles.add(neutron.Profile(net_profile_dict)) - - # 3rd network profile binding - network_profile_binding_dict = {'profile_id': - '00000000-3333-3333-3333-000000000000', - 'tenant_id': '1'} - - TEST.api_network_profile_binding.add(network_profile_binding_dict) - TEST.network_profile_binding.add(neutron.Profile( - network_profile_binding_dict)) - - # 4th network profile for network when using the cisco n1k plugin - # Profile applied on 1st network - net_profile_dict = {'name': 'net_profile_test4', - 'segment_type': 'trunk', - 'sub_type_trunk': 'vlan', - 'id': - '00000000-4444-4444-4444-000000000000', - 'project': '1'} - - TEST.api_net_profiles.add(net_profile_dict) - TEST.net_profiles.add(neutron.Profile(net_profile_dict)) - - # 4th network profile binding - network_profile_binding_dict = {'profile_id': - '00000000-4444-4444-4444-000000000000', - 'tenant_id': '1'} - - TEST.api_network_profile_binding.add(network_profile_binding_dict) - TEST.network_profile_binding.add(neutron.Profile( - network_profile_binding_dict)) - - # Adding a new network and new network and policy profile - # similar to the first to test launching an instance with multiple - # nics and multiple profiles. - - # 4th network to use for testing instances with multiple-nics & profiles - network_dict = {'admin_state_up': True, - 'id': '7aa23d91-ffff-abab-dcdc-3411ae767e8a', - 'name': 'net4', - 'status': 'ACTIVE', - 'subnets': ['31be4a21-aadd-73da-6422-821ff249a4bb'], - 'tenant_id': '1', - 'router:external': False, - 'shared': False} - subnet_dict = {'allocation_pools': [{'end': '11.10.0.254', - 'start': '11.10.0.2'}], - 'dns_nameservers': [], - 'host_routes': [], - 'cidr': '11.10.0.0/24', - 'enable_dhcp': True, - 'gateway_ip': '11.10.0.1', - 'id': network_dict['subnets'][0], - 'ip_version': 4, - 'name': 'mysubnet4', - 'network_id': network_dict['id'], - 'tenant_id': network_dict['tenant_id']} - - TEST.api_networks.add(network_dict) - TEST.api_subnets.add(subnet_dict) - - network = copy.deepcopy(network_dict) - subnet = neutron.Subnet(subnet_dict) - network['subnets'] = [subnet] - TEST.networks.add(neutron.Network(network)) - TEST.subnets.add(subnet) - - # 5th network profile for network when using the cisco n1k plugin - # Network Profile applied on 4th network - net_profile_dict = {'name': 'net_profile_test5', - 'segment_type': 'vlan', - 'physical_network': 'phys5', - 'segment_range': '400-450', - 'id': - '00000000-5555-5555-5555-000000000000', - 'project': TEST.networks.get(name="net4")['tenant_id']} - - TEST.api_net_profiles.add(net_profile_dict) - TEST.net_profiles.add(neutron.Profile(net_profile_dict)) - - # 2nd policy profile for port when using the cisco n1k plugin - policy_profile_dict = {'name': 'policy_profile_test2', - 'id': - '11111111-9999-9999-9999-111111111111'} - - TEST.api_policy_profiles.add(policy_profile_dict) - TEST.policy_profiles.add(neutron.Profile(policy_profile_dict)) - - # network profile binding - network_profile_binding_dict = {'profile_id': - '00000000-5555-5555-5555-000000000000', - 'tenant_id': - TEST.networks.get(name="net4")['tenant_id'] - } - - TEST.api_network_profile_binding.add(network_profile_binding_dict) - TEST.network_profile_binding.add(neutron.Profile( - network_profile_binding_dict)) - - # policy profile binding - policy_profile_binding_dict = {'profile_id': - '11111111-9999-9999-9999-111111111111', - 'tenant_id': - TEST.networks.get(name="net4")['tenant_id']} - - TEST.api_policy_profile_binding.add(policy_profile_binding_dict) - TEST.policy_profile_binding.add(neutron.Profile( - policy_profile_binding_dict)) - - # ports on 4th network - port_dict = {'admin_state_up': True, - 'device_id': '9872faaa-b2b2-eeee-9911-21332eedaa77', - 'device_owner': 'network:dhcp', - 'fixed_ips': [{'ip_address': '11.10.0.3', - 'subnet_id': - TEST.subnets.get(name="mysubnet4")['id']}], - 'id': 'a21dcd22-6733-cccc-aa32-22adafaf16a2', - 'mac_address': '78:22:ff:1a:ba:23', - 'name': 'port5', - 'network_id': TEST.networks.get(name="net4")['id'], - 'status': 'ACTIVE', - 'tenant_id': TEST.networks.get(name="net4")['tenant_id'], - 'binding:vnic_type': 'normal', - 'binding:host_id': 'host'} - TEST.api_ports.add(port_dict) - TEST.ports.add(neutron.Port(port_dict)) diff --git a/code/horizon/openstack_dashboard/test/test_data/nova_data.py b/code/horizon/openstack_dashboard/test/test_data/nova_data.py deleted file mode 100644 index 7e558341..00000000 --- a/code/horizon/openstack_dashboard/test/test_data/nova_data.py +++ /dev/null @@ -1,803 +0,0 @@ -# Copyright 2012 Nebula, 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. - -import json -import uuid - -from novaclient.v2 import aggregates -from novaclient.v2 import availability_zones -from novaclient.v2 import certs -from novaclient.v2 import flavor_access -from novaclient.v2 import flavors -from novaclient.v2 import floating_ips -from novaclient.v2 import hosts -from novaclient.v2 import hypervisors -from novaclient.v2 import keypairs -from novaclient.v2 import quotas -from novaclient.v2 import security_group_rules as rules -from novaclient.v2 import security_groups as sec_groups -from novaclient.v2 import servers -from novaclient.v2 import services -from novaclient.v2 import usage -from novaclient.v2 import volume_snapshots as vol_snaps -from novaclient.v2 import volume_types -from novaclient.v2 import volumes - -from openstack_dashboard.api import base -from openstack_dashboard.api import nova -from openstack_dashboard.usage import quotas as usage_quotas - -from openstack_dashboard.test.test_data import utils - - -class FlavorExtraSpecs(dict): - def __repr__(self): - return "" % self._info - - def __init__(self, info): - super(FlavorExtraSpecs, self).__init__() - self.__dict__.update(info) - self.update(info) - self._info = info - - -SERVER_DATA = """ -{ - "server": { - "OS-EXT-SRV-ATTR:instance_name": "instance-00000005", - "OS-EXT-SRV-ATTR:host": "instance-host", - "OS-EXT-STS:task_state": null, - "addresses": { - "private": [ - { - "version": 4, - "addr": "10.0.0.1" - } - ] - }, - "links": [ - { - "href": "%(host)s/v1.1/%(tenant_id)s/servers/%(server_id)s", - "rel": "self" - }, - { - "href": "%(host)s/%(tenant_id)s/servers/%(server_id)s", - "rel": "bookmark" - } - ], - "image": { - "id": "%(image_id)s", - "links": [ - { - "href": "%(host)s/%(tenant_id)s/images/%(image_id)s", - "rel": "bookmark" - } - ] - }, - "OS-EXT-STS:vm_state": "active", - "flavor": { - "id": "%(flavor_id)s", - "links": [ - { - "href": "%(host)s/%(tenant_id)s/flavors/%(flavor_id)s", - "rel": "bookmark" - } - ] - }, - "id": "%(server_id)s", - "user_id": "%(user_id)s", - "OS-DCF:diskConfig": "MANUAL", - "accessIPv4": "", - "accessIPv6": "", - "progress": null, - "OS-EXT-STS:power_state": 1, - "config_drive": "", - "status": "%(status)s", - "updated": "2012-02-28T19:51:27Z", - "hostId": "c461ea283faa0ab5d777073c93b126c68139e4e45934d4fc37e403c2", - "key_name": "%(key_name)s", - "name": "%(name)s", - "created": "2012-02-28T19:51:17Z", - "tenant_id": "%(tenant_id)s", - "metadata": {"someMetaLabel": "someMetaData", - "somehtmllabel": "