Skip to content

Commit

Permalink
Using subwrap instead of vanilla subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven V. Gonzales committed May 30, 2012
1 parent a321874 commit 713c880
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
3 changes: 3 additions & 0 deletions VEfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
requirements:
- subwrap

---
profile: development

Expand Down
1 change: 1 addition & 0 deletions VEfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
subwrap (subwrap==0.0.1)
nose (nose==1.1.2)
testkit (testkit==0.1.1)
fudge (fudge==1.0.3)
Expand Down
9 changes: 3 additions & 6 deletions overlay4u/overlay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import subprocess
import subwrap
from .mountutils import MountTable

class AlreadyMounted(Exception):
Expand All @@ -22,15 +22,12 @@ def mount(cls, mount_point, lower_dir, upper_dir, mount_table=None):
# Build mount options
options = "rw,lowerdir=%s,upperdir=%s" % (lower_dir, upper_dir)
# Run the actual mount
process = subprocess.Popen(['mount', '-t', 'overlayfs', '-o', options,
process = subwrap.run(['mount', '-t', 'overlayfs', '-o', options,
'overlayfs', mount_point])
# Wait for the mount to complete
process.wait()
return cls(mount_point, lower_dir, upper_dir)

def unmount(self):
process = subprocess.Popen(['umount', self.mount_point])
process.wait()
process = subwrap.run(['umount', self.mount_point])

def __init__(self, mount_point, lower_dir, upper_dir):
self.mount_point = mount_point
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from setuptools import setup, find_packages
import sys, os

VERSION = '0.0.1-dev'

Expand All @@ -18,7 +17,9 @@
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
install_requires=[],
install_requires=[
'subwrap',
],
entry_points={},
classifiers=[
'License :: OSI Approved :: MIT License',
Expand Down
1 change: 0 additions & 1 deletion tests/test_mountutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
TEST_MOUNT_LIST_ENTRY3 = '/dev3/.dir on /dir3/.dir type fstype2 (opt1=val,opt2,opt3=val)'
TEST_MOUNT_LIST_ENTRY4 = '/dev4/dir-with-dash on /dir4/dir-with-dash type fstype2 (opt1=val,opt2,opt3=val)'


def test_generated_match_entry_line():
tests = [
(TEST_MOUNT_LIST_ENTRY1, (
Expand Down
29 changes: 14 additions & 15 deletions tests/test_overlay4u.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import overlay4u
from overlay4u.overlay import AlreadyMounted

@fudge.patch('subprocess.Popen')
def test_fake_mount(fake_popen):
@fudge.patch('subwrap.run')
def test_fake_mount(fake_run):
from overlay4u.overlay import OverlayFS

# Setup Popen expectation
fake_process = fake_popen.expects_call().returns_fake()
fake_process.expects('wait')
# Setup subwrap.run
fake_run.expects_call()

# Setup fake mount table
fake_mount_table = fudge.Fake('mount_table')
Expand All @@ -23,34 +22,34 @@ def test_fake_mount(fake_popen):
assert overlay.lower_dir == 'lower'
assert overlay.upper_dir == 'upper'

@fudge.patch('subprocess.Popen', 'overlay4u.overlay.MountTable')
def test_fake_mount_with_fake_table(fake_popen, fake_table_class):
fake_popen.is_a_stub()
@fudge.patch('subwrap.run', 'overlay4u.overlay.MountTable')
def test_fake_mount_with_fake_table(fake_run, fake_table_class):
fake_run.expects_call()
fake_table = fake_table_class.expects('load').returns_fake()
fake_table.expects('is_mounted').returns(False)

overlay = overlay4u.mount('mount_point', 'lower', 'upper')

@raises(AlreadyMounted)
@fudge.patch('subprocess.Popen')
def test_fake_mount_twice(fake_popen):
@fudge.patch('subwrap.run')
def test_fake_mount_twice(fake_run):
# Setup fake mount table checker
fake_mount_table = fudge.Fake('mount_table')
(fake_mount_table.expects('is_mounted').with_args('mount_point')
.returns(True))

# Make a stub for popen. just in case it gets through
fake_popen.is_a_stub()
# Make a stub for subwrap.run. just in case it gets through
fake_run.expects_call()

# Use dependency injection to change mount verification technique
overlay = overlay4u.mount('mount_point', 'lower', 'upper',
mount_table=fake_mount_table)

@fudge.patch('subprocess.Popen', 'overlay4u.overlay.MountTable')
def test_fake_unmount(fake_popen, fake_table_class):
@fudge.patch('subwrap.run', 'overlay4u.overlay.MountTable')
def test_fake_unmount(fake_run, fake_table_class):
# Tests that unmount method exists.
# FIXME we need to make this a bit better
fake_popen.is_a_stub()
fake_run.expects_call()

fake_table = fake_table_class.expects('load').returns_fake()
fake_table.expects('is_mounted').returns(False)
Expand Down

0 comments on commit 713c880

Please sign in to comment.