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