def test_node_delete2_have_dependency(self, mock_find): dependents = {'nodes': ['NODE1']} node = mock.Mock(id='NODE_ID', status='ACTIVE', dependents=dependents) mock_find.return_value = node req = orno.NodeDeleteRequest(identity='node1') ex = self.assertRaises(rpc.ExpectedException, self.eng.node_delete2, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceInUse, ex.exc_info[0]) self.assertEqual( "The node node1 cannot be deleted: still depended " "by other clusters and/or nodes.", six.text_type(ex.exc_info[1]))
def test_node_delete2_node_not_found(self, mock_find): mock_find.side_effect = exc.ResourceNotFound(type='node', id='Bogus') req = orno.NodeDeleteRequest(identity='Bogus') ex = self.assertRaises(rpc.ExpectedException, self.eng.node_delete2, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0]) self.assertEqual('The node (Bogus) could not be found.', six.text_type(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'Bogus')
def test_node_delete_improper_status(self, mock_find): for bad_status in [consts.NS_CREATING, consts.NS_UPDATING, consts.NS_DELETING, consts.NS_RECOVERING]: fake_node = mock.Mock(id='12345678AB', status=bad_status) mock_find.return_value = fake_node req = orno.NodeDeleteRequest(identity='BUSY', force=False) ex = self.assertRaises(rpc.ExpectedException, self.eng.node_delete, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ActionInProgress, ex.exc_info[0]) self.assertEqual("The node 'BUSY' is in status %s." % bad_status, six.text_type(ex.exc_info[1]))
def test_node_delete(self, mock_find, mock_action, mock_start): mock_find.return_value = mock.Mock(id='12345678AB', status='ACTIVE', dependents={}) mock_action.return_value = 'ACTION_ID' req = orno.NodeDeleteRequest(identity='FAKE_NODE', force=False) result = self.eng.node_delete(self.ctx, req.obj_to_primitive()) self.assertEqual({'action': 'ACTION_ID'}, result) mock_find.assert_called_once_with(self.ctx, 'FAKE_NODE') mock_action.assert_called_once_with( self.ctx, '12345678AB', consts.NODE_DELETE, name='node_delete_12345678', cause=consts.CAUSE_RPC, status=action_mod.Action.READY) mock_start.assert_called_once_with()
def test_node_delete_request(self): sot = nodes.NodeDeleteRequest(**self.body) self.assertEqual('test-node', sot.identity)