Merge "Replace HTTP 'magic numbers' with constants"

This commit is contained in:
Jenkins 2015-08-21 12:32:58 +00:00 committed by Gerrit Code Review
commit da8f9c8529
17 changed files with 270 additions and 248 deletions

View File

@ -17,6 +17,7 @@ import datetime
import pecan
from pecan import rest
from six.moves import http_client
import wsme
from wsme import types as wtypes
@ -236,7 +237,7 @@ class ChassisController(rest.RestController):
chassis_uuid)
return Chassis.convert_with_links(rpc_chassis, fields=fields)
@expose.expose(Chassis, body=Chassis, status_code=201)
@expose.expose(Chassis, body=Chassis, status_code=http_client.CREATED)
def post(self, chassis):
"""Create a new chassis.
@ -281,7 +282,7 @@ class ChassisController(rest.RestController):
rpc_chassis.save()
return Chassis.convert_with_links(rpc_chassis)
@expose.expose(None, types.uuid, status_code=204)
@expose.expose(None, types.uuid, status_code=http_client.NO_CONTENT)
def delete(self, chassis_uuid):
"""Delete a chassis.

View File

@ -22,6 +22,7 @@ from oslo_utils import strutils
from oslo_utils import uuidutils
import pecan
from pecan import rest
from six.moves import http_client
import wsme
from wsme import types as wtypes
@ -144,7 +145,7 @@ class BootDeviceController(rest.RestController):
rpc_node.uuid, topic)
@expose.expose(None, types.uuid_or_name, wtypes.text, types.boolean,
status_code=204)
status_code=http_client.NO_CONTENT)
def put(self, node_ident, boot_device, persistent=False):
"""Set the boot device for a node.
@ -237,7 +238,7 @@ class NodeConsoleController(rest.RestController):
return ConsoleInfo(console_enabled=console_state, console_info=console)
@expose.expose(None, types.uuid_or_name, types.boolean,
status_code=202)
status_code=http_client.ACCEPTED)
def put(self, node_ident, enabled):
"""Start and stop the node console.
@ -326,7 +327,7 @@ class NodeStatesController(rest.RestController):
return NodeStates.convert(rpc_node)
@expose.expose(None, types.uuid_or_name, wtypes.text,
status_code=202)
status_code=http_client.ACCEPTED)
def power(self, node_ident, target):
"""Set the power state of the node.
@ -365,7 +366,7 @@ class NodeStatesController(rest.RestController):
pecan.response.location = link.build_url('nodes', url_args)
@expose.expose(None, types.uuid_or_name, wtypes.text,
wtypes.text, status_code=202)
wtypes.text, status_code=http_client.ACCEPTED)
def provision(self, node_ident, target, configdrive=None):
"""Asynchronous trigger the provisioning of the node.
@ -419,7 +420,8 @@ class NodeStatesController(rest.RestController):
if configdrive and target != ir_states.ACTIVE:
msg = (_('Adding a config drive is only supported when setting '
'provision state to %s') % ir_states.ACTIVE)
raise wsme.exc.ClientSideError(msg, status_code=400)
raise wsme.exc.ClientSideError(
msg, status_code=http_client.BAD_REQUEST)
# Note that there is a race condition. The node state(s) could change
# by the time the RPC call is made and the TaskManager manager gets a
@ -476,7 +478,7 @@ class Node(base.APIBase):
except exception.ChassisNotFound as e:
# Change error code because 404 (NotFound) is inappropriate
# response for a POST request to create a Port
e.code = 400 # BadRequest
e.code = http_client.BAD_REQUEST # BadRequest
raise e
elif value == wtypes.Unset:
self._chassis_uuid = wtypes.Unset
@ -743,13 +745,13 @@ class NodeMaintenanceController(rest.RestController):
try:
topic = pecan.request.rpcapi.get_topic_for(rpc_node)
except exception.NoValidHost as e:
e.code = 400
e.code = http_client.BAD_REQUEST
raise e
pecan.request.rpcapi.update_node(pecan.request.context,
rpc_node, topic=topic)
@expose.expose(None, types.uuid_or_name, wtypes.text,
status_code=202)
status_code=http_client.ACCEPTED)
def put(self, node_ident, reason=None):
"""Put the node in maintenance mode.
@ -759,7 +761,7 @@ class NodeMaintenanceController(rest.RestController):
"""
self._set_maintenance(node_ident, True, reason=reason)
@expose.expose(None, types.uuid_or_name, status_code=202)
@expose.expose(None, types.uuid_or_name, status_code=http_client.ACCEPTED)
def delete(self, node_ident):
"""Remove the node from maintenance mode.
@ -879,7 +881,8 @@ class NodesController(rest.RestController):
if not api_utils.allow_node_logical_names():
raise exception.NotAcceptable()
if not api_utils.is_valid_node_name(name):
raise wsme.exc.ClientSideError(error_msg, status_code=400)
raise wsme.exc.ClientSideError(
error_msg, status_code=http_client.BAD_REQUEST)
def _update_changed_fields(self, node, rpc_node):
"""Update rpc_node based on changed fields in a node.
@ -911,7 +914,7 @@ class NodesController(rest.RestController):
raise wsme.exc.ClientSideError(
_("Node %s can not update the driver while the console is "
"enabled. Please stop the console first.") % node_ident,
status_code=409)
status_code=http_client.CONFLICT)
@expose.expose(NodeCollection, types.uuid, types.uuid, types.boolean,
types.boolean, wtypes.text, types.uuid, int, wtypes.text,
@ -1027,7 +1030,7 @@ class NodesController(rest.RestController):
rpc_node = api_utils.get_rpc_node(node_ident)
return Node.convert_with_links(rpc_node, fields=fields)
@expose.expose(Node, body=Node, status_code=201)
@expose.expose(Node, body=Node, status_code=http_client.CREATED)
def post(self, node):
"""Create a new node.
@ -1049,7 +1052,7 @@ class NodesController(rest.RestController):
# NOTE(deva): convert from 404 to 400 because client can see
# list of available drivers and shouldn't request
# one that doesn't exist.
e.code = 400
e.code = http_client.BAD_REQUEST
raise e
error_msg = _("Cannot create node with invalid name "
@ -1098,7 +1101,8 @@ class NodesController(rest.RestController):
not in ir_states.UPDATE_ALLOWED_STATES):
msg = _("Node %s can not be updated while a state transition "
"is in progress.")
raise wsme.exc.ClientSideError(msg % node_ident, status_code=409)
raise wsme.exc.ClientSideError(
msg % node_ident, status_code=http_client.CONFLICT)
name = api_utils.get_patch_value(patch, '/name')
error_msg = _("Node %(node)s: Cannot change name to invalid "
@ -1125,7 +1129,7 @@ class NodesController(rest.RestController):
# NOTE(deva): convert from 404 to 400 because client can see
# list of available drivers and shouldn't request
# one that doesn't exist.
e.code = 400
e.code = http_client.BAD_REQUEST
raise e
self._check_driver_changed_and_console_enabled(rpc_node, node_ident)
new_node = pecan.request.rpcapi.update_node(
@ -1133,7 +1137,8 @@ class NodesController(rest.RestController):
return Node.convert_with_links(new_node)
@expose.expose(None, types.uuid_or_name, status_code=204)
@expose.expose(None, types.uuid_or_name,
status_code=http_client.NO_CONTENT)
def delete(self, node_ident):
"""Delete a node.
@ -1147,7 +1152,7 @@ class NodesController(rest.RestController):
try:
topic = pecan.request.rpcapi.get_topic_for(rpc_node)
except exception.NoValidHost as e:
e.code = 400
e.code = http_client.BAD_REQUEST
raise e
pecan.request.rpcapi.destroy_node(pecan.request.context,

View File

@ -18,6 +18,7 @@ import datetime
from oslo_utils import uuidutils
import pecan
from pecan import rest
from six.moves import http_client
import wsme
from wsme import types as wtypes
@ -69,7 +70,7 @@ class Port(base.APIBase):
except exception.NodeNotFound as e:
# Change error code because 404 (NotFound) is inappropriate
# response for a POST request to create a Port
e.code = 400 # BadRequest
e.code = http_client.BAD_REQUEST # BadRequest
raise e
elif value == wtypes.Unset:
self._node_uuid = wtypes.Unset
@ -342,7 +343,7 @@ class PortsController(rest.RestController):
rpc_port = objects.Port.get_by_uuid(pecan.request.context, port_uuid)
return Port.convert_with_links(rpc_port, fields=fields)
@expose.expose(Port, body=Port, status_code=201)
@expose.expose(Port, body=Port, status_code=http_client.CREATED)
def post(self, port):
"""Create a new port.
@ -402,7 +403,7 @@ class PortsController(rest.RestController):
return Port.convert_with_links(new_port)
@expose.expose(None, types.uuid, status_code=204)
@expose.expose(None, types.uuid, status_code=http_client.NO_CONTENT)
def delete(self, port_uuid):
"""Delete a port.

View File

@ -18,6 +18,7 @@ from oslo_config import cfg
from oslo_utils import uuidutils
import pecan
import six
from six.moves import http_client
from webob.static import FileIter
import wsme
@ -150,7 +151,7 @@ def vendor_passthru(ident, method, topic, data=None, driver_passthru=False):
else:
response = pecan.request.rpcapi.vendor_passthru(*params)
status_code = 202 if response['async'] else 200
status_code = http_client.ACCEPTED if response['async'] else http_client.OK
return_value = response['return']
response_params = {'status_code': status_code}

View File

@ -16,6 +16,7 @@
from oslo_config import cfg
from pecan import hooks
from six.moves import http_client
from webob import exc
from ironic.common import context
@ -134,7 +135,8 @@ class NoExceptionTracebackHook(hooks.PecanHook):
return
# Do nothing if there is no error.
if 200 <= state.response.status_int < 400:
if (http_client.OK <= state.response.status_int <
http_client.BAD_REQUEST):
return
json_body = state.response.json

View File

@ -25,6 +25,7 @@ SHOULD include dedicated exception logging.
from oslo_config import cfg
from oslo_log import log as logging
import six
from six.moves import http_client
from ironic.common.i18n import _
from ironic.common.i18n import _LE
@ -59,7 +60,7 @@ class IronicException(Exception):
"""
message = _("An unknown exception occurred.")
code = 500
code = http_client.INTERNAL_SERVER_ERROR
headers = {}
safe = False
@ -107,7 +108,7 @@ class IronicException(Exception):
class NotAuthorized(IronicException):
message = _("Not authorized.")
code = 403
code = http_client.FORBIDDEN
class OperationNotPermitted(NotAuthorized):
@ -116,23 +117,23 @@ class OperationNotPermitted(NotAuthorized):
class Invalid(IronicException):
message = _("Unacceptable parameters.")
code = 400
code = http_client.BAD_REQUEST
class Conflict(IronicException):
message = _('Conflict.')
code = 409
code = http_client.CONFLICT
class TemporaryFailure(IronicException):
message = _("Resource temporarily unavailable, please retry.")
code = 503
code = http_client.SERVICE_UNAVAILABLE
class NotAcceptable(IronicException):
# TODO(deva): We need to set response headers in the API for this exception
message = _("Request not acceptable.")
code = 406
code = http_client.NOT_ACCEPTABLE
class InvalidState(Conflict):
@ -221,7 +222,7 @@ class Duplicate(IronicException):
class NotFound(IronicException):
message = _("Resource could not be found.")
code = 404
code = http_client.NOT_FOUND
class DHCPLoadError(IronicException):
@ -442,7 +443,7 @@ class NodeNotLocked(Invalid):
class NoFreeConductorWorker(TemporaryFailure):
message = _('Requested action cannot be performed due to lack of free '
'conductor workers.')
code = 503 # Service Unavailable (temporary).
code = http_client.SERVICE_UNAVAILABLE # Service Unavailable (temporary).
class VendorPassthruException(IronicException):

View File

@ -26,6 +26,7 @@ from oslo_utils import importutils
import requests
import sendfile
import six
from six.moves import http_client
import six.moves.urllib.parse as urlparse
from ironic.common import exception
@ -140,7 +141,7 @@ class HttpImageService(BaseImageService):
"""
try:
response = requests.head(image_href)
if response.status_code != 200:
if response.status_code != http_client.OK:
raise exception.ImageRefValidationFailed(
image_href=image_href,
reason=_("Got HTTP code %s instead of 200 in response to "
@ -163,7 +164,7 @@ class HttpImageService(BaseImageService):
"""
try:
response = requests.get(image_href, stream=True)
if response.status_code != 200:
if response.status_code != http_client.OK:
raise exception.ImageRefValidationFailed(
image_href=image_href,
reason=_("Got HTTP code %s instead of 200 in response to "

View File

@ -18,6 +18,7 @@ are blocked or allowed to be processed.
import mock
from oslo_config import cfg
from six.moves import http_client
from ironic.tests.api import base
from ironic.tests.api import utils
@ -51,7 +52,7 @@ class TestACL(base.FunctionalTest):
def test_non_authenticated(self):
response = self.get_json(self.node_path, expect_errors=True)
self.assertEqual(401, response.status_int)
self.assertEqual(http_client.UNAUTHORIZED, response.status_int)
def test_authenticated(self):
with mock.patch.object(self.dbapi, 'get_node_by_uuid',
@ -69,7 +70,7 @@ class TestACL(base.FunctionalTest):
headers={'X-Auth-Token': utils.MEMBER_TOKEN},
expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
def test_non_admin_with_admin_header(self):
response = self.get_json(self.node_path,
@ -77,7 +78,7 @@ class TestACL(base.FunctionalTest):
'X-Roles': 'admin'},
expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
def test_public_api(self):
# expect_errors should be set to True: If expect_errors is set to False
@ -86,12 +87,12 @@ class TestACL(base.FunctionalTest):
for route in ('/', '/v1'):
response = self.get_json(route,
path_prefix='', expect_errors=True)
self.assertEqual(200, response.status_int)
self.assertEqual(http_client.OK, response.status_int)
def test_public_api_with_path_extensions(self):
routes = {'/v1/': 200,
'/v1.json': 200,
'/v1.xml': 404}
routes = {'/v1/': http_client.OK,
'/v1.json': http_client.OK,
'/v1.xml': http_client.NOT_FOUND}
for url in routes:
response = self.get_json(url,
path_prefix='', expect_errors=True)

View File

@ -14,6 +14,7 @@
# under the License.
import mock
from six.moves import http_client
from webob import exc
from ironic.api.controllers import base as cbase
@ -29,7 +30,7 @@ class TestBase(base.FunctionalTest):
response = self.get_json('/bad/path',
expect_errors=True,
headers={"Accept": "application/json"})
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertEqual("application/json", response.content_type)
self.assertTrue(response.json['error_message'])

View File

@ -20,6 +20,7 @@ import mock
from oslo_config import cfg
import oslo_messaging as messaging
import six
from six.moves import http_client
from webob import exc as webob_exc
from ironic.api.controllers import root
@ -165,7 +166,7 @@ class TestNoExceptionTracebackHook(base.FunctionalTest):
def test_hook_server_debug_on_clientfault(self):
cfg.CONF.set_override('debug', True)
client_error = Exception(self.MSG_WITH_TRACE)
client_error.code = 400
client_error.code = http_client.BAD_REQUEST
self.root_convert_mock.side_effect = client_error
response = self.get_json('/', path_prefix='', expect_errors=True)

View File

@ -22,6 +22,7 @@ from oslo_config import cfg
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from six.moves import http_client
from six.moves.urllib import parse as urlparse
from wsme import types as wtypes
@ -94,7 +95,7 @@ class TestListChassis(test_api_base.FunctionalTest):
'/chassis/%s?fields=%s' % (chassis.uuid, fields),
headers={api_base.Version.string: str(api_v1.MAX_VER)},
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('spongebob', response.json['error_message'])
@ -105,7 +106,7 @@ class TestListChassis(test_api_base.FunctionalTest):
'/chassis/%s?fields=%s' % (chassis.uuid, fields),
headers={api_base.Version.string: str(api_v1.MIN_VER)},
expect_errors=True)
self.assertEqual(406, response.status_int)
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_int)
def test_detail(self):
chassis = obj_utils.create_test_chassis(self.context)
@ -118,7 +119,7 @@ class TestListChassis(test_api_base.FunctionalTest):
chassis = obj_utils.create_test_chassis(self.context)
response = self.get_json('/chassis/%s/detail' % chassis['uuid'],
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
def test_many(self):
ch_list = []
@ -178,7 +179,7 @@ class TestListChassis(test_api_base.FunctionalTest):
for invalid_key in invalid_keys_list:
response = self.get_json('/chassis?sort_key=%s' % invalid_key,
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn(invalid_key, response.json['error_message'])
@ -206,13 +207,13 @@ class TestListChassis(test_api_base.FunctionalTest):
def test_nodes_subresource_no_uuid(self):
response = self.get_json('/chassis/nodes', expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
def test_nodes_subresource_chassis_not_found(self):
non_existent_uuid = 'eeeeeeee-cccc-aaaa-bbbb-cccccccccccc'
response = self.get_json('/chassis/%s/nodes' % non_existent_uuid,
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
class TestPatch(test_api_base.FunctionalTest):
@ -227,7 +228,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/a', 'value': 'b',
'op': 'add'}],
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -242,7 +243,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/description',
'value': description, 'op': 'replace'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
result = self.get_json('/chassis/%s' % chassis.uuid)
self.assertEqual(description, result['description'])
return_updated_at = timeutils.parse_isotime(
@ -258,7 +259,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/foo2',
'value': new_value, 'op': 'replace'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
result = self.get_json('/chassis/%s' % chassis.uuid)
extra["foo2"] = new_value
@ -270,7 +271,7 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/chassis/%s' % chassis.uuid,
[{'path': '/description', 'op': 'remove'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
result = self.get_json('/chassis/%s' % chassis.uuid)
self.assertIsNone(result['description'])
@ -288,7 +289,7 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/chassis/%s' % chassis.uuid,
[{'path': '/extra/foo2', 'op': 'remove'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
result = self.get_json('/chassis/%s' % chassis.uuid)
extra.pop("foo2")
self.assertEqual(extra, result['extra'])
@ -297,7 +298,7 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/chassis/%s' % chassis.uuid,
[{'path': '/extra', 'op': 'remove'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
result = self.get_json('/chassis/%s' % chassis.uuid)
self.assertEqual({}, result['extra'])
@ -312,7 +313,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_add_root(self):
@ -321,7 +322,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/description', 'value': 'test',
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_int)
self.assertEqual(http_client.OK, response.status_int)
def test_add_root_non_existent(self):
chassis = obj_utils.get_test_chassis(self.context)
@ -330,7 +331,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertTrue(response.json['error_message'])
def test_add_multi(self):
@ -341,7 +342,7 @@ class TestPatch(test_api_base.FunctionalTest):
{'path': '/extra/foo2', 'value': 'bar2',
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
result = self.get_json('/chassis/%s' % chassis.uuid)
expected = {"foo1": "bar1", "foo2": "bar2"}
self.assertEqual(expected, result['extra'])
@ -351,14 +352,14 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/chassis/%s/nodes' % chassis.uuid,
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}], expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
def test_remove_uuid(self):
chassis = obj_utils.get_test_chassis(self.context)
response = self.patch_json('/chassis/%s' % chassis.uuid,
[{'path': '/uuid', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -372,7 +373,7 @@ class TestPost(test_api_base.FunctionalTest):
mock_utcnow.return_value = test_time
response = self.post_json('/chassis', cdict)
self.assertEqual(201, response.status_int)
self.assertEqual(http_client.CREATED, response.status_int)
result = self.get_json('/chassis/%s' % cdict['uuid'])
self.assertEqual(cdict['uuid'], result['uuid'])
self.assertFalse(result['updated_at'])
@ -411,7 +412,7 @@ class TestPost(test_api_base.FunctionalTest):
ndict['chassis_uuid'] = chassis.uuid
response = self.post_json('/chassis/nodes', ndict,
expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
def test_create_chassis_valid_extra(self):
cdict = apiutils.chassis_post_data(extra={'str': 'foo', 'int': 123,
@ -437,7 +438,7 @@ class TestDelete(test_api_base.FunctionalTest):
self.delete('/chassis/%s' % chassis.uuid)
response = self.get_json('/chassis/%s' % chassis.uuid,
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -446,7 +447,7 @@ class TestDelete(test_api_base.FunctionalTest):
obj_utils.create_test_node(self.context, chassis_id=chassis.id)
response = self.delete('/chassis/%s' % chassis.uuid,
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
self.assertIn(chassis.uuid, response.json['error_message'])
@ -454,7 +455,7 @@ class TestDelete(test_api_base.FunctionalTest):
def test_delete_chassis_not_found(self):
uuid = uuidutils.generate_uuid()
response = self.delete('/chassis/%s' % uuid, expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -462,4 +463,4 @@ class TestDelete(test_api_base.FunctionalTest):
chassis = obj_utils.create_test_chassis(self.context)
response = self.delete('/chassis/%s/nodes' % chassis.uuid,
expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)

View File

@ -16,6 +16,7 @@
import json
import mock
from six.moves import http_client
from testtools.matchers import HasLength
from ironic.api.controllers.v1 import driver
@ -71,7 +72,7 @@ class TestListDrivers(base.FunctionalTest):
def test_drivers_get_one_not_found(self):
response = self.get_json('/drivers/%s' % self.d1, expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
@mock.patch.object(rpcapi.ConductorAPI, 'driver_vendor_passthru')
def test_driver_vendor_passthru_sync(self, mocked_driver_vendor_passthru):
@ -83,7 +84,7 @@ class TestListDrivers(base.FunctionalTest):
response = self.post_json(
'/drivers/%s/vendor_passthru/do_test' % self.d1,
{'test_key': 'test_value'})
self.assertEqual(200, response.status_int)
self.assertEqual(http_client.OK, response.status_int)
self.assertEqual(mocked_driver_vendor_passthru.return_value['return'],
response.json)
@ -96,7 +97,7 @@ class TestListDrivers(base.FunctionalTest):
response = self.post_json(
'/drivers/%s/vendor_passthru/do_test' % self.d1,
{'test_key': 'test_value'})
self.assertEqual(202, response.status_int)
self.assertEqual(http_client.ACCEPTED, response.status_int)
self.assertIsNone(mocked_driver_vendor_passthru.return_value['return'])
@mock.patch.object(rpcapi.ConductorAPI, 'driver_vendor_passthru')
@ -107,7 +108,7 @@ class TestListDrivers(base.FunctionalTest):
response = self.put_json(
'/drivers/%s/vendor_passthru/do_test' % self.d1,
{'test_key': 'test_value'})
self.assertEqual(202, response.status_int)
self.assertEqual(http_client.ACCEPTED, response.status_int)
self.assertEqual(return_value['return'], response.json)
@mock.patch.object(rpcapi.ConductorAPI, 'driver_vendor_passthru')
@ -126,7 +127,7 @@ class TestListDrivers(base.FunctionalTest):
mock_driver_vendor_passthru.return_value = return_value
response = self.delete(
'/drivers/%s/vendor_passthru/do_test' % self.d1)
self.assertEqual(202, response.status_int)
self.assertEqual(http_client.ACCEPTED, response.status_int)
self.assertEqual(return_value['return'], response.json)
def test_driver_vendor_passthru_driver_not_found(self):
@ -137,7 +138,7 @@ class TestListDrivers(base.FunctionalTest):
{'test_key': 'test_value'},
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
def test_driver_vendor_passthru_method_not_found(self):
response = self.post_json(
@ -145,7 +146,7 @@ class TestListDrivers(base.FunctionalTest):
{'test_key': 'test_value'},
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
error = json.loads(response.json['error_message'])
self.assertEqual('Missing argument: "method"',
error['faultstring'])
@ -219,7 +220,7 @@ class TestDriverProperties(base.FunctionalTest):
mock_properties.return_value = {'prop1': 'Property 1. Required.'}
ret = self.get_json('/drivers/%s/properties' % driver_name,
expect_errors=True)
self.assertEqual(404, ret.status_int)
self.assertEqual(http_client.NOT_FOUND, ret.status_int)
mock_topic.assert_called_once_with(driver_name)
self.assertFalse(mock_properties.called)
@ -233,7 +234,7 @@ class TestDriverProperties(base.FunctionalTest):
driver_name=driver_name)
ret = self.get_json('/drivers/%s/properties' % driver_name,
expect_errors=True)
self.assertEqual(404, ret.status_int)
self.assertEqual(http_client.NOT_FOUND, ret.status_int)
mock_topic.assert_called_once_with(driver_name)
mock_properties.assert_called_once_with(mock.ANY, driver_name,
topic=mock_topic.return_value)

View File

@ -23,6 +23,7 @@ from oslo_config import cfg
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from six.moves import http_client
from six.moves.urllib import parse as urlparse
from testtools.matchers import HasLength
from wsme import types as wtypes
@ -168,7 +169,7 @@ class TestListNodes(test_api_base.FunctionalTest):
'/nodes/%s?fields=%s' % (node.uuid, fields),
headers={api_base.Version.string: str(api_v1.MAX_VER)},
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('spongebob', response.json['error_message'])
@ -180,7 +181,7 @@ class TestListNodes(test_api_base.FunctionalTest):
'/nodes/%s?fields=%s' % (node.uuid, fields),
headers={api_base.Version.string: str(api_v1.MIN_VER)},
expect_errors=True)
self.assertEqual(406, response.status_int)
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_int)
def test_get_one_custom_fields_show_password(self):
node = obj_utils.create_test_node(self.context,
@ -222,7 +223,7 @@ class TestListNodes(test_api_base.FunctionalTest):
node = obj_utils.create_test_node(self.context)
response = self.get_json('/nodes/%s/detail' % node.uuid,
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
def test_mask_available_state(self):
node = obj_utils.create_test_node(self.context,
@ -370,7 +371,7 @@ class TestListNodes(test_api_base.FunctionalTest):
for invalid_key in invalid_keys_list:
response = self.get_json('/nodes?sort_key=%s' % invalid_key,
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn(invalid_key, response.json['error_message'])
@ -401,13 +402,13 @@ class TestListNodes(test_api_base.FunctionalTest):
obj_utils.create_test_port(self.context, node_id=node.id)
# No node id specified
response = self.get_json('/nodes/ports', expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
def test_ports_subresource_node_not_found(self):
non_existent_uuid = 'eeeeeeee-cccc-aaaa-bbbb-cccccccccccc'
response = self.get_json('/nodes/%s/ports' % non_existent_uuid,
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
@mock.patch.object(timeutils, 'utcnow')
def test_node_states(self, mock_utcnow):
@ -488,7 +489,7 @@ class TestListNodes(test_api_base.FunctionalTest):
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
def test_associated_nodes_insensitive(self):
associated_nodes = (self
@ -507,7 +508,7 @@ class TestListNodes(test_api_base.FunctionalTest):
self._create_association_test_nodes()
response = self.get_json('/nodes?associated=blah', expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_unassociated_nodes_insensitive(self):
@ -596,7 +597,7 @@ class TestListNodes(test_api_base.FunctionalTest):
response = self.get_json('/nodes?associated=true&maintenance=blah',
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_maintenance_nodes_associated(self):
@ -640,7 +641,7 @@ class TestListNodes(test_api_base.FunctionalTest):
headers={api_base.Version.string: "1.9"},
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_get_nodes_by_provision_state_not_allowed(self):
@ -648,7 +649,7 @@ class TestListNodes(test_api_base.FunctionalTest):
headers={api_base.Version.string: "1.8"},
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(406, response.status_code)
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_code)
self.assertTrue(response.json['error_message'])
def test_get_console_information(self):
@ -695,7 +696,7 @@ class TestListNodes(test_api_base.FunctionalTest):
extension='console', driver='test-driver')
ret = self.get_json('/nodes/%s/states/console' % node.uuid,
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
mock_gci.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
@mock.patch.object(rpcapi.ConductorAPI, 'get_boot_device')
@ -724,7 +725,7 @@ class TestListNodes(test_api_base.FunctionalTest):
extension='management', driver='test-driver')
ret = self.get_json('/nodes/%s/management/boot_device' % node.uuid,
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
self.assertTrue(ret.json['error_message'])
mock_gbd.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
@ -756,7 +757,7 @@ class TestListNodes(test_api_base.FunctionalTest):
extension='management', driver='test-driver')
ret = self.get_json('/nodes/%s/management/boot_device/supported' %
node.uuid, expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
self.assertTrue(ret.json['error_message'])
mock_gsbd.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
@ -780,7 +781,7 @@ class TestListNodes(test_api_base.FunctionalTest):
node = obj_utils.create_test_node(self.context, name='spam')
ret = self.get_json('/nodes/validate?node=%s' % node.name,
expect_errors=True)
self.assertEqual(406, ret.status_code)
self.assertEqual(http_client.NOT_ACCEPTABLE, ret.status_code)
self.assertFalse(mock_vdi.called)
@mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces')
@ -826,7 +827,7 @@ class TestPatch(test_api_base.FunctionalTest):
'aaaaaaaa-1111-bbbb-2222-cccccccccccc',
'op': 'replace'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(self.mock_update_node.return_value.updated_at,
timeutils.parse_isotime(response.json['updated_at']))
self.mock_update_node.assert_called_once_with(
@ -844,7 +845,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': 'aaaaaaaa-1111-bbbb-2222-cccccccccccc',
'op': 'replace'}],
expect_errors=True)
self.assertEqual(404, response.status_code)
self.assertEqual(http_client.NOT_FOUND, response.status_code)
self.assertFalse(self.mock_update_node.called)
def test_update_ok_by_name(self):
@ -860,7 +861,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace'}],
headers={api_base.Version.string: "1.5"})
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(self.mock_update_node.return_value.updated_at,
timeutils.parse_isotime(response.json['updated_at']))
self.mock_update_node.assert_called_once_with(
@ -871,7 +872,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'power_state': 'new state'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_update_fails_bad_driver_info(self):
@ -888,7 +889,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -903,7 +904,7 @@ class TestPatch(test_api_base.FunctionalTest):
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
def test_add_ok(self):
self.mock_update_node.return_value = self.node
@ -913,7 +914,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': 'bar',
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -926,7 +927,7 @@ class TestPatch(test_api_base.FunctionalTest):
'aaaaaaaa-1111-bbbb-2222-cccccccccccc',
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -936,7 +937,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_ok(self):
@ -946,7 +947,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra',
'op': 'remove'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -957,7 +958,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_update_allowed_in_power_transition(self):
@ -969,7 +970,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/foo',
'value': 'bar',
'op': 'add'}])
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_update_allowed_in_maintenance(self):
node = obj_utils.create_test_node(self.context,
@ -980,7 +981,7 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/nodes/%s' % node.uuid,
[{'path': '/instance_uuid',
'op': 'remove'}])
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_add_state_in_deployfail(self):
node = obj_utils.create_test_node(self.context,
@ -992,7 +993,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -1000,14 +1001,14 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/nodes/%s/ports' % self.node.uuid,
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}], expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
def test_remove_uuid(self):
response = self.patch_json('/nodes/%s' % self.node.uuid,
[{'path': '/uuid', 'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_instance_uuid_clean_backward_compat(self):
@ -1022,7 +1023,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'op': 'remove',
'path': '/instance_uuid'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
# NOTE(lucasagomes): instance_uuid is already removed as part of
# node's tear down, assert update has not been called. This test
# should be removed in the next cycle (Mitaka).
@ -1039,7 +1040,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}], expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertEqual(http_client.CONFLICT, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_mandatory_field(self):
@ -1047,7 +1048,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/driver', 'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_chassis_uuid(self):
@ -1057,7 +1058,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': self.chassis.uuid,
'op': 'replace'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_add_chassis_uuid(self):
self.mock_update_node.return_value = self.node
@ -1066,7 +1067,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': self.chassis.uuid,
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_add_chassis_id(self):
response = self.patch_json('/nodes/%s' % self.node.uuid,
@ -1075,7 +1076,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_chassis_id(self):
@ -1085,7 +1086,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_chassis_id(self):
@ -1094,7 +1095,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_non_existent_chassis_uuid(self):
@ -1104,7 +1105,7 @@ class TestPatch(test_api_base.FunctionalTest):
'eeeeeeee-dddd-cccc-bbbb-aaaaaaaaaaaa',
'op': 'replace'}], expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_internal_field(self):
@ -1112,7 +1113,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/last_error', 'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_internal_field(self):
@ -1121,7 +1122,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': 'fake-state'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_maintenance(self):
@ -1131,7 +1132,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/maintenance', 'op': 'replace',
'value': 'true'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -1145,7 +1146,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': 'true'}],
headers={api_base.Version.string: "1.5"})
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -1156,7 +1157,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace', 'value': True}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_provision_updated_at(self):
@ -1166,7 +1167,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace', 'value': test_time}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_patch_add_name_ok(self):
@ -1178,7 +1179,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': test_name}],
headers={api_base.Version.string: "1.5"})
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_patch_add_name_invalid(self):
self.mock_update_node.return_value = self.node_no_name
@ -1190,7 +1191,7 @@ class TestPatch(test_api_base.FunctionalTest):
headers={api_base.Version.string: "1.10"},
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_patch_name_replace_ok(self):
@ -1202,7 +1203,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': test_name}],
headers={api_base.Version.string: "1.5"})
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_patch_add_replace_invalid(self):
self.mock_update_node.return_value = self.node_no_name
@ -1214,7 +1215,7 @@ class TestPatch(test_api_base.FunctionalTest):
headers={api_base.Version.string: "1.5"},
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_patch_duplicate_name(self):
@ -1229,7 +1230,7 @@ class TestPatch(test_api_base.FunctionalTest):
headers={api_base.Version.string: "1.5"},
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertEqual(http_client.CONFLICT, response.status_code)
self.assertTrue(response.json['error_message'])
@mock.patch.object(api_utils, 'get_rpc_node')
@ -1244,7 +1245,7 @@ class TestPatch(test_api_base.FunctionalTest):
expect_errors=True)
mock_rpc_node.assert_called_once_with(self.node.uuid)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertEqual(http_client.CONFLICT, response.status_code)
self.assertTrue(response.json['error_message'])
def test_update_in_UPDATE_ALLOWED_STATES(self):
@ -1260,7 +1261,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
class TestPost(test_api_base.FunctionalTest):
@ -1279,7 +1280,7 @@ class TestPost(test_api_base.FunctionalTest):
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time
response = self.post_json('/nodes', ndict)
self.assertEqual(201, response.status_int)
self.assertEqual(http_client.CREATED, response.status_int)
result = self.get_json('/nodes/%s' % ndict['uuid'])
self.assertEqual(ndict['uuid'], result['uuid'])
self.assertFalse(result['updated_at'])
@ -1296,7 +1297,7 @@ class TestPost(test_api_base.FunctionalTest):
ndict = test_api_utils.post_get_test_node()
response = self.post_json('/nodes', ndict,
headers={api_base.Version.string: "1.10"})
self.assertEqual(201, response.status_int)
self.assertEqual(http_client.CREATED, response.status_int)
# default state remains NONE/AVAILABLE
result = self.get_json('/nodes/%s' % ndict['uuid'])
@ -1310,7 +1311,7 @@ class TestPost(test_api_base.FunctionalTest):
ndict = test_api_utils.post_get_test_node()
response = self.post_json('/nodes', ndict,
headers={api_base.Version.string: "1.11"})
self.assertEqual(201, response.status_int)
self.assertEqual(http_client.CREATED, response.status_int)
# default state is ENROLL
result = self.get_json('/nodes/%s' % ndict['uuid'])
@ -1356,7 +1357,7 @@ class TestPost(test_api_base.FunctionalTest):
def _test_vendor_passthru_ok(self, mock_vendor, return_value=None,
is_async=True):
expected_status = 202 if is_async else 200
expected_status = http_client.ACCEPTED if is_async else http_client.OK
expected_return_value = json.dumps(return_value)
if six.PY3:
expected_return_value = expected_return_value.encode('utf-8')
@ -1375,7 +1376,7 @@ class TestPost(test_api_base.FunctionalTest):
def _test_vendor_passthru_ok_by_name(self, mock_vendor, return_value=None,
is_async=True):
expected_status = 202 if is_async else 200
expected_status = http_client.ACCEPTED if is_async else http_client.OK
expected_return_value = json.dumps(return_value)
if six.PY3:
expected_return_value = expected_return_value.encode('utf-8')
@ -1411,7 +1412,7 @@ class TestPost(test_api_base.FunctionalTest):
response = self.put_json(
'/nodes/%s/vendor_passthru/do_test' % node.uuid,
{'test_key': 'test_value'})
self.assertEqual(202, response.status_int)
self.assertEqual(http_client.ACCEPTED, response.status_int)
self.assertEqual(return_value['return'], response.json)
@mock.patch.object(rpcapi.ConductorAPI, 'vendor_passthru')
@ -1434,7 +1435,7 @@ class TestPost(test_api_base.FunctionalTest):
mock_vendor_passthru.return_value = return_value
response = self.delete(
'/nodes/%s/vendor_passthru/do_test' % node.uuid)
self.assertEqual(202, response.status_int)
self.assertEqual(http_client.ACCEPTED, response.status_int)
self.assertEqual(return_value['return'], response.json)
def test_vendor_passthru_no_such_method(self):
@ -1450,14 +1451,14 @@ class TestPost(test_api_base.FunctionalTest):
info, expect_errors=True)
mock_vendor.assert_called_once_with(
mock.ANY, uuid, 'test', 'POST', info, 'test-topic')
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
def test_vendor_passthru_without_method(self):
node = obj_utils.create_test_node(self.context)
response = self.post_json('/nodes/%s/vendor_passthru' % node.uuid,
{'foo': 'bar'}, expect_errors=True)
self.assertEqual('application/json', response.content_type, )
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
def test_post_ports_subresource(self):
@ -1466,13 +1467,13 @@ class TestPost(test_api_base.FunctionalTest):
pdict['node_uuid'] = node.uuid
response = self.post_json('/nodes/ports', pdict,
expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
def test_create_node_no_mandatory_field_driver(self):
ndict = test_api_utils.post_get_test_node()
del ndict['driver']
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -1480,7 +1481,7 @@ class TestPost(test_api_base.FunctionalTest):
ndict = test_api_utils.post_get_test_node()
self.mock_gtf.side_effect = exception.NoValidHost('Fake Error')
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -1489,7 +1490,7 @@ class TestPost(test_api_base.FunctionalTest):
del ndict['chassis_uuid']
response = self.post_json('/nodes', ndict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
self.assertEqual(http_client.CREATED, response.status_int)
# Check location header
self.assertIsNotNone(response.location)
expected_location = '/v1/nodes/%s' % ndict['uuid']
@ -1501,7 +1502,7 @@ class TestPost(test_api_base.FunctionalTest):
chassis_uuid=self.chassis.uuid)
response = self.post_json('/nodes', ndict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
self.assertEqual(http_client.CREATED, response.status_int)
result = self.get_json('/nodes/%s' % ndict['uuid'])
self.assertEqual(ndict['chassis_uuid'], result['chassis_uuid'])
# Check location header
@ -1515,7 +1516,7 @@ class TestPost(test_api_base.FunctionalTest):
chassis_uuid='1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e')
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertTrue(response.json['error_message'])
def test_create_node_with_internal_field(self):
@ -1523,7 +1524,7 @@ class TestPost(test_api_base.FunctionalTest):
ndict['reservation'] = 'fake'
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertTrue(response.json['error_message'])
@mock.patch.object(rpcapi.ConductorAPI, 'get_node_vendor_passthru_methods')
@ -1583,7 +1584,7 @@ class TestDelete(test_api_base.FunctionalTest):
mock_gbu.side_effect = exception.NodeNotFound(node=node.uuid)
response = self.delete('/nodes/%s' % node.uuid, expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
mock_gbu.assert_called_once_with(mock.ANY, node.uuid)
@ -1595,7 +1596,7 @@ class TestDelete(test_api_base.FunctionalTest):
response = self.delete('/nodes/%s' % node.name,
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertFalse(mock_gbn.called)
@mock.patch.object(objects.Node, 'get_by_name')
@ -1606,7 +1607,7 @@ class TestDelete(test_api_base.FunctionalTest):
response = self.delete('/nodes/%s' % node.name,
headers={api_base.Version.string: "1.5"},
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
mock_gbn.assert_called_once_with(mock.ANY, node.name)
@ -1615,7 +1616,7 @@ class TestDelete(test_api_base.FunctionalTest):
node = obj_utils.create_test_node(self.context)
response = self.delete('/nodes/%s/ports' % node.uuid,
expect_errors=True)
self.assertEqual(403, response.status_int)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
@mock.patch.object(rpcapi.ConductorAPI, 'destroy_node')
def test_delete_associated(self, mock_dn):
@ -1626,7 +1627,7 @@ class TestDelete(test_api_base.FunctionalTest):
node=node.uuid, instance=node.instance_uuid)
response = self.delete('/nodes/%s' % node.uuid, expect_errors=True)
self.assertEqual(409, response.status_int)
self.assertEqual(http_client.CONFLICT, response.status_int)
mock_dn.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
@mock.patch.object(objects.Node, 'get_by_uuid')
@ -1636,7 +1637,7 @@ class TestDelete(test_api_base.FunctionalTest):
maintenance_reason='blah')
mock_get.return_value = node
response = self.delete('/nodes/%s/maintenance' % node.uuid)
self.assertEqual(202, response.status_int)
self.assertEqual(http_client.ACCEPTED, response.status_int)
self.assertEqual(b'', response.body)
self.assertEqual(False, node.maintenance)
self.assertIsNone(node.maintenance_reason)
@ -1654,7 +1655,7 @@ class TestDelete(test_api_base.FunctionalTest):
mock_get.return_value = node
response = self.delete('/nodes/%s/maintenance' % node.name,
headers={api_base.Version.string: "1.5"})
self.assertEqual(202, response.status_int)
self.assertEqual(http_client.ACCEPTED, response.status_int)
self.assertEqual(b'', response.body)
self.assertEqual(False, node.maintenance)
self.assertIsNone(node.maintenance_reason)
@ -1690,7 +1691,7 @@ class TestPut(test_api_base.FunctionalTest):
def test_power_state(self):
response = self.put_json('/nodes/%s/states/power' % self.node.uuid,
{'target': states.POWER_ON})
self.assertEqual(202, response.status_code)
self.assertEqual(http_client.ACCEPTED, response.status_code)
self.assertEqual(b'', response.body)
self.mock_cnps.assert_called_once_with(mock.ANY,
self.node.uuid,
@ -1706,13 +1707,13 @@ class TestPut(test_api_base.FunctionalTest):
response = self.put_json('/nodes/%s/states/power' % self.node.name,
{'target': states.POWER_ON},
expect_errors=True)
self.assertEqual(404, response.status_code)
self.assertEqual(http_client.NOT_FOUND, response.status_code)
def test_power_state_by_name(self):
response = self.put_json('/nodes/%s/states/power' % self.node.name,
{'target': states.POWER_ON},
headers={api_base.Version.string: "1.5"})
self.assertEqual(202, response.status_code)
self.assertEqual(http_client.ACCEPTED, response.status_code)
self.assertEqual(b'', response.body)
self.mock_cnps.assert_called_once_with(mock.ANY,
self.node.uuid,
@ -1727,7 +1728,7 @@ class TestPut(test_api_base.FunctionalTest):
def test_power_invalid_state_request(self):
ret = self.put_json('/nodes/%s/states/power' % self.node.uuid,
{'target': 'not-supported'}, expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
def test_power_change_when_being_cleaned(self):
for state in (states.CLEANING, states.CLEANWAIT):
@ -1736,17 +1737,17 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/power' % self.node.uuid,
{'target': states.POWER_OFF},
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
def test_provision_invalid_state_request(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': 'not-supported'}, expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
def test_provision_with_deploy(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.ACTIVE})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
self.mock_dnd.assert_called_once_with(
mock.ANY, self.node.uuid, False, None, 'test-topic')
@ -1760,13 +1761,13 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % self.node.name,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(404, ret.status_code)
self.assertEqual(http_client.NOT_FOUND, ret.status_code)
def test_provision_by_name(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.name,
{'target': states.ACTIVE},
headers={api_base.Version.string: "1.5"})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
self.mock_dnd.assert_called_once_with(
mock.ANY, self.node.uuid, False, None, 'test-topic')
@ -1774,7 +1775,7 @@ class TestPut(test_api_base.FunctionalTest):
def test_provision_with_deploy_configdrive(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.ACTIVE, 'configdrive': 'foo'})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
self.mock_dnd.assert_called_once_with(
mock.ANY, self.node.uuid, False, 'foo', 'test-topic')
@ -1788,7 +1789,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.DELETED, 'configdrive': 'foo'},
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
def test_provision_with_tear_down(self):
node = self.node
@ -1797,7 +1798,7 @@ class TestPut(test_api_base.FunctionalTest):
node.save()
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.DELETED})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
self.mock_dntd.assert_called_once_with(
mock.ANY, node.uuid, 'test-topic')
@ -1816,7 +1817,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(409, ret.status_code) # Conflict
self.assertEqual(http_client.CONFLICT, ret.status_code) # Conflict
self.assertFalse(self.mock_dnd.called)
def test_provision_locked_with_correct_state(self):
@ -1830,7 +1831,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(409, ret.status_code) # Conflict
self.assertEqual(http_client.CONFLICT, ret.status_code) # Conflict
self.assertTrue(self.mock_dnd.called)
def test_provision_with_tear_down_in_progress_deploywait(self):
@ -1840,7 +1841,7 @@ class TestPut(test_api_base.FunctionalTest):
node.save()
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.DELETED})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
self.mock_dntd.assert_called_once_with(
mock.ANY, node.uuid, 'test-topic')
@ -1862,7 +1863,7 @@ class TestPut(test_api_base.FunctionalTest):
node.save()
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.ACTIVE})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
self.mock_dnd.assert_called_once_with(
mock.ANY, node.uuid, False, None, 'test-topic')
@ -1878,14 +1879,14 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
def test_manage_raises_error_before_1_2(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.VERBS['manage']},
headers={},
expect_errors=True)
self.assertEqual(406, ret.status_code)
self.assertEqual(http_client.NOT_ACCEPTABLE, ret.status_code)
@mock.patch.object(rpcapi.ConductorAPI, 'do_provisioning_action')
def test_provide_from_manage(self, mock_dpa):
@ -1895,7 +1896,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.VERBS['provide']},
headers={api_base.Version.string: "1.4"})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
mock_dpa.assert_called_once_with(mock.ANY, self.node.uuid,
states.VERBS['provide'],
@ -1910,7 +1911,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.MANAGEABLE},
expect_errors=True)
self.assertEqual(409, ret.status_code) # Conflict
self.assertEqual(http_client.CONFLICT, ret.status_code) # Conflict
@mock.patch.object(rpcapi.ConductorAPI, 'do_provisioning_action')
def test_manage_from_available(self, mock_dpa):
@ -1920,7 +1921,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.VERBS['manage']},
headers={api_base.Version.string: "1.4"})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
mock_dpa.assert_called_once_with(mock.ANY, self.node.uuid,
states.VERBS['manage'],
@ -1935,7 +1936,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
self.assertEqual(0, mock_dpa.call_count)
def test_set_console_mode_enabled(self):
@ -1943,7 +1944,7 @@ class TestPut(test_api_base.FunctionalTest):
'set_console_mode') as mock_scm:
ret = self.put_json('/nodes/%s/states/console' % self.node.uuid,
{'enabled': "true"})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
mock_scm.assert_called_once_with(mock.ANY, self.node.uuid,
True, 'test-topic')
@ -1958,14 +1959,14 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/console' % self.node.name,
{'enabled': "true"},
expect_errors=True)
self.assertEqual(404, ret.status_code)
self.assertEqual(http_client.NOT_FOUND, ret.status_code)
@mock.patch.object(rpcapi.ConductorAPI, 'set_console_mode')
def test_set_console_by_name(self, mock_scm):
ret = self.put_json('/nodes/%s/states/console' % self.node.name,
{'enabled': "true"},
headers={api_base.Version.string: "1.5"})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
mock_scm.assert_called_once_with(mock.ANY, self.node.uuid,
True, 'test-topic')
@ -1975,7 +1976,7 @@ class TestPut(test_api_base.FunctionalTest):
'set_console_mode') as mock_scm:
ret = self.put_json('/nodes/%s/states/console' % self.node.uuid,
{'enabled': "false"})
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
mock_scm.assert_called_once_with(mock.ANY, self.node.uuid,
False, 'test-topic')
@ -1991,7 +1992,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/console' % self.node.uuid,
{'enabled': "invalid-value"},
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
# assert set_console_mode wasn't called
assert not mock_scm.called
@ -2000,7 +2001,7 @@ class TestPut(test_api_base.FunctionalTest):
'set_console_mode') as mock_scm:
ret = self.put_json('/nodes/%s/states/console' % self.node.uuid,
{}, expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
# assert set_console_mode wasn't called
assert not mock_scm.called
@ -2011,7 +2012,7 @@ class TestPut(test_api_base.FunctionalTest):
extension='console', driver='test-driver')
ret = self.put_json('/nodes/%s/states/console' % self.node.uuid,
{'enabled': "true"}, expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
mock_scm.assert_called_once_with(mock.ANY, self.node.uuid,
True, 'test-topic')
@ -2022,7 +2023,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
self.assertTrue(ret.json['error_message'])
@mock.patch.object(rpcapi.ConductorAPI, 'set_boot_device')
@ -2030,7 +2031,7 @@ class TestPut(test_api_base.FunctionalTest):
device = boot_devices.PXE
ret = self.put_json('/nodes/%s/management/boot_device'
% self.node.uuid, {'boot_device': device})
self.assertEqual(204, ret.status_code)
self.assertEqual(http_client.NO_CONTENT, ret.status_code)
self.assertEqual(b'', ret.body)
mock_sbd.assert_called_once_with(mock.ANY, self.node.uuid,
device, persistent=False,
@ -2042,7 +2043,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/management/boot_device'
% self.node.name, {'boot_device': device},
headers={api_base.Version.string: "1.5"})
self.assertEqual(204, ret.status_code)
self.assertEqual(http_client.NO_CONTENT, ret.status_code)
self.assertEqual(b'', ret.body)
mock_sbd.assert_called_once_with(mock.ANY, self.node.uuid,
device, persistent=False,
@ -2056,7 +2057,7 @@ class TestPut(test_api_base.FunctionalTest):
ret = self.put_json('/nodes/%s/management/boot_device'
% self.node.uuid, {'boot_device': device},
expect_errors=True)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
self.assertTrue(ret.json['error_message'])
mock_sbd.assert_called_once_with(mock.ANY, self.node.uuid,
device, persistent=False,
@ -2067,7 +2068,7 @@ class TestPut(test_api_base.FunctionalTest):
device = boot_devices.PXE
ret = self.put_json('/nodes/%s/management/boot_device?persistent=True'
% self.node.uuid, {'boot_device': device})
self.assertEqual(204, ret.status_code)
self.assertEqual(http_client.NO_CONTENT, ret.status_code)
self.assertEqual(b'', ret.body)
mock_sbd.assert_called_once_with(mock.ANY, self.node.uuid,
device, persistent=True,
@ -2080,7 +2081,7 @@ class TestPut(test_api_base.FunctionalTest):
% self.node.uuid, {'boot_device': device},
expect_errors=True)
self.assertEqual('application/json', ret.content_type)
self.assertEqual(400, ret.status_code)
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
def _test_set_node_maintenance_mode(self, mock_update, mock_get, reason,
node_ident, is_by_name=False):
@ -2096,7 +2097,7 @@ class TestPut(test_api_base.FunctionalTest):
headers = {}
ret = self.put_json('/nodes/%s/maintenance' % node_ident,
request_body, headers=headers)
self.assertEqual(202, ret.status_code)
self.assertEqual(http_client.ACCEPTED, ret.status_code)
self.assertEqual(b'', ret.body)
self.assertEqual(True, self.node.maintenance)
self.assertEqual(reason, self.node.maintenance_reason)

View File

@ -22,6 +22,7 @@ from oslo_config import cfg
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from six.moves import http_client
from six.moves.urllib import parse as urlparse
from testtools.matchers import HasLength
from wsme import types as wtypes
@ -119,7 +120,7 @@ class TestListPorts(test_api_base.FunctionalTest):
'/ports/%s?fields=%s' % (port.uuid, fields),
headers={api_base.Version.string: str(api_v1.MAX_VER)},
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('spongebob', response.json['error_message'])
@ -130,7 +131,7 @@ class TestListPorts(test_api_base.FunctionalTest):
'/ports/%s?fields=%s' % (port.uuid, fields),
headers={api_base.Version.string: str(api_v1.MIN_VER)},
expect_errors=True)
self.assertEqual(406, response.status_int)
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_int)
def test_detail(self):
port = obj_utils.create_test_port(self.context, node_id=self.node.id)
@ -145,7 +146,7 @@ class TestListPorts(test_api_base.FunctionalTest):
port = obj_utils.create_test_port(self.context, node_id=self.node.id)
response = self.get_json('/ports/%s/detail' % port.uuid,
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
def test_many(self):
ports = []
@ -228,7 +229,7 @@ class TestListPorts(test_api_base.FunctionalTest):
invalid_address = 'invalid-mac-format'
response = self.get_json('/ports?address=%s' % invalid_address,
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn(invalid_address, response.json['error_message'])
@ -250,7 +251,7 @@ class TestListPorts(test_api_base.FunctionalTest):
for invalid_key in invalid_keys_list:
response = self.get_json('/ports?sort_key=%s' % invalid_key,
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn(invalid_key, response.json['error_message'])
@ -293,7 +294,7 @@ class TestListPorts(test_api_base.FunctionalTest):
data = self.get_json("/ports?node=%s" % 'test-node',
expect_errors=True)
self.assertEqual(0, mock_get_rpc_node.call_count)
self.assertEqual(406, data.status_int)
self.assertEqual(http_client.NOT_ACCEPTABLE, data.status_int)
@mock.patch.object(api_utils, 'get_rpc_node')
def test_detail_by_node_name_ok(self, mock_get_rpc_node):
@ -314,7 +315,7 @@ class TestListPorts(test_api_base.FunctionalTest):
data = self.get_json('/ports/detail?node=%s' % 'test-node',
expect_errors=True)
self.assertEqual(0, mock_get_rpc_node.call_count)
self.assertEqual(406, data.status_int)
self.assertEqual(http_client.NOT_ACCEPTABLE, data.status_int)
@mock.patch.object(api_port.PortsController, '_get_ports_collection')
def test_detail_with_incorrect_api_usage(self, mock_gpc):
@ -350,7 +351,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': 'bar',
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(extra, response.json['extra'])
kargs = mock_upd.call_args[0][1]
@ -366,7 +367,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertIn(self.port.address, response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -378,7 +379,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(404, response.status_int)
self.assertEqual(http_client.NOT_FOUND, response.status_int)
self.assertTrue(response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -391,7 +392,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': address,
'op': 'replace'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(address, response.json['address'])
self.assertTrue(mock_upd.called)
@ -407,7 +408,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertEqual(http_client.CONFLICT, response.status_code)
self.assertTrue(response.json['error_message'])
self.assertTrue(mock_upd.called)
@ -421,7 +422,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': self.node.uuid,
'op': 'replace'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_add_node_uuid(self, mock_upd):
mock_upd.return_value = self.port
@ -430,7 +431,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': self.node.uuid,
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_add_node_id(self, mock_upd):
response = self.patch_json('/ports/%s' % self.port.uuid,
@ -439,7 +440,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertFalse(mock_upd.called)
def test_replace_node_id(self, mock_upd):
@ -449,7 +450,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertFalse(mock_upd.called)
def test_remove_node_id(self, mock_upd):
@ -458,7 +459,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertFalse(mock_upd.called)
def test_replace_non_existent_node_uuid(self, mock_upd):
@ -469,7 +470,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertIn(node_uuid, response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -491,7 +492,7 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/ports/%s' % self.port.uuid,
patch)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(extra, response.json['extra'])
kargs = mock_upd.call_args[0][1]
self.assertEqual(extra, kargs.extra)
@ -509,7 +510,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/extra/foo1',
'op': 'remove'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(extra, response.json['extra'])
kargs = mock_upd.call_args[0][1]
self.assertEqual(extra, kargs.extra)
@ -520,7 +521,7 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/ports/%s' % self.port.uuid,
[{'path': '/extra', 'op': 'remove'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual({}, response.json['extra'])
kargs = mock_upd.call_args[0][1]
self.assertEqual(extra, kargs.extra)
@ -535,7 +536,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -545,7 +546,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertEqual(http_client.BAD_REQUEST, response.status_code)
self.assertTrue(response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -558,7 +559,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': address,
'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(address, response.json['address'])
self.assertTrue(mock_upd.called)
kargs = mock_upd.call_args[0][1]
@ -571,7 +572,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertTrue(response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -587,7 +588,7 @@ class TestPatch(test_api_base.FunctionalTest):
response = self.patch_json('/ports/%s' % self.port.uuid,
patch)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(extra, response.json['extra'])
kargs = mock_upd.call_args[0][1]
self.assertEqual(extra, kargs.extra)
@ -597,7 +598,7 @@ class TestPatch(test_api_base.FunctionalTest):
[{'path': '/uuid',
'op': 'remove'}],
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -609,7 +610,7 @@ class TestPatch(test_api_base.FunctionalTest):
'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertTrue(response.json['error_message'])
self.assertFalse(mock_upd.called)
@ -622,7 +623,7 @@ class TestPatch(test_api_base.FunctionalTest):
'value': address,
'op': 'replace'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
self.assertEqual(address.lower(), response.json['address'])
kargs = mock_upd.call_args[0][1]
self.assertEqual(address.lower(), kargs.address)
@ -640,7 +641,7 @@ class TestPost(test_api_base.FunctionalTest):
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time
response = self.post_json('/ports', pdict)
self.assertEqual(201, response.status_int)
self.assertEqual(http_client.CREATED, response.status_int)
result = self.get_json('/ports/%s' % pdict['uuid'])
self.assertEqual(pdict['uuid'], result['uuid'])
self.assertFalse(result['updated_at'])
@ -685,7 +686,7 @@ class TestPost(test_api_base.FunctionalTest):
pdict = post_get_test_port()
del pdict['address']
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -693,14 +694,14 @@ class TestPost(test_api_base.FunctionalTest):
pdict = post_get_test_port()
del pdict['node_uuid']
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_port_invalid_addr_format(self):
pdict = post_get_test_port(address='invalid-format')
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -717,7 +718,7 @@ class TestPost(test_api_base.FunctionalTest):
hyphensMAC = colonsMAC.replace(':', '-')
pdict['address'] = hyphensMAC
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -725,7 +726,7 @@ class TestPost(test_api_base.FunctionalTest):
pdict = post_get_test_port(node_uuid='invalid-format')
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertTrue(response.json['error_message'])
def test_node_uuid_to_node_id_mapping(self):
@ -740,7 +741,7 @@ class TestPost(test_api_base.FunctionalTest):
node_uuid='1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e')
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertTrue(response.json['error_message'])
def test_create_port_address_already_exist(self):
@ -749,7 +750,7 @@ class TestPost(test_api_base.FunctionalTest):
self.post_json('/ports', pdict)
pdict['uuid'] = uuidutils.generate_uuid()
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(409, response.status_int)
self.assertEqual(http_client.CONFLICT, response.status_int)
self.assertEqual('application/json', response.content_type)
error_msg = response.json['error_message']
self.assertTrue(error_msg)
@ -773,7 +774,7 @@ class TestDelete(test_api_base.FunctionalTest):
def test_delete_port_byaddress(self, mock_dpt):
response = self.delete('/ports/%s' % self.port.address,
expect_errors=True)
self.assertEqual(400, response.status_int)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn(self.port.address, response.json['error_message'])
@ -786,6 +787,6 @@ class TestDelete(test_api_base.FunctionalTest):
mock_dpt.side_effect = exception.NodeLocked(node='fake-node',
host='fake-host')
ret = self.delete('/ports/%s' % self.port.uuid, expect_errors=True)
self.assertEqual(409, ret.status_code)
self.assertEqual(http_client.CONFLICT, ret.status_code)
self.assertTrue(ret.json['error_message'])
self.assertTrue(mock_dpt.called)

View File

@ -17,6 +17,7 @@
import mock
import six
from six.moves import http_client
import webtest
import wsme
from wsme import types as wtypes
@ -133,68 +134,68 @@ class TestJsonPatchType(base.TestCase):
{'path': '/dict', 'op': 'add',
'value': {'cat': 'meow'}}]
ret = self._patch_json(valid_patches, False)
self.assertEqual(200, ret.status_int)
self.assertEqual(http_client.OK, ret.status_int)
self.assertItemsEqual(valid_patches, ret.json)
def test_cannot_update_internal_attr(self):
patch = [{'path': '/internal', 'op': 'replace', 'value': 'foo'}]
ret = self._patch_json(patch, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_cannot_update_internal_dict_attr(self):
patch = [{'path': '/internal/test', 'op': 'replace',
'value': 'foo'}]
ret = self._patch_json(patch, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_mandatory_attr(self):
patch = [{'op': 'replace', 'path': '/mandatory', 'value': 'foo'}]
ret = self._patch_json(patch, False)
self.assertEqual(200, ret.status_int)
self.assertEqual(http_client.OK, ret.status_int)
self.assertEqual(patch, ret.json)
def test_cannot_remove_mandatory_attr(self):
patch = [{'op': 'remove', 'path': '/mandatory'}]
ret = self._patch_json(patch, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_missing_required_fields_path(self):
missing_path = [{'op': 'remove'}]
ret = self._patch_json(missing_path, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_missing_required_fields_op(self):
missing_op = [{'path': '/foo'}]
ret = self._patch_json(missing_op, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_invalid_op(self):
patch = [{'path': '/foo', 'op': 'invalid'}]
ret = self._patch_json(patch, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_invalid_path(self):
patch = [{'path': 'invalid-path', 'op': 'remove'}]
ret = self._patch_json(patch, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_cannot_add_with_no_value(self):
patch = [{'path': '/extra/foo', 'op': 'add'}]
ret = self._patch_json(patch, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])
def test_cannot_replace_with_no_value(self):
patch = [{'path': '/foo', 'op': 'replace'}]
ret = self._patch_json(patch, True)
self.assertEqual(400, ret.status_int)
self.assertEqual(http_client.BAD_REQUEST, ret.status_int)
self.assertTrue(ret.json['faultstring'])

View File

@ -18,6 +18,7 @@ import mock
from oslo_config import cfg
from oslo_utils import uuidutils
import pecan
from six.moves import http_client
from webob.static import FileIter
import wsme
@ -204,7 +205,7 @@ class TestVendorPassthru(base.TestCase):
self.assertIsInstance(response, wsme.api.Response)
self.assertEqual('SpongeBob', response.obj)
self.assertEqual(response.return_type, wsme.types.Unset)
sc = 202 if async else 200
sc = http_client.ACCEPTED if async else http_client.OK
self.assertEqual(sc, response.status_code)
def test_vendor_passthru_async(self):
@ -243,7 +244,7 @@ class TestVendorPassthru(base.TestCase):
self.assertIsInstance(response, wsme.api.Response)
self.assertIsNone(response.obj)
self.assertIsNone(response.return_type)
self.assertEqual(200, response.status_code)
self.assertEqual(http_client.OK, response.status_code)
def test_vendor_passthru_attach(self):
self._test_vendor_passthru_attach('foo', b'foo')

View File

@ -19,6 +19,7 @@ import requests
import sendfile
import six
import six.moves.builtins as __builtin__
from six.moves import http_client
from ironic.common import exception
from ironic.common.glance_service.v1 import image_service as glance_v1_service
@ -40,21 +41,21 @@ class HttpImageServiceTestCase(base.TestCase):
@mock.patch.object(requests, 'head', autospec=True)
def test_validate_href(self, head_mock):
response = head_mock.return_value
response.status_code = 200
response.status_code = http_client.OK
self.service.validate_href(self.href)
head_mock.assert_called_once_with(self.href)
response.status_code = 204
response.status_code = http_client.NO_CONTENT
self.assertRaises(exception.ImageRefValidationFailed,
self.service.validate_href,
self.href)
response.status_code = 400
response.status_code = http_client.BAD_REQUEST
self.assertRaises(exception.ImageRefValidationFailed,
self.service.validate_href,
self.href)
@mock.patch.object(requests, 'head', autospec=True)
def test_validate_href_error_code(self, head_mock):
head_mock.return_value.status_code = 400
head_mock.return_value.status_code = http_client.BAD_REQUEST
self.assertRaises(exception.ImageRefValidationFailed,
self.service.validate_href, self.href)
head_mock.assert_called_once_with(self.href)
@ -68,7 +69,7 @@ class HttpImageServiceTestCase(base.TestCase):
@mock.patch.object(requests, 'head', autospec=True)
def _test_show(self, head_mock, mtime, mtime_date):
head_mock.return_value.status_code = 200
head_mock.return_value.status_code = http_client.OK
head_mock.return_value.headers = {
'Content-Length': 100,
'Last-Modified': mtime
@ -92,7 +93,7 @@ class HttpImageServiceTestCase(base.TestCase):
@mock.patch.object(requests, 'head', autospec=True)
def test_show_no_content_length(self, head_mock):
head_mock.return_value.status_code = 200
head_mock.return_value.status_code = http_client.OK
head_mock.return_value.headers = {}
self.assertRaises(exception.ImageRefValidationFailed,
self.service.show, self.href)
@ -102,7 +103,7 @@ class HttpImageServiceTestCase(base.TestCase):
@mock.patch.object(requests, 'get', autospec=True)
def test_download_success(self, req_get_mock, shutil_mock):
response_mock = req_get_mock.return_value
response_mock.status_code = 200
response_mock.status_code = http_client.OK
response_mock.raw = mock.MagicMock(spec=file)
file_mock = mock.Mock(spec=file)
self.service.download(self.href, file_mock)
@ -123,7 +124,7 @@ class HttpImageServiceTestCase(base.TestCase):
@mock.patch.object(requests, 'get', autospec=True)
def test_download_fail_ioerror(self, req_get_mock, shutil_mock):
response_mock = req_get_mock.return_value
response_mock.status_code = 200
response_mock.status_code = http_client.OK
response_mock.raw = mock.MagicMock(spec=file)
file_mock = mock.Mock(spec=file)
shutil_mock.side_effect = IOError