(DataError) invalid input syntax for type inet: "my.invalid.ip"

Bug #1386525 reported by Joe Gordon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Invalid
Low
Eli Qiao
oslo.db
Invalid
Undecided
Unassigned

Bug Description

DataError: (DataError) invalid input syntax for type inet: "my.invalid.ip"

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/oslo/db/sqlalchemy/compat/handle_error.py", line 59, in _handle_dbapi_exception
    e, statement, parameters, cursor, context)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1024, in _handle_dbapi_exception
    exc_info
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 196, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 867, in _execute_context
    context)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 324, in do_execute
    cursor.execute(statement, parameters)
DataError: (DataError) invalid input syntax for type inet: "my.invalid.ip"
LINE 3: ...ERE fixed_ips.deleted = 0 AND fixed_ips.address = 'my.invali...
                                                             ^
 'SELECT fixed_ips.created_at AS fixed_ips_created_at, fixed_ips.updated_at AS fixed_ips_updated_at, fixed_ips.deleted_at AS fixed_ips_deleted_at, fixed_ips.deleted AS fixed_ips_deleted, fixed_ips.id AS fixed_ips_id, fixed_ips.address AS fixed_ips_address, fixed_ips.network_id AS fixed_ips_network_id, fixed_ips.virtual_interface_id AS fixed_ips_virtual_interface_id, fixed_ips.instance_uuid AS fixed_ips_instance_uuid, fixed_ips.allocated AS fixed_ips_allocated, fixed_ips.leased AS fixed_ips_leased, fixed_ips.reserved AS fixed_ips_reserved, fixed_ips.host AS fixed_ips_host \nFROM fixed_ips \nWHERE fixed_ips.deleted = %(deleted_1)s AND fixed_ips.address = %(address_1)s \n LIMIT %(param_1)s' {'param_1': 1, 'address_1': 'my.invalid.ip', 'deleted_1': 0}
2014-10-27 17:44:32.094 25193 TRACE oslo.db.sqlalchemy.exc_filters

Seen in nova-api

Tags: db stacktrace
Revision history for this message
Joe Gordon (jogo) wrote :

The exception here makes sense as we commonly use the DB for validation. But this should not be throwing a stacktace.

Changed in nova:
status: New → Confirmed
tags: added: db stacktrace
Changed in nova:
importance: Undecided → Low
Revision history for this message
Joe Gordon (jogo) wrote :
Revision history for this message
Eli Qiao (taget-9) wrote :

After reading the stack trace of gate.
I think this is an tempest test case error.

in sqlalchemy api.

def _fixed_ip_get_by_address(context, address, session=None,
                             columns_to_join=None):

...

    with session.begin(subtransactions=True):
        try:
            result = model_query(context, models.FixedIp, session=session)
            for column in columns_to_join:
                result = result.options(joinedload_all(column))
            result = result.filter_by(address=address).first()
            if not result:
                raise exception.FixedIpNotFoundForAddress(address=address)
        except db_exc.DBError:
            msg = _("Invalid fixed IP Address %s in request") % address
            LOG.warn(msg)
            raise exception.FixedIpInvalid(msg)

if passing a invalid address to db, it will raises a DBError, and will reraise an FixedIpInvalid exception.

in nova-api, it will except FixedIpInvalid exception and raise an HTTPBadRequest
         except exception.FixedIpInvalid:
            msg = _("Fixed IP %s not valid") % address
            raise webob.exc.HTTPBadRequest(explanation=msg)

but seen from tempest test case.

    def test_set_reserve_with_invalid_ip(self):
        # NOTE(maurosr): since this exercises the same code snippet, we do it
        # only for reserve action
        body = {"reserve": "None"}
        self.assertRaises(exceptions.NotFound, <<<----- here should be HTTPBadRequest
                          self.client.reserve_fixed_ip,
                          "my.invalid.ip", body)

compared with nova api unit test

def test_fixed_ip_reserve_invalid_ip_address(self):
        body = {'reserve': None}
        req = fakes.HTTPRequest.blank('%s/inv.ali.d.ip/action' % self.url)
        action = self._get_reserve_action()

        self.assertRaises(webob.exc.HTTPBadRequest,
                          action, req, 'inv.ali.d.ip', body)

I will submit a tempest patch to fix this one.

Eli.

Changed in nova:
assignee: nobody → Eli Qiao (taget-9)
Revision history for this message
Eli Qiao (taget-9) wrote :

opps... ignore me, I'v added the code..

I'v add this..
    def test_set_reserve_with_invalid_ip(self):
        # NOTE(maurosr): since this exercises the same code snippet, we do it
        # only for reserve action
        body = {"reserve": "None"}
        # NOTE(eliqiao): in Juno, the exception is NotFound, but in master, we
        # change the error code to BadRequest, both exceptions should be
        # accepted by tempest
        self.assertRaises((exceptions.NotFound, exceptions.BadRequest),
                          self.client.reserve_fixed_ip,
                          "my.invalid.ip", body)

Revision history for this message
Roman Podoliaka (rpodolyaka) wrote :

This fails directly in PostgreSQL when the SQL statement is executed. There is nothing oslo.db can do for you except raising a correct exception (DataError).

Changed in oslo.db:
status: New → Invalid
Changed in nova:
status: Confirmed → Invalid
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.