Skip to contentSkip to conversation

Added functionality to the preprocessor to run scripts

PATCH Michael Goldish 2 participants 2 messages Jun 3, 2009 1 message not in the archive KVM

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 35 lines · ----- "Avi Kivity
Quoted 3 lines · Michael Goldish
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

- What if we're interested in the status for some reason? Its

value

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

may indicate what went wrong with the child process.

Put it in the exception string.

But I want its value to be examined programmatically in the code. It's less comfortable to retrieve it from a string.

Then create a custom exception object and put it in a field.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- If we throw an exception we should add a parameter that

controls

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

whether an exception should be thrown (something like

"ignore_status")

Quoted 3 lines

because in some cases we don't want to throw an exception.

I'll complain every time I see it. If you don't care if the

command

Quoted 4 lines
Quoted 2 lines

succeeds or not, why run it in the first place?

I care, but sometimes I don't want to fail the test when a command

fails.

Quoted 1 line

I can put every run_bg() call in a try-except statement, but that

Quoted 8 lines

misses the

Quoted 2 lines

point of raising exceptions in the first place.

I think it's very rare to want to let the test continue even if some command fails.

Can you give examples?

Some commands are not critical, like one that converts the screendumps from PPM to PNG format. We don't want to fail the test if you don't have ImageMagick installed.

A similar function used for remote commands is sometimes used for checking if a file exists on the guest and getting its size at the same time, using ls. If the file doesn't exist we should SCP it into the guest, not fail the test.

Quoted 20 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

exception such as "something failed after migration"?

Chained exceptions can provide detailed information.

Wouldn't it complicate the test code?
How can I provide a detailed message such as "test command failed

after migration" --

Quoted 2 lines

can you illustrate this in a small example?

try:
code
code
code
except e:
raise ChainedException('exception while running migration test',
e)

Quoted 2 lines

Instead of checking each code line, you provide a wrapper for the entire test.

It's not informative to add it for the entire test, because we already know what test failed -- we don't need the exception string for that.

Instead, we'd have to wrap small sections of the test separately and provide a different exception string for each. The migration test may be split to four sections: setup, pre-migration, the migration itself and post-migration. This may not be so bad, but do you still think it's a good solution?

There's also another issue: the utility functions that should raise exceptions don't know what they're being used for, so there can be exception string collisions. For example, both run_bg(), used for local processes, and kvm_spawn.get_command_status_output(), used for SSH commands, would say something like "command %s failed". It would be incorrect to hardcode a more specific message into any of them (in my opinion).

Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

But if status != 0, will there actually be a pid to kill?

If the timeout expires and the process is still running, status

is

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

None.

Quoted 2 lines

functions which can return with three possible outcomes are

difficult

Quoted 3 lines
Quoted 2 lines

to use.

Quoted 8 lines
Quoted 1 line

I tend to see it as two possible outcomes: completion or timeout. In

the former

Quoted 2 lines

case, status is returned. In the latter, None is returned.

The caller has to test for three possible outcomes. Success, failure, and 'command is running in the background'. If your callsites don't check for all three, something's wrong.

When we want the command to succeed on time, we just test for status == 0. If it's a nonzero integer or None, something went wrong, and we should kill the process just in case it's still running.

Quoted 3 lines
Signature · 2 lines
Do not meddle in the internals of kernels, for they are subtle and
quick to panic.
#2 lore raw
Quoted 9 lines · Michael Goldish
Quoted 4 lines

I think it's very rare to want to let the test continue even if some command fails.

Can you give examples?

Some commands are not critical, like one that converts the screendumps from PPM to PNG format. We don't want to fail the test if you don't have ImageMagick installed.

I think you don't want to run the test at all in that case. But if you do, you shouldn't invoke ImageMagick if you don't have it installed. Otherwise you can't distinguish between failure due to a corrupted source image, out of disk space, or ImageMagick not installed.

Ignoring errors is usually a bug.

Quoted 5 lines

A similar function used for remote commands is sometimes used for checking if a file exists on the guest and getting its size at the same time, using ls. If the file doesn't exist we should SCP it into the guest, not fail the test.

Again it doesn't distinguish between real errors and 'file does not exist'. Use something like 'if test -f file; then ls -l file; else echo missing; fi'.

You can use rsync to implement 'copy unless exists'.

Quoted 13 lines
Quoted 9 lines

try:
code
code
code
except e:
raise ChainedException('exception while running migration test',
e)

Quoted 3 lines

Instead of checking each code line, you provide a wrapper for the entire test.

Quoted 8 lines

It's not informative to add it for the entire test, because we already know what test failed -- we don't need the exception string for that.

Instead, we'd have to wrap small sections of the test separately and provide a different exception string for each. The migration test may be split to four sections: setup, pre-migration, the migration itself and post-migration. This may not be so bad, but do you still think it's a good solution?

You can have a 'stage' variable and assign it your current stage, and use it when reporting errors.

Anything is better than a maze of ifs.

Quoted 8 lines

There's also another issue: the utility functions that should raise exceptions don't know what they're being used for, so there can be exception string collisions. For example, both run_bg(), used for local processes, and kvm_spawn.get_command_status_output(), used for SSH commands, would say something like "command %s failed". It would be incorrect to hardcode a more specific message into any of them (in my opinion).

The message should explain what happened, no more, no less.

Quoted 8 lines
Quoted 3 lines

The caller has to test for three possible outcomes. Success, failure,
and 'command is running in the background'. If your callsites don't check for all three, something's wrong.

When we want the command to succeed on time, we just test for status == 0. If it's a nonzero integer or None, something went wrong, and we should kill the process just in case it's still running.

But if it's nonzero it has exited already!

However, I feel I'm not making any progress, so I'll stop. I just wish I could use exceptions in the code I write.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.