raise exception when create container with invalid bay status
raise exception when create container with invalid bay status instead of just print out the error message. Added unit test for create container with invalid bay status. Change-Id: I821a9b1e814c45a4f197579740794fdb48285e68
This commit is contained in:
parent
c915e5425b
commit
70dea1147c
@ -14,6 +14,7 @@
|
||||
|
||||
import mock
|
||||
|
||||
from magnumclient import exceptions
|
||||
from magnumclient.tests.v1 import shell_test_base
|
||||
|
||||
|
||||
@ -58,6 +59,20 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
self._mandatory_arg_error)
|
||||
self.assertFalse(mock_create.called)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
@mock.patch('magnumclient.v1.containers.ContainerManager.create')
|
||||
def test_container_create_failure_invalid_bay_status(self, mock_create,
|
||||
mock_bay_get):
|
||||
mock_bay = mock.MagicMock()
|
||||
mock_bay.status = "CREATE_IN_PROGRESS"
|
||||
mock_bay_get.return_value = mock_bay
|
||||
self.assertRaises(exceptions.InvalidAttribute, self._test_arg_failure,
|
||||
'container-create '
|
||||
'--image test-image '
|
||||
'--bay test-bay',
|
||||
self._bay_status_error)
|
||||
self.assertFalse(mock_create.called)
|
||||
|
||||
@mock.patch('magnumclient.v1.containers.ContainerManager.delete')
|
||||
def test_container_delete_success(self, mock_delete):
|
||||
self._test_arg_success('container-delete xxx')
|
||||
|
@ -15,6 +15,7 @@
|
||||
import json
|
||||
|
||||
from magnumclient.common import utils as magnum_utils
|
||||
from magnumclient import exceptions
|
||||
from magnumclient.openstack.common import cliutils as utils
|
||||
|
||||
|
||||
@ -43,10 +44,12 @@ def _show_container(container):
|
||||
def do_container_create(cs, args):
|
||||
"""Create a container."""
|
||||
bay = cs.bays.get(args.bay)
|
||||
if bay.status not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']:
|
||||
print('Bay status for %s is: %s. We can not create a %s there'
|
||||
' until the status is CREATE_COMPLETE or UPDATE_COMPLETE.' %
|
||||
(bay.uuid, bay.status, "container"))
|
||||
if bay.status not in ['CREATE_COMPLETE',
|
||||
'UPDATE_IN_PROGRESS', 'UPDATE_COMPLETE']:
|
||||
raise exceptions.InvalidAttribute(
|
||||
'Bay status for %s is: %s. We cannot create a %s'
|
||||
' unless the status is CREATE_COMPLETE, UPDATE_IN_PROGRESS'
|
||||
' or UPDATE_COMPLETE.' % (bay.uuid, bay.status, "container"))
|
||||
return
|
||||
opts = {}
|
||||
opts['name'] = args.name
|
||||
|
Loading…
Reference in New Issue
Block a user