summaryrefslogtreecommitdiff
path: root/openstack_dashboard/test
diff options
context:
space:
mode:
authorTimur Sufiev <tsufiev@mirantis.com>2016-05-19 18:15:24 +0300
committerTimur Sufiev <tsufiev@mirantis.com>2016-07-26 13:38:58 +0000
commit7e65af5f135a272eed975edd0a797c3bdf086b82 (patch)
tree64f031a8dc32463c8b91ddd12d29a200679249a5 /openstack_dashboard/test
parentc9d9df0788b2f97bc818da6054289179f4a92021 (diff)
downloadhorizon-7e65af5f135a272eed975edd0a797c3bdf086b82.tar.gz
Embed support for external data sinks into api.glance
In case 'data' image attribute is a base string (instead of in-memory or on-disk file), api.glance sends back an image wrapper with a redirect url and a token to its caller, so the caller could upload the file to that url directly. Provide a unit test for api.glance behavior when an external upload location is used. That also requires to fix glance stub endpoint data in keystone_data.py since it didn't reflect the reality. Also document the new HORIZON_IMAGES_UPLOAD_MODE setting that will govern direct images upload and the define approach to deprecating the old HORIZON_IMAGES_ALLOW_UPLOAD setting. The old setting is deprecated as of Newton release and planned to be removed in P. 'Removing' means that it will no longer be used / referenced at all in code, not the actual presence in settings.py (it is removed from settings.py in this commit). What really matters is if the customized value of HORIZON_IMAGES_ALLOW_UPLOAD in local_settings.py will be still considered during the deprecation period. Help text in Django Create Image form in case if local file upload was enabled was wrong, fixed that. Related-Bug: #1403129 Partially implements blueprint: horizon-glance-large-image-upload Change-Id: I24ff55e0135514fae89c20175cf9c764e871969b
Diffstat (limited to 'openstack_dashboard/test')
-rw-r--r--openstack_dashboard/test/api_tests/base_tests.py4
-rw-r--r--openstack_dashboard/test/api_tests/glance_tests.py18
-rw-r--r--openstack_dashboard/test/settings.py9
-rw-r--r--openstack_dashboard/test/test_data/keystone_data.py6
4 files changed, 28 insertions, 9 deletions
diff --git a/openstack_dashboard/test/api_tests/base_tests.py b/openstack_dashboard/test/api_tests/base_tests.py
index e707ea1bd..7780573df 100644
--- a/openstack_dashboard/test/api_tests/base_tests.py
+++ b/openstack_dashboard/test/api_tests/base_tests.py
@@ -190,10 +190,10 @@ class ApiHelperTests(test.TestCase):
def test_url_for(self):
url = api_base.url_for(self.request, 'image')
- self.assertEqual('http://public.glance.example.com:9292/v1', url)
+ self.assertEqual('http://public.glance.example.com:9292', url)
url = api_base.url_for(self.request, 'image', endpoint_type='adminURL')
- self.assertEqual('http://admin.glance.example.com:9292/v1', url)
+ self.assertEqual('http://admin.glance.example.com:9292', url)
url = api_base.url_for(self.request, 'compute')
self.assertEqual('http://public.nova.example.com:8774/v2', url)
diff --git a/openstack_dashboard/test/api_tests/glance_tests.py b/openstack_dashboard/test/api_tests/glance_tests.py
index c3662378b..6d0feef46 100644
--- a/openstack_dashboard/test/api_tests/glance_tests.py
+++ b/openstack_dashboard/test/api_tests/glance_tests.py
@@ -20,6 +20,7 @@ from django.conf import settings
from django.test.utils import override_settings
from openstack_dashboard import api
+from openstack_dashboard.api import base
from openstack_dashboard.test import helpers as test
@@ -311,3 +312,20 @@ class GlanceApiTests(test.APITestCase):
res_types = api.glance.metadefs_resource_types_list(self.request)
self.assertItemsEqual(res_types, [])
+
+ def test_image_create_external_upload(self):
+ expected_image = self.images.first()
+ service = base.get_service_from_catalog(self.service_catalog, 'image')
+ base_url = base.get_url_for_service(service, 'RegionOne', 'publicURL')
+ file_upload_url = '%s/v1/images/%s' % (base_url, expected_image.id)
+
+ glanceclient = self.stub_glanceclient()
+ glanceclient.images = self.mox.CreateMockAnything()
+ glanceclient.images.create().AndReturn(expected_image)
+ self.mox.ReplayAll()
+
+ actual_image = api.glance.image_create(self.request, data='sample.iso')
+ actual_image_dict = actual_image.to_dict()
+ self.assertEqual(file_upload_url, actual_image_dict['upload_url'])
+ self.assertEqual(self.request.user.token.id,
+ actual_image_dict['token_id'])
diff --git a/openstack_dashboard/test/settings.py b/openstack_dashboard/test/settings.py
index d78a5a1c7..fdd0a4afc 100644
--- a/openstack_dashboard/test/settings.py
+++ b/openstack_dashboard/test/settings.py
@@ -118,10 +118,11 @@ HORIZON_CONFIG['swift_panel'] = 'legacy'
find_static_files(HORIZON_CONFIG, AVAILABLE_THEMES,
THEME_COLLECTION_DIR, ROOT_PATH)
-# Set to True to allow users to upload images to glance via Horizon server.
-# When enabled, a file form field will appear on the create image form.
-# See documentation for deployment considerations.
-HORIZON_IMAGES_ALLOW_UPLOAD = True
+# Set to 'legacy' or 'direct' to allow users to upload images to glance via
+# Horizon server. When enabled, a file form field will appear on the create
+# image form. If set to 'off', there will be no file form field on the create
+# image form. See documentation for deployment considerations.
+HORIZON_IMAGES_UPLOAD_MODE = 'legacy'
AVAILABLE_REGIONS = [
('http://localhost:5000/v2.0', 'local'),
diff --git a/openstack_dashboard/test/test_data/keystone_data.py b/openstack_dashboard/test/test_data/keystone_data.py
index a57cc55f3..3b9cd1517 100644
--- a/openstack_dashboard/test/test_data/keystone_data.py
+++ b/openstack_dashboard/test/test_data/keystone_data.py
@@ -68,9 +68,9 @@ SERVICE_CATALOG = [
"endpoints_links": [],
"endpoints": [
{"region": "RegionOne",
- "adminURL": "http://admin.glance.example.com:9292/v1",
- "internalURL": "http://int.glance.example.com:9292/v1",
- "publicURL": "http://public.glance.example.com:9292/v1"}]},
+ "adminURL": "http://admin.glance.example.com:9292",
+ "internalURL": "http://int.glance.example.com:9292",
+ "publicURL": "http://public.glance.example.com:9292"}]},
{"type": "identity",
"name": "keystone",
"endpoints_links": [],