← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1726209] [NEW] Db expand fails if the db is previously synced using 'db sync' command

 

Public bug reported:

If you have synced the database using "db sync" command and if you
attempt to run "db expand" command, it gives following error.

Actual Result:
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_expand01, add visibility to images
CRITI [glance] Unhandled error
Traceback (most recent call last):
  File "/usr/local/bin/glance-manage", line 10, in <module>
    sys.exit(main())
  File "/opt/stack/glance/glance/cmd/manage.py", line 464, in main
    return CONF.command.action_fn(*func_args, **func_kwargs)
  File "/opt/stack/glance/glance/cmd/manage.py", line 144, in expand
    self.sync(version=expand_head)
  File "/opt/stack/glance/glance/cmd/manage.py", line 120, in sync
    alembic_command.upgrade(a_config, version)
  File "/usr/local/lib/python2.7/dist-packages/alembic/command.py", line 254, in upgrade
    script.run_env()
  File "/usr/local/lib/python2.7/dist-packages/alembic/script/base.py", line 425, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/usr/local/lib/python2.7/dist-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/local/lib/python2.7/dist-packages/alembic/util/compat.py", line 75, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/env.py", line 88, in <module>
    run_migrations_online()
  File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/env.py", line 83, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/local/lib/python2.7/dist-packages/alembic/runtime/environment.py", line 836, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/local/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 330, in run_migrations
    step.migration_fn(**kw)
  File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/versions/ocata_expand01_add_visibility.py", line 149, in upgrade
    _add_visibility_column(meta)
  File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/versions/ocata_expand01_add_visibility.py", line 126, in _add_visibility_column
    op.add_column('images', v_col)
  File "<string>", line 8, in add_column
  File "<string>", line 3, in add_column
  File "/usr/local/lib/python2.7/dist-packages/alembic/operations/ops.py", line 1565, in add_column
    return operations.invoke(op)
  File "/usr/local/lib/python2.7/dist-packages/alembic/operations/base.py", line 318, in invoke
    return fn(self, operation)
  File "/usr/local/lib/python2.7/dist-packages/alembic/operations/toimpl.py", line 123, in add_column
    schema=schema
  File "/usr/local/lib/python2.7/dist-packages/alembic/ddl/impl.py", line 172, in add_column
    self._exec(base.AddColumn(table_name, column, schema=schema))
  File "/usr/local/lib/python2.7/dist-packages/alembic/ddl/impl.py", line 118, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 945, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1002, in _execute_ddl
    compiled
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1398, in _handle_dbapi_exception
    util.raise_from_cause(newraise, exc_info)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 856, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1057, in _read_query_result
    result.read()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1340, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1014, in _read_packet
    packet.check_error()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 393, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
DBError: (pymysql.err.InternalError) (1060, u"Duplicate column name 'visibility'") [SQL: u"ALTER TABLE images ADD COLUMN visibility ENUM('private','public','shared','community')"]

Expected result: It shouldn't allow operator to run "db expand" command as the db is already synced to pike01. There are two methods to upgrade the db.
A. db sync
B. db expand/migrate/contract

If operator has upgraded the db using method A, then it shouldn't allow
operator to upgrade the db again using method B and vice versa.

Steps to reproduce:
1. Install glance using devstack (basically it creates and upgrades db using "db sync" command)
2. Run glance-manage db expand

** Affects: glance
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to Glance.
https://bugs.launchpad.net/bugs/1726209

Title:
  Db expand fails if the db is previously synced using 'db sync' command

Status in Glance:
  New

Bug description:
  If you have synced the database using "db sync" command and if you
  attempt to run "db expand" command, it gives following error.

  Actual Result:
  INFO  [alembic.runtime.migration] Context impl MySQLImpl.
  INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
  INFO  [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_expand01, add visibility to images
  CRITI [glance] Unhandled error
  Traceback (most recent call last):
    File "/usr/local/bin/glance-manage", line 10, in <module>
      sys.exit(main())
    File "/opt/stack/glance/glance/cmd/manage.py", line 464, in main
      return CONF.command.action_fn(*func_args, **func_kwargs)
    File "/opt/stack/glance/glance/cmd/manage.py", line 144, in expand
      self.sync(version=expand_head)
    File "/opt/stack/glance/glance/cmd/manage.py", line 120, in sync
      alembic_command.upgrade(a_config, version)
    File "/usr/local/lib/python2.7/dist-packages/alembic/command.py", line 254, in upgrade
      script.run_env()
    File "/usr/local/lib/python2.7/dist-packages/alembic/script/base.py", line 425, in run_env
      util.load_python_file(self.dir, 'env.py')
    File "/usr/local/lib/python2.7/dist-packages/alembic/util/pyfiles.py", line 93, in load_python_file
      module = load_module_py(module_id, path)
    File "/usr/local/lib/python2.7/dist-packages/alembic/util/compat.py", line 75, in load_module_py
      mod = imp.load_source(module_id, path, fp)
    File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/env.py", line 88, in <module>
      run_migrations_online()
    File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/env.py", line 83, in run_migrations_online
      context.run_migrations()
    File "<string>", line 8, in run_migrations
    File "/usr/local/lib/python2.7/dist-packages/alembic/runtime/environment.py", line 836, in run_migrations
      self.get_context().run_migrations(**kw)
    File "/usr/local/lib/python2.7/dist-packages/alembic/runtime/migration.py", line 330, in run_migrations
      step.migration_fn(**kw)
    File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/versions/ocata_expand01_add_visibility.py", line 149, in upgrade
      _add_visibility_column(meta)
    File "/opt/stack/glance/glance/db/sqlalchemy/alembic_migrations/versions/ocata_expand01_add_visibility.py", line 126, in _add_visibility_column
      op.add_column('images', v_col)
    File "<string>", line 8, in add_column
    File "<string>", line 3, in add_column
    File "/usr/local/lib/python2.7/dist-packages/alembic/operations/ops.py", line 1565, in add_column
      return operations.invoke(op)
    File "/usr/local/lib/python2.7/dist-packages/alembic/operations/base.py", line 318, in invoke
      return fn(self, operation)
    File "/usr/local/lib/python2.7/dist-packages/alembic/operations/toimpl.py", line 123, in add_column
      schema=schema
    File "/usr/local/lib/python2.7/dist-packages/alembic/ddl/impl.py", line 172, in add_column
      self._exec(base.AddColumn(table_name, column, schema=schema))
    File "/usr/local/lib/python2.7/dist-packages/alembic/ddl/impl.py", line 118, in _exec
      return conn.execute(construct, *multiparams, **params)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 945, in execute
      return meth(self, multiparams, params)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
      return connection._execute_ddl(self, multiparams, params)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1002, in _execute_ddl
      compiled
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context
      context)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1398, in _handle_dbapi_exception
      util.raise_from_cause(newraise, exc_info)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
      reraise(type(exception), exception, tb=exc_tb, cause=cause)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
      context)
    File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 470, in do_execute
      cursor.execute(statement, parameters)
    File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 166, in execute
      result = self._query(query)
    File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 322, in _query
      conn.query(q)
    File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 856, in query
      self._affected_rows = self._read_query_result(unbuffered=unbuffered)
    File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1057, in _read_query_result
      result.read()
    File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1340, in read
      first_packet = self.connection._read_packet()
    File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1014, in _read_packet
      packet.check_error()
    File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 393, in check_error
      err.raise_mysql_exception(self._data)
    File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception
      raise errorclass(errno, errval)
  DBError: (pymysql.err.InternalError) (1060, u"Duplicate column name 'visibility'") [SQL: u"ALTER TABLE images ADD COLUMN visibility ENUM('private','public','shared','community')"]

  Expected result: It shouldn't allow operator to run "db expand" command as the db is already synced to pike01. There are two methods to upgrade the db.
  A. db sync
  B. db expand/migrate/contract

  If operator has upgraded the db using method A, then it shouldn't
  allow operator to upgrade the db again using method B and vice versa.

  Steps to reproduce:
  1. Install glance using devstack (basically it creates and upgrades db using "db sync" command)
  2. Run glance-manage db expand

To manage notifications about this bug go to:
https://bugs.launchpad.net/glance/+bug/1726209/+subscriptions