Handle traceback when Node is locked

When node is locked, any attempt to delete this node, is finished
with traceback. Add handling of exceptions to prevent this
situation.

Change-Id: Ie7b8c2c6575a104817c51016a8515b5533e4ca98
Closes-Bug: 1437236
This commit is contained in:
Dariusz Smigiel (dasm) 2015-04-04 15:49:18 +02:00
parent 46df327c22
commit 5f236273ec
2 changed files with 32 additions and 1 deletions

View File

@ -11,9 +11,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from ironicclient import exceptions as ironic_exceptions
from openstack_dashboard import exceptions
from tuskarclient.openstack.common.apiclient import exceptions as tuskarclient
NOT_FOUND = exceptions.NOT_FOUND
RECOVERABLE = exceptions.RECOVERABLE + (tuskarclient.ClientException,)
RECOVERABLE = exceptions.RECOVERABLE + (
ironic_exceptions.Conflict, tuskarclient.ClientException,
)
UNAUTHORIZED = exceptions.UNAUTHORIZED

View File

@ -18,6 +18,7 @@ import json
from ceilometerclient.v2 import client as ceilometer_client
from django.core import urlresolvers
from horizon import exceptions as horizon_exceptions
from ironicclient import exceptions as ironic_exceptions
import mock
from novaclient import exceptions as nova_exceptions
from openstack_dashboard.test.test_data import utils
@ -54,6 +55,9 @@ class NodesTests(test.BaseAdminViewTests):
def _raise_horizon_exception_not_found(self, request, *args, **kwargs):
raise horizon_exceptions.NotFound
def _raise_ironic_exception(self, request, *args, **kwargs):
raise ironic_exceptions.Conflict
def stub_ceilometerclient(self):
if not hasattr(self, "ceilometerclient"):
self.mox.StubOutWithMock(ceilometer_client, 'Client')
@ -556,3 +560,27 @@ class NodesTests(test.BaseAdminViewTests):
deployment_ramdisk='8',
),
])
def test_delete_deployed_on_servers(self):
all_nodes = [api.node.Node(node)
for node in self.ironicclient_nodes.list()]
node = all_nodes[6]
data = {'action': 'all_nodes_table__delete',
'object_ids': [node.uuid]}
with contextlib.nested(
mock.patch('tuskar_ui.api.node.Node', **{
'spec_set': [
'list',
'delete',
],
'list.return_value': [node],
'delete.side_effect': self._raise_ironic_exception,
}),
mock.patch('openstack_dashboard.api.nova.server_list',
return_value=([], False)),
):
res = self.client.post(INDEX_URL, data)
self.assertMessageCount(error=1, warning=0)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)