import repository from arizona
[raven.git] / 2.0 / python / test / planetlab_shareTest.py
1 #! /usr/bin/env python
2 """
3 <Module>
4    planetlab_shareTest
5 <Author>
6    Justin Cappos
7 <Started>
8    December 10th, 2005   
9 <Purpose>
10    Test module for planetlab_share.  See planetlab_share.py for more details.
11 """
12
13
14 badclientname = "adsfkj"
15 clientname = "arizona_client1"
16 client = clientname+"@alice.cs.princeton.edu"
17 nestname = "arizona_stork2"
18 nest = nestname+"@alice.cs.princeton.edu"
19 nestdir = "/tmp/planetlab_shareTest_dir"
20
21
22 import os
23 import sys
24 import planetlab_share
25 import arizonaunittest
26 import arizonaconfig
27 import arizonageneral
28
29 # Unit tests for each function, listed in code order
30 class test(arizonaunittest.TestCase):
31
32    #------------------------------------------------------------------
33    # init_sharing_program():
34    #------------------------------------------------------------------
35    def test_init_sharing_program(self):
36
37       temp_slicename = arizonaconfig.get_option("slicename")
38       arizonaconfig.set_option("slicename",None)
39
40       # Nothing set, should exit because slicename is unset
41       self.assertException(SystemExit, planetlab_share.init_sharing_program)
42
43       arizonaconfig.set_option("slicename",temp_slicename)
44
45       planetlab_share.init_sharing_program()
46       
47
48
49
50
51
52    #------------------------------------------------------------------
53    # identify(data):
54    #------------------------------------------------------------------
55    def test_identify(self):
56       #TODO
57       pass
58
59       
60
61       
62          
63
64    #------------------------------------------------------------------
65    # identifyready(junk_data):
66    #------------------------------------------------------------------
67    def test_identifyready(self):
68       #TODO
69       pass
70
71       
72
73       
74
75       
76    #------------------------------------------------------------------
77    # share_directory(source_slice, source_dir, target_slice, target_dir, flags):
78    #------------------------------------------------------------------
79    def test_share_directory(self):
80       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
81       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
82       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
83       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
84       try:
85          # Share a dir (basic)
86          arizonageneral.remote_popen(nest,"sudo sh -c 'mkdir /tmp/foo'")
87          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory\(\)'"),(['True'],[]))
88
89          # check inode numbers
90          inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -id /tmp/foo'")[0][0].split()[0]
91          inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -id /tmp/foo2'")[0][0].split()[0]
92          self.assertEquals(inode, inode2)
93
94          # Repeated operation should have no effect
95          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory\(\)'"),(['True'],[]))
96
97          # check inode numbers
98          inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -id /tmp/foo'")[0][0].split()[0]
99          inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -id /tmp/foo2'")[0][0].split()[0]
100          self.assertEquals(inode, inode2)
101
102          # undo the sharing...
103          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'"),(['True'],[]))
104
105
106          # Check the read-only sharing
107          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory_ro\(\)'"),(['True'],[]))
108
109          # check inode numbers
110          inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -id /tmp/foo'")[0][0].split()[0]
111          inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -id /tmp/foo2'")[0][0].split()[0]
112          self.assertEquals(inode, inode2)
113       
114       
115          # Make sure there was some error output
116          self.assertNotEquals(arizonageneral.remote_popen(nest,"sudo sh -c 'touch /tmp/foo2/new'")[1],[])
117
118       
119          # Share with a bad client
120          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory_bad\(\)'"),(['False'],[]))
121          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory_bad_2\(\)'"),(['False'],[]))
122
123       finally:
124          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo")
125          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo2")
126          arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
127          arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
128          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo")
129          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo2")
130          
131
132       
133
134
135       
136    #------------------------------------------------------------------
137    # unshare_directory(source_slice, source_dir):
138    #------------------------------------------------------------------
139    def test_unshare_directory(self):
140       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
141       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
142       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
143       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
144       try:
145          # Share a dir (nest -> nest) and unshare it
146          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory\(\)'"),(['True'],[]))
147          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'"),(['True'],[]))
148
149          # Unshare read-only dir
150          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory_ro\(\)'"),(['True'],[]))
151          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'"),(['True'],[]))
152       
153          # Unshare nest-client dir
154          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory_c\(\)'"),(['True'],[]))
155          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'"),(['True'],[]))
156       
157          # Unshare client-nest dir
158          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory_c_n\(\)'"),(['True'],[]))
159          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'"),(['True'],[]))
160       
161
162 ### SEEMS TO BE A PROPER PROBLEM (can't do client to client sharing)
163          # Unshare client-client dir
164          #self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_share_directory_c_c\(\)'"),(['True'],[]))
165          #self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'"),(['True'],[]))
166       finally:
167          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo")
168          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo2")
169          arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
170          arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
171          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo")
172          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo2")
173          
174
175       
176       
177          
178
179
180
181
182
183
184    #------------------------------------------------------------------
185    # copy_file(source_slice,source_file, target_slice, target_file):
186    #------------------------------------------------------------------
187    def test_copy_file(self):
188       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
189       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
190       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
191       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
192
193       # Create and copy a file within the nest
194       arizonageneral.remote_popen(nest,"sudo sh -c 'echo hello > /tmp/foo'")
195       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_copy_file\(\)'"),(['True'],[]))
196
197       # check inodes (should be different)
198       inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
199       inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
200       self.assertNotEquals(inode, inode2)
201       # Check contents (should be same)
202       data = arizonageneral.remote_popen(nest,"sudo sh -c 'cat /tmp/foo'")
203       data2 = arizonageneral.remote_popen(nest,"sudo sh -c 'cat /tmp/foo2'")
204       self.assertEquals(data, data2)
205       
206
207       # Should be able to do this twice with the same result (overwrite test)
208       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_copy_file\(\)'"),(['True'],[]))
209
210       # check inode numbers (should be different)
211       inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
212       inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
213       self.assertNotEquals(inode, inode2)
214       # Check contents (should be same)
215       data = arizonageneral.remote_popen(nest,"sudo sh -c 'cat /tmp/foo'")
216       data2 = arizonageneral.remote_popen(nest,"sudo sh -c 'cat /tmp/foo2'")
217       self.assertEquals(data, data2)
218
219       # Try to copy to a non-existant client
220       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_copy_file_bad\(\)'"),(['False'],[]))
221
222       # Clean up
223       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -f /tmp/foo /tmp/foo2'")
224
225
226
227       # nest -> client copying
228       arizonageneral.remote_popen(nest,"sudo sh -c 'echo hello > /tmp/foo'")
229       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_copy_file_c\(\)'"),(['True'],[]))
230
231       # check inode numbers (should be different)
232       inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
233       inode2 = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
234       self.assertNotEquals(inode, inode2)
235       # Check contents (should be same)
236       data = arizonageneral.remote_popen(nest,"sudo sh -c 'cat /tmp/foo'")
237       data2 = arizonageneral.remote_popen(client,"sudo sh -c 'cat /tmp/foo2'")
238       self.assertEquals(data, data2)
239
240       # Clean up
241       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -f /tmp/foo'")
242       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /tmp/foo2'")
243
244
245
246
247       # client -> nest copying
248       arizonageneral.remote_popen(client,"sudo sh -c 'echo hello >> /tmp/foo'")
249       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_copy_file_c_n\(\)'"),(['True'],[]))
250
251       # check inode numbers (should be different)
252       inode = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
253       inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
254       self.assertNotEquals(inode, inode2)
255       # Check contents (should be same)
256       data = arizonageneral.remote_popen(client,"sudo sh -c 'cat /tmp/foo'")
257       data2 = arizonageneral.remote_popen(nest,"sudo sh -c 'cat /tmp/foo2'")
258       self.assertEquals(data, data2)
259
260       # Clean up
261       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /tmp/foo'")
262       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -f /tmp/foo2'")
263
264
265
266       # client -> client copying
267       arizonageneral.remote_popen(client,"sudo sh -c 'echo hello >> /tmp/foo'")
268       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_copy_file_c_c\(\)'"),(['True'],[]))
269
270       # check inode numbers (should be different)
271       inode = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
272       inode2 = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
273       self.assertNotEquals(inode, inode2)
274       # Check contents (should be same)
275       data = arizonageneral.remote_popen(client,"sudo sh -c 'cat /tmp/foo'")
276       data2 = arizonageneral.remote_popen(client,"sudo sh -c 'cat /tmp/foo2'")
277       self.assertEquals(data, data2)
278
279       # Try to mount to a non-existant client
280       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_copy_file_bad_2\(\)'"),(['False'],[]))
281
282       # Clean up
283       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /tmp/foo /tmp/foo2'")
284
285       
286          
287
288
289    #------------------------------------------------------------------
290    # link_file(source_slice, source_file, target_slice, target_file):
291    #------------------------------------------------------------------
292    def test_link_file(self):
293       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
294       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
295       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
296       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
297
298
299       # Create and link a file within the nest
300       arizonageneral.remote_popen(nest,"sudo sh -c 'echo hello >> /tmp/foo'")
301       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_link_file\(\)'"),(['True'],[]))
302
303       # check inode numbers
304       inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
305       inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
306       self.assertEquals(inode, inode2)
307
308       # Should be able to do this twice with the same result (overwrite test)
309       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_link_file\(\)'"),(['True'],[]))
310
311       # check inode numbers
312       inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
313       inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
314       self.assertEquals(inode, inode2)
315
316       # Try to mount to a non-existant client
317       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_link_file_bad\(\)'"),(['False'],[]))
318
319       # Clean up
320       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -f /tmp/foo /tmp/foo2'")
321
322
323
324       # nest -> client linking
325       arizonageneral.remote_popen(nest,"sudo sh -c 'echo hello >> /tmp/foo'")
326       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_link_file_c\(\)'"),(['True'],[]))
327
328       # check inode numbers
329       inode = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
330       inode2 = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
331       self.assertEquals(inode, inode2)
332
333       # Clean up
334       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -f /tmp/foo'")
335       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /tmp/foo2'")
336
337
338
339
340       # client -> nest linking
341       arizonageneral.remote_popen(client,"sudo sh -c 'echo hello >> /tmp/foo'")
342       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_link_file_c_n\(\)'"),(['True'],[]))
343
344       # check inode numbers
345       inode = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
346       inode2 = arizonageneral.remote_popen(nest,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
347       self.assertEquals(inode, inode2)
348
349       # Clean up
350       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /tmp/foo'")
351       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -f /tmp/foo2'")
352
353
354
355       # client -> client linking
356       arizonageneral.remote_popen(client,"sudo sh -c 'echo hello >> /tmp/foo'")
357       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_link_file_c_c\(\)'"),(['True'],[]))
358
359       # check inode numbers
360       inode = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo'")[0][0].split()[0]
361       inode2 = arizonageneral.remote_popen(client,"sudo sh -c 'ls -i /tmp/foo2'")[0][0].split()[0]
362       self.assertEquals(inode, inode2)
363
364       # Try to mount to a non-existant client
365       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_link_file_bad_2\(\)'"),(['False'],[]))
366
367       # Clean up
368       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /tmp/foo /tmp/foo2'")
369
370
371
372
373
374
375       
376          
377
378    #------------------------------------------------------------------
379    # unlink_file(target_slice, target_file):
380    #------------------------------------------------------------------
381    def test_unlink_file(self):
382       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
383       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
384       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
385       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
386
387       # Create and unlink a file
388       arizonageneral.remote_popen(nest,"sudo sh -c 'echo hello >> /tmp/foo'")
389       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unlink_file\(\)'"),(['True'],[]))
390       # Make sure we did remove the file
391       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c 'ls /tmp/foo'")[0],[])
392
393       # Unlink should fail now (file not found)
394       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unlink_file\(\)'"),(['False'],[]))
395
396       # Try this for a file in the client
397       arizonageneral.remote_popen(client,"sudo sh -c 'echo hello >> /tmp/foo'")
398       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unlink_file_c\(\)'"),(['True'],[]))
399       # Make sure we did remove the file
400       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c 'ls /tmp/foo'")[0],[])
401
402       # Unlink should fail now (file not found)
403       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unlink_file_c\(\)'"),(['False'],[]))
404
405       # Unlink should fail (bad slice)
406       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unlink_file_bad\(\)'"),(['False'],[]))
407
408
409
410
411
412    #------------------------------------------------------------------
413    # protect_file(target_slice, target_file):
414    #------------------------------------------------------------------
415    def test_protect_file(self):
416       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory\(\)'")
417       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_unshare_directory_c\(\)'")
418       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
419       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo /tmp/foo2'")
420
421
422       try:
423          # Create a file
424          arizonageneral.remote_popen(nest,"sudo sh -c 'echo hello > /tmp/foo'")
425          # protect a file of ours
426          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_protect_file\(\)'"),(['True'],[]))
427          # Try to append to it
428          arizonageneral.remote_popen(nest,"sudo sh -c 'echo goodbye >> /tmp/foo'")
429          # Check the contents
430          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c 'cat /tmp/foo'"),(['hello'], []))
431       finally:
432          arizonageneral.remote_popen(nest,"sudo sh -c 'rm -f /tmp/foo'")
433          
434       # Make sure we did  remove the file
435       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c 'ls /tmp/foo'")[0],[])
436       
437       # Can't protect a non-existant file
438       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_protect_file\(\)'"),(['False'],[]))
439
440
441
442
443       try:
444          # Create a file on the client
445          arizonageneral.remote_popen(client,"sudo sh -c 'echo hello > /tmp/foo'")
446          # protect a file of theirs
447          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_protect_file_c\(\)'"),(['True'],[]))
448          # Try to append to it
449          arizonageneral.remote_popen(client,"sudo sh -c 'echo goodbye >> /tmp/foo'")
450          # Check the contents
451          self.assertEquals(arizonageneral.remote_popen(client,"sudo sh -c 'cat /tmp/foo'"),(['hello'], []))
452       finally:
453          arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /tmp/foo'")
454          
455       # Make sure we did remove the file
456       self.assertEquals(arizonageneral.remote_popen(client,"sudo sh -c 'ls /tmp/foo'")[0],[])
457       
458       # Can't protect a non-existant file
459       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_protect_file_c\(\)'"),(['False'],[]))
460
461
462       # Try to do this for a bad client
463       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_protect_file_bad\(\)'"),(['False'],[]))
464
465       
466
467
468
469
470
471
472
473
474    #------------------------------------------------------------------
475    # init_client(client_name):
476    #------------------------------------------------------------------
477    def test_init_client(self):
478
479          
480       # Try a non-existant client
481       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_init_client_bad\(\)'"),(['False'], []))
482
483       # remove the share name
484       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /.exportdir'")
485
486       # Try finally here so I restore the file properly if this fails
487       try:
488          # Should fail now
489          self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_init_client\(\)'"),(['False'], []))
490
491       finally:
492          # re-set up the client
493          arizonageneral.remote_popen(client,"sudo sh -c 'echo "+nestname+" > /.exportdir'")
494
495       # Should pass now
496       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_init_client\(\)'"),(['True'], []))
497
498       # Should not hurt to do this multiple times...
499       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_init_client\(\)'"),(['True'], []))
500
501       # Should not hurt to do this multiple times...
502       self.assertEquals(arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_init_client\(\)'"),(['True'], []))
503          
504
505
506
507
508
509    #------------------------------------------------------------------
510    # share_name():
511    #------------------------------------------------------------------
512    def test_share_name(self):
513       self.assertEquals(planetlab_share.share_name(), "planetlab")
514
515
516
517
518
519
520
521 def remote_share_directory():
522    return planetlab_share.share_directory(nestname, "/tmp/foo", nestname, "/tmp/foo2","")
523
524 def remote_share_directory_ro():
525    return planetlab_share.share_directory(nestname, "/tmp/foo", nestname, "/tmp/foo2","ro")
526
527 def remote_share_directory_c():
528    return planetlab_share.share_directory(nestname, "/tmp/foo", clientname, "/tmp/foo2","")
529
530 def remote_share_directory_c_n():
531    return planetlab_share.share_directory(clientname, "/tmp/foo", nestname, "/tmp/foo2","")
532
533 def remote_share_directory_c_c():
534    return planetlab_share.share_directory(clientname, "/tmp/foo", clientname, "/tmp/foo2","")
535
536 def remote_share_directory_bad():
537    return planetlab_share.share_directory(nestname, "/tmp/foo", badclientname, "/tmp/foo2","")
538
539 def remote_share_directory_bad_2():
540    return planetlab_share.share_directory(badclientname, "/tmp/foo", nestname, "/tmp/foo2","")
541
542
543
544
545
546
547 def remote_unshare_directory():
548    return planetlab_share.unshare_directory(nestname, "/tmp/foo2")
549
550 def remote_unshare_directory_c():
551    return planetlab_share.unshare_directory(clientname, "/tmp/foo2")
552
553
554
555
556 def remote_copy_file():
557    return planetlab_share.copy_file(nestname, "/tmp/foo", nestname, "/tmp/foo2")
558
559 def remote_copy_file_c():
560    return planetlab_share.copy_file(nestname, "/tmp/foo", clientname, "/tmp/foo2")
561
562 def remote_copy_file_c_n():
563    return planetlab_share.copy_file(clientname, "/tmp/foo", nestname, "/tmp/foo2")
564
565 def remote_copy_file_c_c():
566    return planetlab_share.copy_file(clientname, "/tmp/foo", clientname, "/tmp/foo2")
567
568 def remote_copy_file_bad():
569    return planetlab_share.copy_file(nestname, "/tmp/foo", badclientname, "/tmp/foo2")
570
571 def remote_copy_file_bad_2():
572    return planetlab_share.copy_file(badclientname, "/tmp/foo", nestname, "/tmp/foo2")
573
574
575
576
577 def remote_link_file():
578    return planetlab_share.link_file(nestname, "/tmp/foo", nestname, "/tmp/foo2")
579
580 def remote_link_file_c():
581    return planetlab_share.link_file(nestname, "/tmp/foo", clientname, "/tmp/foo2")
582
583 def remote_link_file_c_n():
584    return planetlab_share.link_file(clientname, "/tmp/foo", nestname, "/tmp/foo2")
585
586 def remote_link_file_c_c():
587    return planetlab_share.link_file(clientname, "/tmp/foo", clientname, "/tmp/foo2")
588
589 def remote_link_file_bad():
590    return planetlab_share.link_file(nestname, "/tmp/foo", badclientname, "/tmp/foo2")
591
592 def remote_link_file_bad_2():
593    return planetlab_share.link_file(badclientname, "/tmp/foo", nestname, "/tmp/foo2")
594
595
596
597
598 def remote_unlink_file():
599    return planetlab_share.unlink_file(nestname, "/tmp/foo")
600
601 def remote_unlink_file_c():
602    return planetlab_share.unlink_file(clientname, "/tmp/foo")
603
604 def remote_unlink_file_bad():
605    return planetlab_share.unlink_file(badclientname, "/tmp/foo")
606
607
608
609 def remote_protect_file():
610    return planetlab_share.protect_file(nestname, "/tmp/foo")
611
612 def remote_protect_file_c():
613    return planetlab_share.protect_file(clientname, "/tmp/foo")
614
615 def remote_protect_file_bad():
616    return planetlab_share.protect_file(badclientname, "/tmp/foo")
617
618
619 def remote_init_client():
620    return planetlab_share.init_client(clientname)
621
622 def remote_init_client_bad():
623    return planetlab_share.init_client(badclientname)
624
625
626
627 # Run tests
628 if __name__=='__main__':
629    # Init config options...
630    args = arizonaconfig.init_options()
631    arizonaconfig.set_option("slicename",nestname)
632
633    # if we are running a test on the remote system then do it...
634    if args:
635       print eval(' '.join(args))
636       sys.exit(0)
637
638    try:
639       # Set up the tests
640       arizonageneral.remote_popen(nest,"mkdir "+nestdir)
641       os.system("scp *.py "+nest+":"+nestdir)
642       os.system("scp ../stork-slice "+nest+":"+nestdir)
643       arizonageneral.remote_popen(client,"sudo sh -c 'echo "+nestname+" > /.exportdir'")
644
645       # Init so the client is setup...
646       arizonageneral.remote_popen(nest,"sudo sh -c '"+nestdir+"/planetlab_shareTest.py remote_init_client\(\)'")
647
648
649       # Run the tests
650       arizonaunittest.main()
651    finally:
652       # clean up the nest
653       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf "+nestdir+"'")
654       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo'")
655       arizonageneral.remote_popen(nest,"sudo sh -c 'rm -rf /tmp/foo2'")
656       # clean up the client
657       arizonageneral.remote_popen(client,"sudo sh -c 'rm -f /.exportdir'")
658       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo'")
659       arizonageneral.remote_popen(client,"sudo sh -c 'rm -rf /tmp/foo2'")
660       pass
661