18
18
19
19
from nova .api .openstack .compute import admin_actions \
20
20
as admin_actions_v21
21
+ from nova .compute import instance_actions
21
22
from nova .compute import vm_states
22
23
from nova import exception
23
24
from nova import objects
@@ -59,18 +60,27 @@ def _check_instance_state(self, expected):
59
60
def _get_request (self ):
60
61
return fakes .HTTPRequest .blank ('' )
61
62
63
+ @mock .patch (
64
+ 'nova.objects.instance_action.InstanceAction.action_start' ,
65
+ new = mock .Mock (spec = objects .InstanceAction ))
62
66
def test_no_state (self ):
63
67
self .assertRaises (self .bad_request ,
64
68
self .admin_api ._reset_state ,
65
69
self .request , self .uuid ,
66
70
body = {"os-resetState" : None })
67
71
72
+ @mock .patch (
73
+ 'nova.objects.instance_action.InstanceAction.action_start' ,
74
+ new = mock .Mock (spec = objects .InstanceAction ))
68
75
def test_bad_state (self ):
69
76
self .assertRaises (self .bad_request ,
70
77
self .admin_api ._reset_state ,
71
78
self .request , self .uuid ,
72
79
body = {"os-resetState" : {"state" : "spam" }})
73
80
81
+ @mock .patch (
82
+ 'nova.objects.instance_action.InstanceAction.action_start' ,
83
+ new = mock .Mock (spec = objects .InstanceAction ))
74
84
def test_no_instance (self ):
75
85
self .compute_api .get = mock .MagicMock (
76
86
side_effect = exception .InstanceNotFound (instance_id = 'inst_ud' ))
@@ -84,11 +94,14 @@ def test_no_instance(self):
84
94
self .context , self .uuid , expected_attrs = None ,
85
95
cell_down_support = False )
86
96
87
- def test_reset_active (self ):
97
+ @mock .patch ('nova.objects.instance_action.InstanceAction.action_start' )
98
+ def test_reset_active (self , mock_instance_action_start ):
88
99
expected = dict (vm_state = vm_states .ACTIVE , task_state = None )
89
100
self .instance .save = mock .MagicMock (
90
101
side_effect = lambda ** kw : self ._check_instance_state (expected ))
91
102
self .compute_api .get = mock .MagicMock (return_value = self .instance )
103
+ mock_instance_action = mock .Mock (spec = objects .InstanceAction )
104
+ mock_instance_action_start .return_value = mock_instance_action
92
105
93
106
body = {"os-resetState" : {"state" : "active" }}
94
107
result = self .admin_api ._reset_state (self .request , self .uuid ,
@@ -107,11 +120,18 @@ def test_reset_active(self):
107
120
cell_down_support = False )
108
121
self .instance .save .assert_called_once_with (admin_state_reset = True )
109
122
110
- def test_reset_error (self ):
123
+ mock_instance_action_start .assert_called_once_with (
124
+ self .context , self .instance .uuid , instance_actions .RESET_STATE )
125
+ mock_instance_action .finish .assert_called_once ()
126
+
127
+ @mock .patch ('nova.objects.instance_action.InstanceAction.action_start' )
128
+ def test_reset_error (self , mock_instance_action_start ):
111
129
expected = dict (vm_state = vm_states .ERROR , task_state = None )
112
130
self .instance .save = mock .MagicMock (
113
131
side_effect = lambda ** kw : self ._check_instance_state (expected ))
114
132
self .compute_api .get = mock .MagicMock (return_value = self .instance )
133
+ mock_instance_action = mock .Mock (spec = objects .InstanceAction )
134
+ mock_instance_action_start .return_value = mock_instance_action
115
135
116
136
body = {"os-resetState" : {"state" : "error" }}
117
137
result = self .admin_api ._reset_state (self .request , self .uuid ,
@@ -129,3 +149,7 @@ def test_reset_error(self):
129
149
self .context , self .instance .uuid , expected_attrs = None ,
130
150
cell_down_support = False )
131
151
self .instance .save .assert_called_once_with (admin_state_reset = True )
152
+
153
+ mock_instance_action_start .assert_called_once_with (
154
+ self .context , self .instance .uuid , instance_actions .RESET_STATE )
155
+ mock_instance_action .finish .assert_called_once ()
0 commit comments