1818
1919from nova .api .openstack .compute import admin_actions \
2020 as admin_actions_v21
21+ from nova .compute import instance_actions
2122from nova .compute import vm_states
2223from nova import exception
2324from nova import objects
@@ -59,18 +60,27 @@ def _check_instance_state(self, expected):
5960 def _get_request (self ):
6061 return fakes .HTTPRequest .blank ('' )
6162
63+ @mock .patch (
64+ 'nova.objects.instance_action.InstanceAction.action_start' ,
65+ new = mock .Mock (spec = objects .InstanceAction ))
6266 def test_no_state (self ):
6367 self .assertRaises (self .bad_request ,
6468 self .admin_api ._reset_state ,
6569 self .request , self .uuid ,
6670 body = {"os-resetState" : None })
6771
72+ @mock .patch (
73+ 'nova.objects.instance_action.InstanceAction.action_start' ,
74+ new = mock .Mock (spec = objects .InstanceAction ))
6875 def test_bad_state (self ):
6976 self .assertRaises (self .bad_request ,
7077 self .admin_api ._reset_state ,
7178 self .request , self .uuid ,
7279 body = {"os-resetState" : {"state" : "spam" }})
7380
81+ @mock .patch (
82+ 'nova.objects.instance_action.InstanceAction.action_start' ,
83+ new = mock .Mock (spec = objects .InstanceAction ))
7484 def test_no_instance (self ):
7585 self .compute_api .get = mock .MagicMock (
7686 side_effect = exception .InstanceNotFound (instance_id = 'inst_ud' ))
@@ -84,11 +94,14 @@ def test_no_instance(self):
8494 self .context , self .uuid , expected_attrs = None ,
8595 cell_down_support = False )
8696
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 ):
8899 expected = dict (vm_state = vm_states .ACTIVE , task_state = None )
89100 self .instance .save = mock .MagicMock (
90101 side_effect = lambda ** kw : self ._check_instance_state (expected ))
91102 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
92105
93106 body = {"os-resetState" : {"state" : "active" }}
94107 result = self .admin_api ._reset_state (self .request , self .uuid ,
@@ -107,11 +120,18 @@ def test_reset_active(self):
107120 cell_down_support = False )
108121 self .instance .save .assert_called_once_with (admin_state_reset = True )
109122
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 ):
111129 expected = dict (vm_state = vm_states .ERROR , task_state = None )
112130 self .instance .save = mock .MagicMock (
113131 side_effect = lambda ** kw : self ._check_instance_state (expected ))
114132 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
115135
116136 body = {"os-resetState" : {"state" : "error" }}
117137 result = self .admin_api ._reset_state (self .request , self .uuid ,
@@ -129,3 +149,7 @@ def test_reset_error(self):
129149 self .context , self .instance .uuid , expected_attrs = None ,
130150 cell_down_support = False )
131151 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