From nobody Wed May 14 06:09:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152587996411966.18926927643122; Wed, 9 May 2018 08:32:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42A37C00366A; Wed, 9 May 2018 15:32:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7019E18023; Wed, 9 May 2018 15:32:41 +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 439801808850; Wed, 9 May 2018 15:32:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w49FWYtc009811 for ; Wed, 9 May 2018 11:32:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2FAC2010CBA; Wed, 9 May 2018 15:32:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6EEE2010CA0 for ; Wed, 9 May 2018 15:32:32 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2FD830CB6F9 for ; Wed, 9 May 2018 15:32:30 +0000 (UTC) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w49FKwDW076160 for ; Wed, 9 May 2018 11:32:30 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hv2efcn6s-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 09 May 2018 11:32:29 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 May 2018 16:32:28 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 9 May 2018 16:32:26 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w49FWOtn51249174 for ; Wed, 9 May 2018 15:32:25 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DDB54AE2E6 for ; Wed, 9 May 2018 15:46:40 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C544DAE590 for ; Wed, 9 May 2018 15:46:40 +0100 (BST) Received: from marc-ibm.boeblingen.de.ibm.com (unknown [9.152.224.71]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Wed, 9 May 2018 15:46:40 +0100 (BST) From: Marc Hartmayer To: Date: Wed, 9 May 2018 16:56:20 +0200 In-Reply-To: <20180509145622.23049-1-mhartmay@linux.vnet.ibm.com> References: <20180509145622.23049-1-mhartmay@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18050915-0040-0000-0000-00000437CF1E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18050915-0041-0000-0000-0000263C106E Message-Id: <20180509145622.23049-11-mhartmay@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-09_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805090142 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 09 May 2018 15:32:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 09 May 2018 15:32:31 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mhartmay@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.7 (RCVD_IN_DNSWL_LOW) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/12] tests: Add tests for virDomainCreateWithParams 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 09 May 2018 15:32:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski --- src/test/test_driver.c | 6 + tests/objecteventtest.c | 321 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 327 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index cb5377004df7..6536e41bf4ad 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -444,6 +444,12 @@ static const char *defaultConnXML =3D " " " hvm" " " +" " +" " +" " +" " +" " +" " "" "" "" diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c index 4b12572eb45b..cc7287e2fc66 100644 --- a/tests/objecteventtest.c +++ b/tests/objecteventtest.c @@ -472,6 +472,325 @@ testDomainStartStopEvent(const void *data) return ret; } =20 + +typedef struct { + int count_boot_order; + int count_os_boot; + char *bootdeviceIdentifier; + char *kernel; + char *initrd; + char *cmdline; +} bootConfiguration; + + +static void +bootConfigurationFree(bootConfiguration *conf) +{ + if (!conf) + return; + + VIR_FREE(conf->bootdeviceIdentifier); + VIR_FREE(conf->kernel); + VIR_FREE(conf->initrd); + VIR_FREE(conf->cmdline); + VIR_FREE(conf); +} + + +static bool +bootConfigurationEqual(bootConfiguration *a, + bootConfiguration *b) +{ + if (!a || !b) + return a =3D=3D b; + + return a->count_boot_order =3D=3D b->count_boot_order && + a->count_os_boot =3D=3D b->count_os_boot && + STREQ_NULLABLE(a->bootdeviceIdentifier, b->bootdeviceIdentifier) && + STREQ_NULLABLE(a->kernel, b->kernel) && + STREQ_NULLABLE(a->initrd, b->initrd) && + STREQ_NULLABLE(a->cmdline, b->cmdline); +} + + +/* Caller must free() the returned value */ +static bootConfiguration* +getBootConfiguration(virDomainPtr dom) +{ + bootConfiguration* ret; + char *xml =3D NULL; + xmlDocPtr doc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + xmlNodePtr node =3D NULL; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + if (!(xml =3D virDomainGetXMLDesc(dom, 0))) + goto error; + + if (!(doc =3D virXMLParseStringCtxt(xml, "(domain_definition)", &ctxt)= )) + goto error; + + ret->kernel =3D virXPathString("string(./os/kernel[1])", ctxt); + ret->initrd =3D virXPathString("string(./os/initrd[1])", ctxt); + ret->cmdline =3D virXPathString("string(./os/cmdline[1])", ctxt); + + if (virXPathInt("count(./os/boot)", ctxt, &ret->count_boot_order) < 0) + goto error; + + if ((virXPathInt("count(./devices/*/boot[@order=3D'1'])", ctxt, &ret->= count_boot_order) < 0)) + goto error; + + if (ret->count_boot_order > 0) { + node =3D virXPathNode("./devices/*/boot[@order=3D'1']/..", ctxt); + if (!node) + goto error; + + ctxt->node =3D node; + + /* As we're using a heuristic for setting the boot device do + * the same here. + * + * Represents the XML node a disk? */ + ret->bootdeviceIdentifier =3D virXPathString("string(./target/@dev= )", ctxt); + + /* Represents the XML node a network interface? (we only allow + * MAC addresses as boot device identifier for the tests (at + * least for the moment)) */ + if (!ret->bootdeviceIdentifier) + ret->bootdeviceIdentifier =3D virXPathString("string(./mac/@ad= dress)", ctxt); + } else { + ret->bootdeviceIdentifier =3D NULL; + } + + cleanup: + xmlFreeDoc(doc); + xmlXPathFreeContext(ctxt); + VIR_FREE(xml); + return ret; + + error: + bootConfigurationFree(ret); + ret =3D NULL; + goto cleanup; +} + + +static int +verifyOriginalState(virDomainPtr dom, bootConfiguration *original_conf) +{ + bool ret; + bootConfiguration *current_conf =3D getBootConfiguration(dom); + + if (!current_conf) + return false; + + ret =3D bootConfigurationEqual(original_conf, + current_conf); + bootConfigurationFree(current_conf); + return ret; +} + + +static int +verifyChanges(virDomainPtr dom, + const char *bootdevice, + const char *kernel, + const char *initrd, + const char *cmdline) +{ + int ret =3D -1; + bootConfiguration *current_conf; + + if (!(current_conf =3D getBootConfiguration(dom))) + goto cleanup; + + /* verify the new boot order */ + if (bootdevice) { + if (STRNEQ_NULLABLE(current_conf->bootdeviceIdentifier, bootdevice= )) + goto cleanup; + + if (current_conf->count_os_boot !=3D 0) + goto cleanup; + + if (current_conf->count_boot_order < 1) + goto cleanup; + } + + /* verify the other OS node changes */ + if ((kernel && virStringIsEmpty(kernel) && current_conf->kernel) || + (!virStringIsEmpty(kernel) && STRNEQ_NULLABLE(current_conf->kernel= , kernel))) + goto cleanup; + + if ((initrd && virStringIsEmpty(initrd) && current_conf->initrd) || + (!virStringIsEmpty(initrd) && STRNEQ_NULLABLE(current_conf->initrd= , initrd))) + goto cleanup; + + if ((cmdline && virStringIsEmpty(cmdline) && current_conf->cmdline) || + (!virStringIsEmpty(cmdline) && STRNEQ_NULLABLE(current_conf->cmdli= ne, cmdline))) + goto cleanup; + + ret =3D 0; + cleanup: + bootConfigurationFree(current_conf); + return ret; +} + + +static int +testDomainCreateWithParamsHelper(virDomainPtr dom, lifecycleEventCounter *= counter, + bool failure_expected, const char *bootde= vice, + const char *kernel, const char *initrd, + const char *cmdline, unsigned int flags, = bootConfiguration *original_conf) +{ + int rc; + int ret =3D -1; + virTypedParameterPtr params =3D NULL; + int nparams =3D 0; + int maxparams =3D 0; + + lifecycleEventCounter_reset(counter); + + if (bootdevice) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_DEVICE_IDENTIFI= ER, + VIR_TYPED_PARAM_STRING, + bootdevice); + + if (kernel) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_KERNEL, + VIR_TYPED_PARAM_STRING, + kernel); + + if (initrd) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_INITRD, + VIR_TYPED_PARAM_STRING, + initrd); + + if (cmdline) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_CMDLINE, + VIR_TYPED_PARAM_STRING, + cmdline); + + rc =3D virDomainCreateWithParams(dom, + params, + nparams, + flags); + if (rc < 0) { + if (failure_expected) + ret =3D 0; + goto cleanup; + } + + if (virEventRunDefaultImpl() < 0) + goto cleanup; + + if (counter->startEvents !=3D 1 || + counter->stopEvents !=3D 0) + goto cleanup; + + if (verifyChanges(dom, bootdevice, kernel, initrd, cmdline) < 0) + goto cleanup; + + if (virDomainDestroy(dom) < 0) + goto cleanup; + + if (verifyOriginalState(dom, original_conf) < 0) + goto cleanup; + + if (virEventRunDefaultImpl() < 0) + goto cleanup; + + if (counter->startEvents !=3D 1 || + counter->stopEvents !=3D 1) + goto cleanup; + + ret =3D 0; + cleanup: + virTypedParamsFree(params, nparams); + return ret; +} + + +static int +testDomainCreateWithParams(const void *data) +{ + const objecteventTest *test =3D data; + lifecycleEventCounter counter; + int eventId =3D VIR_DOMAIN_EVENT_ID_LIFECYCLE; + int id; + int ret =3D -1; + virDomainPtr dom; + bootConfiguration *original_boot_conf =3D NULL; + + dom =3D virDomainLookupByName(test->conn, "test"); + if (!dom) + return -1; + + /* First clean up, register for the life cycle events, and get the + * original, persistent boot configuration of the domain */ + virDomainDestroy(dom); + + id =3D virConnectDomainEventRegisterAny(test->conn, dom, eventId, + VIR_DOMAIN_EVENT_CALLBACK(&domai= nLifecycleCb), + &counter, NULL); + + if (!(original_boot_conf =3D getBootConfiguration(dom))) + goto cleanup; + + if (testDomainCreateWithParamsHelper(dom, &counter, true, "notAvailabl= eBootDevice", + NULL, NULL, NULL, 0, original_boo= t_conf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, NULL, NULL,= NULL, + NULL, 0, original_boot_conf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, NULL, "newK= ernel", + NULL, NULL, 0, original_boot_conf= ) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, NULL, NULL,= "newInitrd", + NULL, 0, original_boot_conf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, true, "notAvailabl= eBootDevice", + "newInitrd", NULL, NULL, 0, origi= nal_boot_conf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, NULL, NULL,= NULL, "newCmdline", + 0, original_boot_conf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, NULL, "newK= ernel", "newInitrd", + "newCmdline", 0, original_boot_co= nf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, NULL, "", "= ", "", 0, + original_boot_conf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, "vda", NULL= , NULL, NULL, + 0, original_boot_conf) < 0) + goto cleanup; + if (testDomainCreateWithParamsHelper(dom, &counter, false, "vda", NULL= , "blaa", "bla", + 0, original_boot_conf) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + bootConfigurationFree(original_boot_conf); + virConnectDomainEventDeregisterAny(test->conn, id); + virDomainFree(dom); + + return ret; +} + + static int testNetworkCreateXML(const void *data) { @@ -864,6 +1183,8 @@ mymain(void) ret =3D EXIT_FAILURE; if (virTestRun("Domain start stop events", testDomainStartStopEvent, &= test) < 0) ret =3D EXIT_FAILURE; + if (virTestRun("Domain start stop events with params", testDomainCreat= eWithParams, &test) < 0) + ret =3D EXIT_FAILURE; =20 /* Network event tests */ /* Tests requiring the test network not to be set up*/ --=20 2.13.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list