mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Add logic for handling systemd-machined non-existance
If systemd machine does not exist, return -2 instead of -1, so that applications don't need to repeat the tedious error checking code Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
@@ -82,35 +82,60 @@ static int testCreateNoSystemd(const void *opaque ATTRIBUTE_UNUSED)
|
||||
3, 3, 3, 3,
|
||||
4, 4, 4, 4
|
||||
};
|
||||
int rv;
|
||||
|
||||
setenv("FAIL_NO_SERVICE", "1", 1);
|
||||
|
||||
if (virSystemdCreateMachine("demo",
|
||||
"qemu",
|
||||
true,
|
||||
uuid,
|
||||
NULL,
|
||||
123,
|
||||
false,
|
||||
NULL) == 0) {
|
||||
if ((rv = virSystemdCreateMachine("demo",
|
||||
"qemu",
|
||||
true,
|
||||
uuid,
|
||||
NULL,
|
||||
123,
|
||||
false,
|
||||
NULL)) == 0) {
|
||||
fprintf(stderr, "%s", "Unexpected create machine success\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
virErrorPtr err = virGetLastError();
|
||||
|
||||
if (!err) {
|
||||
fprintf(stderr, "No error raised");
|
||||
if (rv != -2) {
|
||||
fprintf(stderr, "%s", "Unexpected create machine error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (err->code == VIR_ERR_DBUS_SERVICE &&
|
||||
STREQ(err->str2, "org.freedesktop.DBus.Error.ServiceUnknown"))
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Unexpected error code %d / message %s\n",
|
||||
err->code, err->str2);
|
||||
return -1;
|
||||
static int testCreateBadSystemd(const void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
unsigned char uuid[VIR_UUID_BUFLEN] = {
|
||||
1, 1, 1, 1,
|
||||
2, 2, 2, 2,
|
||||
3, 3, 3, 3,
|
||||
4, 4, 4, 4
|
||||
};
|
||||
int rv;
|
||||
|
||||
setenv("FAIL_BAD_SERVICE", "1", 1);
|
||||
|
||||
if ((rv = virSystemdCreateMachine("demo",
|
||||
"qemu",
|
||||
true,
|
||||
uuid,
|
||||
NULL,
|
||||
123,
|
||||
false,
|
||||
NULL)) == 0) {
|
||||
fprintf(stderr, "%s", "Unexpected create machine success\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rv != -1) {
|
||||
fprintf(stderr, "%s", "Unexpected create machine error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -122,7 +147,9 @@ mymain(void)
|
||||
ret = -1;
|
||||
if (virtTestRun("Test create machine ", 1, testCreateMachine, NULL) < 0)
|
||||
ret = -1;
|
||||
if (virtTestRun("Test create nosystemd ", 1, testCreateNoSystemd, NULL) < 0)
|
||||
if (virtTestRun("Test create no systemd ", 1, testCreateNoSystemd, NULL) < 0)
|
||||
ret = -1;
|
||||
if (virtTestRun("Test create bad systemd ", 1, testCreateBadSystemd, NULL) < 0)
|
||||
ret = -1;
|
||||
|
||||
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
||||
Reference in New Issue
Block a user