1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-27 07:22:07 +03:00

test driver: Deny some operations on inactive domains

Some operations like reboot, save, coreDump, blockStats,
ifaceStats make sense iff domain is running. While it is
technically possible for our test driver to return success
regardless of domain state, we should copy constraints from
other drivers and thus deny these operations over inactive
domains.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2016-11-08 09:49:22 +01:00
parent f694f3ff6b
commit c6b6e737e8

View File

@ -1867,6 +1867,12 @@ static int testDomainReboot(virDomainPtr domain,
if (!(privdom = testDomObjFromDomain(domain))) if (!(privdom = testDomObjFromDomain(domain)))
goto cleanup; goto cleanup;
if (!virDomainObjIsActive(privdom)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
}
virDomainObjSetState(privdom, VIR_DOMAIN_SHUTDOWN, virDomainObjSetState(privdom, VIR_DOMAIN_SHUTDOWN,
VIR_DOMAIN_SHUTDOWN_USER); VIR_DOMAIN_SHUTDOWN_USER);
@ -1987,6 +1993,12 @@ testDomainSaveFlags(virDomainPtr domain, const char *path,
if (!(privdom = testDomObjFromDomain(domain))) if (!(privdom = testDomObjFromDomain(domain)))
goto cleanup; goto cleanup;
if (!virDomainObjIsActive(privdom)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
}
xml = virDomainDefFormat(privdom->def, privconn->caps, xml = virDomainDefFormat(privdom->def, privconn->caps,
VIR_DOMAIN_DEF_FORMAT_SECURE); VIR_DOMAIN_DEF_FORMAT_SECURE);
@ -2185,6 +2197,12 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain,
if (!(privdom = testDomObjFromDomain(domain))) if (!(privdom = testDomObjFromDomain(domain)))
goto cleanup; goto cleanup;
if (!virDomainObjIsActive(privdom)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
}
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) { if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("domain '%s' coredump: failed to open %s"), _("domain '%s' coredump: failed to open %s"),
@ -3064,6 +3082,12 @@ static int testDomainBlockStats(virDomainPtr domain,
if (!(privdom = testDomObjFromDomain(domain))) if (!(privdom = testDomObjFromDomain(domain)))
return ret; return ret;
if (!virDomainObjIsActive(privdom)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto error;
}
if (virDomainDiskIndexByName(privdom->def, path, false) < 0) { if (virDomainDiskIndexByName(privdom->def, path, false) < 0) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("invalid path: %s"), path); _("invalid path: %s"), path);
@ -3103,6 +3127,12 @@ static int testDomainInterfaceStats(virDomainPtr domain,
if (!(privdom = testDomObjFromDomain(domain))) if (!(privdom = testDomObjFromDomain(domain)))
return -1; return -1;
if (!virDomainObjIsActive(privdom)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto error;
}
for (i = 0; i < privdom->def->nnets; i++) { for (i = 0; i < privdom->def->nnets; i++) {
if (privdom->def->nets[i]->ifname && if (privdom->def->nets[i]->ifname &&
STREQ(privdom->def->nets[i]->ifname, path)) { STREQ(privdom->def->nets[i]->ifname, path)) {