os.rename causes rabbitmq-server charm to fail if /tmp and /etc sit on different partitions

Bug #1833804 reported by Pedro Guimarães
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack RabbitMQ Server Charm
Fix Released
Low
David Ames

Bug Description

Using latest charm from cs:rabbitmq-server
Ubuntu Xenial distro

When deployed, charm is failing at config-changed hook with:

Traceback (most recent call last):
  File "./hooks/config-changed", line 972, in <module>
    hooks.execute(sys.argv)
  File "/var/lib/juju/agents/unit-landscape-rabbitmq-server-1/charm/charmhelpers/core/hookenv.py", line 914, in execute
    self._hooks[hook_name]()
  File "/var/lib/juju/agents/unit-landscape-rabbitmq-server-1/charm/hooks/rabbit_utils.py", line 885, in wrapped_f
    f(*args, **kwargs)
  File "/var/lib/juju/agents/unit-landscape-rabbitmq-server-1/charm/charmhelpers/contrib/hardening/harden.py", line 93, in _harden_inner2
    return f(*args, **kwargs)
  File "./hooks/config-changed", line 788, in config_changed
    rabbit.update_hosts_file({cluster_ip: rabbit.get_unit_hostname()})
  File "/var/lib/juju/agents/unit-landscape-rabbitmq-server-1/charm/hooks/rabbit_utils.py", line 740, in update_hosts_file
    os.rename(tmpfile.name, HOSTS_FILE)
OSError: [Errno 18] Invalid cross-device link: '/tmp/tmplitmyyi7' -> '/etc/hosts'

os.rename do not work if we have source and destination sitting on different partitions.

Digging on this error, I've found:
Following: https://github.com/google/clusterfuzz-tools/pull/360

Which basically replaces os.rename for shutil.move function.
Manually applying this same change fixed the problem and rerunning the hook fixed the issue.

Tags: cpe-onsite
James Page (james-page)
Changed in charm-rabbitmq-server:
status: New → Triaged
importance: Undecided → Low
Jeff Hillman (jhillman)
tags: added: cpe-onsite
David Ames (thedac)
Changed in charm-rabbitmq-server:
assignee: nobody → David Ames (thedac)
milestone: none → 19.10
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to charm-rabbitmq-server (master)

Fix proposed to branch: master
Review: https://review.opendev.org/680494

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

Reviewed: https://review.opendev.org/680494
Committed: https://git.openstack.org/cgit/openstack/charm-rabbitmq-server/commit/?id=fb1b4bec0ff838e4af15058ae015e5ee6842c12a
Submitter: Zuul
Branch: master

commit fb1b4bec0ff838e4af15058ae015e5ee6842c12a
Author: David Ames <email address hidden>
Date: Thu Sep 5 12:05:00 2019 -0700

    Use shutil.move rather than os.rename

    When the source and destination file paths are not on the same partition
    os.rename raises OSError: [Errno 18] Invalid cross-device link.

    Use shutil.move instead.

    Change-Id: I28d6cb6c15a4496243fab7ec6c7eedcd1422f4c2
    Closes-Bug: #1833804

Changed in charm-rabbitmq-server:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to charm-rabbitmq-server (stable/19.07)

Fix proposed to branch: stable/19.07
Review: https://review.opendev.org/680635

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to charm-rabbitmq-server (stable/19.07)

Reviewed: https://review.opendev.org/680635
Committed: https://git.openstack.org/cgit/openstack/charm-rabbitmq-server/commit/?id=ba24fa2056ea5e5870470425dd0a99e428f1729c
Submitter: Zuul
Branch: stable/19.07

commit ba24fa2056ea5e5870470425dd0a99e428f1729c
Author: David Ames <email address hidden>
Date: Thu Sep 5 12:05:00 2019 -0700

    Use shutil.move rather than os.rename

    When the source and destination file paths are not on the same partition
    os.rename raises OSError: [Errno 18] Invalid cross-device link.

    Use shutil.move instead.

    Change-Id: I28d6cb6c15a4496243fab7ec6c7eedcd1422f4c2
    Closes-Bug: #1833804
    (cherry picked from commit fb1b4bec0ff838e4af15058ae015e5ee6842c12a)

David Ames (thedac)
Changed in charm-rabbitmq-server:
status: Fix Committed → Fix Released
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.