DBError when creating alarm with no auth

Bug #1242617 reported by Guangyu Suo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ceilometer
Fix Released
Medium
Julien Danjou

Bug Description

I set auth_strategy=noauth in ceilometer.conf, using mysql as backend, and create an alarm without x-auth-token in header, got the following error:

2013-10-21 16:13:51.065 15808 DEBUG ceilometer.openstack.common.policy [-] Rule context_is_admin will be now enforced enforce /opt/stack/ceilometer/ceilometer/openstack/common/policy.py:253
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py:331: Warning: Field 'id' doesn't have a default value
  cursor.execute(statement, parameters)
2013-10-21 16:13:51.167 15808 ERROR ceilometer.openstack.common.db.sqlalchemy.session [-] DB exception wrapped.
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session Traceback (most recent call last):
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session File "/opt/stack/ceilometer/ceilometer/openstack/common/db/sqlalchemy/session.py", line 533, in _wrap
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session return f(*args, **kwargs)
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session File "/opt/stack/ceilometer/ceilometer/openstack/common/db/sqlalchemy/session.py", line 728, in flush
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session return super(Session, self).flush(*args, **kwargs)
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1718, in flush
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session self._flush(objects)
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1793, in _flush
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session flush_context.finalize_flush_changes()
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 347, in finalize_flush_changes
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session self.session._register_newly_persistent(state)
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1316, in _register_newly_persistent
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session "a load() event." % mapperutil.state_str(state)
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session FlushError: Instance <User at 0x46dbe10> has a NULL identity key. If this is an auto-generated value, check that the database
2013-10-21 16:13:51.167 15808 TRACE ceilometer.openstack.common.db.sqlalchemy.session
2013-10-21 16:13:51.185 15808 ERROR wsme.api [-] Server-side error: "Instance <User at 0x46dbe10> has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of ne
Traceback (most recent call last):

  File "/usr/local/lib/python2.7/dist-packages/wsmeext/pecan.py", line 77, in callfunction
    result = f(self, *args, **kwargs)

  File "/opt/stack/ceilometer/ceilometer/api/controllers/v2.py", line 1391, in put_state
    type=storage.models.AlarmChange.STATE_TRANSITION)

  File "/opt/stack/ceilometer/ceilometer/api/controllers/v2.py", line 1293, in _record_change
    self.conn.record_alarm_change(payload)

  File "/opt/stack/ceilometer/ceilometer/storage/impl_sqlalchemy.py", line 737, in record_alarm_change
    session.merge(Project(id=alarm_change['project_id']))

  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1466, in merge
    self._autoflush()

  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1120, in _autoflush
    self.flush()

  File "/opt/stack/ceilometer/ceilometer/openstack/common/db/sqlalchemy/session.py", line 554, in _wrap
    raise exception.DBError(e)

DBError: Instance <User at 0x46dbe10> has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is c

Revision history for this message
Guangyu Suo (yugsuo) wrote :

condering this bug: https://bugs.launchpad.net/ceilometer/+bug/1226470, I think we should do unified user_id and project_id in alarm and alarm_history.

Julien Danjou (jdanjou)
Changed in ceilometer:
importance: Undecided → Medium
status: New → Triaged
tags: added: havana-backport-potential
Changed in ceilometer:
assignee: nobody → Julien Danjou (jdanjou)
Revision history for this message
Julien Danjou (jdanjou) wrote :

So the problem is actually in the other drivers that are able to store an alarm without any user nor project id set… It's great to have model validation, thanks SQL.

I've got a working test case, I'll try to work on a fix soon.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ceilometer (master)

Fix proposed to branch: master
Review: https://review.openstack.org/72406

Changed in ceilometer:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ceilometer (master)

Reviewed: https://review.openstack.org/72406
Committed: https://git.openstack.org/cgit/openstack/ceilometer/commit/?id=8e546a461f1076aa9c003a0c6f4f690ee25c03ad
Submitter: Jenkins
Branch: master

commit 8e546a461f1076aa9c003a0c6f4f690ee25c03ad
Author: Julien Danjou <email address hidden>
Date: Thu Oct 31 16:53:14 2013 +0100

    Test case for creating an alarm without auth headers

    This bug seems to have been fixed in the meantime. This is just a test
    case proving it.

    Closes-Bug: #1242617

    Change-Id: I990ffc8b20b8bc09a8b85cf5aa3e4f17a416d93c

Changed in ceilometer:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: none → icehouse-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: icehouse-3 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.