From nobody Fri May 3 19:21:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1626179018343329.0501499052451; Tue, 13 Jul 2021 05:23:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-5-chzhSrN6KWgTQ_LFTbaw-1; Tue, 13 Jul 2021 08:23:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF53C5074F; Tue, 13 Jul 2021 12:23:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BD696091B; Tue, 13 Jul 2021 12:23:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A85D14EA2F; Tue, 13 Jul 2021 12:23:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16DCNG2O016949 for ; Tue, 13 Jul 2021 08:23:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 04876D29CC; Tue, 13 Jul 2021 12:23:16 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F3D84D7B05 for ; Tue, 13 Jul 2021 12:23:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BBCF189B841 for ; Tue, 13 Jul 2021 12:23:12 +0000 (UTC) Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-303-YSKNzJu4P-mDuEfaG5Vu6w-1; Tue, 13 Jul 2021 08:23:10 -0400 Received: by mail-pj1-f45.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso1986868pjp.2 for ; Tue, 13 Jul 2021 05:23:10 -0700 (PDT) Received: from localhost ([103.142.141.217]) by smtp.gmail.com with ESMTPSA id x10sm15426384pfr.150.2021.07.13.05.23.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 05:23:09 -0700 (PDT) X-MC-Unique: 5-chzhSrN6KWgTQ_LFTbaw-1 X-MC-Unique: YSKNzJu4P-mDuEfaG5Vu6w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=r7ab55ipgJJHgWxertYh1QAinGSHf+3dZkmGx772P+A=; b=CVfqwDY1R3RdZDeNzcXR9QyU8gyljt42/QFx53hAXyYNaHiVEOYbdpdp9yuZdipQDS 6w+mRJq9Nu/323i+SQm4X71bUastp5hi4GjSND98F3oeE0QiMqmPHohjJTMuLLASdNZu 0ywzPH4CNhsfvqszvvXhzEJo4a6GdWZFi0Ala/67i/UPztOifAPUOQYPntMzYGb5FkAP mUQuJQ1WSp99vqNTzeX8HXD73+Jf9e2UhwuY7pHW1t7joEU/aS7xmGFsJpDjej+gurAr TV08ABnFXGEoz3FB9xlVckbYaMvsstxxRppIZ7FWQmch4DJxQD12UO/U0tb6Y8tlBdSE hTCA== X-Gm-Message-State: AOAM532NgHJUy7UqfuIdr3wVmaKNX0/R7RMdcvTJYYOAo1cA+gBkTxwS lwmrSO6DxQU8kn1ndymhtWGGxKRlUjriDh+bo7Q= X-Google-Smtp-Source: ABdhPJy+Qj/Whm8RiRNSiEdVFOilYIxtX8n0iM+OQPTlmiNcMpfllV8MTkTFesoSyNA2roJGjKE+oA== X-Received: by 2002:a17:90b:214:: with SMTP id fy20mr18963758pjb.62.1626178989310; Tue, 13 Jul 2021 05:23:09 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH] test_driver: Implement virDomainGetControlInfo and add test Date: Tue, 13 Jul 2021 20:21:32 +0800 Message-Id: <20210713122132.447132-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1626179019150100001 Content-Type: text/plain; charset="utf-8" As test driver won't have real background job running, in order to get all possible states, the time is used here to decide which state to be returned. The default time will get `ok` as return value. Note that using `virsh domtime fc4 200` won't take effect for the test driver, to get other states, you have to enter virsh interactive terminal and set time. Signed-off-by: Luke Yue Reviewed-by: Michal Privoznik --- src/test/test_driver.c | 63 ++++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 11 ++++++++ 2 files changed, 74 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ef0ddab54d..892dc978f2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2080,6 +2080,68 @@ testDomainGetState(virDomainPtr domain, return 0; } =20 +static int +testDomainGetControlInfo(virDomainPtr dom, + virDomainControlInfoPtr info, + unsigned int flags) +{ + virDomainObj *vm; + testDomainObjPrivate *priv; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(vm =3D testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + priv =3D vm->privateData; + + memset(info, 0, sizeof(*info)); + + if (priv->seconds > 0 && priv->seconds < 10000) { + info->state =3D VIR_DOMAIN_CONTROL_JOB; + info->stateTime =3D priv->seconds; + } else if (priv->seconds < 30000 && priv->seconds >=3D 10000) { + info->state =3D VIR_DOMAIN_CONTROL_OCCUPIED; + info->stateTime =3D priv->seconds - 10000; + } else if (priv->seconds < 60000 && priv->seconds >=3D 30000) { + info->state =3D VIR_DOMAIN_CONTROL_ERROR; + switch (priv->seconds % 4) { + case 0: + info->details =3D VIR_DOMAIN_CONTROL_ERROR_REASON_NONE; + break; + + case 1: + info->details =3D VIR_DOMAIN_CONTROL_ERROR_REASON_UNKNOWN; + break; + + case 2: + info->details =3D VIR_DOMAIN_CONTROL_ERROR_REASON_MONITOR; + break; + + case 3: + info->details =3D VIR_DOMAIN_CONTROL_ERROR_REASON_INTERNAL; + break; + + default: + info->details =3D VIR_DOMAIN_CONTROL_ERROR_REASON_NONE; + break; + } + info->stateTime =3D priv->seconds - 30000; + } else { + info->state =3D VIR_DOMAIN_CONTROL_OK; + } + + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static int testDomainGetTime(virDomainPtr dom, long long *seconds, @@ -9335,6 +9397,7 @@ static virHypervisorDriver testHypervisorDriver =3D { .domainGetHostname =3D testDomainGetHostname, /* 5.5.0 */ .domainGetInfo =3D testDomainGetInfo, /* 0.1.1 */ .domainGetState =3D testDomainGetState, /* 0.9.2 */ + .domainGetControlInfo =3D testDomainGetControlInfo, /* 7.6.0 */ .domainGetTime =3D testDomainGetTime, /* 5.4.0 */ .domainSetTime =3D testDomainSetTime, /* 5.7.0 */ .domainSave =3D testDomainSave, /* 0.3.2 */ diff --git a/tests/virshtest.c b/tests/virshtest.c index c1974c46cb..fe0c420958 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -250,6 +250,13 @@ static int testCompareDomstateByName(const void *data = G_GNUC_UNUSED) return testCompareOutputLit(exp, NULL, argv); } =20 +static int testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED) +{ + const char *const argv[] =3D { VIRSH_CUSTOM, "domcontrol", "fc4", NULL= }; + const char *exp =3D "ok\n\n"; + return testCompareOutputLit(exp, NULL, argv); +} + struct testInfo { const char *const *argv; const char *result; @@ -334,6 +341,10 @@ mymain(void) testCompareDomstateByName, NULL) !=3D 0) ret =3D -1; =20 + if (virTestRun("virsh domcontrol (by name)", + testCompareDomControlInfoByName, NULL) !=3D 0) + ret =3D -1; + /* It's a bit awkward listing result before argument, but that's a * limitation of C99 vararg macros. */ # define DO_TEST(i, result, ...) \ --=20 2.32.0