Browse Source

Merge "Add support for both soft and hard reboot options"

Jenkins 6 years ago
parent
commit
7d13abc477

+ 1
- 1
openstack_dashboard/api/nova.py View File

@@ -30,7 +30,7 @@ from django.utils.translation import ugettext as _
30 30
 from novaclient.v1_1 import client as nova_client
31 31
 from novaclient.v1_1 import security_group_rules as nova_rules
32 32
 from novaclient.v1_1.security_groups import SecurityGroup as NovaSecurityGroup
33
-from novaclient.v1_1.servers import REBOOT_HARD
33
+from novaclient.v1_1.servers import REBOOT_HARD, REBOOT_SOFT
34 34
 
35 35
 from horizon.conf import HORIZON_CONFIG
36 36
 from horizon.utils.memoized import memoized

+ 5
- 5
openstack_dashboard/dashboards/admin/instances/tables.py View File

@@ -26,9 +26,9 @@ from horizon.utils.filters import replace_underscores
26 26
 from openstack_dashboard import api
27 27
 from openstack_dashboard.dashboards.project.instances.tables import (
28 28
         TerminateInstance, EditInstance, ConsoleLink, LogLink, CreateSnapshot,
29
-        TogglePause, ToggleSuspend, RebootInstance, ConfirmResize,
30
-        RevertResize, get_size, UpdateRow, get_ips, get_power_state,
31
-        is_deleting, ACTIVE_STATES, STATUS_DISPLAY_CHOICES,
29
+        TogglePause, ToggleSuspend, RebootInstance, SoftRebootInstance,
30
+        ConfirmResize, RevertResize, get_size, UpdateRow, get_ips,
31
+        get_power_state, is_deleting, ACTIVE_STATES, STATUS_DISPLAY_CHOICES,
32 32
         TASK_DISPLAY_CHOICES)
33 33
 
34 34
 LOG = logging.getLogger(__name__)
@@ -118,5 +118,5 @@ class AdminInstancesTable(tables.DataTable):
118 118
         row_class = AdminUpdateRow
119 119
         row_actions = (ConfirmResize, RevertResize, AdminEditInstance,
120 120
                        ConsoleLink, LogLink, CreateSnapshot, TogglePause,
121
-                       ToggleSuspend, MigrateInstance, RebootInstance,
122
-                       TerminateInstance)
121
+                       ToggleSuspend, MigrateInstance, SoftRebootInstance,
122
+                       RebootInstance, TerminateInstance)

+ 14
- 5
openstack_dashboard/dashboards/project/instances/tables.py View File

@@ -88,8 +88,8 @@ class TerminateInstance(tables.BatchAction):
88 88
 
89 89
 class RebootInstance(tables.BatchAction):
90 90
     name = "reboot"
91
-    action_present = _("Reboot")
92
-    action_past = _("Rebooted")
91
+    action_present = _("Hard Reboot")
92
+    action_past = _("Hard Rebooted")
93 93
     data_type_singular = _("Instance")
94 94
     data_type_plural = _("Instances")
95 95
     classes = ('btn-danger', 'btn-reboot')
@@ -100,7 +100,16 @@ class RebootInstance(tables.BatchAction):
100 100
                 and not is_deleting(instance))
101 101
 
102 102
     def action(self, request, obj_id):
103
-        api.nova.server_reboot(request, obj_id)
103
+        api.nova.server_reboot(request, obj_id, api.nova.REBOOT_HARD)
104
+
105
+
106
+class SoftRebootInstance(RebootInstance):
107
+    name = "soft_reboot"
108
+    action_present = _("Soft Reboot")
109
+    action_past = _("Soft Rebooted")
110
+
111
+    def action(self, request, obj_id):
112
+        api.nova.server_reboot(request, obj_id, api.nova.REBOOT_SOFT)
104 113
 
105 114
 
106 115
 class TogglePause(tables.BatchAction):
@@ -471,5 +480,5 @@ class InstancesTable(tables.DataTable):
471 480
                        SimpleAssociateIP, AssociateIP,
472 481
                        SimpleDisassociateIP, EditInstance,
473 482
                        EditInstanceSecurityGroups, ConsoleLink, LogLink,
474
-                       TogglePause, ToggleSuspend, RebootInstance,
475
-                       TerminateInstance)
483
+                       TogglePause, ToggleSuspend, SoftRebootInstance,
484
+                       RebootInstance, TerminateInstance)

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

@@ -262,7 +262,8 @@ class InstanceTests(test.TestCase):
262 262
             .AndReturn(self.flavors.list())
263 263
         api.nova.server_list(IsA(http.HttpRequest)) \
264 264
             .AndReturn(self.servers.list())
265
-        api.nova.server_reboot(IsA(http.HttpRequest), server.id)
265
+        api.nova.server_reboot(IsA(http.HttpRequest), server.id,
266
+                               api.nova.REBOOT_HARD)
266 267
 
267 268
         self.mox.ReplayAll()
268 269
 
@@ -281,7 +282,8 @@ class InstanceTests(test.TestCase):
281 282
             .AndReturn(self.flavors.list())
282 283
         api.nova.server_list(IsA(http.HttpRequest)) \
283 284
             .AndReturn(self.servers.list())
284
-        api.nova.server_reboot(IsA(http.HttpRequest), server.id) \
285
+        api.nova.server_reboot(IsA(http.HttpRequest), server.id,
286
+                               api.nova.REBOOT_HARD) \
285 287
             .AndRaise(self.exceptions.nova)
286 288
 
287 289
         self.mox.ReplayAll()
@@ -291,6 +293,26 @@ class InstanceTests(test.TestCase):
291 293
 
292 294
         self.assertRedirectsNoFollow(res, INDEX_URL)
293 295
 
296
+    @test.create_stubs({api.nova: ('server_reboot',
297
+                                   'server_list',
298
+                                   'flavor_list',)})
299
+    def test_soft_reboot_instance(self):
300
+        server = self.servers.first()
301
+
302
+        api.nova.flavor_list(IsA(http.HttpRequest)) \
303
+            .AndReturn(self.flavors.list())
304
+        api.nova.server_list(IsA(http.HttpRequest)) \
305
+            .AndReturn(self.servers.list())
306
+        api.nova.server_reboot(IsA(http.HttpRequest), server.id,
307
+                               api.nova.REBOOT_SOFT)
308
+
309
+        self.mox.ReplayAll()
310
+
311
+        formData = {'action': 'instances__soft_reboot__%s' % server.id}
312
+        res = self.client.post(INDEX_URL, formData)
313
+
314
+        self.assertRedirectsNoFollow(res, INDEX_URL)
315
+
294 316
     @test.create_stubs({api.nova: ('server_suspend',
295 317
                                    'server_list',
296 318
                                    'flavor_list',)})

+ 13
- 0
openstack_dashboard/test/api_tests/nova_tests.py View File

@@ -59,6 +59,19 @@ class ComputeApiTests(test.APITestCase):
59 59
         ret_val = api.nova.server_reboot(self.request, server.id)
60 60
         self.assertIsNone(ret_val)
61 61
 
62
+    def test_server_soft_reboot(self):
63
+        server = self.servers.first()
64
+        HARDNESS = servers.REBOOT_SOFT
65
+
66
+        novaclient = self.stub_novaclient()
67
+        novaclient.servers = self.mox.CreateMockAnything()
68
+        novaclient.servers.get(server.id).AndReturn(server)
69
+        novaclient.servers.reboot(server.id, HARDNESS)
70
+        self.mox.ReplayAll()
71
+
72
+        ret_val = api.nova.server_reboot(self.request, server.id, HARDNESS)
73
+        self.assertIsNone(ret_val)
74
+
62 75
     def test_server_vnc_console(self):
63 76
         server = self.servers.first()
64 77
         console = self.servers.vnc_console_data

Loading…
Cancel
Save