root / scripts / gnt-debug @ e3876ccb
History | View | Annotate | Download (7.3 kB)
1 | fd3ee040 | Iustin Pop | #!/usr/bin/python |
---|---|---|---|
2 | fd3ee040 | Iustin Pop | # |
3 | fd3ee040 | Iustin Pop | |
4 | fd3ee040 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc. |
5 | fd3ee040 | Iustin Pop | # |
6 | fd3ee040 | Iustin Pop | # This program is free software; you can redistribute it and/or modify |
7 | fd3ee040 | Iustin Pop | # it under the terms of the GNU General Public License as published by |
8 | fd3ee040 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or |
9 | fd3ee040 | Iustin Pop | # (at your option) any later version. |
10 | fd3ee040 | Iustin Pop | # |
11 | fd3ee040 | Iustin Pop | # This program is distributed in the hope that it will be useful, but |
12 | fd3ee040 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | fd3ee040 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | fd3ee040 | Iustin Pop | # General Public License for more details. |
15 | fd3ee040 | Iustin Pop | # |
16 | fd3ee040 | Iustin Pop | # You should have received a copy of the GNU General Public License |
17 | fd3ee040 | Iustin Pop | # along with this program; if not, write to the Free Software |
18 | fd3ee040 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | fd3ee040 | Iustin Pop | # 02110-1301, USA. |
20 | fd3ee040 | Iustin Pop | |
21 | fd3ee040 | Iustin Pop | |
22 | 2f79bd34 | Iustin Pop | # pylint: disable-msg=W0401,W0614 |
23 | 2f79bd34 | Iustin Pop | # W0401: Wildcard import ganeti.cli |
24 | 2f79bd34 | Iustin Pop | # W0614: Unused import %s from wildcard import (since we need cli) |
25 | 2f79bd34 | Iustin Pop | |
26 | fd3ee040 | Iustin Pop | import sys |
27 | f1c66d13 | Iustin Pop | import simplejson |
28 | f1c66d13 | Iustin Pop | import time |
29 | f1c66d13 | Iustin Pop | |
30 | fd3ee040 | Iustin Pop | from ganeti.cli import * |
31 | 9d5ba39a | Iustin Pop | from ganeti import cli |
32 | fd3ee040 | Iustin Pop | from ganeti import opcodes |
33 | fd3ee040 | Iustin Pop | from ganeti import constants |
34 | fd3ee040 | Iustin Pop | from ganeti import utils |
35 | fd3ee040 | Iustin Pop | from ganeti import errors |
36 | fd3ee040 | Iustin Pop | |
37 | fd3ee040 | Iustin Pop | |
38 | fd3ee040 | Iustin Pop | def Delay(opts, args): |
39 | fd3ee040 | Iustin Pop | """Sleeps for a while |
40 | fd3ee040 | Iustin Pop | |
41 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
42 | 6099bfcf | Iustin Pop | @type args: list |
43 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the duration |
44 | 6099bfcf | Iustin Pop | the sleep |
45 | 6099bfcf | Iustin Pop | @rtype: int |
46 | 6099bfcf | Iustin Pop | @return: the desired exit code |
47 | 6099bfcf | Iustin Pop | |
48 | fd3ee040 | Iustin Pop | """ |
49 | fd3ee040 | Iustin Pop | delay = float(args[0]) |
50 | fd3ee040 | Iustin Pop | op = opcodes.OpTestDelay(duration=delay, |
51 | fd3ee040 | Iustin Pop | on_master=opts.on_master, |
52 | fd3ee040 | Iustin Pop | on_nodes=opts.on_nodes) |
53 | 17621a25 | Michael Hanselmann | SubmitOpCode(op) |
54 | fd3ee040 | Iustin Pop | |
55 | fd3ee040 | Iustin Pop | return 0 |
56 | fd3ee040 | Iustin Pop | |
57 | fd3ee040 | Iustin Pop | |
58 | f1c66d13 | Iustin Pop | def GenericOpCodes(opts, args): |
59 | 6099bfcf | Iustin Pop | """Send any opcode to the master. |
60 | 6099bfcf | Iustin Pop | |
61 | 6099bfcf | Iustin Pop | @todo: The function is broken and needs to be converted to the |
62 | 6099bfcf | Iustin Pop | current job queue API |
63 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
64 | 6099bfcf | Iustin Pop | @type args: list |
65 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the path of |
66 | 6099bfcf | Iustin Pop | the file with the opcode definition |
67 | 6099bfcf | Iustin Pop | @rtype: int |
68 | 6099bfcf | Iustin Pop | @return: the desired exit code |
69 | f1c66d13 | Iustin Pop | |
70 | f1c66d13 | Iustin Pop | """ |
71 | 9d5ba39a | Iustin Pop | cl = cli.GetClient() |
72 | 9d95c3af | Iustin Pop | jex = cli.JobExecutor(cl=cl, verbose=opts.verbose) |
73 | 9d95c3af | Iustin Pop | |
74 | 9d95c3af | Iustin Pop | job_cnt = 0 |
75 | 9d95c3af | Iustin Pop | op_cnt = 0 |
76 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
77 | 9d95c3af | Iustin Pop | ToStdout("Loading...") |
78 | 9d95c3af | Iustin Pop | for job_idx in range(opts.rep_job): |
79 | 9d95c3af | Iustin Pop | for fname in args: |
80 | 4d5fe81b | Michael Hanselmann | op_data = simplejson.loads(utils.ReadFile(fname)) |
81 | 9d95c3af | Iustin Pop | op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data] |
82 | 9d95c3af | Iustin Pop | op_list = op_list * opts.rep_op |
83 | 9d95c3af | Iustin Pop | jex.QueueJob("file %s/%d" % (fname, job_idx), *op_list) |
84 | 9d95c3af | Iustin Pop | op_cnt += len(op_list) |
85 | 9d95c3af | Iustin Pop | job_cnt += 1 |
86 | 9d95c3af | Iustin Pop | |
87 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
88 | 9d95c3af | Iustin Pop | t1 = time.time() |
89 | 9d95c3af | Iustin Pop | ToStdout("Submitting...") |
90 | 4d5fe81b | Michael Hanselmann | |
91 | 9d95c3af | Iustin Pop | jex.SubmitPending() |
92 | 9d95c3af | Iustin Pop | |
93 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
94 | 9d95c3af | Iustin Pop | t2 = time.time() |
95 | 9d95c3af | Iustin Pop | ToStdout("Executing...") |
96 | b59252fe | Iustin Pop | |
97 | b59252fe | Iustin Pop | jex.GetResults() |
98 | 9d95c3af | Iustin Pop | if opts.timing_stats: |
99 | 9d95c3af | Iustin Pop | t3 = time.time() |
100 | 9d95c3af | Iustin Pop | ToStdout("C:op %4d" % op_cnt) |
101 | 9d95c3af | Iustin Pop | ToStdout("C:job %4d" % job_cnt) |
102 | 9d95c3af | Iustin Pop | ToStdout("T:submit %4.4f" % (t2-t1)) |
103 | 9d95c3af | Iustin Pop | ToStdout("T:exec %4.4f" % (t3-t2)) |
104 | 9d95c3af | Iustin Pop | ToStdout("T:total %4.4f" % (t3-t1)) |
105 | f1c66d13 | Iustin Pop | return 0 |
106 | f1c66d13 | Iustin Pop | |
107 | f1c66d13 | Iustin Pop | |
108 | d61df03e | Iustin Pop | def TestAllocator(opts, args): |
109 | 6099bfcf | Iustin Pop | """Runs the test allocator opcode. |
110 | d61df03e | Iustin Pop | |
111 | 6099bfcf | Iustin Pop | @param opts: the command line options selected by the user |
112 | 6099bfcf | Iustin Pop | @type args: list |
113 | 6099bfcf | Iustin Pop | @param args: should contain only one element, the iallocator name |
114 | 6099bfcf | Iustin Pop | @rtype: int |
115 | 6099bfcf | Iustin Pop | @return: the desired exit code |
116 | 6099bfcf | Iustin Pop | |
117 | 6099bfcf | Iustin Pop | """ |
118 | d61df03e | Iustin Pop | try: |
119 | d61df03e | Iustin Pop | disks = [{"size": utils.ParseUnit(val), "mode": 'w'} |
120 | d61df03e | Iustin Pop | for val in opts.disks.split(",")] |
121 | d61df03e | Iustin Pop | except errors.UnitParseError, err: |
122 | 3a24c527 | Iustin Pop | ToStderr("Invalid disks parameter '%s': %s", opts.disks, err) |
123 | d61df03e | Iustin Pop | return 1 |
124 | d61df03e | Iustin Pop | |
125 | d61df03e | Iustin Pop | nics = [val.split("/") for val in opts.nics.split(",")] |
126 | d61df03e | Iustin Pop | for row in nics: |
127 | d61df03e | Iustin Pop | while len(row) < 3: |
128 | d61df03e | Iustin Pop | row.append(None) |
129 | d61df03e | Iustin Pop | for i in range(3): |
130 | d61df03e | Iustin Pop | if row[i] == '': |
131 | d61df03e | Iustin Pop | row[i] = None |
132 | d61df03e | Iustin Pop | nic_dict = [{"mac": v[0], "ip": v[1], "bridge": v[2]} for v in nics] |
133 | d61df03e | Iustin Pop | |
134 | d61df03e | Iustin Pop | if opts.tags is None: |
135 | d61df03e | Iustin Pop | opts.tags = [] |
136 | d61df03e | Iustin Pop | else: |
137 | d61df03e | Iustin Pop | opts.tags = opts.tags.split(",") |
138 | d61df03e | Iustin Pop | |
139 | d61df03e | Iustin Pop | op = opcodes.OpTestAllocator(mode=opts.mode, |
140 | d61df03e | Iustin Pop | name=args[0], |
141 | d61df03e | Iustin Pop | mem_size=opts.mem, |
142 | d61df03e | Iustin Pop | disks=disks, |
143 | d61df03e | Iustin Pop | disk_template=opts.disk_template, |
144 | d61df03e | Iustin Pop | nics=nic_dict, |
145 | d61df03e | Iustin Pop | os=opts.os_type, |
146 | d61df03e | Iustin Pop | vcpus=opts.vcpus, |
147 | d61df03e | Iustin Pop | tags=opts.tags, |
148 | d61df03e | Iustin Pop | direction=opts.direction, |
149 | d61df03e | Iustin Pop | allocator=opts.allocator, |
150 | d61df03e | Iustin Pop | ) |
151 | d61df03e | Iustin Pop | result = SubmitOpCode(op) |
152 | 3a24c527 | Iustin Pop | ToStdout("%s" % result) |
153 | d61df03e | Iustin Pop | return 0 |
154 | d61df03e | Iustin Pop | |
155 | d61df03e | Iustin Pop | |
156 | fd3ee040 | Iustin Pop | commands = { |
157 | a8005e17 | Michael Hanselmann | 'delay': (Delay, [ArgUnknown(min=1, max=1)], |
158 | fd3ee040 | Iustin Pop | [DEBUG_OPT, |
159 | c38c44ad | Michael Hanselmann | cli_option("--no-master", dest="on_master", default=True, |
160 | c38c44ad | Michael Hanselmann | action="store_false", |
161 | c38c44ad | Michael Hanselmann | help="Do not sleep in the master code"), |
162 | c38c44ad | Michael Hanselmann | cli_option("-n", dest="on_nodes", default=[], |
163 | c38c44ad | Michael Hanselmann | action="append", |
164 | c38c44ad | Michael Hanselmann | help="Select nodes to sleep on"), |
165 | fd3ee040 | Iustin Pop | ], |
166 | 9a033156 | Iustin Pop | "[opts...] <duration>", "Executes a TestDelay OpCode"), |
167 | 4d5fe81b | Michael Hanselmann | 'submit-job': (GenericOpCodes, [ArgFile(min=1)], |
168 | 9cdb9578 | Iustin Pop | [DEBUG_OPT, VERBOSE_OPT, |
169 | 4d5fe81b | Michael Hanselmann | cli_option("--op-repeat", type="int", default="1", |
170 | 4d5fe81b | Michael Hanselmann | dest="rep_op", |
171 | 4d5fe81b | Michael Hanselmann | help="Repeat the opcode sequence this number" |
172 | 4d5fe81b | Michael Hanselmann | " of times"), |
173 | 4d5fe81b | Michael Hanselmann | cli_option("--job-repeat", type="int", default="1", |
174 | 4d5fe81b | Michael Hanselmann | dest="rep_job", |
175 | 4d5fe81b | Michael Hanselmann | help="Repeat the job this number" |
176 | 4d5fe81b | Michael Hanselmann | " of times"), |
177 | 4d5fe81b | Michael Hanselmann | cli_option("--timing-stats", default=False, |
178 | 4d5fe81b | Michael Hanselmann | action="store_true", |
179 | 4d5fe81b | Michael Hanselmann | help="Show timing stats"), |
180 | f1c66d13 | Iustin Pop | ], |
181 | 99036060 | Iustin Pop | "<op_list_file...>", "Submits jobs built from json files" |
182 | 99036060 | Iustin Pop | " containing a list of serialized opcodes"), |
183 | 4a265c08 | Michael Hanselmann | 'allocator': (TestAllocator, ARGS_ONE_INSTANCE, |
184 | d61df03e | Iustin Pop | [DEBUG_OPT, |
185 | c38c44ad | Michael Hanselmann | cli_option("--dir", dest="direction", |
186 | c38c44ad | Michael Hanselmann | default="in", choices=["in", "out"], |
187 | c38c44ad | Michael Hanselmann | help="Show allocator input (in) or allocator" |
188 | c38c44ad | Michael Hanselmann | " results (out)"), |
189 | 4eb62659 | Iustin Pop | IALLOCATOR_OPT, |
190 | c38c44ad | Michael Hanselmann | cli_option("-m", "--mode", default="relocate", |
191 | c38c44ad | Michael Hanselmann | choices=["relocate", "allocate"], |
192 | c38c44ad | Michael Hanselmann | help="Request mode, either allocate or" |
193 | c38c44ad | Michael Hanselmann | " relocate"), |
194 | d61df03e | Iustin Pop | cli_option("--mem", default=128, type="unit", |
195 | d61df03e | Iustin Pop | help="Memory size for the instance (MiB)"), |
196 | c38c44ad | Michael Hanselmann | cli_option("--disks", default="4096,4096", |
197 | c38c44ad | Michael Hanselmann | help="Comma separated list of disk sizes (MiB)"), |
198 | 4f365444 | Iustin Pop | DISK_TEMPLATE_OPT, |
199 | c38c44ad | Michael Hanselmann | cli_option("--nics", default="00:11:22:33:44:55", |
200 | c38c44ad | Michael Hanselmann | help="Comma separated list of nics, each nic" |
201 | c38c44ad | Michael Hanselmann | " definition is of form mac/ip/bridge, if" |
202 | c38c44ad | Michael Hanselmann | " missing values are replace by None"), |
203 | d3ed23ff | Iustin Pop | OS_OPT, |
204 | c38c44ad | Michael Hanselmann | cli_option("-p", "--vcpus", default=1, type="int", |
205 | c38c44ad | Michael Hanselmann | help="Select number of VCPUs for the instance"), |
206 | c38c44ad | Michael Hanselmann | cli_option("--tags", default=None, |
207 | c38c44ad | Michael Hanselmann | help="Comma separated list of tags"), |
208 | d61df03e | Iustin Pop | ], |
209 | 9a033156 | Iustin Pop | "{opts...} <instance>", "Executes a TestAllocator OpCode"), |
210 | fd3ee040 | Iustin Pop | } |
211 | fd3ee040 | Iustin Pop | |
212 | fd3ee040 | Iustin Pop | |
213 | fd3ee040 | Iustin Pop | if __name__ == '__main__': |
214 | fd3ee040 | Iustin Pop | sys.exit(GenericMain(commands)) |