Edgewall Software
Modify

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#12988 closed defect (fixed)

Upgrade reported as failed if trac.ini.sample is not writable

Reported by: Ryan J Ollos Owned by: Jun Omae
Priority: normal Milestone: 1.0.17
Component: general Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

OSError is handled when writing sample configuration file on Environment upgrade.

API Changes:
Internal Changes:

Description

Upgrade reported as failed if trac.ini.sample is not writable:

$ trac-admin /var/trac/trac upgrade

The upgrade failed. Please fix the issue and try again.

OSError: [Errno 13] Permission denied: '/var/trac/trac/conf/trac.ini.sample'

However, since trac.ini.sample is updated after the database upgrade, the database upgrade has succeeded and executing upgrade again reports that upgrade isn't needed. This might be confusing to the user.

Better behavior would be to update the trac.ini.sample before the upgrade so that the database isn't upgraded in the event of failure updating trac.ini.sample.

I've only tested with trunk so far. At least on trunk, the following change seems to be good:

  • trac/env.py

    diff --git a/trac/env.py b/trac/env.py
    index b7dae8351..cc24b6577 100644
    a b class Environment(Component, ComponentManager):  
    770770            except Exception as e:
    771771                raise BackupError(e)
    772772
     773        self._update_sample_config()
     774
    773775        for participant in upgraders:
    774776            self.log.info("upgrading %s...", participant)
    775777            with self.component_guard(participant, reraise=True):
    class Environment(Component, ComponentManager):  
    779781            if dbm.connection_uri != 'sqlite::memory:':
    780782                dbm.shutdown()
    781783
    782         self._update_sample_config()
    783784        del self.database_version
    784785        return True

Attachments (0)

Change History (5)

comment:1 by Jun Omae, 3 years ago

I'm trying to reproduce it with non-writable $ENV/conf/trac.ini.sample file or $ENV/conf directory but cannot reproduce….

Anyway, IOError is trapped when writing the sample file but OSError is not trapped at source:/tags/trac-1.2.2/trac/env.py@:894#L882. I consider we should trap EnvironmentError rather than IOError.

         try:
             config.save()
             self.log.info("Wrote sample configuration file with the new "
                           "settings and their default values: %s",
                           filename)
-        except IOError as e:
+        except EnvironmentError as e:
             self.log.warn("Couldn't write sample configuration file (%s)", e,
                           exc_info=True)

comment:2 by Ryan J Ollos, 3 years ago

Did you try using trunk? I can reproduce on Linux and OSX running db45.py upgrade step.

$ ls -al ../tracenvs/proj-1.3/conf/trac.ini.sample
-rw-r--r--  1 root  staff  8543 Mar  2 22:33 ../tracenvs/proj-1.3/conf/trac.ini.sample
Last edited 3 years ago by Ryan J Ollos (previous) (diff)

comment:3 by Jun Omae, 3 years ago

Okay. Reproduced it when upgrading 1.0.15 to 1.2.2 with different user id with owner of trac.ini.sample.

$ /venv/trac/1.2.2/bin/trac-admin /dev/shm/tracenv initenv 'My Project' sqlite:db/trac.db
$ /venv/trac/1.2.2/bin/trac-admin /dev/shm/tracenv config set logging log_type file
$ sudo chown root:root /dev/shm/tracenv/conf/trac.ini.sample
$ ls -la /dev/shm/tracenv/conf
total 16
drwxr-xr-x 2 jun66j5 jun66j5   80 Mar  5 17:11 .
drwxr-xr-x 8 jun66j5 jun66j5  200 Mar  5 17:11 ..
-rw------- 1 jun66j5 jun66j5 6074 Mar  5 17:11 trac.ini
-rw-r--r-- 1 root    root    5534 Mar  5 17:11 trac.ini.sample
$ id
uid=1000(jun66j5) gid=1000(jun66j5) groups=1000(jun66j5),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),111(lpadmin),112(sambashare)
$ /venv/trac/1.2.2/bin/trac-admin /dev/shm/tracenv upgrade
The upgrade failed. Please fix the issue and try again.

OSError: [Errno 13] Permission denied: '/run/shm/tracenv/conf/trac.ini.sample'

trac.log:

2018-03-05 17:27:05,293 Trac[console] ERROR: Exception in trac-admin command: u'upgrade'
Traceback (most recent call last):
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/admin/console.py", line 112, in onecmd
    rv = cmd.Cmd.onecmd(self, line) or 0
  File "/usr/lib/python2.6/cmd.py", line 218, in onecmd
    return self.default(line)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/admin/console.py", line 291, in default
    return self.cmd_mgr.execute_command(*args)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/admin/api.py", line 127, in execute_command
    return f(*fargs)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/env.py", line 1100, in _do_upgrade
    self.env.upgrade(backup=no_backup is None)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/env.py", line 836, in upgrade
    participant.upgrade_environment(*args)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/env.py", line 878, in upgrade_environment
    self._update_sample_config()
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/env.py", line 890, in _update_sample_config
    config.save()
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/config.py", line 351, in save
    self._write(parser)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/config.py", line 435, in _write
    wait_for_file_mtime_change(self.filename)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/util/compat.py", line 99, in wait_for_file_mtime_change
    touch_file(filename)
  File "/venv/trac/1.2.2/lib/python2.6/site-packages/trac/util/__init__.py", line 283, in touch_file
    os.utime(filename, None)
OSError: [Errno 13] Permission denied: '/run/shm/tracenv/conf/trac.ini.sample'
Last edited 3 years ago by Jun Omae (previous) (diff)

comment:4 by Ryan J Ollos, 3 years ago

Milestone: 1.2.31.0.17
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Trapping EnvironmentError seems like the right solution. Committed to 1.0-stable in r16437, merged in r16438, r16439.

comment:5 by Ryan J Ollos, 3 years ago

Owner: changed from Ryan J Ollos to Jun Omae

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.