search with error regex causes a 500 error

Bug #1603728 reported by wanghongxu on 2016-07-17
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Anton Kremenetsky

Bug Description

When I search instance with a wrong regx, such as '+', nova-api will return a 500 error.

Steps to reproduce
nova list --name +

Expected result
After the execution of the steps above, We can get a prompt of regx error message.

Actual result
ERROR (ClientException): Unexpected API Error. Please report this at and attach the Nova API log if possible.
<class 'oslo_db.exception.DBError'> (HTTP 500) (Request-ID: req-f6a78623-4db5-4f5b-94b1-8edb281b5e7a)

There are the nova-api.log:
 Traceback (most recent call last):
   File "/usr/lib/python2.7/site-packages/nova/api/openstack/", line 478, in wrapped
     return f(*args, **kwargs)
   File "/usr/lib/python2.7/site-packages/nova/api/openstack/compute/", line 294, in detail
     servers = self._get_servers(req, is_detail=True)
   File "/usr/lib/python2.7/site-packages/nova/api/openstack/compute/", line 409, in _get_servers
     sort_keys=sort_keys, sort_dirs=sort_dirs)
   File "/usr/lib/python2.7/site-packages/nova/compute/", line 2128, in get_all
     sort_keys=sort_keys, sort_dirs=sort_dirs)
   File "/usr/lib/python2.7/site-packages/nova/compute/", line 2178, in _get_instances_by_filters
     expected_attrs=fields, sort_keys=sort_keys, sort_dirs=sort_dirs)
   File "/usr/lib/python2.7/site-packages/oslo_versionedobjects/", line 181, in wrapper
     result = fn(cls, context, *args, **kwargs)
   File "/usr/lib/python2.7/site-packages/nova/objects/", line 1065, in get_by_filters
     use_slave=use_slave, sort_keys=sort_keys, sort_dirs=sort_dirs)
   File "/usr/lib/python2.7/site-packages/nova/db/sqlalchemy/", line 285, in wrapper
     return f(*args, **kwargs)
   File "/usr/lib/python2.7/site-packages/nova/objects/", line 1049, in _get_by_filters_impl
     sort_keys=sort_keys, sort_dirs=sort_dirs)
   File "/usr/lib/python2.7/site-packages/nova/db/", line 734, in instance_get_all_by_filters_sort
   File "/usr/lib/python2.7/site-packages/nova/db/sqlalchemy/", line 229, in wrapper
     return f(*args, **kwargs)
   File "/usr/lib/python2.7/site-packages/nova/db/sqlalchemy/", line 330, in wrapped
     return f(context, *args, **kwargs)
   File "/usr/lib/python2.7/site-packages/nova/db/sqlalchemy/", line 2308, in instance_get_all_by_filters_sort
     return _instances_fill_metadata(context, query_prefix.all(), manual_joins)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/", line 2588, in all
     return list(self)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/", line 2736, in __iter__
     return self._execute_and_instances(context)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/", line 2751, in _execute_and_instances
     result = conn.execute(querycontext.statement, self._params)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/", line 914, in execute
     return meth(self, multiparams, params)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/", line 323, in _execute_on_connection
     return connection._execute_clauseelement(self, multiparams, params)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/", line 1010, in _execute_clauseelement
     compiled_sql, distilled_params
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/", line 1146, in _execute_context
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/", line 1337, in _handle_dbapi_exception
     util.raise_from_cause(newraise, exc_info)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/", line 200, in raise_from_cause
     reraise(type(exception), exception, tb=exc_tb)
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/", line 1139, in _execute_context
   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/", line 450, in do_execute
     cursor.execute(statement, parameters)
   File "/usr/lib/python2.7/site-packages/pymysql/", line 146, in execute
     result = self._query(query)
   File "/usr/lib/python2.7/site-packages/pymysql/", line 296, in _query
   File "/usr/lib/python2.7/site-packages/pymysql/", line 781, in query
     self._affected_rows = self._read_query_result(unbuffered=unbuffered)
   File "/usr/lib/python2.7/site-packages/pymysql/", line 942, in _read_query_result
   File "/usr/lib/python2.7/site-packages/pymysql/", line 1138, in read
     first_packet = self.connection._read_packet()
   File "/usr/lib/python2.7/site-packages/pymysql/", line 906, in _read_packet
   File "/usr/lib/python2.7/site-packages/pymysql/", line 367, in check_error
   File "/usr/lib/python2.7/site-packages/pymysql/", line 120, in raise_mysql_exception
   File "/usr/lib/python2.7/site-packages/pymysql/", line 115, in _check_mysql_exception
     raise InternalError(errno, errorvalue)

DBError: (pymysql.err.InternalError) (1139, u"Got error 'nothing to repeat at offset 0' from regexp")

Libvirt + KVM

Changed in nova:
status: New → Confirmed
Changed in nova:
assignee: nobody → Anton Kremenetsky (anton-kremenetsky)
Changed in nova:
status: Confirmed → In Progress

Submitter: Jenkins
Branch: master

commit d01695886f3fb6ec1ffe4204e7f4bc72737992cf
Author: Anton Kremenetsky <email address hidden>
Date: Wed Jul 20 13:24:43 2016 -0400

    Add server name verification in instance search

    There are Nova API calls that can accept a server name
    as a regex parameter. For example, if the command
    'nova list --name <some_pattern>' is invoked with
    an incorrect value of the pattern, the nova-api makes
    a request to database and returns Http 500 error. Seems
    it's not convenient.

    This fix checks the pattern. If it isn't correct,
    the nova-api returns error 400 with a prompt of a bad regex.

    Change-Id: Iad63c668d09ec6a82ace29700fb4949c1acfbe1c
    Closes-Bug: #1603728

Changed in nova:
status: In Progress → Fix Released

This issue was fixed in the openstack/nova development milestone.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers