Browse Source

Merge "Redirect VM console dynamically" into stable/pike

Zuul 1 year ago
parent
commit
39d863ec23

+ 3
- 3
openstack_dashboard/dashboards/project/instances/tests.py View File

@@ -1274,7 +1274,7 @@ class InstanceTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
1274 1274
 
1275 1275
             self.assertContains(res, "Unable to get log for")
1276 1276
 
1277
-    def test_instance_vnc(self):
1277
+    def test_instance_auto_console(self):
1278 1278
         server = self.servers.first()
1279 1279
         CONSOLE_OUTPUT = '/vncserver'
1280 1280
         CONSOLE_TITLE = '&title=%s(%s)' % (server.name, server.id)
@@ -1287,12 +1287,12 @@ class InstanceTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
1287 1287
         self.mox.StubOutWithMock(console, 'get_console')
1288 1288
         api.nova.server_get(IsA(http.HttpRequest), server.id) \
1289 1289
             .AndReturn(server)
1290
-        console.get_console(IgnoreArg(), 'VNC', server) \
1290
+        console.get_console(IgnoreArg(), 'AUTO', server) \
1291 1291
             .AndReturn(('VNC', CONSOLE_URL))
1292 1292
 
1293 1293
         self.mox.ReplayAll()
1294 1294
 
1295
-        url = reverse('horizon:project:instances:vnc',
1295
+        url = reverse('horizon:project:instances:auto_console',
1296 1296
                       args=[server.id])
1297 1297
         res = self.client.get(url)
1298 1298
         redirect = CONSOLE_URL

+ 1
- 0
openstack_dashboard/dashboards/project/instances/urls.py View File

@@ -34,6 +34,7 @@ urlpatterns = [
34 34
     url(INSTANCES % 'serial', views.SerialConsoleView.as_view(),
35 35
         name='serial'),
36 36
     url(INSTANCES % 'console', views.console, name='console'),
37
+    url(INSTANCES % 'auto_console', views.auto_console, name='auto_console'),
37 38
     url(INSTANCES % 'vnc', views.vnc, name='vnc'),
38 39
     url(INSTANCES % 'spice', views.spice, name='spice'),
39 40
     url(INSTANCES % 'rdp', views.rdp, name='rdp'),

+ 13
- 0
openstack_dashboard/dashboards/project/instances/views.py View File

@@ -198,6 +198,19 @@ def console(request, instance_id):
198 198
     return http.HttpResponse(data.encode('utf-8'), content_type='text/plain')
199 199
 
200 200
 
201
+def auto_console(request, instance_id):
202
+    console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO')
203
+    try:
204
+        instance = api.nova.server_get(request, instance_id)
205
+        console_url = project_console.get_console(request, console_type,
206
+                                                  instance)[1]
207
+        return shortcuts.redirect(console_url)
208
+    except Exception:
209
+        redirect = reverse("horizon:project:instances:index")
210
+        msg = _('Unable to get console for instance "%s".') % instance_id
211
+        exceptions.handle(request, msg, redirect=redirect)
212
+
213
+
201 214
 def vnc(request, instance_id):
202 215
     try:
203 216
         instance = api.nova.server_get(request, instance_id)

+ 14
- 19
openstack_dashboard/dashboards/project/network_topology/tests.py View File

@@ -20,7 +20,6 @@ from mox3.mox import IsA
20 20
 from oslo_serialization import jsonutils
21 21
 
22 22
 from openstack_dashboard import api
23
-from openstack_dashboard.dashboards.project.instances import console
24 23
 from openstack_dashboard.dashboards.project.network_topology.views import \
25 24
     TranslationHelper
26 25
 from openstack_dashboard.test import helpers as test
@@ -37,8 +36,7 @@ class NetworkTopologyTests(test.TestCase):
37 36
                         api.neutron: ('network_list_for_tenant',
38 37
                                       'network_list',
39 38
                                       'router_list',
40
-                                      'port_list',),
41
-                        console: ('get_console',)})
39
+                                      'port_list')})
42 40
     def test_json_view(self):
43 41
         self._test_json_view()
44 42
 
@@ -46,12 +44,20 @@ class NetworkTopologyTests(test.TestCase):
46 44
         OPENSTACK_NEUTRON_NETWORK={'enable_router': False})
47 45
     @test.create_stubs({api.nova: ('server_list',),
48 46
                         api.neutron: ('network_list_for_tenant',
49
-                                      'port_list'),
50
-                        console: ('get_console',)})
47
+                                      'port_list')})
51 48
     def test_json_view_router_disabled(self):
52 49
         self._test_json_view(router_enable=False)
53 50
 
54
-    def _test_json_view(self, router_enable=True):
51
+    @django.test.utils.override_settings(CONSOLE_TYPE=None)
52
+    @test.create_stubs({api.nova: ('server_list',),
53
+                        api.neutron: ('network_list_for_tenant',
54
+                                      'network_list',
55
+                                      'router_list',
56
+                                      'port_list')})
57
+    def test_json_view_console_disabled(self):
58
+        self._test_json_view(with_console=False)
59
+
60
+    def _test_json_view(self, router_enable=True, with_console=True):
55 61
         api.nova.server_list(
56 62
             IsA(http.HttpRequest)).AndReturn([self.servers.list(), False])
57 63
 
@@ -63,17 +69,6 @@ class NetworkTopologyTests(test.TestCase):
63 69
             IsA(http.HttpRequest),
64 70
             self.tenant.id).AndReturn(tenant_networks)
65 71
 
66
-        for server in self.servers.list():
67
-            if server.status != u'BUILD':
68
-                CONSOLE_OUTPUT = '/vncserver'
69
-                CONSOLE_TITLE = '&title=%s' % server.id
70
-                CONSOLE_URL = CONSOLE_OUTPUT + CONSOLE_TITLE
71
-
72
-                console_mock = self.mox.CreateMock(api.nova.VNCConsole)
73
-                console_mock.url = CONSOLE_OUTPUT
74
-                console.get_console(IsA(http.HttpRequest), 'AUTO', server) \
75
-                    .AndReturn(('VNC', CONSOLE_URL))
76
-
77 72
         # router1 : gateway port not in the port list
78 73
         # router2 : no gateway port
79 74
         # router3 : gateway port included in port list
@@ -109,8 +104,8 @@ class NetworkTopologyTests(test.TestCase):
109 104
                 'task': None,
110 105
                 'url': '/project/instances/%s/' % server.id
111 106
             }
112
-            if server.status != 'BUILD':
113
-                expect_server['console'] = 'vnc'
107
+            if server.status != 'BUILD' and with_console:
108
+                expect_server['console'] = 'auto_console'
114 109
             expect_server_urls.append(expect_server)
115 110
         self.assertEqual(expect_server_urls, data['servers'])
116 111
 

+ 2
- 8
openstack_dashboard/dashboards/project/network_topology/views.py View File

@@ -45,8 +45,6 @@ from openstack_dashboard.dashboards.project.network_topology \
45 45
     import tabs as topology_tabs
46 46
 from openstack_dashboard.dashboards.project.network_topology import utils
47 47
 
48
-from openstack_dashboard.dashboards.project.instances import\
49
-    console as i_console
50 48
 from openstack_dashboard.dashboards.project.instances.tables import \
51 49
     STATUS_DISPLAY_CHOICES as instance_choices
52 50
 from openstack_dashboard.dashboards.project.instances import\
@@ -251,12 +249,8 @@ class JSONView(View):
251 249
             # Avoid doing extra calls for console if the server is in
252 250
             # a invalid status for console connection
253 251
             if server.status.lower() not in console_invalid_status:
254
-                try:
255
-                    console = i_console.get_console(
256
-                        request, console_type, server)[0].lower()
257
-                    server_data['console'] = console
258
-                except exceptions.NotAvailable:
259
-                    pass
252
+                if console_type:
253
+                    server_data['console'] = 'auto_console'
260 254
 
261 255
             data.append(server_data)
262 256
         self.add_resource_url('horizon:project:instances:detail', data)

Loading…
Cancel
Save