Abstract 'rm' shell command in guestagent

Bug #1438429 reported by Petr Malik
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack DBaaS (Trove)
Fix Released
Low
Petr Malik

Bug Description

Abstract 'rm/chmod' shell commands in guestagent

see-also: bug/1431618

The goal of this patch set is to provide a simple straightforward
interface for most common shell calls used across the guestagent
code while encapsulating the related shell code into a single module.

This patch set includes refactoring of 'rm' and 'chmod'
calls. It adds unit tests ('guestagent/test_operating_system')
for the above implementations.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to trove (master)

Fix proposed to branch: master
Review: https://review.openstack.org/170642

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

Reviewed: https://review.openstack.org/170642
Committed: https://git.openstack.org/cgit/openstack/trove/commit/?id=2eb05f8897bb17def1573380da0a05942c42cf29
Submitter: Jenkins
Branch: master

commit 2eb05f8897bb17def1573380da0a05942c42cf29
Author: Petr Malik <email address hidden>
Date: Thu Apr 2 15:23:57 2015 -0400

    Abstract rm/chmod shell commands in guestagent

    The guestagent commonly executes basic shell commands
    across multiple files and datastores.
    Each datastore currently scripts its own shell calls.
    Apart from cluttering the Python code with shell constructs,
    it also makes maintenance of the shell calls more difficult by
    requiring the same change be made across multiple lines,
    source files and/or potentially even datastores.

    The goal of this patch set is to provide a simple straightforward
    interface for most common shell calls used across the guestagent
    code while encapsulating the related shell code into a single module.

    This patch set includes refactoring of 'rm' and 'chmod' calls.
    It also introduces unit tests ('guestagent/test_operating_system')
    for the above implementations.

    The shell code was moved into 'common/operating_system' module.
    The replacing interface is:

    def remove(path, force=False, recursive=True, **kwargs):
        """Remove a given file or directory.

    def chmod(path, mode, recursive=True, force=False, **kwargs):
        """Changes the mode of a given file.

    The calls also take optional keyword arguments:
        :param as_root: Execute as root.
        :type as_root: boolean

        :param timeout: Number of seconds if specified,
                                 default if not.
                                 There is no timeout if set to None.
        :type timeout: integer

    Notes on the representation of file permissions (modes):

    Generally, one can 'reset' (set modes to an exact value) or
    'add'/'remove' modes to/from the current mode.
    The above operations are represented by a new
    'operating_system.FileMode' class.
    For example, the read permission for all can be represented in the octal
    form as '444'.
    Mode on a given file can be 'reset' to this exact value
    (chmod =444 "path")
    The permissions can be added to (chmod +444 "path")
    ... or removed from the current mode (chmod -444 "path")

    The Modes constructor takes three optional lists of octal modes (flags),
    one for each of the above operations.

    "chmod u+x,g=rw,o=r" can be represented as:
    FileMode(reset=[0064], add=[0100])
    or
    FileMode(reset=[0040, 0020, 0004], add=[0100])
    or
    FileMode(reset=[0040 | 0020 | 0004], add=[0100])

    See 'operating_system.FileMode' struct for some common file modes.
    See the Python 'stat' module for more flags also accepted by the
    Python build-in functions such as 'os.chmod'.

    Change-Id: Idbfa05fdc5c48aed31989578f828a7f57aca3be2
    Closes-Bug: 1438429
    Related-Bug: 1431618
    Related-Bug: 1438430

Changed in trove:
status: In Progress → Fix Committed
Changed in trove:
milestone: none → liberty-1
importance: Undecided → Low
Thierry Carrez (ttx)
Changed in trove:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in trove:
milestone: liberty-1 → 4.0.0
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.