From nobody Fri Nov 21 10:09:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1763628152; cv=none; d=zohomail.com; s=zohoarc; b=hCO2ZuJFNyGqK+XpPg1VyxI7FaLcIKYSDf59eYQh30rHAAYaG5bYGkFMW7wiVU2YGajiVg9JjPUifVD+zQIkqg0e5Lr67QCc1xmMVF14QnxhviFUJQDpqlbPGbQZmx7JSjHeTIU4YajmRxl0bgtAL8X86/ca6eeY6SKq8NENrYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763628152; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=3qq4IMXgWa95Fies3FqkO4nPJyxJMA8JCnM+vWKKuKc=; b=kDISdomrDPFsohrqZJ60KHi+2uz3izn6lUPp7waCYBsVxolNOuEFWQJMSj44QVrsJ/iqSD+fmytZTxnZYQDK1piy72CAQqh6olAhtagUosd7qawbvy2RA/7qTRwD5CXcTNhlqdWJ/AdaXzlEfPsVtdwBpS8B/Wbz3c/Ok9+5pXU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1763628152069184.45358612175733; Thu, 20 Nov 2025 00:42:32 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3397A44197; Thu, 20 Nov 2025 03:42:31 -0500 (EST) Received: from [172.19.199.53] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 019D63F313; Thu, 20 Nov 2025 03:37:21 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 9D5FD41C0F; Thu, 20 Nov 2025 03:33:09 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 74FD43FCA6 for ; Thu, 20 Nov 2025 03:33:08 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-igVPelI7MiWmTolPU_5XeQ-1; Thu, 20 Nov 2025 03:33:06 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B7B931800372 for ; Thu, 20 Nov 2025 08:33:05 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D47E180049F for ; Thu, 20 Nov 2025 08:33:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763627588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3qq4IMXgWa95Fies3FqkO4nPJyxJMA8JCnM+vWKKuKc=; b=E+nvBQzzYbsde4AAEwxBonN00DGcHbYkByQ/x3y1iy8JZS+rXPDnT5FPiEOyTzbEo0C9QM A28lGHP/N3d4n9oJMKJTROnPd4OWaFyFMSU7UnezKlZtk+9vOHHnB4YHz6/puDdQulq/1+ KsRTmsrT6UMaiQ2NBCaWNke5fCtI3gI= X-MC-Unique: igVPelI7MiWmTolPU_5XeQ-1 X-Mimecast-MFC-AGG-ID: igVPelI7MiWmTolPU_5XeQ_1763627585 To: devel@lists.libvirt.org Subject: [PATCH 6/9] tests: Introduce vmx2xmlmock Date: Thu, 20 Nov 2025 09:32:51 +0100 Message-ID: <9a2629aee6de47c0abd8fe22d09ebba95f81e048.1763627556.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6SB4CezKTjw988BOJwRBpnNw4MumaGA32qXYpGTh8OU_1763627585 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: H7C2KSOVUI7GZBONRM4JS4TNCSI2ITRY X-Message-ID-Hash: H7C2KSOVUI7GZBONRM4JS4TNCSI2ITRY X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1763628154208018900 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik If we want vmx2xmltest to use actual file name parser that's used in production (esxParseVMXFileName()) we need a mock to stop it from doing any HTTP requests and also to return predictable data. So far, the function can call three functions that do HTTP requests: esxVI_LookupDatastoreList(), esxVI_LookupDatastoreHostMount() and esxVI_LookupDatastoreByName(). Mock all three of them. And since their implementation uses some other symbols (like allocators or _AppendToList() helpers) we need to expose these symbols too. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/libvirt_esx.syms | 10 ++++++ tests/meson.build | 3 ++ tests/vmx2xmlmock.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 tests/vmx2xmlmock.c diff --git a/src/libvirt_esx.syms b/src/libvirt_esx.syms index d05684fd97..d228e2bef7 100644 --- a/src/libvirt_esx.syms +++ b/src/libvirt_esx.syms @@ -18,8 +18,18 @@ esxVI_LookupDatastoreList; =20 =20 # esx/esx_vi_types.h +esxVI_AnyType_Alloc; esxVI_DateTime_ConvertToCalendarTime; =20 + +# esx/esx/esx_vi_types.generated.h +esxVI_DatastoreHostMount_Alloc; +esxVI_DynamicProperty_Alloc; +esxVI_DynamicProperty_AppendToList; +esxVI_HostMountInfo_Alloc; +esxVI_ObjectContent_Alloc; +esxVI_ObjectContent_AppendToList; + # Let emacs know we want case-insensitive sorting # Local Variables: # sort-fold-case: t diff --git a/tests/meson.build b/tests/meson.build index 0d76d37959..9adf172b7f 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -553,6 +553,9 @@ if conf.has('WITH_VMX') { 'name': 'vmx2xmltest' }, { 'name': 'xml2vmxtest' }, ] + mock_libs +=3D [ + { 'name': 'vmx2xmlmock', 'deps': [ esx_dep ] }, + ] endif =20 if conf.has('WITH_JSON') diff --git a/tests/vmx2xmlmock.c b/tests/vmx2xmlmock.c new file mode 100644 index 0000000000..ce4a9a426b --- /dev/null +++ b/tests/vmx2xmlmock.c @@ -0,0 +1,79 @@ +#include + +#include "internal.h" +#include "esx_vi.h" + +int +esxVI_LookupDatastoreList(esxVI_Context *ctx G_GNUC_UNUSED, + esxVI_String *propertyNameList, + esxVI_ObjectContent **datastoreList) +{ + esxVI_String *tmp; + + for (tmp =3D propertyNameList; tmp; tmp =3D tmp->_next) { + esxVI_ObjectContent *obj =3D NULL; + + if (STREQ(tmp->value, "summary.name")) { + esxVI_DynamicProperty *prop =3D NULL; + + esxVI_ObjectContent_Alloc(&obj); + + esxVI_DynamicProperty_Alloc(&prop); + prop->name =3D g_strdup("summary.name"); + + esxVI_AnyType_Alloc(&prop->val); + prop->val->type =3D esxVI_Type_String; + prop->val->other =3D g_strdup("xsd:string"); + prop->val->value =3D g_strdup("datastore"); + prop->val->string =3D prop->val->value; + esxVI_DynamicProperty_AppendToList(&obj->propSet, prop); + } + + if (obj) { + esxVI_ObjectContent_AppendToList(datastoreList, obj); + } + } + + return 0; +} + + +int +esxVI_LookupDatastoreHostMount(esxVI_Context *ctx G_GNUC_UNUSED, + esxVI_ManagedObjectReference *datastore G_G= NUC_UNUSED, + esxVI_DatastoreHostMount **hostMount, + esxVI_Occurrence occurrence G_GNUC_UNUSED) +{ + esxVI_DatastoreHostMount *hm =3D NULL; + + esxVI_DatastoreHostMount_Alloc(&hm); + esxVI_HostMountInfo_Alloc(&hm->mountInfo); + hm->mountInfo->path =3D g_strdup("/non/existent"); + hm->mountInfo->accessMode =3D g_strdup("readWrite"); + hm->mountInfo->accessible =3D esxVI_Boolean_True; + + *hostMount =3D hm; + return 0; +} + + +int +esxVI_LookupDatastoreByName(esxVI_Context *ctx G_GNUC_UNUSED, + const char *name, + esxVI_String *propertyNameList G_GNUC_UNUSED, + esxVI_ObjectContent **datastore, + esxVI_Occurrence occurrence G_GNUC_UNUSED) +{ + esxVI_ObjectContent *obj =3D NULL; + + if (STREQ(name, "missing") || STREQ(name, "ds")) { + *datastore =3D NULL; + return 0; + } + + /* No need to return anything useful, empty object is fine. */ + esxVI_ObjectContent_Alloc(&obj); + esxVI_ObjectContent_AppendToList(datastore, obj); + + return 0; +} --=20 2.51.0