"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cyborg/tests/unit/common/test_nova_client.py" between
openstack-cyborg-6.0.0.tar.gz and openstack-cyborg-7.0.0.tar.gz

About: OpenStack Cyborg provides a general purpose management framework for acceleration resources.
The "Xena" series (latest release).

test_nova_client.py  (openstack-cyborg-6.0.0):test_nova_client.py  (openstack-cyborg-7.0.0)
skipping to change at line 24 skipping to change at line 24
# under the License. # under the License.
import copy import copy
import fixtures import fixtures
from unittest import mock from unittest import mock
from cyborg.common import exception from cyborg.common import exception
from cyborg.common import nova_client from cyborg.common import nova_client
from cyborg.tests import base from cyborg.tests import base
class NovaAPITest(base.TestCase): class NovaAPITest(base.TestCase):
wsgi_api_version = '2.81' # TODO(Sundar): Make this 2.82 wsgi_api_version = '2.82'
def setUp(self): def setUp(self):
super(NovaAPITest, self).setUp() super(NovaAPITest, self).setUp()
self.instance_uuid = '00000000-0000-0000-0000-000000000001' self.instance_uuid = '00000000-0000-0000-0000-000000000001'
template = {'name': 'accelerator-request-bound', template = {'name': 'accelerator-request-bound',
'server_uuid': self.instance_uuid, 'server_uuid': self.instance_uuid,
'code': 200, 'code': 200,
'status': 'completed'} 'status': 'completed'}
tags = ['00000000-0000-0000-0000-000000000002', tags = ['00000000-0000-0000-0000-000000000002',
'00000000-0000-0000-0000-000000000003'] '00000000-0000-0000-0000-000000000003']
skipping to change at line 70 skipping to change at line 70
mock_ret.json.return_value = nova_resp mock_ret.json.return_value = nova_resp
self.mock_sdk.post.return_value = mock_ret self.mock_sdk.post.return_value = mock_ret
nova = nova_client.NovaAPI() nova = nova_client.NovaAPI()
nova._send_events(self.events) nova._send_events(self.events)
msg = ('Ignoring Nova notification error that the instance %s is not ' msg = ('Ignoring Nova notification error that the instance %s is not '
'yet associated with a host.') 'yet associated with a host.')
self.mock_log_info.assert_called_once_with(msg, self.instance_uuid) self.mock_log_info.assert_called_once_with(msg, self.instance_uuid)
def test_send_events_422_exception(self): def test_send_events_with_event_code_422_exception(self):
# If Nova returns HTTP 207 with event code 422 for some events, # If Nova returns HTTP 207 with event code 422 for some events,
# but not all, raise an exception. This is not expected to # but not all, raise an exception. This is not expected to
# happen with current code. # happen with current code.
resp_events = copy.deepcopy(self.events) resp_events = copy.deepcopy(self.events)
resp_events[0].update({'status': 'failed', 'code': 422}) resp_events[0].update({'status': 'failed', 'code': 422})
nova_resp = {'events': resp_events} nova_resp = {'events': resp_events}
mock_ret = mock.Mock(status_code=207) mock_ret = mock.Mock(status_code=207)
mock_ret.json.return_value = nova_resp mock_ret.json.return_value = nova_resp
self.mock_sdk.post.return_value = mock_ret self.mock_sdk.post.return_value = mock_ret
nova = nova_client.NovaAPI() nova = nova_client.NovaAPI()
self.assertRaises(exception.InvalidAPIResponse, self.assertRaises(exception.InvalidAPIResponse,
nova._send_events, self.events) nova._send_events, self.events)
def test_send_events_non_422_exception(self): def test_send_events_with_event_code_400_exception(self):
# If Nova returns HTTP 207 with event code other than 422, # If Nova returns HTTP 207 with event code 400 for some events,
# raise an exception. # raise an exception.
resp_events = copy.deepcopy(self.events) resp_events = copy.deepcopy(self.events)
resp_events[0].update({'status': 'failed', 'code': 400}) resp_events[0].update({'status': 'failed', 'code': 400})
nova_resp = {'events': resp_events} nova_resp = {'events': resp_events}
mock_ret = mock.Mock(status_code=207) mock_ret = mock.Mock(status_code=207)
mock_ret.json.return_value = nova_resp mock_ret.json.return_value = nova_resp
self.mock_sdk.post.return_value = mock_ret self.mock_sdk.post.return_value = mock_ret
nova = nova_client.NovaAPI() nova = nova_client.NovaAPI()
self.assertRaises(exception.InvalidAPIResponse, self.assertRaises(exception.InvalidAPIResponse,
nova._send_events, self.events) nova._send_events, self.events)
def test_send_events_with_all_event_code_400_exception(self):
# If Nova returns HTTP 207 with event code 400 for all events,
# raise an exception.
resp_events = copy.deepcopy(self.events)
for ev in resp_events:
ev.update({'status': 'failed', 'code': 400})
nova_resp = {'events': resp_events}
mock_ret = mock.Mock(status_code=207)
mock_ret.json.return_value = nova_resp
self.mock_sdk.post.return_value = mock_ret
nova = nova_client.NovaAPI()
self.assertRaises(exception.InvalidAPIResponse,
nova._send_events, self.events)
def test_send_events_failure(self): def test_send_events_failure(self):
# Nova is expected to return 200/207 but this is future-proofing. # Nova is expected to return 200/207 but this is future-proofing.
mock_ret = mock.Mock(status_code=400) mock_ret = mock.Mock(status_code=400)
mock_ret.json.return_value = {} # Dummy response mock_ret.json.return_value = {} # Dummy response
self.mock_sdk.post.return_value = mock_ret self.mock_sdk.post.return_value = mock_ret
nova = nova_client.NovaAPI() nova = nova_client.NovaAPI()
self.assertRaises(exception.InvalidAPIResponse, self.assertRaises(exception.InvalidAPIResponse,
nova._send_events, self.events) nova._send_events, self.events)
 End of changes. 4 change blocks. 
4 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)