Skip to content

Commit 31ea055

Browse files
authored
Merge pull request #28 from E3SM-Project/v1.3
v0.3.0
2 parents 8a8fa8e + dfde53d commit 31ea055

File tree

15 files changed

+660
-116
lines changed

15 files changed

+660
-116
lines changed

conda/meta.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package:
22
name: zstash
3-
version: 0.2.0
3+
version: 0.3.0
44

55
source:
66
git_url: https://github.com/E3SM-Project/zstash
7-
git_rev: v0.2.0
7+
git_rev: v0.3.0
88

99
build:
1010
script: python setup.py install
1111

1212
requirements:
1313
build:
14-
- python 2
14+
- python 3
1515
- setuptools
1616

1717
run:
18-
- python 2
18+
- python 3
1919

2020
about:
2121
home: https://github.com/E3SM-Project/zstash

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="zstash",
5-
version="0.2.0",
5+
version="0.3.0",
66
author="Chris Golaz, Zeshawn Shaheen",
77
88
description="Long term HPSS archiving software for E3SM",

tests/test.py

Lines changed: 187 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
Run the test suite like:
3+
python test.py
4+
You'll get a statement printed
5+
if all of the tests pass.
6+
"""
7+
18
import os
29
import sys
310
import subprocess
@@ -19,6 +26,14 @@ def run_cmd(cmd):
1926
cmd = cmd.split()
2027
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2128
output, err = p.communicate()
29+
30+
# When running in Python 3, the output of subprocess.Popen.communicate()
31+
# is a bytes object. We need to convert it to a string.
32+
if isinstance(output, bytes):
33+
output = output.decode("utf-8")
34+
if isinstance(err, bytes):
35+
err = err.decode("utf-8")
36+
2237
print(output)
2338
print(err)
2439
return output, err
@@ -52,6 +67,8 @@ def cleanup():
5267
shutil.rmtree('zstash_test')
5368
if os.path.exists('zstash_test_backup'):
5469
shutil.rmtree('zstash_test_backup')
70+
if os.path.exists('zstash'):
71+
shutil.rmtree('zstash')
5572
cmd = 'hsi rm -R {}'.format(HPSS_PATH)
5673
run_cmd(cmd)
5774

@@ -62,9 +79,9 @@ def stop():
6279
cleanup()
6380
sys.exit()
6481

65-
66-
# TODO: Change the hpss directory to a dir that's accessable to everyone.
67-
HPSS_PATH='/home/z/zshaheen/zstash_test'
82+
# Makes this in the home dir of the user on HPSS.
83+
# Ex: /home/z/zshaheen/zstash_test
84+
HPSS_PATH='zstash_test'
6885

6986
# Create files and directories
7087
print('Creating files.')
@@ -92,29 +109,16 @@ def stop():
92109
if not os.path.lexists('zstash_test/file0_hard.txt'):
93110
os.link('zstash_test/file0.txt', 'zstash_test/file0_hard.txt')
94111

112+
95113
print('Adding files to HPSS')
96114
cmd = 'zstash create --hpss={} zstash_test'.format(HPSS_PATH)
97115
output, err = run_cmd(cmd)
98116
str_in(output+err, 'Transferring file to HPSS')
99117
str_not_in(output+err, 'ERROR')
100118

101-
print('Testing ls')
102-
cmd = 'zstash ls --hpss={}'.format(HPSS_PATH)
103-
output, err = run_cmd(cmd)
104-
str_in(output+err, 'file0.txt')
105-
str_not_in(output+err, 'ERROR')
106-
cmd = 'zstash ls -l --hpss={}'.format(HPSS_PATH)
107-
output, err = run_cmd(cmd)
108-
str_in(output+err, 'tar')
109-
str_not_in(output+err, 'ERROR')
110119

111120
print('Testing chgrp')
112121
GROUP = 'acme'
113-
print('First, make sure that the files are not already in the {} group'.format(GROUP))
114-
cmd = 'hsi ls -l {}'.format(HPSS_PATH)
115-
output, err = run_cmd(cmd)
116-
str_not_in(output+err, GROUP)
117-
str_not_in(output+err, 'ERROR')
118122
print('Running zstash chgrp')
119123
cmd = 'zstash chgrp -R {} {}'.format(GROUP, HPSS_PATH)
120124
output, err = run_cmd(cmd)
@@ -125,6 +129,7 @@ def stop():
125129
str_in(output+err, 'acme')
126130
str_not_in(output+err, 'ERROR')
127131

132+
128133
print('Running update on the newly created directory, nothing should happen')
129134
os.chdir('zstash_test')
130135
cmd = 'zstash update --hpss={}'.format(HPSS_PATH)
@@ -133,6 +138,7 @@ def stop():
133138
str_in(output+err, 'Nothing to update')
134139
str_not_in(output+err, 'ERROR')
135140

141+
136142
print('Testing update with an actual change')
137143
if not os.path.exists('zstash_test/dir2'):
138144
os.mkdir('zstash_test/dir2')
@@ -145,24 +151,108 @@ def stop():
145151
os.chdir('../')
146152
str_in(output+err, 'Transferring file to HPSS')
147153
str_not_in(output+err, 'ERROR')
148-
# Make sure none of the old files are moved
154+
# Make sure none of the old files are moved.
149155
str_not_in(output+err, 'file0')
150156
str_not_in(output+err, 'file_empty')
151157
str_not_in(output+err, 'empty_dir')
152158
str_not_in(output+err, 'ERROR')
153159

160+
161+
print('Adding many more files to the HPSS archive.')
162+
msg = 'This is because we need many separate tar archives'
163+
msg += ' for testing zstash extract/check with parallel.'
164+
print(msg)
165+
write_file('zstash_test/file3.txt', 'file3 stuff')
166+
os.chdir('zstash_test')
167+
cmd = 'zstash update --hpss={}'.format(HPSS_PATH)
168+
output, err = run_cmd(cmd)
169+
os.chdir('../')
170+
write_file('zstash_test/file4.txt', 'file4 stuff')
171+
os.chdir('zstash_test')
172+
cmd = 'zstash update --hpss={}'.format(HPSS_PATH)
173+
output, err = run_cmd(cmd)
174+
os.chdir('../')
175+
write_file('zstash_test/file5.txt', 'file5 stuff')
176+
os.chdir('zstash_test')
177+
cmd = 'zstash update --hpss={}'.format(HPSS_PATH)
178+
output, err = run_cmd(cmd)
179+
os.chdir('../')
180+
181+
182+
print('Testing ls')
183+
cmd = 'zstash ls --hpss={}'.format(HPSS_PATH)
184+
output, err = run_cmd(cmd)
185+
str_in(output+err, 'file0.txt')
186+
str_not_in(output+err, 'ERROR')
187+
cmd = 'zstash ls -l --hpss={}'.format(HPSS_PATH)
188+
output, err = run_cmd(cmd)
189+
str_in(output+err, 'tar')
190+
str_not_in(output+err, 'ERROR')
191+
192+
154193
print('Testing the checking functionality')
155194
cmd = 'zstash check --hpss={}'.format(HPSS_PATH)
156195
output, err = run_cmd(cmd)
196+
str_in(output+err, 'Checking file0.txt')
197+
str_in(output+err, 'Checking file0_hard.txt')
198+
str_in(output+err, 'Checking file0_soft.txt')
199+
str_in(output+err, 'Checking file_empty.txt')
200+
str_in(output+err, 'Checking dir/file1.txt')
201+
str_in(output+err, 'Checking empty_dir')
202+
str_in(output+err, 'Checking dir2/file2.txt')
203+
str_in(output+err, 'Checking file3.txt')
204+
str_in(output+err, 'Checking file4.txt')
205+
str_in(output+err, 'Checking file5.txt')
157206
str_not_in(output+err, 'ERROR')
158207

208+
159209
print('Testing the extract functionality')
160210
os.rename('zstash_test', 'zstash_test_backup')
161211
os.mkdir('zstash_test')
162212
os.chdir('zstash_test')
163213
cmd = 'zstash extract --hpss={}'.format(HPSS_PATH)
164214
output, err = run_cmd(cmd)
165215
os.chdir('../')
216+
str_in(output+err, 'Extracting file0.txt')
217+
str_in(output+err, 'Extracting file0_hard.txt')
218+
str_in(output+err, 'Extracting file0_soft.txt')
219+
str_in(output+err, 'Extracting file_empty.txt')
220+
str_in(output+err, 'Extracting dir/file1.txt')
221+
str_in(output+err, 'Extracting empty_dir')
222+
str_in(output+err, 'Extracting dir2/file2.txt')
223+
str_in(output+err, 'Extracting file3.txt')
224+
str_in(output+err, 'Extracting file4.txt')
225+
str_in(output+err, 'Extracting file5.txt')
226+
str_not_in(output+err, 'ERROR')
227+
str_not_in(output+err, 'Not extracting')
228+
229+
print('Testing the extract functionality again, nothing should happen')
230+
os.chdir('zstash_test')
231+
cmd = 'zstash extract --hpss={}'.format(HPSS_PATH)
232+
output, err = run_cmd(cmd)
233+
os.chdir('../')
234+
str_in(output+err, 'Not extracting file0.txt')
235+
str_in(output+err, 'Not extracting file0_hard.txt')
236+
# It's okay to extract the symlinks.
237+
str_not_in(output+err, 'Not extracting file0_soft.txt')
238+
str_in(output+err, 'Not extracting file_empty.txt')
239+
str_in(output+err, 'Not extracting dir/file1.txt')
240+
# It's okay to extract empty dirs.
241+
str_not_in(output+err, 'Not extracting empty_dir')
242+
str_in(output+err, 'Not extracting dir2/file2.txt')
243+
str_in(output+err, 'Not extracting file3.txt')
244+
str_in(output+err, 'Not extracting file4.txt')
245+
str_in(output+err, 'Not extracting file5.txt')
246+
str_not_in(output+err, 'ERROR')
247+
248+
249+
print('Deleting the extracted files and doing it again in parallel.')
250+
shutil.rmtree('zstash_test')
251+
os.mkdir('zstash_test')
252+
os.chdir('zstash_test')
253+
cmd = 'zstash extract --hpss={} --workers=3'.format(HPSS_PATH)
254+
output, err = run_cmd(cmd)
255+
os.chdir('../')
166256
str_in(output+err, 'Transferring from HPSS')
167257
str_in(output+err, 'Extracting file0.txt')
168258
str_in(output+err, 'Extracting file0_hard.txt')
@@ -171,19 +261,93 @@ def stop():
171261
str_in(output+err, 'Extracting dir/file1.txt')
172262
str_in(output+err, 'Extracting empty_dir')
173263
str_in(output+err, 'Extracting dir2/file2.txt')
264+
str_in(output+err, 'Extracting file3.txt')
265+
str_in(output+err, 'Extracting file4.txt')
266+
str_in(output+err, 'Extracting file5.txt')
174267
str_not_in(output+err, 'ERROR')
268+
str_not_in(output+err, 'Not extracting')
269+
# Checking that the printing was done in order.
270+
tar_order = []
271+
console_output = output+err
272+
for word in console_output.replace('\n', ' ').split(' '):
273+
if '.tar' in word:
274+
word = word.replace('zstash/', '')
275+
tar_order.append(word)
276+
if tar_order != sorted(tar_order):
277+
print('*'*40)
278+
print('The tars were printed in this order: {}'.format(tar_order))
279+
print('When it should have been in this order: {}'.format(sorted(tar_order)))
280+
print('*'*40)
281+
stop()
282+
175283

176-
print('Running update on the newly extracted directory, nothing should happen')
284+
print('Checking the files again in parallel.')
177285
os.chdir('zstash_test')
178-
cmd = 'zstash update --hpss={}'.format(HPSS_PATH)
286+
cmd = 'zstash check --hpss={} --workers=3'.format(HPSS_PATH)
179287
output, err = run_cmd(cmd)
180288
os.chdir('../')
181-
str_in(output+err, 'Nothing to update')
289+
str_in(output+err, 'Checking file0.txt')
290+
str_in(output+err, 'Checking file0_hard.txt')
291+
str_in(output+err, 'Checking file0_soft.txt')
292+
str_in(output+err, 'Checking file_empty.txt')
293+
str_in(output+err, 'Checking dir/file1.txt')
294+
str_in(output+err, 'Checking empty_dir')
295+
str_in(output+err, 'Checking dir2/file2.txt')
296+
str_in(output+err, 'Checking file3.txt')
297+
str_in(output+err, 'Checking file4.txt')
298+
str_in(output+err, 'Checking file5.txt')
182299
str_not_in(output+err, 'ERROR')
183300

301+
302+
print('Causing MD5 mismatch errors and checking the files.')
303+
os.chdir('zstash_test')
304+
shutil.copy('zstash/index.db', 'zstash/index_old.db')
305+
print('Messing up the MD5 of all of the files with an even id.')
306+
cmd = ['sqlite3', 'zstash/index.db', 'UPDATE files SET md5 = 0 WHERE id % 2 = 0;']
307+
run_cmd(cmd)
308+
cmd = 'zstash check --hpss={}'.format(HPSS_PATH)
309+
output, err = run_cmd(cmd)
310+
str_in(output+err, 'md5 mismatch for: dir/file1.txt')
311+
str_in(output+err, 'md5 mismatch for: file3.txt')
312+
str_in(output+err, 'md5 mismatch for: file3.txt')
313+
str_in(output+err, 'ERROR: 000001.tar')
314+
str_in(output+err, 'ERROR: 000004.tar')
315+
str_in(output+err, 'ERROR: 000002.tar')
316+
str_not_in(output+err, 'ERROR: 000000.tar')
317+
str_not_in(output+err, 'ERROR: 000003.tar')
318+
str_not_in(output+err, 'ERROR: 000005.tar')
319+
# Put the original index.db back.
320+
os.remove('zstash/index.db')
321+
shutil.copy('zstash/index_old.db', 'zstash/index.db')
322+
os.chdir('../')
323+
324+
325+
print('Causing MD5 mismatch errors and checking the files in parallel.')
326+
os.chdir('zstash_test')
327+
shutil.copy('zstash/index.db', 'zstash/index_old.db')
328+
print('Messing up the MD5 of all of the files with an even id.')
329+
cmd = ['sqlite3', 'zstash/index.db', 'UPDATE files SET md5 = 0 WHERE id % 2 = 0;']
330+
run_cmd(cmd)
331+
cmd = 'zstash check --hpss={} --workers=3'.format(HPSS_PATH)
332+
output, err = run_cmd(cmd)
333+
str_in(output+err, 'md5 mismatch for: dir/file1.txt')
334+
str_in(output+err, 'md5 mismatch for: file3.txt')
335+
str_in(output+err, 'md5 mismatch for: file3.txt')
336+
str_in(output+err, 'ERROR: 000001.tar')
337+
str_in(output+err, 'ERROR: 000004.tar')
338+
str_in(output+err, 'ERROR: 000002.tar')
339+
str_not_in(output+err, 'ERROR: 000000.tar')
340+
str_not_in(output+err, 'ERROR: 000003.tar')
341+
str_not_in(output+err, 'ERROR: 000005.tar')
342+
# Put the original index.db back.
343+
os.remove('zstash/index.db')
344+
shutil.copy('zstash/index_old.db', 'zstash/index.db')
345+
os.chdir('../')
346+
347+
184348
print('Verifying the data from database with the actual files')
185349
# Checksums from HPSS
186-
cmd = ['sqlite3', 'zstash_test/zstash/index.db', 'select md5, name from files;']
350+
cmd = ['sqlite3', 'zstash_test/zstash/index.db', 'SELECT md5, name FROM files;']
187351
output_hpss, err_hpss = run_cmd(cmd)
188352
hpss_dict = {}
189353

@@ -210,6 +374,7 @@ def stop():
210374
for k in local_dict:
211375
print('{}|{}|{}'.format(k, hpss_dict[k], local_dict[k]))
212376

377+
213378
cleanup()
214379
print('*'*40)
215380
print('All of the tests passed! :)')

zstash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = 'v0.2.0'
1+
__version__ = 'v0.3.0'
22

zstash/check.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import print_function, absolute_import
2+
13
import logging
2-
import extract
4+
from . import extract
35

46
def check():
57
"""

zstash/chgrp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import print_function, absolute_import
2+
13
import sys
24
import argparse
3-
from hpss import hpss_chgrp
5+
from .hpss import hpss_chgrp
46

57
def chgrp():
68

zstash/create.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function, absolute_import
2+
13
import argparse
24
import errno
35
import logging
@@ -6,12 +8,10 @@
68
import sys
79
import sqlite3
810
import tarfile
9-
1011
from subprocess import Popen, PIPE
11-
12-
from hpss import hpss_put
13-
from utils import addfiles, excludeFiles
14-
from settings import config, CACHE, BLOCK_SIZE, DB_FILENAME
12+
from .hpss import hpss_put
13+
from .utils import addfiles, excludeFiles
14+
from .settings import config, CACHE, BLOCK_SIZE, DB_FILENAME
1515

1616

1717
def create():

0 commit comments

Comments
 (0)