Re: [dbus PATCH 03/15] Implement StorageVolCreateXML method for StoragePool Interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 12, 2018 at 11:00:16AM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
> ---
>  data/org.libvirt.StoragePool.xml |  7 +++++++
>  src/storagepool.c                | 34 ++++++++++++++++++++++++++++++++++
>  tests/libvirttest.py             | 17 +++++++++++++++++
>  tests/test_storage.py            |  4 ++++
>  4 files changed, 62 insertions(+)
> 
> diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml
> index 764c9c1..51d65ab 100644
> --- a/data/org.libvirt.StoragePool.xml
> +++ b/data/org.libvirt.StoragePool.xml
> @@ -68,6 +68,13 @@
>          value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/>
>        <arg name="flags" type="u" direction="in"/>
>      </method>
> +    <method name="StorageVolCreateXML">
> +      <annotation name="org.gtk.GDBus.DocString"
> +        value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML"/>
> +      <arg name="xml" type="s" direction="in"/>
> +      <arg name="flags" type="u" direction="in"/>
> +      <arg name="storageVol" type="o" direction="out"/>
> +    </method>
>      <method name="Undefine">
>        <annotation name="org.gtk.GDBus.DocString"
>          value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine"/>
> diff --git a/src/storagepool.c b/src/storagepool.c
> index 11e356c..c3fd0bf 100644
> --- a/src/storagepool.c
> +++ b/src/storagepool.c
> @@ -368,6 +368,39 @@ virtDBusStoragePoolRefresh(GVariant *inArgs,
>          virtDBusUtilSetLastVirtError(error);
>  }
>  
> +static void
> +virtDBusStoragePoolStorageVolCreateXML(GVariant *inArgs,
> +                                       GUnixFDList *inFDs G_GNUC_UNUSED,
> +                                       const gchar *objectPath,
> +                                       gpointer userData,
> +                                       GVariant **outArgs,
> +                                       GUnixFDList **outFDs G_GNUC_UNUSED,
> +                                       GError **error)
> +{
> +    virtDBusConnect *connect = userData;
> +    g_autoptr(virStoragePool) storagePool = NULL;
> +    g_autoptr(virStorageVol) storageVol = NULL;
> +    gchar *xml;
> +    guint flags;
> +    g_autofree gchar *path = NULL;
> +
> +    g_variant_get(inArgs, "(&su)", &xml, &flags);
> +
> +    storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath,
> +                                                       error);
> +    if (!storagePool)
> +        return;
> +
> +    storageVol = virStorageVolCreateXML(storagePool, xml, flags);
> +    if (!storageVol)
> +        return virtDBusUtilSetLastVirtError(error);
> +
> +    path = virtDBusUtilBusPathForVirStorageVol(storageVol,
> +                                               connect->storageVolPath);
> +
> +    *outArgs = g_variant_new("(o)", path);
> +}
> +
>  static void
>  virtDBusStoragePoolUndefine(GVariant *inArgs G_GNUC_UNUSED,
>                              GUnixFDList *inFDs G_GNUC_UNUSED,
> @@ -408,6 +441,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = {
>      { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc },
>      { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes },
>      { "Refresh", virtDBusStoragePoolRefresh },
> +    { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML },
>      { "Undefine", virtDBusStoragePoolUndefine },
>      { 0 }
>  };
> diff --git a/tests/libvirttest.py b/tests/libvirttest.py
> index 3cd02ef..f65251a 100644
> --- a/tests/libvirttest.py
> +++ b/tests/libvirttest.py
> @@ -100,6 +100,23 @@ class BaseTestClass():
>          obj = self.bus.get_object('org.libvirt', path)
>          return path, obj
>  
> +    def test_storage_vol(self):
> +        minimal_storage_vol_xml = '''
> +        <volume>
> +          <name>sparse.img</name>
> +          <capacity unit="G">2</capacity>
> +          <target>
> +            <path>/var/lib/virt/images/sparse.img</path>
> +          </target>
> +        </volume>
> +        '''
> +        _, test_storage_pool = self.test_storage_pool()
> +        interface_obj = dbus.Interface(test_storage_pool,
> +                                       'org.libvirt.StoragePool')
> +        path = interface_obj.StorageVolCreateXML(minimal_storage_vol_xml, 0)
> +        obj = self.bus.get_object('org.libvirt', path)
> +        return path, obj

Right, so there is no default volume defined for the test driver so we
cannot use the same approach as for other object types.  However, the
XML of the new storage volume should be in the storage_pool test file as
we have new domain XML in the connect test file.  Or we can move all the
XMLs into specific file and include it.

> +
>  
>  class DomainEvent(IntEnum):
>      DEFINED = 0
> diff --git a/tests/test_storage.py b/tests/test_storage.py
> index 79e0c16..1cd1249 100755
> --- a/tests/test_storage.py
> +++ b/tests/test_storage.py
> @@ -126,6 +126,10 @@ class TestStoragePool(libvirttest.BaseTestClass):
>  
>          self.main_loop()
>  
> +    def test_storage_pool_volume_create(self):
> +        path, _ = self.test_storage_vol()
> +        assert isinstance(path, dbus.ObjectPath)
> +

The test_storage_vol hides the actual StorageVolCreateXML call.  I
understand the we need to create the storage volume for every single
test-case because the libvirt-dbus deamon is restarted every time.
It would be nice to do it differently, for example to have some method
that would precreate the storage volume and this one would do the same
as for other objects.

Otherwise looks good.  If it turn out to be difficult to make it work
that way we can use this current solution for tests.

Pavel

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux