Exemplo n.º 1
0
def host_create(context, values):
    host = models.Host()
    host.update(values)
    try:
        host.save(session=context.session)
    except db_exc.DBDuplicateEntry:
        raise exception.HostExists(name=host.name)

    return _host_get_by_uuid(context, host.uuid)
Exemplo n.º 2
0
 def test_update_with_duplicated_name(self, mock_update_host):
     test_data = {"host": {"name": "host-1"}}
     mock_update_host.side_effect = exception.HostExists(name="host-1")
     self.assertRaises(exc.HTTPConflict,
                       self.controller.update,
                       self.req,
                       uuidsentinel.fake_segment1,
                       uuidsentinel.fake_host_1,
                       body=test_data)
Exemplo n.º 3
0
def host_update(context, host_uuid, values):
    host = _host_get_by_uuid(context, host_uuid)

    host.update(values)
    try:
        host.save(session=context.session)
    except db_exc.DBDuplicateEntry:
        raise exception.HostExists(name=values.get('name'))

    return _host_get_by_uuid(context, host.uuid)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def test_create_with_duplicate_host_name(self, mock_create):

        mock_create.side_effect = (exception.HostExists(name='host-1'))
        body = {
            "host": {
                "name": "host-1",
                "type": "fake",
                "reserved": False,
                "on_maintenance": False,
                "control_attributes": "fake-control_attributes"
            }
        }
        self.assertRaises(exc.HTTPConflict,
                          self.controller.create,
                          self.req,
                          uuidsentinel.fake_segment1,
                          body=body)
Exemplo n.º 6
0
    def test_save_host_already_exists(self, mock_host_update,
                                      mock_notify_about_host_api):

        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)
        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)