Exemple #1
0
    def test_save_host_already_exists(self, mock_host_update):

        mock_host_update.side_effect = exception.HostExists(name="foo-host")

        host_object = host.Host(context=self.context)
        host_object.name = "foo-host"
        host_object.id = 123
        host_object.uuid = uuidsentinel.fake_host

        self.assertRaises(exception.HostExists, host_object.save)
Exemple #2
0
    def test_save_host_not_found(self, mock_host_update):

        mock_host_update.side_effect = exception.HostNotFound(name="foo-host")

        host_object = host.Host(context=self.context)
        host_object.name = "foo-host"
        host_object.id = 123
        host_object.uuid = uuidsentinel.fake_host

        self.assertRaises(exception.HostNotFound, host_object.save)
Exemple #3
0
    def _host_create_attributes(self):

        host_obj = host.Host(context=self.context)
        host_obj.name = 'foo-host'
        host_obj.failover_segment_id = uuidsentinel.fake_segment
        host_obj.type = 'fake-type'
        host_obj.reserved = False
        host_obj.on_maintenance = False
        host_obj.control_attributes = 'fake_attributes'
        host_obj.uuid = uuidsentinel.fake_host

        return host_obj
Exemple #4
0
    def test_save_host_not_found(self, mock_host_update,
                                 mock_notify_about_host_api):

        mock_host_update.side_effect = exception.HostNotFound(id="foo-host")

        host_object = host.Host(context=self.context)
        host_object.name = "foo-host"
        host_object.id = 123
        host_object.uuid = uuidsentinel.fake_host

        self.assertRaises(exception.HostNotFound, host_object.save)
        action = fields.EventNotificationAction.HOST_UPDATE
        phase_start = fields.EventNotificationPhase.START
        notify_calls = [
            mock.call(self.context, host_object, action=action,
                      phase=phase_start)]
        mock_notify_about_host_api.assert_has_calls(notify_calls)
Exemple #5
0
    def _host_create_attributes(self):

        failover_segment = fakes_data.create_fake_failover_segment(
            name="fake_segment",
            id=123,
            description="fakefake",
            service_type="COMPUTE",
            recovery_method="auto",
            uuid=uuidsentinel.fake_segment)

        host_obj = host.Host(context=self.context)
        host_obj.name = 'foo-host'
        host_obj.failover_segment = failover_segment
        host_obj.type = 'fake-type'
        host_obj.reserved = False
        host_obj.on_maintenance = False
        host_obj.control_attributes = 'fake_attributes'
        host_obj.uuid = uuidsentinel.fake_host

        return host_obj
Exemple #6
0
    def test_notify_about_host_api(
        self, mock_from_exception, mock_HostApiPayload,
        mock_HostApiNotification, mock_NotificationPublisher, mock_EventType):
        mock_fault = mock.Mock()
        mock_from_exception.return_value = mock_fault
        mock_payload = mock.Mock()
        mock_HostApiPayload.return_value = mock_payload
        mock_api_notification = mock.Mock()
        mock_HostApiNotification.return_value = mock_api_notification
        mock_api_notification.emit.return_value = None
        mock_publisher = mock.Mock()
        mock_NotificationPublisher.return_value = mock_publisher
        mock_event_type = mock.Mock()
        mock_EventType.return_value = mock_event_type

        mock_context = mock.Mock()
        host = host_obj.Host()
        action = fields.EventNotificationAction.HOST_CREATE
        phase = fields.EventNotificationPhase.ERROR
        e = Exception()

        api_utils.notify_about_host_api(mock_context, host, action=action,
            phase=phase, exception=e)

        mock_from_exception.assert_called_once_with(e, None)
        mock_HostApiPayload.assert_called_once_with(
            host=host, fault=mock_fault)
        mock_HostApiNotification.assert_called_once_with(
            context=mock_context,
            priority=fields.EventNotificationPriority.ERROR,
            publisher=mock_publisher,
            event_type=mock_event_type,
            payload=mock_payload)
        mock_NotificationPublisher.assert_called_once_with(
            context=mock_context, host=socket.gethostname(),
            binary='masakari-api')
        mock_api_notification.emit.assert_called_once_with(mock_context)
        mock_EventType.assert_called_once_with(
            action=action, phase=phase)
Exemple #7
0
def _make_hosts_list(hosts_list):
    return host_obj.Host(objects=[_make_host_obj(a) for a in hosts_list])
Exemple #8
0
def _make_host_obj(host_dict):
    return host_obj.Host(**host_dict)
Exemple #9
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from masakari.notifications.objects import base
from masakari.notifications.objects import exception
from masakari.notifications.objects import notification as event_notification
from masakari.objects import host as host_obj
from masakari.objects import notification as notification_obj
from masakari.objects import segment as segment_obj

segment = segment_obj.FailoverSegment()
host = host_obj.Host()
notification = notification_obj.Notification()
fault = None

init_args = {
    event_notification.SegmentApiPayloadBase: [segment],
    event_notification.SegmentApiPayload: [segment, fault],
    event_notification.HostApiPayloadBase: [host],
    event_notification.HostApiPayload: [host, fault],
    event_notification.NotificationApiPayloadBase: [notification],
    event_notification.NotificationApiPayload: [notification, fault],
    event_notification.SegmentApiNotification: [],
    event_notification.HostApiNotification: [],
    event_notification.NotificationApiNotification: [],
    exception.ExceptionPayload: [],
    exception.ExceptionNotification: [],