-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functional test for mount/unmount
- Loading branch information
Reuven V. Gonzales
committed
May 29, 2012
1 parent
3db89b8
commit a321874
Showing
6 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
import sys | ||
|
||
TEST_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
PROJECT_DIR = os.path.abspath(os.path.join(TEST_DIR, '..')) | ||
|
||
sys.path.insert(0, PROJECT_DIR) | ||
|
||
def fixtures_path(file_path=''): | ||
return os.path.join(TEST_DIR, 'fixtures', file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello, world! |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
tests.test_as_root | ||
~~~~~~~~~~~~~~~~~~ | ||
These are tests that must be run as root. They will be skipped by nose | ||
automatically if you are not root. | ||
These tests are meant to be as close to truly functional as possible. Take | ||
extra caution when running these tests. If this is not a stable release please | ||
do not run these tests in a production system. | ||
""" | ||
import os | ||
from testkit import temp_directory, random_string | ||
from tests import fixtures_path | ||
from .utils import only_as_root | ||
import overlay4u | ||
|
||
def read_file_data(filepath): | ||
f = open(filepath) | ||
data = f.read() | ||
f.close() | ||
return data | ||
|
||
@only_as_root | ||
def test_mount(): | ||
# Get lower directory from fixtures | ||
lower_dir = fixtures_path('lower_dir') | ||
# Read the hello.txt file in the lower_dir | ||
hello_orig_path = os.path.join(lower_dir, 'hello.txt') | ||
hello_orig_data = read_file_data(hello_orig_path) | ||
# Use a temp directory for the upper directory | ||
with temp_directory() as temp_upper_dir: | ||
# Use a temp directory for the mount point | ||
with temp_directory() as temp_mount_point: | ||
# Mount the overlay | ||
overlay = overlay4u.mount(temp_mount_point, lower_dir, temp_upper_dir) | ||
|
||
# Read the hello.txt file in the mount_point | ||
hello_overlay_path = os.path.join(temp_mount_point, 'hello.txt') | ||
hello_overlay_read_data = read_file_data(hello_overlay_path) | ||
|
||
# Assert that the text file's contents | ||
assert hello_orig_data == hello_overlay_read_data, ('Data ' | ||
'for hello.txt should be same in overlay and lower dir') | ||
|
||
# Write data to the overlay hello.txt | ||
hello_overlay_write = open(hello_overlay_path, 'w') | ||
|
||
# Generate a random string | ||
hello_overlay_write_data = random_string(50) | ||
|
||
# Write that string to the file | ||
hello_overlay_write.write(hello_overlay_write_data) | ||
|
||
# Save the file | ||
hello_overlay_write.close() | ||
|
||
# Unmount the overlay | ||
overlay.unmount() | ||
|
||
# Check that the file doesn't exist at the mount point now (means | ||
# successful unmount) | ||
assert os.path.exists(hello_overlay_path) == False, ('Mount ' | ||
'point should have nothing in it') | ||
|
||
# Check that the upper directory's hello.txt has the correct data | ||
# from the random generated string | ||
hello_upper_path = os.path.join(temp_upper_dir, 'hello.txt') | ||
hello_upper_data = read_file_data(hello_upper_path) | ||
assert hello_upper_data == hello_overlay_write_data | ||
|
||
# Check that the original file still has the same content | ||
current_orig_data = read_file_data(hello_orig_path) | ||
assert hello_orig_data == current_orig_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
from functools import wraps | ||
from nose.plugins.skip import SkipTest | ||
|
||
def only_as_root(f): | ||
@wraps(f) | ||
def decorated_function(*args, **kwargs): | ||
euid = os.geteuid() | ||
if euid != 0: | ||
raise SkipTest("Sorry. Test requires root") | ||
return f(*args, **kwargs) | ||
return decorated_function |