示例#1
0
    def test_send_events(self):
        self.mock_sdk.post.return_value = mock.Mock(status_code=200)

        nova = nova_client.NovaAPI()
        nova._send_events(self.events)

        msg = 'Sucessfully sent events to Nova, events: %(events)s'
        self.mock_log_info.assert_called_once_with(msg,
                                                   {'events': self.events})
示例#2
0
    def test_send_events_failure(self):
        # Nova is expected to return 200/207 but this is future-proofing.
        mock_ret = mock.Mock(status_code=400)
        mock_ret.json.return_value = {}  # Dummy response
        self.mock_sdk.post.return_value = mock_ret

        nova = nova_client.NovaAPI()
        self.assertRaises(exception.InvalidAPIResponse, nova._send_events,
                          self.events)
示例#3
0
    def test_send_events_with_event_code_400_exception(self):
        # If Nova returns HTTP 207 with event code 400 for some events,
        # raise an exception.
        resp_events = copy.deepcopy(self.events)
        resp_events[0].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)
示例#4
0
    def test_send_events_422_exception(self):
        # If Nova returns HTTP 207 with event code 422 for some events,
        # but not all, raise an exception. This is not expected to
        # happen with current code.
        resp_events = copy.deepcopy(self.events)
        resp_events[0].update({'status': 'failed', 'code': 422})
        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)
示例#5
0
    def test_send_events_422(self):
        # If Nova returns HTTP 207 with event code 422 for all events,
        # ignore it.
        resp_events = copy.deepcopy(self.events)
        for ev in resp_events:
            ev.update({'status': 'failed', 'code': 422})
        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()
        nova._send_events(self.events)

        msg = ('Ignoring Nova notification error that the instance %s is not '
               'yet associated with a host.')
        self.mock_log_info.assert_called_once_with(msg, self.instance_uuid)
示例#6
0
 def bind_notify(cls, instance_uuid, arq_bind_statuses):
     """Notify the bind status to nova."""
     nova_api = nova_client.NovaAPI()
     nova_api.notify_binding(instance_uuid, arq_bind_statuses)