1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# TODO:
# - check if everything is filled in (computers, params, preparation)
# - improve scoring
# - test
# - switch to a real SSH/SFTP client to properly handle filenames
instructions = {
'si':u"""
Ustvari dva navidezna računalnika. Za prvega uporabi sliko diska simpleArbiterDhcp. Na drugem računalniku
ustvari uporabnika test z geslom test.
Na sliki diska simpleArbiterDhcp najdeš imenik s 100 datotekami. Prekopiraj vse datoteke na drugi računalnik v domači imenik uporabnika test.
Spremeni vsebino datotek tako, da vse male črke spremeniš v velike. Poskrbi, da se bo s prvega računalnika (simpleArbiterDhcp) mogoče prek
ssh prijaviti na drugi računalnik in prebrati predelane datoteke.
""",
'en': u'''
Create two virtual machines. For the first, use the `simpleArbiterDhcp' image.
On the second machine, create a user `test' with the password `test'.
The `simpleArbiterDhcp' disk image contains a folder with 100 files. Copy all
of these files to the other computer into the home folder of theuser `test'.
Modify the content of these files by converting all lowercase letters into
uppercase. Make sure that the first machine (`simpleArbiterDhcp') can use ssh
to access the second machine and read the processed files.
''',
}
computers = {
'SimpleArbiter': {
'disks': [
{
'name': 'simpleArbiterDhcp',
},
],
'network_interfaces': [
{
'network': 'net1',
},
],
'flavor': 'm1.tiny',
'config_drive': False,
}
}
networks = {
'net1': {
'public': True,
},
}
params_meta = {
'folder': {
'descriptions': {
'si': 'Mapa, ki vsebuje 100 datotek',
'en': 'A folder with 100 files',
},
'w': False,
'public': True,
'type': 'dirname',
'generated': False,
},
'host': {
'descriptions': {
'si': 'Naslov racunalnika, na katerega kopiramo datoteke',
'en': 'The address of the computer to which the files are copied',
},
'w': True,
'public': True,
'type': 'IP',
'generated': False,
},
}
def task(host, folder):
import pxssh
# ideally, this would be done using a SFTP client instead of pxssh
target = pxssh.pxssh()
target.login(host, 'test', 'test')
results = {
'files': target.run('ls -1').split('\n'), # XXX: file may have newlines
'contents': target.run("cat *"), # XXX: may include other files in $HOME
}
target.logout()
return results
def gen_params(user_id, params_meta):
pass
def task_check(results, params):
import os
score = 0
hints = []
matched = 0
files = os.listdir(params['folder'])
for fn in files:
if fn in results['files']:
matched += 1
if matched > 0:
score = 1
else:
hints += ["no files"]
if matched > len(files)/2:
score += 2
else:
hints += ["less than half the files"]
if (matched == len(files)):
score += 3
else:
hints += ["wrong number of files"]
rl = results['contents'].split('\n')
rl.sort()
tl = []
for fn in files:
with open(fn) as f:
tl += f.read().upper().split('\n')
tl.sort()
if rl == tl:
score += 4
else:
hints += ["wrong files"]
return hints, score
def prepare_disks(templates, params):
pass
|