]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
tests: Add functional test run class
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 21 Jun 2019 15:32:44 +0000 (09:32 -0600)
committerDhaval Giani <dhaval.giani@oracle.com>
Tue, 17 Sep 2019 22:14:02 +0000 (15:14 -0700)
commitb9cfa8dd92b6230e37f06acb815b5d9018c499c2
treee904d95ad13de4eba6d0494aa2fb337edb1318e5
parentdd324beed63e2e236f861224421e0d8f20128789
tests: Add functional test run class

This commit adds a Run() class that can invoke Python's Popen
command.  This class provides a static method, run(), that will
execute the command via Python's subprocess module.

Example usages:
  # delete foo.conf
  Run.run(['rm', '-f', '/tmp/foo.conf'])

  # Use cgset to set SomeCgroup's cpu.shares to 500
  cmd = ['cgset', '-r', 'cpu.shares=500', 'SomeCgroup']
  Run.run(cmd)

  # get info on current user
  Run.run('id')

  # write to a file.  Note that this must be run in a shell
  Run.run(['echo', 'some data', '>>', 'some_file'], shell_bool=True)

Example output:

  Jun 27 12:34:18: DEBUG: run:
          command = sudo lxc-info --config=lxc.rootfs -n test_libcg
          ret = 0
          stdout = lxc.rootfs = /container/test_libcg/rootfs
          stderr =

  Jun 27 12:34:18: DEBUG: run:
          command = sudo lxc-attach -n test_libcg -- /libcg/src/tools/.libs/cgget -n -v -r cpu.shares 001cgget
          ret = 0
          stdout = 512
          stderr =

If the command fails, Run.run() throws a RunError exception which
contains the return code, stdout, and stderr from the command.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Dhaval Giani <dhaval.giani@oracle.com>
Signed-off-by: Dhaval Giani <dhaval.giani@oracle.com>
tests/ftests/run.py [new file with mode: 0644]