Discussion:
[libvirt] Help needed in simulating libvirt
Arun Viswanath
2013-09-10 18:03:36 UTC
Permalink
Hi All,
I'm need to simulate libvirt API's say to mock the libvirt API
responses. (Actually I need to simulate qemu API's response). Because of my
project needs I need to write this simulated libvirt server in Java. I
believe the simulated libvirt can be written as java RPC which should
capable to receive the client RPC request calls and by dispatcher we can
dispatch to the simulated java functions. I searched for .x file to be used
for generating server stubs but unfortunately .x files like
"remote_protocol.x", "virnetprotocol.x", "qemu_protocol.x" and
"lxc_monitor_protocol.x" are not containing any procedure for libvirt API's
that exposed. Please let me know which files will have these exposed
procedures and how can I use it in java,

Also I'm not sure how to implement the ssl layer support for the
libvirt server in java. I need to write a java server in such a way that
python client should capable to create a connection with uri
"qemu+tls://systemip:port?no_tty=1". Also with the created connection
object it should able to call the libvirt API's like getCapabilities, etc.

Any help and ideas on this will be really helpful.

Thanks in Advance,
Arun V
Eric Blake
2013-09-10 18:44:10 UTC
Permalink
Post by Arun Viswanath
Hi All,
I'm need to simulate libvirt API's say to mock the libvirt API
responses. (Actually I need to simulate qemu API's response). Because of my
project needs I need to write this simulated libvirt server in Java. I
believe the simulated libvirt can be written as java RPC which should
capable to receive the client RPC request calls and by dispatcher we can
dispatch to the simulated java functions. I searched for .x file to be used
for generating server stubs but unfortunately .x files like
"remote_protocol.x", "virnetprotocol.x", "qemu_protocol.x" and
"lxc_monitor_protocol.x" are not containing any procedure for libvirt API's
that exposed. Please let me know which files will have these exposed
procedures and how can I use it in java,
Rather than trying to write your own RPC handler, have you considered
using the existing libvirt-java bindings and just targetting the
test:/// URI connection? This will give you a fairly reliable exposure
to the libvirt APIs, without actually needing a working qemu.

The .x files implement the driver API; so also does the test driver.
Basically, src/libvirt.c is the public API, which then delegates to the
appropriate driver based on what URI you connected to; if the URI is
remote (as qemu:/// and all other stateful drivers are), then libvirt.so
passes it to src/remote/remote_driver.c to be bundled up into RPC calls
which mirror the semantics of the public API. If you want to install
your own mock driver, it may be easier to build a new URI and implement
the same C interface as the test driver (see src/test/test_driver.c)
than it is to implement your own RPC parser.
Post by Arun Viswanath
Also I'm not sure how to implement the ssl layer support for the
libvirt server in java. I need to write a java server in such a way that
python client should capable to create a connection with uri
"qemu+tls://systemip:port?no_tty=1". Also with the created connection
object it should able to call the libvirt API's like getCapabilities, etc.
Again, instead of trying to write your own RPC server, I'd instead focus
on utilizing the existing test:/// driver as your point of mocked calls.

As this is mostly development-related, I've set the reply-to to
libvir-list (we can drop libvirt-users from the rest of this thread).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Arun Viswanath
2013-09-11 07:20:37 UTC
Permalink
Hi Eric,

Thanks for your response.
I like to know how test driver works.

In the libvirt.org for test driver it is mentioned as "It can start with a
pre-configured default config, or be given a path to an alternate config".
Is the config is an xml file where we mentioned some dummy data so that the
test driver will return it as response. If yes then where can I find this
dummy file?

As mentioned earlier my intention is to mock qemu calls. so it test driver
works then I'm planning to remove the qemu driver and register "test"
driver as "qemu" driver and take the fake data from the config file. Please
let me know which are the files I need to look into to register "test" as
"qemu" and make its operations to work.

Thanks In Advance,
Arun V
Post by Eric Blake
Post by Arun Viswanath
Hi All,
I'm need to simulate libvirt API's say to mock the libvirt API
responses. (Actually I need to simulate qemu API's response). Because of
my
Post by Arun Viswanath
project needs I need to write this simulated libvirt server in Java. I
believe the simulated libvirt can be written as java RPC which should
capable to receive the client RPC request calls and by dispatcher we can
dispatch to the simulated java functions. I searched for .x file to be
used
Post by Arun Viswanath
for generating server stubs but unfortunately .x files like
"remote_protocol.x", "virnetprotocol.x", "qemu_protocol.x" and
"lxc_monitor_protocol.x" are not containing any procedure for libvirt
API's
Post by Arun Viswanath
that exposed. Please let me know which files will have these exposed
procedures and how can I use it in java,
Rather than trying to write your own RPC handler, have you considered
using the existing libvirt-java bindings and just targetting the
test:/// URI connection? This will give you a fairly reliable exposure
to the libvirt APIs, without actually needing a working qemu.
The .x files implement the driver API; so also does the test driver.
Basically, src/libvirt.c is the public API, which then delegates to the
appropriate driver based on what URI you connected to; if the URI is
remote (as qemu:/// and all other stateful drivers are), then libvirt.so
passes it to src/remote/remote_driver.c to be bundled up into RPC calls
which mirror the semantics of the public API. If you want to install
your own mock driver, it may be easier to build a new URI and implement
the same C interface as the test driver (see src/test/test_driver.c)
than it is to implement your own RPC parser.
Post by Arun Viswanath
Also I'm not sure how to implement the ssl layer support for the
libvirt server in java. I need to write a java server in such a way that
python client should capable to create a connection with uri
"qemu+tls://systemip:port?no_tty=1". Also with the created connection
object it should able to call the libvirt API's like getCapabilities,
etc.
Again, instead of trying to write your own RPC server, I'd instead focus
on utilizing the existing test:/// driver as your point of mocked calls.
As this is mostly development-related, I've set the reply-to to
libvir-list (we can drop libvirt-users from the rest of this thread).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Daniel P. Berrange
2013-09-11 08:53:20 UTC
Permalink
Post by Arun Viswanath
Hi Eric,
Thanks for your response.
I like to know how test driver works.
In the libvirt.org for test driver it is mentioned as "It can start with a
pre-configured default config, or be given a path to an alternate config".
Is the config is an xml file where we mentioned some dummy data so that the
test driver will return it as response. If yes then where can I find this
dummy file?
As mentioned earlier my intention is to mock qemu calls. so it test driver
works then I'm planning to remove the qemu driver and register "test"
driver as "qemu" driver and take the fake data from the config file. Please
let me know which are the files I need to look into to register "test" as
"qemu" and make its operations to work.
The XML file is provided via the URI. For example

test:///default

uses a built-in config, but you can supply a real path eg

test:///home/berrange/testnode.xml


Take a look at examples/xml/test/testnode.xml in the libvirt source
tree for an example.

FYI, the test driver is used very successfully in virt-install and
virt-manager for testing their functionality in an automated way,
so I can strongly recommend its use, over trying to mock the APIs
or wire protocol yourself.

Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Arun Viswanath
2013-09-11 11:00:13 UTC
Permalink
Hi,

Thanks for the response.

I've used the URI:
"test+ssh://<ipaddress>/default" and the connection is successful and with
that connection I issued getCapabilities and its result is attached.
I'm not sure how is result xml generated by the files in the /examples
folder.
Will you please explain how is this xml generated.

Also my client is not going to modified. My client is going to connect with
the URI "qemu+tls://<host>/system?no_tty=1", so I can't directly use the
test driver here so I need to replace the qemu driver with the test driver
and give my dummy response. So I need to know how to replace the driver say
qemu with test driver and generating my desired output.

If the test driver is not going to support me too much then I might want to
write new driver. Is there is any reference how to write new driver.

Regards,
Arun V
Post by Arun Viswanath
Post by Arun Viswanath
Hi Eric,
Thanks for your response.
I like to know how test driver works.
In the libvirt.org for test driver it is mentioned as "It can start
with a
Post by Arun Viswanath
pre-configured default config, or be given a path to an alternate
config".
Post by Arun Viswanath
Is the config is an xml file where we mentioned some dummy data so that
the
Post by Arun Viswanath
test driver will return it as response. If yes then where can I find this
dummy file?
As mentioned earlier my intention is to mock qemu calls. so it test
driver
Post by Arun Viswanath
works then I'm planning to remove the qemu driver and register "test"
driver as "qemu" driver and take the fake data from the config file.
Please
Post by Arun Viswanath
let me know which are the files I need to look into to register "test" as
"qemu" and make its operations to work.
The XML file is provided via the URI. For example
test:///default
uses a built-in config, but you can supply a real path eg
test:///home/berrange/testnode.xml
Take a look at examples/xml/test/testnode.xml in the libvirt source
tree for an example.
FYI, the test driver is used very successfully in virt-install and
virt-manager for testing their functionality in an automated way,
so I can strongly recommend its use, over trying to mock the APIs
or wire protocol yourself.
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/:|
|: http://libvirt.org -o- http://virt-manager.org:|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/:|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc:|
Daniel P. Berrange
2013-09-11 11:09:32 UTC
Permalink
Post by Arun Viswanath
Hi,
Thanks for the response.
"test+ssh://<ipaddress>/default" and the connection is successful and with
that connection I issued getCapabilities and its result is attached.
I'm not sure how is result xml generated by the files in the /examples
folder.
Will you please explain how is this xml generated.
You write the XML yourself to describe the initiall characteristics of the
host scenario you are trying to simulate. eg the XML file describes what
guests you want to pre-create, the capabilities of the host, the storage
pools, storage volumes, etc, etc. The examples/xml/test directory shows
some illustrations of how todo this.
Post by Arun Viswanath
Also my client is not going to modified. My client is going to connect with
the URI "qemu+tls://<host>/system?no_tty=1", so I can't directly use the
test driver here so I need to replace the qemu driver with the test driver
and give my dummy response. So I need to know how to replace the driver say
qemu with test driver and generating my desired output.
Why can't you modify your client. It is pretty reasonable to have the
URI be configurable for any libvirt based app, so I don't see why this
should be a blocker.
Post by Arun Viswanath
If the test driver is not going to support me too much then I might want to
write new driver. Is there is any reference how to write new driver.
I don't see any compelling reason to create a new driver for the scenario
you are describing, and would likely reject any patches aiming to do so
based in the info you have provided so far.

Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Arun Viswanath
2013-09-11 11:37:47 UTC
Permalink
Hi Daniel,

We are writing a scale test scenario for our client. So for the purpose of
scale test with the real code we can't request them to change the URI's, so
not too much scope on changing the client.
Also we are having some simulated java object of Domain, hypervisor(kvm),
etc for which we have to populate the API Call response.

Our aim it to simulate one libvirt for more than one KVM hosts so that by
some way we will identify to which host particular call come and from that
java model we will populate the response.
So what I'm trying is to do is to create the initial xml from our java
object and then we will start the libvirt test driver. So on the driver
I'll try to find the host request and populate the response from the
particular xmls.

Any good reference or document about how to populate the test response will
be really helpful.
This is my entire scenario. Any idea or new approach is also really
appreciable.

Thanks In Advance,
Arun V
Post by Daniel P. Berrange
Post by Arun Viswanath
Hi,
Thanks for the response.
"test+ssh://<ipaddress>/default" and the connection is successful and
with
Post by Arun Viswanath
that connection I issued getCapabilities and its result is attached.
I'm not sure how is result xml generated by the files in the /examples
folder.
Will you please explain how is this xml generated.
You write the XML yourself to describe the initiall characteristics of the
host scenario you are trying to simulate. eg the XML file describes what
guests you want to pre-create, the capabilities of the host, the storage
pools, storage volumes, etc, etc. The examples/xml/test directory shows
some illustrations of how todo this.
Post by Arun Viswanath
Also my client is not going to modified. My client is going to connect
with
Post by Arun Viswanath
the URI "qemu+tls://<host>/system?no_tty=1", so I can't directly use the
test driver here so I need to replace the qemu driver with the test
driver
Post by Arun Viswanath
and give my dummy response. So I need to know how to replace the driver
say
Post by Arun Viswanath
qemu with test driver and generating my desired output.
Why can't you modify your client. It is pretty reasonable to have the
URI be configurable for any libvirt based app, so I don't see why this
should be a blocker.
Post by Arun Viswanath
If the test driver is not going to support me too much then I might want
to
Post by Arun Viswanath
write new driver. Is there is any reference how to write new driver.
I don't see any compelling reason to create a new driver for the scenario
you are describing, and would likely reject any patches aiming to do so
based in the info you have provided so far.
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/:|
|: http://libvirt.org -o- http://virt-manager.org:|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/:|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc:|
Loading...