ruby-libvirt-0.5.1/0000775000175000017500000000000012253415712015473 5ustar clalancetteclalancetteruby-libvirt-0.5.1/Rakefile0000664000175000017500000001120312253415670017140 0ustar clalancetteclalancette# -*- ruby -*- # Rakefile: build ruby libvirt bindings # # Copyright (C) 2007,2010 Red Hat, Inc. # Copyright (C) 2013 Chris Lalancette # # Distributed under the GNU Lesser General Public License v2.1 or later. # See COPYING for details # # David Lutterkort # Rakefile for ruby-rpm -*- ruby -*- require 'rake/clean' begin require 'rdoc/task' rescue LoadError require 'rake/rdoctask' end require 'rake/testtask' require 'rubygems/package_task' require 'rbconfig' PKG_NAME='ruby-libvirt' PKG_VERSION='0.5.1' EXT_CONF='ext/libvirt/extconf.rb' MAKEFILE="ext/libvirt/Makefile" LIBVIRT_MODULE="ext/libvirt/_libvirt.so" SPEC_FILE="ruby-libvirt.spec" LIBVIRT_SRC=Dir.glob("ext/libvirt/*.c") LIBVIRT_SRC << MAKEFILE # # Additional files for clean/clobber # CLEAN.include [ "ext/**/*.o", LIBVIRT_MODULE, "ext/**/depend", "ext/**/*.gcda", "ext/**/*.gcno", "ext/**/*.gcov" ] CLOBBER.include [ "config.save", "ext/**/mkmf.log", "ext/**/extconf.h", MAKEFILE ] task :default => :build # # Build locally # file MAKEFILE => EXT_CONF do |t| Dir::chdir(File::dirname(EXT_CONF)) do extra = "" args = ARGV.grep(/^--with-libvirt-include=/) extra += args[0].chomp unless args.empty? args = ARGV.grep(/^--with-libvirt-lib=/) extra += " " + args[0].chomp unless args.empty? unless sh "ruby #{File::basename(EXT_CONF)} #{extra}" $stderr.puts "Failed to run extconf" break end end end file LIBVIRT_MODULE => LIBVIRT_SRC do |t| Dir::chdir(File::dirname(EXT_CONF)) do unless sh "make" $stderr.puts "make failed" break end end end desc "Build the native library" task :build => LIBVIRT_MODULE # # Test task # Rake::TestTask.new(:test) do |t| t.test_files = [ 'tests/test_conn.rb', 'tests/test_domain.rb', 'tests/test_interface.rb', 'tests/test_network.rb', 'tests/test_nodedevice.rb', 'tests/test_nwfilter.rb', 'tests/test_open.rb', 'tests/test_secret.rb', 'tests/test_storage.rb', 'tests/test_stream.rb' ] t.libs = [ 'lib', 'ext/libvirt' ] end task :test => :build # # Documentation tasks # RDOC_FILES = FileList[ "README.rdoc", "lib/libvirt.rb", "ext/libvirt/_libvirt.c", "ext/libvirt/connect.c", "ext/libvirt/domain.c", "ext/libvirt/interface.c", "ext/libvirt/network.c", "ext/libvirt/nodedevice.c", "ext/libvirt/nwfilter.c", "ext/libvirt/secret.c", "ext/libvirt/storage.c", "ext/libvirt/stream.c" ] Rake::RDocTask.new do |rd| rd.main = "README.rdoc" rd.rdoc_dir = "doc/site/api" rd.rdoc_files.include(RDOC_FILES) end Rake::RDocTask.new(:ri) do |rd| rd.main = "README.rdoc" rd.rdoc_dir = "doc/ri" rd.options << "--ri-system" rd.rdoc_files.include(RDOC_FILES) end # # Splint task # task :splint => [ MAKEFILE ] do |t| Dir::chdir(File::dirname(EXT_CONF)) do unless sh "splint -I" + Config::CONFIG['vendorarchdir'] + " *.c" $stderr.puts "Failed to run splint" break end end end # # Package tasks # PKG_FILES = FileList[ "Rakefile", "COPYING", "README", "NEWS", "README.rdoc", "lib/**/*.rb", "ext/**/*.[ch]", "ext/**/MANIFEST", "ext/**/extconf.rb", "tests/**/*", "spec/**/*" ] DIST_FILES = FileList[ "pkg/*.src.rpm", "pkg/*.gem", "pkg/*.zip", "pkg/*.tgz" ] SPEC = Gem::Specification.new do |s| s.name = PKG_NAME s.version = PKG_VERSION s.email = "libvir-list@redhat.com" s.homepage = "http://libvirt.org/ruby/" s.summary = "Ruby bindings for LIBVIRT" s.files = PKG_FILES s.required_ruby_version = '>= 1.8.1' s.extensions = "ext/libvirt/extconf.rb" s.author = "David Lutterkort, Chris Lalancette" s.rubyforge_project = "None" s.description = "Ruby bindings for libvirt." s.license = "LGPLv2" end Gem::PackageTask.new(SPEC) do |pkg| pkg.need_tar = true pkg.need_zip = true end desc "Build (S)RPM for #{PKG_NAME}" task :rpm => [ :package ] do |t| system("sed -e 's/@VERSION@/#{PKG_VERSION}/' #{SPEC_FILE} > pkg/#{SPEC_FILE}") Dir::chdir("pkg") do |dir| dir = File::expand_path(".") system("rpmbuild --define '_topdir #{dir}' --define '_sourcedir #{dir}' --define '_srcrpmdir #{dir}' --define '_rpmdir #{dir}' --define '_builddir #{dir}' -ba #{SPEC_FILE} > rpmbuild.log 2>&1") if $? != 0 raise "rpmbuild failed" end end end ruby-libvirt-0.5.1/NEWS0000664000175000017500000001143212253415172016173 0ustar clalancetteclalancette2013-12-15 * Fixes to compile against older libvirt * Fixes to compile against ruby 1.8 2013-12-09 0.5.0 * Updated Network class, implementing almost all libvirt APIs * Updated Domain class, implementing almost all libvirt APIs * Updated Connection class, implementing almost all libvirt APIs * Updated DomainSnapshot class, implementing almost all libvirt APIs * Updated NodeDevice class, implementing almost all libvirt APIs * Updated Storage class, implementing almost all libvirt APIs * Add constants for almost all libvirt defines * Improved performance in the library by using alloca 2011-07-27 0.4.0 * Updated Domain class, implementing dom.memory_parameters=, dom.memory_parameters, dom.updated?, dom.migrate2, dom.migrate_to_uri2, dom.migrate_set_max_speed, dom.qemu_monitor_command, dom.blkio_parameters, dom.blkio_parameters=, dom.state, dom.open_console, dom.screenshot, and dom.inject_nmi * Implementation of the Stream class, which covers the libvirt virStream APIs * Add the ability to build against non-system libvirt libraries * Updated Error object, which now includes the libvirt code, component and level of the error, as well as all of the error constants from libvirt.h * Updated Connect class, implementing conn.sys_info, conn.stream, conn.interface_change_begin, conn.interface_change_commit, and conn.interface_change_rollback * Updated StorageVol class, implementing vol.download and vol.upload * Various bugfixes 2010-12-12 0.3.0 * Implementation of Libvirt::open_auth, Libvirt::event_register_impl * Updated Connect class, implementing conn.compare_cpu, conn.baseline_cpu, conn.domain_event_register_any, conn.domain_event_deregister_any, conn.domain_event_register, conn.domain_event_deregister, and conn.create_domain_xml. * Updated Domain class, implementing dom.get_vcpus, dom.update_device, dom.scheduler_type, dom.scheduler_parameters, dom.scheduler_parameters=, dom.num_vcpus, dom.vcpus_flags=, and dom.qemu_monitor_command. * Updated Interface class, implementing interface.free * Many potential memory leaks have been fixed. * Many bugfixes. * Documentation update of many methods, including all of the lookup methods that were missing before. 2010-11-10 * Gem for version 0.2.0 pushed to rubygems.org 2010-07-01 0.2.0 * Updated Storage class, implementing pool.active?, pool.persistent?, pool.vol_create_xml_from. * Updated Connect class, implementing conn.node_free_memory, conn.node_cells_free_memory, conn.node_get_security_model, conn.encrypted?, conn.libversion, and conn.secure? * Updated Network class, implementing network.active? and network.persistent? * Update Domain class, implementing conn.domain_xml_from_native, conn.domain_xml_to_native, dom.migrate_to_uri, dom.migrate_set_max_downtime, dom.managed_save, dom.has_managed_save?, dom.managed_save_remove, dom.security_label, dom.block_stats, dom.memory_stats, dom.blockinfo, dom.block_peek, dom.memory_peek, dom.active?, dom.persistent?, dom.snapshot_create_xml, dom.num_of_snapshots, dom.list_snapshots, dom.lookup_snapshot_by_name, dom.has_current_snapshot?, dom.revert_to_snapshot, dom.current_snapshot, snapshot.xml_desc, snapshot.delete, dom.job_info, and dom.abort_job. * Implementation of the NodeDevice class. * Implementation of the Secret class. * Implementation of the NWFilter class. * Implementation of the Interface class. * Conversion of the development tree to git. * New maintainer (Chris Lalancette). David Lutterkort has agreed to transfer maintainership since he is not actively involved in their development anymore. 2008-11-18 0.1.0 * Add binding for virConnectFindStoragePoolSources (clalance) * Fix dom_migrate (clalance) * Add the MIGRATE_LIVE (enum virDomainMigrateFlags) flag * Slight improvements of the unit tests 2008-04-15 0.0.7 * Binding for virDomainMigrate * Fix crash caused by using virResetError * More sensible message included in exceptions 2008-04-02 0.0.6 * Fix test failure exposed by the Fedora builders 2008-04-02 0.0.5 * Explicit free methods for various objects (based on a patch by Vadim Zaliva) * Make the FLAGS argument for various calls optional, and default it to 0. (Chris Lalancette) * More finegrained exceptions on errors, containing libvirt error message (Mohammed Morsi) 2008-04-01 0.0.4 * Bindings for the libvirt storage API (requires libvirt 0.4.1) * Suppress some bindings if the underlying libvirt doesn't support it * Bindings for virDomainSetMemory, virDomainPinVcpu, and virDomainSetVcpus (Vadim Zaliva) 2007-12-06 0.0.2 * Add virNodeGetInfo binding * Convert Ruby API from StudlyCaps to under_score_separation, since that's the Ruby convention 2007-11-19 0.0.1 * Initial release ruby-libvirt-0.5.1/COPYING0000664000175000017500000006365011376561242016545 0ustar clalancetteclalancette GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. ^L Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. ^L GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. ^L Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. ^L 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. ^L 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. ^L 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. ^L 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS ^L How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ruby-libvirt-0.5.1/tests/0000775000175000017500000000000012253415712016635 5ustar clalancetteclalancetteruby-libvirt-0.5.1/tests/test_stream.rb0000664000175000017500000001157112224343510021513 0ustar clalancetteclalancette#!/usr/bin/ruby # Test the stream methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("stream") conn = Libvirt::open("qemu:///system") # TESTGROUP: stream.send st = conn.stream expect_too_many_args(st, "send", 1, 2) expect_too_few_args(st, "send") expect_invalid_arg_type(st, "send", 1) expect_invalid_arg_type(st, "send", nil) expect_invalid_arg_type(st, "send", []) expect_invalid_arg_type(st, "send", {}) # FIXME: we need to setup a proper stream for this to work #expect_success(st, "buffer arg", "send", buffer) st.free # TESTGROUP: stream.recv st = conn.stream expect_too_many_args(st, "recv", 1, 2) expect_too_few_args(st, "recv") expect_invalid_arg_type(st, "recv", nil) expect_invalid_arg_type(st, "recv", 'foo') expect_invalid_arg_type(st, "recv", []) expect_invalid_arg_type(st, "recv", {}) # FIXME: we need to setup a proper stream for this to work #expect_success(st, "bytes arg", "recv", 12) st.free # TESTGROUP: stream.sendall st = conn.stream # equivalent to expect_too_many_args begin st.sendall(1, 2) {|x,y| x = y} rescue NoMethodError puts_skipped "#{$test_object}.sendall does not exist" rescue ArgumentError => e puts_ok "#{$test_object}.sendall too many args threw #{ArgumentError.to_s}" rescue => e puts_fail "#{$test_object}.sendall too many args expected to throw #{ArgumentError.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}" else puts_fail "#{$test_object}.sendall too many args expected to throw #{ArgumentError.to_s}, but threw nothing" end expect_fail(st, RuntimeError, "no block given", "sendall") # FIXME: we need to setup a proper stream for this to work #st.sendall {|opaque,nbytes| return opaque} st.free # TESTGROUP: stream.recvall st = conn.stream # equivalent to expect_too_many_args begin st.recvall(1, 2) {|x,y| x = y} rescue NoMethodError puts_skipped "#{$test_object}.recvall does not exist" rescue ArgumentError => e puts_ok "#{$test_object}.recvall too many args threw #{ArgumentError.to_s}" rescue => e puts_fail "#{$test_object}.recvall too many args expected to throw #{ArgumentError.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}" else puts_fail "#{$test_object}.recvall too many args expected to throw #{ArgumentError.to_s}, but threw nothing" end expect_fail(st, RuntimeError, "no block given", "recvall") # FIXME: we need to setup a proper stream for this to work #st.recvall {|data,opaque| return opaque} st.free # TESTGROUP: stream.event_add_callback st_event_callback_proc = lambda {|st,events,opaque| } st = conn.stream expect_too_many_args(st, "event_add_callback", 1, 2, 3, 4) expect_too_few_args(st, "event_add_callback") expect_too_few_args(st, "event_add_callback", 1) expect_invalid_arg_type(st, "event_add_callback", nil, st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", 'foo', st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", [], st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", {}, st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", 1, nil) expect_invalid_arg_type(st, "event_add_callback", 1, 'foo') expect_invalid_arg_type(st, "event_add_callback", 1, 1) expect_invalid_arg_type(st, "event_add_callback", 1, []) expect_invalid_arg_type(st, "event_add_callback", 1, {}) # FIXME: I get "this function is not support by the connection driver" #expect_success(st, "events and callback arg", "event_add_callback", Libvirt::Stream::EVENT_READABLE, st_event_callback_proc) #st.event_remove_callback st.free # TESTGROUP: stream.event_update_callback st = conn.stream expect_too_many_args(st, "event_update_callback", 1, 2) expect_too_few_args(st, "event_update_callback") expect_invalid_arg_type(st, "event_update_callback", nil) expect_invalid_arg_type(st, "event_update_callback", 'foo') expect_invalid_arg_type(st, "event_update_callback", []) expect_invalid_arg_type(st, "event_update_callback", {}) # FIXME: we would need to get st.event_add_callback working to get this working #expect_success(st, "events arg", "event_update_callback", Libvirt::Stream::EVENT_WRITABLE) st.free # TESTGROUP: stream.remove_callback st = conn.stream expect_too_many_args(st, "event_remove_callback", 1) # FIXME: we would need to get st.event_add_callback working to get this working #expect_success(st, "no arg", "event_remove_callback") st.free # TESTGROUP: stream.finish st = conn.stream expect_too_many_args(st, "finish", 1) # FIXME: I get "this function is not support by the connection driver" #expect_success(st, "no arg", "finish") st.free # TESTGROUP: stream.abort st = conn.stream expect_too_many_args(st, "abort", 1) # FIXME: I get "this function is not support by the connection driver" #expect_success(st, "no arg", "abort") st.free # TESTGROUP: stream.abort st = conn.stream expect_too_many_args(st, "free", 1) expect_success(st, "no arg", "free") # END TESTS conn.close finish_tests ruby-libvirt-0.5.1/tests/test_conn.rb0000664000175000017500000010003612252736716021167 0ustar clalancetteclalancette#!/usr/bin/ruby # Test the conn methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("connect") conn = Libvirt::open("qemu:///system") cleanup_test_domain(conn) cleanup_test_network(conn) # test setup begin `rm -f /etc/sysconfig/network-scripts/ifcfg-ruby-libvirt-tester` `brctl delbr ruby-libvirt-tester >& /dev/null` rescue end `qemu-img create -f qcow2 #{$GUEST_DISK} 5G` `rm -rf #{$POOL_PATH}; mkdir #{$POOL_PATH} ; echo $?` cpu_xml = < x86_64 athlon EOF # TESTGROUP: conn.close conn2 = Libvirt::open("qemu:///system") expect_too_many_args(conn2, "close", 1) expect_success(conn2, "no args", "close") # TESTGROUP: conn.closed? conn2 = Libvirt::open("qemu:///system") expect_too_many_args(conn2, "closed?", 1) expect_success(conn2, "no args", "closed?") {|x| x == false } conn2.close expect_success(conn2, "no args", "closed?") {|x| x == true } # TESTGROUP: conn.type expect_too_many_args(conn, "type", 1) expect_success(conn, "no args", "type") {|x| x == "QEMU"} # TESTGROUP: conn.version expect_too_many_args(conn, "version", 1) expect_success(conn, "no args", "version") # TESTGROUP: conn.libversion expect_too_many_args(conn, "libversion", 1) expect_success(conn, "no args", "libversion") # TESTGROUP: conn.hostname expect_too_many_args(conn, "hostname", 1) expect_success(conn, "no args", "hostname") # TESTGROUP: conn.uri expect_too_many_args(conn, "uri", 1) expect_success(conn, "no args", "uri") {|x| x == "qemu:///system" } # TESTGROUP: conn.max_vcpus expect_too_many_args(conn, "max_vcpus", 'kvm', 1) expect_fail(conn, Libvirt::RetrieveError, "invalid arg", "max_vcpus", "foo") expect_success(conn, "no args", "max_vcpus") expect_success(conn, "nil arg", "max_vcpus") expect_success(conn, "kvm arg", "max_vcpus") expect_success(conn, "qemu arg", "max_vcpus") # TESTGROUP: conn.node_get_info expect_too_many_args(conn, "node_get_info", 1) expect_success(conn, "no args", "node_get_info") # TESTGROUP: conn.node_free_memory expect_too_many_args(conn, "node_free_memory", 1) expect_success(conn, "no args", "node_free_memory") # TESTGROUP: conn.node_cells_free_memory expect_too_many_args(conn, "node_cells_free_memory", 1, 2, 3) expect_invalid_arg_type(conn, "node_cells_free_memory", 'start') expect_invalid_arg_type(conn, "node_cells_free_memory", 0, 'end') expect_success(conn, "no args", "node_cells_free_memory") expect_success(conn, "start cell", "node_cells_free_memory", 0) expect_success(conn, "start cell and max cells", "node_cells_free_memory", 0, 1) # TESTGROUP: conn.node_get_security_model expect_too_many_args(conn, "node_get_security_model", 1) expect_success(conn, "no args", "node_get_security_model") # TESTGROUP: conn.encrypted? expect_too_many_args(conn, "encrypted?", 1) expect_success(conn, "no args", "encrypted?") # TESTGROUP: conn.secure? expect_too_many_args(conn, "secure?", 1) expect_success(conn, "no args", "secure?") {|x| x == true} # TESTGROUP: conn.capabilities expect_too_many_args(conn, "capabilities", 1) expect_success(conn, "no args", "capabilities") # TESTGROUP: conn.compare_cpu expect_too_many_args(conn, "compare_cpu", 1, 2, 3) expect_too_few_args(conn, "compare_cpu") expect_invalid_arg_type(conn, "compare_cpu", 1) expect_invalid_arg_type(conn, "compare_cpu", "hello", 'bar') expect_fail(conn, Libvirt::RetrieveError, "invalid XML", "compare_cpu", "hello") expect_success(conn, "CPU XML", "compare_cpu", cpu_xml) # TESTGROUP: conn.baseline_cpu expect_too_many_args(conn, "baseline_cpu", 1, 2, 3) expect_too_few_args(conn, "baseline_cpu") expect_invalid_arg_type(conn, "baseline_cpu", 1) expect_invalid_arg_type(conn, "baseline_cpu", [cpu_xml], "foo") expect_fail(conn, ArgumentError, "empty array", "baseline_cpu", []) expect_success(conn, "CPU XML", "baseline_cpu", [cpu_xml]) # TESTGROUP: conn.domain_event_register_any dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque| } # def dom_event_callback_symbol(conn, dom, event, detail, opaque) # end expect_too_many_args(conn, "domain_event_register_any", 1, 2, 3, 4, 5) expect_too_few_args(conn, "domain_event_register_any") expect_too_few_args(conn, "domain_event_register_any", 1) expect_invalid_arg_type(conn, "domain_event_register_any", "hello", 1) expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, 1) expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, 1) expect_fail(conn, ArgumentError, "invalid event ID", "domain_event_register_any", 456789, dom_event_callback_proc) # callbackID = expect_success(conn, "eventID and proc", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc) # conn.domain_event_deregister_any(callbackID) # callbackID = expect_success(conn, "eventID and symbol", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, :dom_event_callback_symbol) # conn.domain_event_deregister_any(callbackID) # callbackID = expect_success(conn, "eventID, proc, nil domain", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil) # conn.domain_event_deregister_any(callbackID) # callbackID = expect_success(conn, "eventID, proc, nil domain, opaque", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil, "opaque user data") # conn.domain_event_deregister_any(callbackID) # # TESTGROUP: conn.domain_event_deregister_any # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque| # } # callbackID = conn.domain_event_register_any(Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc) expect_too_many_args(conn, "domain_event_deregister_any", 1, 2) expect_too_few_args(conn, "domain_event_deregister_any") expect_invalid_arg_type(conn, "domain_event_deregister_any", "hello") # expect_success(conn, "callbackID", "domain_event_deregister_any", callbackID) # TESTGROUP: conn.domain_event_register # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque| # } # def dom_event_callback_symbol(conn, dom, event, detail, opaque) # end expect_too_many_args(conn, "domain_event_register", 1, 2, 3) expect_too_few_args(conn, "domain_event_register") expect_invalid_arg_type(conn, "domain_event_register", "hello") # expect_success(conn, "proc", "domain_event_register", dom_event_callback_proc) # conn.domain_event_deregister # expect_success(conn, "symbol", "domain_event_register", :dom_event_callback_symbol) # conn.domain_event_deregister # expect_success(conn, "proc and opaque", "domain_event_register", dom_event_callback_proc, "opaque user data") # conn.domain_event_deregister # # TESTGROUP: conn.domain_event_deregister # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque| # } # conn.domain_event_register(dom_event_callback_proc) expect_too_many_args(conn, "domain_event_deregister", 1) # expect_success(conn, "no args", "domain_event_deregister") # TESTGROUP: conn.num_of_domains expect_too_many_args(conn, "num_of_domains", 1) expect_success(conn, "no args", "num_of_domains") # TESTGROUP: conn.list_domains expect_too_many_args(conn, "list_domains", 1) expect_success(conn, "no args", "list_domains") newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_success(conn, "no args", "list_domains") newdom.destroy # TESTGROUP: conn.num_of_defined_domains expect_too_many_args(conn, "num_of_defined_domains", 1) expect_success(conn, "no args", "num_of_defined_domains") # TESTGROUP: conn.list_defined_domains expect_too_many_args(conn, "list_defined_domains", 1) expect_success(conn, "no args", "list_defined_domains") # TESTGROUP: conn.create_domain_linux expect_too_many_args(conn, "create_domain_linux", $new_dom_xml, 0, 1) expect_too_few_args(conn, "create_domain_linux") expect_invalid_arg_type(conn, "create_domain_linux", nil) expect_invalid_arg_type(conn, "create_domain_linux", 1) expect_invalid_arg_type(conn, "create_domain_linux", $new_dom_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "create_domain_linux", "hello") newdom = expect_success(conn, "domain xml", "create_domain_linux", $new_dom_xml) {|x| x.class == Libvirt::Domain} sleep 1 expect_fail(conn, Libvirt::Error, "already existing domain", "create_domain_linux", $new_dom_xml) newdom.destroy # TESTGROUP: conn.create_domain_xml expect_too_many_args(conn, "create_domain_xml", $new_dom_xml, 0, 1) expect_too_few_args(conn, "create_domain_xml") expect_invalid_arg_type(conn, "create_domain_xml", nil) expect_invalid_arg_type(conn, "create_domain_xml", 1) expect_invalid_arg_type(conn, "create_domain_xml", $new_dom_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "create_domain_xml", "hello") newdom = expect_success(conn, "domain xml", "create_domain_xml", $new_dom_xml) {|x| x.class == Libvirt::Domain} sleep 1 expect_fail(conn, Libvirt::Error, "already existing domain", "create_domain_xml", $new_dom_xml) newdom.destroy # TESTGROUP: conn.lookup_domain_by_name newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(conn, "lookup_domain_by_name", 1, 2) expect_too_few_args(conn, "lookup_domain_by_name") expect_invalid_arg_type(conn, "lookup_domain_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_domain_by_name", "foobarbazsucker") expect_success(conn, "name arg for running domain", "lookup_domain_by_name", "ruby-libvirt-tester") {|x| x.name == "ruby-libvirt-tester"} newdom.destroy newdom = conn.define_domain_xml($new_dom_xml) expect_success(conn, "name arg for defined domain", "lookup_domain_by_name", "ruby-libvirt-tester") {|x| x.name == "ruby-libvirt-tester"} newdom.undefine # TESTGROUP: conn.lookup_domain_by_id newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(conn, "lookup_domain_by_id", 1, 2) expect_too_few_args(conn, "lookup_domain_by_id") expect_invalid_arg_type(conn, "lookup_domain_by_id", "foo") expect_fail(conn, Libvirt::Error, "with negative value", "lookup_domain_by_id", -1) expect_success(conn, "id arg for running domain", "lookup_domain_by_id", newdom.id) newdom.destroy # TESTGROUP: conn.lookup_domain_by_uuid newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(conn, "lookup_domain_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_domain_by_uuid") expect_invalid_arg_type(conn, "lookup_domain_by_uuid", 1) expect_fail(conn, Libvirt::RetrieveError, "invalid UUID", "lookup_domain_by_uuid", "abcd") expect_success(conn, "UUID arg for running domain", "lookup_domain_by_uuid", newdom.uuid) {|x| x.uuid == $GUEST_UUID} newdom.destroy newdom = conn.define_domain_xml($new_dom_xml) expect_success(conn, "UUID arg for defined domain", "lookup_domain_by_uuid", newdom.uuid) {|x| x.uuid == $GUEST_UUID} newdom.undefine # TESTGROUP: conn.define_domain_xml expect_too_many_args(conn, "define_domain_xml", 1, 2) expect_too_few_args(conn, "define_domain_xml") expect_invalid_arg_type(conn, "define_domain_xml", 1) expect_invalid_arg_type(conn, "define_domain_xml", nil) expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_domain_xml", "hello") newdom = expect_success(conn, "domain xml arg", "define_domain_xml", $new_dom_xml) newdom.undefine # TESTGROUP: conn.domain_xml_from_native expect_too_many_args(conn, "domain_xml_from_native", 1, 2, 3, 4) expect_too_few_args(conn, "domain_xml_from_native") expect_too_few_args(conn, "domain_xml_from_native", 1) expect_invalid_arg_type(conn, "domain_xml_from_native", 1, 2) expect_invalid_arg_type(conn, "domain_xml_from_native", nil, 2) expect_invalid_arg_type(conn, "domain_xml_from_native", "qemu-argv", 2) expect_invalid_arg_type(conn, "domain_xml_from_native", "qemu-argv", nil) expect_invalid_arg_type(conn, "domain_xml_from_native", "qemu-argv", "foo", "bar") expect_fail(conn, Libvirt::Error, "unsupported first arg", "domain_xml_from_native", "foo", "bar") expect_success(conn, "qemu-argv and qemu_cmd_line", "domain_xml_from_native", "qemu-argv", $qemu_cmd_line) # TESTGROUP: conn.domain_xml_to_native expect_too_many_args(conn, "domain_xml_to_native", 1, 2, 3, 4) expect_too_few_args(conn, "domain_xml_to_native") expect_too_few_args(conn, "domain_xml_to_native", 1) expect_invalid_arg_type(conn, "domain_xml_to_native", 1, 2) expect_invalid_arg_type(conn, "domain_xml_to_native", nil, 2) expect_invalid_arg_type(conn, "domain_xml_to_native", "qemu-argv", 2) expect_invalid_arg_type(conn, "domain_xml_to_native", "qemu-argv", nil) expect_invalid_arg_type(conn, "domain_xml_to_native", "qemu-argv", "foo", "bar") expect_fail(conn, Libvirt::Error, "unsupported first arg", "domain_xml_to_native", "foo", "bar") expect_success(conn, "qemu-argv and domain XML", "domain_xml_to_native", "qemu-argv", $new_dom_xml) # TESTGROUP: conn.num_of_interfaces expect_too_many_args(conn, "num_of_interfaces", 1) expect_success(conn, "no args", "num_of_interfaces") # TESTGROUP: conn.list_interfaces expect_too_many_args(conn, "list_interfaces", 1) expect_success(conn, "no args", "list_interfaces") # TESTGROUP: conn.num_of_defined_interfaces expect_too_many_args(conn, "num_of_defined_interfaces", 1) expect_success(conn, "no args", "num_of_defined_interfaces") # TESTGROUP: conn.list_defined_interfaces expect_too_many_args(conn, "list_defined_interfaces", 1) expect_success(conn, "no args", "list_defined_interfaces") # TESTGROUP: conn.lookup_interface_by_name newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(conn, "lookup_interface_by_name", 1, 2) expect_too_few_args(conn, "lookup_interface_by_name") expect_invalid_arg_type(conn, "lookup_interface_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_interface_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_interface_by_name", "ruby-libvirt-tester") newiface.destroy expect_success(conn, "name arg", "lookup_interface_by_name", "ruby-libvirt-tester") newiface.undefine # TESTGROUP: conn.lookup_interface_by_mac newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(conn, "lookup_interface_by_mac", 1, 2) expect_too_few_args(conn, "lookup_interface_by_mac") expect_invalid_arg_type(conn, "lookup_interface_by_mac", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent mac arg", "lookup_interface_by_mac", "foobarbazsucker") # FIXME: we can't look up an interface by MAC address on an inactive interface, # but we also can't start up the interface without a /etc/sysconfig file. #expect_success(conn, "mac arg", "lookup_interface_by_mac", $NEW_INTERFACE_MAC) {|x| x.mac == $NEW_INTERFACE_MAC} newiface.undefine # TESTGROUP: conn.define_interface_xml expect_too_many_args(conn, "define_interface_xml", 1, 2, 3) expect_too_few_args(conn, "define_interface_xml") expect_invalid_arg_type(conn, "define_interface_xml", 1) expect_invalid_arg_type(conn, "define_interface_xml", nil) expect_invalid_arg_type(conn, "define_interface_xml", "hello", 'foo') expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_interface_xml", "hello") expect_success(conn, "interface XML", "define_interface_xml", $new_interface_xml) newiface.undefine # TESTGROUP: conn.num_of_networks expect_too_many_args(conn, "num_of_networks", 1) expect_success(conn, "no args", "num_of_networks") # TESTGROUP: conn.list_networks expect_too_many_args(conn, "list_networks", 1) expect_success(conn, "no args", "list_networks") # TESTGROUP: conn.num_of_defined_networks expect_too_many_args(conn, "num_of_defined_networks", 1) expect_success(conn, "no args", "num_of_defined_networks") # TESTGROUP: conn.list_defined_networks expect_too_many_args(conn, "list_defined_networks", 1) expect_success(conn, "no args", "list_defined_networks") # TESTGROUP: conn.lookup_network_by_name newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(conn, "lookup_network_by_name", 1, 2) expect_too_few_args(conn, "lookup_network_by_name") expect_invalid_arg_type(conn, "lookup_network_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_network_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_network_by_name", "ruby-libvirt-tester") newnet.destroy newnet = conn.define_network_xml($new_net_xml) expect_success(conn, "name arg", "lookup_network_by_name", "ruby-libvirt-tester") newnet.undefine # TESTGROUP: conn.lookup_network_by_uuid newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(conn, "lookup_network_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_network_by_uuid") expect_invalid_arg_type(conn, "lookup_network_by_uuid", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent uuid arg", "lookup_network_by_uuid", "foobarbazsucker") expect_success(conn, "uuid arg", "lookup_network_by_uuid", $NETWORK_UUID) newnet.destroy newnet = conn.define_network_xml($new_net_xml) expect_success(conn, "uuid arg", "lookup_network_by_uuid", $NETWORK_UUID) newnet.undefine # TESTGROUP: conn.create_network_xml expect_too_many_args(conn, "create_network_xml", $new_net_xml, 0) expect_too_few_args(conn, "create_network_xml") expect_invalid_arg_type(conn, "create_network_xml", nil) expect_invalid_arg_type(conn, "create_network_xml", 1) expect_fail(conn, Libvirt::Error, "invalid xml", "create_network_xml", "hello") newnet = expect_success(conn, "network XML", "create_network_xml", $new_net_xml) expect_fail(conn, Libvirt::Error, "already existing network", "create_network_xml", $new_net_xml) newnet.destroy # TESTGROUP: conn.define_network_xml expect_too_many_args(conn, "define_network_xml", 1, 2) expect_too_few_args(conn, "define_network_xml") expect_invalid_arg_type(conn, "define_network_xml", 1) expect_invalid_arg_type(conn, "define_network_xml", nil) expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_network_xml", "hello") newnet = expect_success(conn, "network XML", "define_network_xml", $new_net_xml) newnet.undefine # TESTGROUP: conn.num_of_nodedevices expect_too_many_args(conn, "num_of_nodedevices", 1, 2, 3) expect_invalid_arg_type(conn, "num_of_nodedevices", 1) expect_invalid_arg_type(conn, "num_of_nodedevices", 'foo', 'bar') expect_success(conn, "no args", "num_of_nodedevices") # TESTGROUP: conn.list_nodedevices expect_too_many_args(conn, "list_nodedevices", 1, 2, 3) expect_invalid_arg_type(conn, "list_nodedevices", 1) expect_invalid_arg_type(conn, "list_nodedevices", 'foo', 'bar') expect_success(conn, "no args", "list_nodedevices") # TESTGROUP: conn.lookup_nodedevice_by_name testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(conn, "lookup_nodedevice_by_name", 1, 2) expect_too_few_args(conn, "lookup_nodedevice_by_name") expect_invalid_arg_type(conn, "lookup_nodedevice_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_nodedevice_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_nodedevice_by_name", testnode.name) # TESTGROUP: conn.create_nodedevice_xml expect_too_many_args(conn, "create_nodedevice_xml", 1, 2, 3) expect_too_few_args(conn, "create_nodedevice_xml") expect_invalid_arg_type(conn, "create_nodedevice_xml", 1) expect_invalid_arg_type(conn, "create_nodedevice_xml", "foo", 'bar') expect_fail(conn, Libvirt::Error, "invalid XML", "create_nodedevice_xml", "hello") #expect_success(conn, "nodedevice XML", "create_nodedevice_xml", "") # TESTGROUP: conn.num_of_nwfilters expect_too_many_args(conn, "num_of_nwfilters", 1) expect_success(conn, "no args", "num_of_nwfilters") # TESTGROUP: conn.list_nwfilters expect_too_many_args(conn, "list_nwfilters", 1) expect_success(conn, "no args", "list_nwfilters") # TESTGROUP: conn.lookup_nwfilter_by_name newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(conn, "lookup_nwfilter_by_name", 1, 2) expect_too_few_args(conn, "lookup_nwfilter_by_name") expect_invalid_arg_type(conn, "lookup_nwfilter_by_name", 1) expect_success(conn, "name arg", "lookup_nwfilter_by_name", "ruby-libvirt-tester") newnw.undefine # TESTGROUP: conn.lookup_nwfilter_by_uuid newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(conn, "lookup_nwfilter_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_nwfilter_by_uuid") expect_invalid_arg_type(conn, "lookup_nwfilter_by_uuid", 1) expect_success(conn, "uuid arg", "lookup_nwfilter_by_uuid", $NWFILTER_UUID) {|x| x.uuid == $NWFILTER_UUID} newnw.undefine # TESTGROUP: conn.define_nwfilter_xml expect_too_many_args(conn, "define_nwfilter_xml", 1, 2) expect_too_few_args(conn, "define_nwfilter_xml") expect_invalid_arg_type(conn, "define_nwfilter_xml", 1) expect_invalid_arg_type(conn, "define_nwfilter_xml", nil) expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_nwfilter_xml", "hello") newnw = expect_success(conn, "nwfilter XML", "define_nwfilter_xml", $new_nwfilter_xml) newnw.undefine # TESTGROUP: conn.num_of_secrets expect_too_many_args(conn, "num_of_secrets", 1) expect_success(conn, "no args", "num_of_secrets") # TESTGROUP: conn.list_secrets expect_too_many_args(conn, "list_secrets", 1) expect_success(conn, "no args", "list_secrets") # TESTGROUP: conn.lookup_secret_by_uuid newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(conn, "lookup_secret_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_secret_by_uuid") expect_invalid_arg_type(conn, "lookup_secret_by_uuid", 1) expect_success(conn, "uuid arg", "lookup_secret_by_uuid", $SECRET_UUID) {|x| x.uuid == $SECRET_UUID} newsecret.undefine # TESTGROUP: conn.lookup_secret_by_usage newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(conn, "lookup_secret_by_usage", 1, 2, 3) expect_too_few_args(conn, "lookup_secret_by_usage") expect_invalid_arg_type(conn, "lookup_secret_by_usage", 'foo', 1) expect_invalid_arg_type(conn, "lookup_secret_by_usage", 1, 2) expect_fail(conn, Libvirt::RetrieveError, "invalid secret", "lookup_secret_by_usage", Libvirt::Secret::USAGE_TYPE_VOLUME, "foo") expect_success(conn, "usage type and key", "lookup_secret_by_usage", Libvirt::Secret::USAGE_TYPE_VOLUME, "/var/lib/libvirt/images/mail.img") newsecret.undefine # TESTGROUP: conn.define_secret_xml expect_too_many_args(conn, "define_secret_xml", 1, 2, 3) expect_too_few_args(conn, "define_secret_xml") expect_invalid_arg_type(conn, "define_secret_xml", 1) expect_invalid_arg_type(conn, "define_secret_xml", nil) expect_invalid_arg_type(conn, "define_secret_xml", "hello", 'foo') expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_secret_xml", "hello") expect_success(conn, "secret XML", "define_secret_xml", $new_secret_xml) newsecret.undefine # TESTGROUP: conn.list_storage_pools expect_too_many_args(conn, "list_storage_pools", 1) expect_success(conn, "no args", "list_storage_pools") # TESTGROUP: conn.num_of_storage_pools expect_too_many_args(conn, "num_of_storage_pools", 1) expect_success(conn, "no args", "num_of_storage_pools") # TESTGROUP: conn.list_defined_storage_pools expect_too_many_args(conn, "list_defined_storage_pools", 1) expect_success(conn, "no args", "list_defined_storage_pools") # TESTGROUP: conn.num_of_defined_storage_pools expect_too_many_args(conn, "num_of_defined_storage_pools", 1) expect_success(conn, "no args", "num_of_defined_storage_pools") # TESTGROUP: conn.lookup_storage_pool_by_name newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(conn, "lookup_storage_pool_by_name", 1, 2) expect_too_few_args(conn, "lookup_storage_pool_by_name") expect_invalid_arg_type(conn, "lookup_storage_pool_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_storage_pool_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_storage_pool_by_name", "ruby-libvirt-tester") newpool.destroy newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_success(conn, "name arg", "lookup_storage_pool_by_name", "ruby-libvirt-tester") newpool.undefine # TESTGROUP: conn.lookup_storage_pool_by_uuid newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(conn, "lookup_storage_pool_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_storage_pool_by_uuid") expect_invalid_arg_type(conn, "lookup_storage_pool_by_uuid", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent uuid arg", "lookup_storage_pool_by_uuid", "foobarbazsucker") expect_success(conn, "uuid arg", "lookup_storage_pool_by_uuid", $POOL_UUID) newpool.destroy newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_success(conn, "uuid arg", "lookup_storage_pool_by_uuid", $POOL_UUID) newpool.undefine # TESTGROUP: conn.create_storage_pool_xml expect_too_many_args(conn, "create_storage_pool_xml", $new_storage_pool_xml, 0, 1) expect_too_few_args(conn, "create_storage_pool_xml") expect_invalid_arg_type(conn, "create_storage_pool_xml", nil) expect_invalid_arg_type(conn, "create_storage_pool_xml", 1) expect_invalid_arg_type(conn, "create_storage_pool_xml", $new_storage_pool_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "create_storage_pool_xml", "hello") expect_success(conn, "storage pool XML", "create_storage_pool_xml", $new_storage_pool_xml) expect_fail(conn, Libvirt::Error, "already existing domain", "create_storage_pool_xml", $new_storage_pool_xml) newpool.destroy # TESTGROUP: conn.define_storage_pool_xml expect_too_many_args(conn, "define_storage_pool_xml", $new_storage_pool_xml, 0, 1) expect_too_few_args(conn, "define_storage_pool_xml") expect_invalid_arg_type(conn, "define_storage_pool_xml", nil) expect_invalid_arg_type(conn, "define_storage_pool_xml", 1) expect_invalid_arg_type(conn, "define_storage_pool_xml", $new_storage_pool_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "define_storage_pool_xml", "hello") expect_success(conn, "storage pool XML", "define_storage_pool_xml", $new_storage_pool_xml) newpool.undefine # TESTGROUP: conn.discover_storage_pool_sources expect_too_many_args(conn, "discover_storage_pool_sources", 1, 2, 3, 4) expect_too_few_args(conn, "discover_storage_pool_sources") expect_invalid_arg_type(conn, "discover_storage_pool_sources", 1) expect_invalid_arg_type(conn, "discover_storage_pool_sources", "foo", 1) expect_invalid_arg_type(conn, "discover_storage_pool_sources", "foo", "bar", "baz") expect_fail(conn, Libvirt::Error, "invalid pool type", "discover_storage_pool_sources", "foo") expect_success(conn, "pool type", "discover_storage_pool_sources", "logical") # TESTGROUP: conn.sys_info expect_too_many_args(conn, "sys_info", 1, 2) expect_invalid_arg_type(conn, "sys_info", "foo") expect_success(conn, "system info", "sys_info") # TESTGROUP: conn.interface_change_begin expect_too_many_args(conn, "interface_change_begin", 1, 2) expect_invalid_arg_type(conn, "interface_change_begin", 'hello') expect_success(conn, "interface change begin", "interface_change_begin") conn.interface_change_rollback # TESTGROUP: conn.interface_change_commit expect_too_many_args(conn, "interface_change_commit", 1, 2) expect_invalid_arg_type(conn, "interface_change_commit", 'foo') # FIXME: libvirt throws an error on commit with no changes. What changes can # we do here? #expect_success(conn, "interface change commit", "interface_change_commit") # TESTGROUP: conn.interface_change_rollback conn.interface_change_begin expect_too_many_args(conn, "interface_change_rollback", 1, 2) expect_invalid_arg_type(conn, "interface_change_rollback", 'foo') expect_success(conn, "interface change rollback", "interface_change_rollback") # TESTGROUP: conn.node_cpu_stats expect_too_many_args(conn, "node_cpu_stats", 1, 2, 3) expect_invalid_arg_type(conn, "node_cpu_stats", 'foo') expect_invalid_arg_type(conn, "node_cpu_stats", 1, 'bar') expect_success(conn, "node cpu stats", "node_cpu_stats") # TESTGROUP: conn.node_memory_stats expect_too_many_args(conn, "node_memory_stats", 1, 2, 3) expect_invalid_arg_type(conn, "node_memory_stats", 'foo') expect_invalid_arg_type(conn, "node_memory_stats", 1, 'bar') expect_success(conn, "node memory status", "node_memory_stats") # TESTGROUP: conn.save_image_xml_desc newdom = conn.define_domain_xml($new_dom_xml) newdom.create sleep 1 newdom.save($GUEST_SAVE) expect_too_many_args(conn, "save_image_xml_desc", 1, 2, 3) expect_too_few_args(conn, "save_image_xml_desc") expect_invalid_arg_type(conn, "save_image_xml_desc", nil) expect_invalid_arg_type(conn, "save_image_xml_desc", 1) expect_invalid_arg_type(conn, "save_image_xml_desc", 'foo', 'bar') expect_success(conn, "save image path", "save_image_xml_desc", $GUEST_SAVE) `rm -f #{$GUEST_SAVE}` # TESTGROUP: conn.define_save_image_xml expect_too_many_args(conn, "define_save_image_xml", 1, 2, 3, 4) expect_too_few_args(conn, "define_save_image_xml") expect_too_few_args(conn, "define_save_image_xml", 'foo') expect_invalid_arg_type(conn, "define_save_image_xml", nil, 'foo') expect_invalid_arg_type(conn, "define_save_image_xml", 1, 'foo') expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', nil) expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', 1) expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', 'bar', 'baz') # TESTGROUP: conn.alive? expect_too_many_args(conn, "alive?", 1) expect_success(conn, "alive connection", "alive?") {|x| x == true} # TESTGROUP: conn.list_all_nwfilters expect_too_many_args(conn, "list_all_nwfilters", 1, 2) expect_invalid_arg_type(conn, "list_all_nwfilters", "foo") expect_success(conn, "no args", "list_all_nwfilters") # TESTGROUP: conn.list_all_storage_pools expect_too_many_args(conn, "list_all_storage_pools", 1, 2) expect_invalid_arg_type(conn, "list_all_storage_pools", "foo") expect_success(conn, "no args", "list_all_storage_pools") # TESTGROUP: conn.list_all_nodedevices expect_too_many_args(conn, "list_all_nodedevices", 1, 2) expect_invalid_arg_type(conn, "list_all_nodedevices", "foo") expect_success(conn, "no args", "list_all_nodedevices") # TESTGROUP: conn.list_all_secrets expect_too_many_args(conn, "list_all_secrets", 1, 2) expect_invalid_arg_type(conn, "list_all_secrets", "foo") expect_success(conn, "no args", "list_all_secrets") # TESTGROUP: conn.list_all_interfaces expect_too_many_args(conn, "list_all_interfaces", 1, 2) expect_invalid_arg_type(conn, "list_all_interfaces", "foo") expect_success(conn, "no args", "list_all_interfaces") # TESTGROUP: conn.list_all_networks expect_too_many_args(conn, "list_all_networks", 1, 2) expect_invalid_arg_type(conn, "list_all_networks", "foo") expect_success(conn, "no args", "list_all_networks") # TESTGROUP: conn.list_all_domains expect_too_many_args(conn, "list_all_domains", 1, 2) expect_invalid_arg_type(conn, "list_all_domains", "foo") expect_success(conn, "no args", "list_all_domains") # TESTGROUP: conn.set_keepalive expect_too_many_args(conn, "set_keepalive", 1, 2, 3, 4) expect_too_few_args(conn, "set_keepalive") expect_too_few_args(conn, "set_keepalive", 1) expect_invalid_arg_type(conn, "set_keepalive", 'foo', 0) expect_invalid_arg_type(conn, "set_keepalive", 0, 'foo') # FIXME: somehow we need an event loop implementation for this to work #expect_success(conn, "interval and count", "set_keepalive", 1, 10) # TESTGROUP: conn.node_suspend_for_duration expect_too_many_args(conn, "node_suspend_for_duration", 1, 2, 3, 4) expect_too_few_args(conn, "node_suspend_for_duration") expect_too_few_args(conn, "node_suspend_for_duration", 1) expect_invalid_arg_type(conn, "node_suspend_for_duration", 'foo', 1) expect_invalid_arg_type(conn, "node_suspend_for_duration", 1, 'foo') expect_invalid_arg_type(conn, "node_suspend_for_duration", 1, 2, 'foo') # TESTGROUP: conn.node_memory_parameters expect_too_many_args(conn, "node_memory_parameters", 1, 2) expect_invalid_arg_type(conn, "node_memory_parameters", 'foo') expect_success(conn, "no args", "node_memory_parameters") # TESTGROUP: conn.node_memory_paramters= expect_too_many_args(conn, "node_memory_parameters=", 1, 2) expect_invalid_arg_type(conn, "node_memory_parameters=", nil) expect_invalid_arg_type(conn, "node_memory_parameters=", ['foo', 0]) expect_invalid_arg_type(conn, "node_memory_parameters=", [{}, 'foo']) # TESTGROUP: conn.keepalive= expect_too_many_args(conn, "keepalive=", 1, 2) expect_too_few_args(conn, "keepalive=", []) expect_too_few_args(conn, "keepalive=", [1]) expect_invalid_arg_type(conn, "keepalive=", 1) expect_invalid_arg_type(conn, "keepalive=", ['foo', 1]) expect_invalid_arg_type(conn, "keepalive=", [1, 'foo']) # FIXME: somehow we need an event loop implementation for this to work #expect_success(conn, "interval and count", "keepalive=", 1, 10) # END TESTS conn.close finish_tests ruby-libvirt-0.5.1/tests/test_open.rb0000664000175000017500000002437212252736716021203 0ustar clalancetteclalancette#!/usr/bin/ruby # Test the open calls that the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("Libvirt") def expect_connect_error(func, args) expect_fail(Libvirt, Libvirt::ConnectionError, "invalid driver", func, *args) end # TESTGROUP: Libvirt::version expect_too_many_args(Libvirt, "version", "test", 1) expect_invalid_arg_type(Libvirt, "version", 1) expect_success(Libvirt, "no args", "version") {|x| x.class == Array and x.length == 2} expect_success(Libvirt, "nil arg", "version", nil) {|x| x.class == Array and x.length == 2} expect_success(Libvirt, "Test arg", "version", "Test") {|x| x.class == Array and x.length == 2} # TESTGROUP: Libvirt::open expect_too_many_args(Libvirt, "open", "qemu:///system", 1) expect_connect_error("open", "foo:///system") conn = expect_success(Libvirt, "no args", "open") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "qemu:///system", "open", "qemu:///system") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "nil arg", "open", nil) {|x| x.class == Libvirt::Connect } conn.close # TESTGROUP: Libvirt::open_read_only expect_too_many_args(Libvirt, "open_read_only", "qemu:///system", 1) expect_connect_error("open_read_only", "foo:///system") conn = expect_success(Libvirt, "no args", "open_read_only") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "qemu:///system", "open_read_only", "qemu:///system") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "nil arg", "open_read_only", nil) {|x| x.class == Libvirt::Connect } conn.close # TESTGROUP: Libvirt::open_auth expect_too_many_args(Libvirt, "open_auth", "qemu:///system", [], "hello there", 1, 2) expect_connect_error("open_auth", "foo:///system") expect_invalid_arg_type(Libvirt, "open_auth", 1) expect_invalid_arg_type(Libvirt, "open_auth", "qemu:///system", [], "hello", "foo") conn = expect_success(Libvirt, "no args", "open_auth") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri arg", "open_auth", "qemu:///system") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri and empty cred args", "open_auth", "qemu:///system", []) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri and full cred args", "open_auth", "qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri, full cred, and user args", "open_auth", "qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") {|x| x.class == Libvirt::Connect } conn.close # equivalent to expect_invalid_arg_type begin conn = Libvirt::open_auth("qemu:///system", {}) do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" else puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing" end # equivalent to expect_invalid_arg_type begin conn = Libvirt::open_auth("qemu:///system", 1) do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" else puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing" end # equivalent to expect_invalid_arg_type begin conn = Libvirt::open_auth("qemu:///system", 'foo') do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" else puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing" end # equivalent to "expect_success" begin conn = Libvirt::open_auth("qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") do |cred| if not cred["userdata"].nil? puts "userdata is #{cred["userdata"]}" end if cred["type"] == Libvirt::CRED_AUTHNAME print "#{cred['prompt']}: " res = gets # strip off the \n res = res[0..-2] elsif cred["type"] == Libvirt::CRED_PASSPHRASE print "#{cred['prompt']}: " res = gets res = res[0..-2] else raise "Unsupported credential #{cred['type']}" end res end puts_ok "Libvirt.open_auth uri, creds, userdata, auth block succeeded" conn.close rescue NoMethodError puts_skipped "Libvirt.open_auth does not exist" rescue => e puts_fail "Libvirt.open_auth uri, creds, userdata, auth block expected to succeed, threw #{e.class.to_s}: #{e.to_s}" end # equivalent to "expect_success" begin conn = Libvirt::open_auth("qemu:///system") do |cred| end puts_ok "Libvirt.open_auth uri, succeeded" conn.close rescue NoMethodError puts_skipped "Libvirt.open_auth does not exist" rescue => e puts_fail "Libvirt.open_auth uri expected to succeed, threw #{e.class.to_s}: #{e.to_s}" end # equivalent to "expect_success" begin conn = Libvirt::open_auth("qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello", Libvirt::CONNECT_RO) do |cred| if not cred["userdata"].nil? puts "userdata is #{cred["userdata"]}" end if cred["type"] == Libvirt::CRED_AUTHNAME print "#{cred['prompt']}: " res = gets # strip off the \n res = res[0..-2] elsif cred["type"] == Libvirt::CRED_PASSPHRASE print "#{cred['prompt']}: " res = gets res = res[0..-2] else raise "Unsupported credential #{cred['type']}" end res end puts_ok "Libvirt.open_auth uri, creds, userdata, R/O flag, auth block succeeded" conn.close rescue NoMethodError puts_skipped "Libvirt.open_auth does not exist" rescue => e puts_fail "Libvirt.open_auth uri, creds, userdata, R/O flag, auth block expected to succeed, threw #{e.class.to_s}: #{e.to_s}" end # TESTGROUP: Libvirt::event_invoke_handle_callback conn = Libvirt::open("qemu:///system") expect_too_many_args(Libvirt, "event_invoke_handle_callback", 1, 2, 3, 4, 5) expect_too_few_args(Libvirt, "event_invoke_handle_callback") expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1) expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1, 2) expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1, 2, 3) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, 1) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, []) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, nil) # this is a bit bizarre; I am constructing a bogus hash to pass as the 4th # parameter to event_invoke_handle_callback. In a real situation, I would # have been given this hash from libvirt earlier, and just pass it on. I # don't want all of that complexity here, though, so I create the bogus hash. # One caveat; the data inside the hash *must* be of type T_DATA, so I pass in # a fake conn object just to appease the type checker (so I can test out the # other arguments properly) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, "hello", 1, { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, "hello", { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, 1, { "libvirt_cb" => "hello", "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, 1, { "libvirt_cb" => conn, "opaque" => "hello" }) conn.close # TESTGROUP: Libvirt::event_invoke_timeout_callback conn = Libvirt::open("qemu:///system") expect_too_many_args(Libvirt, "event_invoke_timeout_callback", 1, 2, 3) expect_too_few_args(Libvirt, "event_invoke_timeout_callback") expect_too_few_args(Libvirt, "event_invoke_timeout_callback", 1) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", 1) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", []) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", nil) # this is a bit bizarre; I am constructing a bogus hash to pass as the 4th # parameter to event_invoke_handle_callback. In a real situation, I would # have been given this hash from libvirt earlier, and just pass it on. I # don't want all of that complexity here, though, so I create the bogus hash. # One caveat; the data inside the hash *must* be of type T_DATA, so I pass in # a fake conn object just to appease the type checker (so I can test out the # other arguments properly) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", 1, { "libvirt_cb" => "hello", "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", 1, { "libvirt_cb" => conn, "opaque" => "hello" }) conn.close # TESTGROUP: Libvirt::event_register_impl expect_too_many_args(Libvirt, "event_register_impl", 1, 2, 3, 4, 5, 6, 7) expect_invalid_arg_type(Libvirt, "event_register_impl", 1) # symbol callbacks def virEventAddHandleImpl(fd, events, opaque) end def virEventUpdateHandleImpl(watch, event) end def virEventRemoveHandleImpl(handleID) end def virEventAddTimerImpl(interval, opaque) end def virEventUpdateTimerImpl(timer, timeout) end def virEventRemoveTimerImpl(timerID) end # proc callbacks virEventAddHandleProc = lambda {|fd, events, opaque| } virEventUpdateHandleProc = lambda {|watch, event| } virEventRemoveHandleProc = lambda {|handleID| } virEventAddTimerProc = lambda {|interval, opaque| } virEventUpdateTimerProc = lambda {|timer, timeout| } virEventRemoveTimerProc = lambda {|timerID| } expect_success(Libvirt, "all Symbol callbacks", "event_register_impl", :virEventAddHandleImpl, :virEventUpdateHandleImpl, :virEventRemoveHandleImpl, :virEventAddTimerImpl, :virEventUpdateTimerImpl, :virEventRemoveTimerImpl) expect_success(Libvirt, "unregister all callbacks", "event_register_impl", nil, nil, nil, nil, nil, nil) expect_success(Libvirt, "all Proc callbacks", "event_register_impl", virEventAddHandleProc, virEventUpdateHandleProc, virEventRemoveHandleProc, virEventAddTimerProc, virEventUpdateTimerProc, virEventRemoveTimerProc) expect_success(Libvirt, "unregister all callbacks", "event_register_impl") # END TESTS finish_tests ruby-libvirt-0.5.1/tests/test_domain.rb0000664000175000017500000012637112252736716021513 0ustar clalancetteclalancette#!/usr/bin/ruby # Test the domain methods the bindings support. Note that this tester requires # the qemu driver to be enabled and available for use. # Note that the order of the TESTGROUPs below match the order that the # functions are defined in the ext/libvirt/domain.c file $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("domain") conn = Libvirt::open("qemu:///system") cleanup_test_domain(conn) # setup for later tests `qemu-img create -f qcow2 #{$GUEST_DISK} 5G` new_hostdev_xml = <
EOF # start tests # TESTGROUP: dom.migrate_max_speed newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "migrate_max_speed", 1, 2) expect_invalid_arg_type(newdom, "migrate_max_speed", 'foo') expect_invalid_arg_type(newdom, "migrate_max_speed", []) expect_invalid_arg_type(newdom, "migrate_max_speed", {}) expect_success(newdom, "no args", "migrate_max_speed") newdom.destroy # TESTGROUP: dom.reset newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "reset", 1, 2) expect_invalid_arg_type(newdom, "reset", 'foo') expect_invalid_arg_type(newdom, "reset", []) expect_invalid_arg_type(newdom, "reset", {}) expect_success(newdom, "no args", "reset") newdom.destroy # TESTGROUP: dom.hostname newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "hostname", 1, 2) expect_invalid_arg_type(newdom, "hostname", 'foo') expect_invalid_arg_type(newdom, "hostname", []) expect_invalid_arg_type(newdom, "hostname", {}) # FIXME: spits an error "this function is not supported by the connection driver" #expect_success(newdom, "no args", "hostname") newdom.destroy # TESTGROUP: dom.metadata newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "metadata", 1, 2, 3, 4) expect_too_few_args(newdom, "metadata") expect_invalid_arg_type(newdom, "metadata", 'foo') expect_invalid_arg_type(newdom, "metadata", nil) expect_invalid_arg_type(newdom, "metadata", []) expect_invalid_arg_type(newdom, "metadata", {}) expect_invalid_arg_type(newdom, "metadata", 1, 1) expect_invalid_arg_type(newdom, "metadata", 1, 'foo', 'bar') expect_success(newdom, "no args", "metadata", Libvirt::Domain::METADATA_DESCRIPTION) {|x| x == "Ruby Libvirt Tester"} newdom.destroy # TESTGROUP: dom.metadata= newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "metadata=", 1, 2, 3, 4, 5, 6) expect_too_few_args(newdom, "metadata=") expect_too_few_args(newdom, "metadata=", [1]) expect_invalid_arg_type(newdom, "metadata=", 1) expect_invalid_arg_type(newdom, "metadata=", 'foo') expect_invalid_arg_type(newdom, "metadata=", nil) expect_invalid_arg_type(newdom, "metadata=", {}) expect_invalid_arg_type(newdom, "metadata=", ['foo', nil]) expect_invalid_arg_type(newdom, "metadata=", [nil, nil]) expect_invalid_arg_type(newdom, "metadata=", [[], nil]) expect_invalid_arg_type(newdom, "metadata=", [{}, nil]) expect_invalid_arg_type(newdom, "metadata=", [1, 1]) expect_invalid_arg_type(newdom, "metadata=", [1, []]) expect_invalid_arg_type(newdom, "metadata=", [1, {}]) expect_success(newdom, "no args", "metadata=", [Libvirt::Domain::METADATA_DESCRIPTION, 'foo']) expect_success(newdom, "no args", "metadata=", [Libvirt::Domain::METADATA_DESCRIPTION, 'foo', nil, nil, 0]) expect_success(newdom, "no args", "metadata", Libvirt::Domain::METADATA_DESCRIPTION) {|x| x == "foo"} newdom.destroy # TESTGROUP: dom.updated? newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "updated?", 1) expect_success(newdom, "no args", "updated?") newdom.destroy # TESTGROUP: dom.inject_nmi newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "inject_nmi", 1, 2) expect_invalid_arg_type(newdom, "inject_nmi", 'foo') expect_success(newdom, "no args", "inject_nmi") newdom.destroy # TESTGROUP: dom.control_info newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "control_info", 1, 2) expect_invalid_arg_type(newdom, "control_info", 'foo') expect_success(newdom, "no args", "control_info") newdom.destroy # TESTGROUP: dom.send_key newdom = conn.create_domain_xml($new_dom_xml) sleep 30 expect_too_many_args(newdom, "send_key", 1, 2, 3, 4) expect_too_few_args(newdom, "send_key") expect_too_few_args(newdom, "send_key", 1) expect_too_few_args(newdom, "send_key", 1, 2) expect_invalid_arg_type(newdom, "send_key", nil, 0, []) expect_invalid_arg_type(newdom, "send_key", nil, 0, [1]) expect_invalid_arg_type(newdom, "send_key", 'foo', 0, []) expect_invalid_arg_type(newdom, "send_key", 0, nil, []) expect_invalid_arg_type(newdom, "send_key", 0, 'foo', []) expect_invalid_arg_type(newdom, "send_key", 0, 1, nil) expect_invalid_arg_type(newdom, "send_key", 0, 1, 'foo') expect_invalid_arg_type(newdom, "send_key", 0, 1, 2) expect_invalid_arg_type(newdom, "send_key", nil, 0, [nil]) expect_invalid_arg_type(newdom, "send_key", nil, 0, ['foo']) # FIXME: this fails for reasons that are unclear to me #expect_success(newdom, "codeset, holdtime, keycodes args", "send_key", 0, 1, []) newdom.destroy # TESTGROUP: dom.migrate newdom = conn.create_domain_xml($new_dom_xml) sleep 1 dconn = Libvirt::open("qemu:///system") expect_too_many_args(newdom, "migrate", 1, 2, 3, 4, 5, 6) expect_too_few_args(newdom, "migrate") expect_fail(newdom, ArgumentError, "invalid connection object", "migrate", "foo") expect_invalid_arg_type(newdom, "migrate", dconn, 'foo') expect_invalid_arg_type(newdom, "migrate", dconn, 0, 1) expect_invalid_arg_type(newdom, "migrate", dconn, 0, 'foo', 1) expect_invalid_arg_type(newdom, "migrate", dconn, 0, 'foo', 'bar', 'baz') # FIXME: how can we make this work? #expect_success(newdom, "conn arg", "migrate", dconn) dconn.close newdom.destroy # TESTGROUP: dom.migrate_to_uri newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "migrate_to_uri", 1, 2, 3, 4, 5) expect_too_few_args(newdom, "migrate_to_uri") expect_invalid_arg_type(newdom, "migrate_to_uri", 1) expect_invalid_arg_type(newdom, "migrate_to_uri", "qemu:///system", 'foo') expect_invalid_arg_type(newdom, "migrate_to_uri", "qemu:///system", 0, 1) expect_invalid_arg_type(newdom, "migrate_to_uri", "qemu:///system", 0, 'foo', 'bar') #expect_success(newdom, "URI arg", "migrate_to_uri", "qemu://remote/system") dconn.close newdom.destroy # TESTGROUP: dom.migrate_set_max_downtime newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "migrate_set_max_downtime", 1, 2, 3) expect_too_few_args(newdom, "migrate_set_max_downtime") expect_invalid_arg_type(newdom, "migrate_set_max_downtime", 'foo') expect_invalid_arg_type(newdom, "migrate_set_max_downtime", 10, 'foo') expect_fail(newdom, Libvirt::Error, "on off domain", "migrate_set_max_downtime", 10) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_fail(newdom, Libvirt::Error, "while no migration in progress", "migrate_set_max_downtime", 10) #newdom.migrate_to_uri("qemu://remote/system") #expect_success(newdom, "10 second downtime", "migrate_set_max_downtime", 10) newdom.destroy # TESTGROUP: dom.migrate2 newdom = conn.create_domain_xml($new_dom_xml) sleep 1 dconn = Libvirt::open("qemu:///system") expect_too_many_args(newdom, "migrate2", 1, 2, 3, 4, 5, 6, 7) expect_too_few_args(newdom, "migrate2") expect_fail(newdom, ArgumentError, "invalid connection object", "migrate2", "foo") expect_invalid_arg_type(newdom, "migrate2", dconn, 0) # FIXME: how can we make this work? #expect_success(newdom, "conn arg", "migrate2", dconn) dconn.close newdom.destroy # TESTGROUP: dom.migrate_to_uri2 newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "migrate_to_uri2", 1, 2, 3, 4, 5, 6, 7) expect_invalid_arg_type(newdom, "migrate_to_uri2", 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 'bar', 'baz') expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 'bar', 0, 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", "qemu:///system", 'foo', 'bar', 0, 'foo', 'baz') #expect_success(newdom, "URI arg", "migrate_to_uri2", "qemu://remote/system") dconn.close newdom.destroy # TESTGROUP: dom.migrate_set_max_speed newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "migrate_set_max_speed", 1, 2, 3) expect_too_few_args(newdom, "migrate_set_max_speed") expect_invalid_arg_type(newdom, "migrate_set_max_speed", 'foo') expect_invalid_arg_type(newdom, "migrate_set_max_speed", 5, 'foo') #expect_success(newdom, "Bandwidth arg", "migrate_set_max_speed", 5) newdom.destroy # TESTGROUP: dom.shutdown newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "shutdown", 1, 2) expect_success(newdom, "no args", "shutdown") sleep 1 newdom.destroy # TESTGROUP: dom.reboot newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "reboot", 1, 2) expect_invalid_arg_type(newdom, "reboot", "hello") expect_success(newdom, "no args", "reboot") sleep 1 expect_success(newdom, "flags arg", "reboot", 0) sleep 1 newdom.destroy # TESTGROUP: dom.destroy newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "destroy", 1, 2) expect_success(newdom, "no args", "destroy") # TESTGROUP: dom.suspend newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "suspend", 1) expect_success(newdom, "no args", "suspend") newdom.destroy # TESTGROUP: dom.resume newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_success(newdom, "no args running domain", "resume") newdom.suspend expect_too_many_args(newdom, "resume", 1) expect_success(newdom, "no args suspended domain", "resume") newdom.destroy # TESTGROUP: dom.save newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "save", 1, 2, 3, 4) expect_too_few_args(newdom, "save") expect_invalid_arg_type(newdom, "save", 1) expect_invalid_arg_type(newdom, "save", nil) expect_fail(newdom, Libvirt::Error, "non-existent path", "save", "/this/path/does/not/exist") expect_success(newdom, "path arg", "save", $GUEST_SAVE) `rm -f #{$GUEST_SAVE}` # TESTGROUP: dom.managed_save newdom = conn.define_domain_xml($new_dom_xml) newdom.create sleep 1 expect_too_many_args(newdom, "managed_save", 1, 2) expect_invalid_arg_type(newdom, "managed_save", "hello") expect_success(newdom, "no args", "managed_save") newdom.undefine(Libvirt::Domain::UNDEFINE_MANAGED_SAVE) # TESTGROUP: dom.has_managed_save? newdom = conn.define_domain_xml($new_dom_xml) newdom.create sleep 1 expect_too_many_args(newdom, "has_managed_save?", 1, 2) expect_invalid_arg_type(newdom, "has_managed_save?", "hello") if newdom.has_managed_save? puts_fail "domain.has_managed_save? reports true on a new domain" else puts_ok "domain.has_managed_save? not true on new domain" end newdom.managed_save if not newdom.has_managed_save? puts_fail "domain.has_managed_save? reports false after a managed save" else puts_ok "domain.has_managed_save? reports true after a managed save" end newdom.undefine(Libvirt::Domain::UNDEFINE_MANAGED_SAVE) # TESTGROUP: dom.managed_save_remove newdom = conn.define_domain_xml($new_dom_xml) newdom.create sleep 1 newdom.managed_save expect_too_many_args(newdom, "managed_save_remove", 1, 2) expect_invalid_arg_type(newdom, "managed_save_remove", "hello") if not newdom.has_managed_save? puts_fail "prior to domain.managed_save_remove, no managed save file" end expect_success(newdom, "no args", "managed_save_remove") if newdom.has_managed_save? puts_fail "after domain.managed_save_remove, managed save file still exists" else puts_ok "after domain.managed_save_remove, managed save file no longer exists" end newdom.undefine # TESTGROUP: dom.core_dump newdom = conn.define_domain_xml($new_dom_xml) newdom.create sleep 1 expect_too_many_args(newdom, "core_dump", 1, 2, 3) expect_too_few_args(newdom, "core_dump") expect_invalid_arg_type(newdom, "core_dump", 1, 2) expect_invalid_arg_type(newdom, "core_dump", "/path", "foo") expect_fail(newdom, Libvirt::Error, "invalid path", "core_dump", "/this/path/does/not/exist") expect_success(newdom, "live with path arg", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core") `rm -f /var/lib/libvirt/images/ruby-libvirt-test.core` expect_success(newdom, "crash with path arg", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core", Libvirt::Domain::DUMP_CRASH) expect_fail(newdom, Libvirt::Error, "of shut-off domain", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core", Libvirt::Domain::DUMP_CRASH) `rm -f /var/lib/libvirt/images/ruby-libvirt-test.core` newdom.undefine # TESTGROUP: Libvirt::Domain::restore newdom = conn.define_domain_xml($new_dom_xml) newdom.create sleep 1 newdom.save($GUEST_SAVE) expect_too_many_args(Libvirt::Domain, "restore", 1, 2, 3) expect_too_few_args(Libvirt::Domain, "restore") expect_invalid_arg_type(Libvirt::Domain, "restore", 1, 2) expect_invalid_arg_type(Libvirt::Domain, "restore", conn, 2) expect_fail(Libvirt::Domain, Libvirt::Error, "invalid path", "restore", conn, "/this/path/does/not/exist") `touch /tmp/foo` expect_fail(Libvirt::Domain, Libvirt::Error, "invalid save file", "restore", conn, "/tmp/foo") `rm -f /tmp/foo` expect_success(Libvirt::Domain, "2 args", "restore", conn, $GUEST_SAVE) `rm -f #{$GUEST_SAVE}` newdom.destroy newdom.undefine # TESTGROUP: dom.info newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "info", 1) expect_success(newdom, "no args", "info") {|x| x.state == Libvirt::Domain::RUNNING and x.max_mem == 1048576 and x.memory == 1048576 and x.nr_virt_cpu == 2} newdom.destroy # TESTGROUP: dom.security_label newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "security_label", 1) expect_success(newdom, "no args", "security_label") newdom.destroy # TESTGROUP: dom.block_stats newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "block_stats", 1, 2) expect_too_few_args(newdom, "block_stats") expect_invalid_arg_type(newdom, "block_stats", 1) expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "block_stats", "foo") expect_success(newdom, "block device arg", "block_stats", "vda") newdom.destroy # TESTGROUP: dom.memory_stats newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "memory_stats", 1, 2) expect_invalid_arg_type(newdom, "memory_stats", "foo") expect_success(newdom, "no args", "memory_stats") newdom.destroy # TESTGROUP: dom.blockinfo newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "blockinfo", 1, 2, 3) expect_too_few_args(newdom, "blockinfo") expect_invalid_arg_type(newdom, "blockinfo", 1) expect_invalid_arg_type(newdom, "blockinfo", "foo", "bar") expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "blockinfo", "foo") expect_success(newdom, "path arg", "blockinfo", $GUEST_DISK) newdom.destroy # TESTGROUP: dom.block_peek newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "block_peek", 1, 2, 3, 4, 5) expect_too_few_args(newdom, "block_peek") expect_too_few_args(newdom, "block_peek", 1) expect_too_few_args(newdom, "block_peek", 1, 2) expect_invalid_arg_type(newdom, "block_peek", 1, 2, 3) expect_invalid_arg_type(newdom, "block_peek", "foo", "bar", 3) expect_invalid_arg_type(newdom, "block_peek", "foo", 0, "bar") expect_invalid_arg_type(newdom, "block_peek", "foo", 0, 512, "baz") expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "block_peek", "foo", 0, 512) blockpeek = newdom.block_peek($GUEST_DISK, 0, 512) # 0x51 0x46 0x49 0xfb are the first 4 bytes of a qcow2 image if blockpeek[0].unpack('C')[0] != 0x51 or blockpeek[1].unpack('C')[0] != 0x46 or blockpeek[2].unpack('C')[0] != 0x49 or blockpeek[3].unpack('C')[0] != 0xfb puts_fail "domain.block_peek read did not return valid data" else puts_ok "domain.block_peek read valid data" end newdom.destroy # TESTGROUP: dom.memory_peek newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "memory_peek", 1, 2, 3, 4) expect_too_few_args(newdom, "memory_peek") expect_too_few_args(newdom, "memory_peek", 1) expect_invalid_arg_type(newdom, "memory_peek", "foo", 2) expect_invalid_arg_type(newdom, "memory_peek", 0, "bar") expect_invalid_arg_type(newdom, "memory_peek", 0, 512, "baz") expect_success(newdom, "offset and size args", "memory_peek", 0, 512) newdom.destroy # TESTGROUP: dom.get_vcpus expect_too_many_args(newdom, "get_vcpus", 1) newdom = conn.define_domain_xml($new_dom_xml) expect_success(newdom, "get_vcpus on shutoff domain", "get_vcpus") {|x| x.length == 2} newdom.create sleep 1 expect_success(newdom, "no args", "get_vcpus") {|x| x.length == 2} newdom.destroy newdom.undefine # TESTGROUP: dom.active? expect_too_many_args(newdom, "active?", 1) newdom = conn.define_domain_xml($new_dom_xml) expect_success(newdom, "no args", "active?") {|x| x == false} newdom.create sleep 1 expect_success(newdom, "no args", "active?") {|x| x == true} newdom.destroy newdom.undefine # TESTGROUP: dom.persistent? newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "persistent?", 1) expect_success(newdom, "no args", "persistent?") {|x| x == false} newdom.destroy newdom = conn.define_domain_xml($new_dom_xml) expect_success(newdom, "no args", "persistent?") {|x| x == true} newdom.undefine # TESTGROUP: dom.ifinfo newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "ifinfo", 1, 2) expect_too_few_args(newdom, "ifinfo") expect_invalid_arg_type(newdom, "ifinfo", 1) expect_fail(newdom, Libvirt::RetrieveError, "invalid arg", "ifinfo", "foo") expect_success(newdom, "interface arg", "ifinfo", "rl556") newdom.destroy # TESTGROUP: dom.name newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "name", 1) expect_success(newdom, "no args", "name") {|x| x == "ruby-libvirt-tester"} newdom.destroy # TESTGROUP: dom.id newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "id", 1) expect_success(newdom, "no args", "id") newdom.destroy # TESTGROUP: dom.uuid newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "uuid", 1) expect_success(newdom, "no args", "uuid") {|x| x == $GUEST_UUID} newdom.destroy # TESTGROUP: dom.os_type newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "os_type", 1) expect_success(newdom, "no args", "os_type") {|x| x == "hvm"} newdom.destroy # TESTGROUP: dom.max_memory newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "max_memory", 1) expect_success(newdom, "no args", "max_memory") {|x| x == 1048576} newdom.destroy # TESTGROUP: dom.max_memory= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "max_memory=", 1, 2) expect_too_few_args(newdom, "max_memory=") expect_invalid_arg_type(newdom, "max_memory=", 'foo') expect_success(newdom, "memory arg", "max_memory=", 200000) newdom.undefine # TESTGROUP: dom.memory= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "memory=", 1, 2) expect_too_many_args(newdom, "memory=", [1, 2, 3]) expect_too_few_args(newdom, "memory=") expect_too_few_args(newdom, "memory=", []) expect_invalid_arg_type(newdom, "memory=", 'foo') expect_fail(newdom, Libvirt::Error, "shutoff domain", "memory=", [2, Libvirt::Domain::AFFECT_LIVE]) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_success(newdom, "number arg", "memory=", 200000) newdom.destroy # TESTGROUP: dom.max_vcpus newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "max_vcpus", 1) expect_success(newdom, "no args", "max_vcpus") newdom.destroy # TESTGROUP: dom.vcpus= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "vcpus=", 1, 2) expect_too_many_args(newdom, "vcpus=", [0, 1, 2]) expect_too_few_args(newdom, "vcpus=") expect_too_few_args(newdom, "vcpus=", []) expect_invalid_arg_type(newdom, "vcpus=", 'foo') expect_fail(newdom, Libvirt::Error, "shutoff domain", "vcpus=", [2, Libvirt::Domain::AFFECT_LIVE]) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_success(newdom, "number arg", "vcpus=", 2) newdom.destroy # TESTGROUP: dom.pin_vcpu newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "pin_vcpu", 1, 2, 3, 4) expect_too_few_args(newdom, "pin_vcpu") expect_invalid_arg_type(newdom, "pin_vcpu", 'foo', [0]) expect_invalid_arg_type(newdom, "pin_vcpu", 0, 1) expect_success(newdom, "cpu args", "pin_vcpu", 0, [0]) newdom.destroy # TESTGROUP: dom.xml_desc newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_too_many_args(newdom, "xml_desc", 1, 2) expect_invalid_arg_type(newdom, "xml_desc", "foo") expect_success(newdom, "no args", "xml_desc") newdom.destroy # TESTGROUP: dom.undefine newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "undefine", 1, 2) expect_success(newdom, "no args", "undefine") # TESTGROUP: dom.create newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "create", 1, 2) expect_invalid_arg_type(newdom, "create", "foo") expect_success(newdom, "no args", "create") expect_fail(newdom, Libvirt::Error, "on already running domain", "create") newdom.destroy newdom.undefine # TESTGROUP: dom.autostart? newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "autostart?", 1) expect_success(newdom, "no args", "autostart?") {|x| x == false} newdom.autostart = true expect_success(newdom, "no args", "autostart?") {|x| x == true} newdom.undefine # TESTGROUP: dom.autostart= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "autostart=", 1, 2) expect_invalid_arg_type(newdom, "autostart=", 'foo') expect_invalid_arg_type(newdom, "autostart=", nil) expect_invalid_arg_type(newdom, "autostart=", 1234) expect_success(newdom, "true arg", "autostart=", true) if not newdom.autostart? puts_fail "domain.autostart= did not set autostart to true" else puts_ok "domain.autostart= set autostart to true" end expect_success(newdom, "false arg", "autostart=", false) if newdom.autostart? puts_fail "domain.autostart= did not set autostart to false" else puts_ok "domain.autostart= set autostart to false" end newdom.undefine # TESTGROUP: dom.attach_device newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "attach_device", 1, 2, 3) expect_too_few_args(newdom, "attach_device") expect_invalid_arg_type(newdom, "attach_device", 1) expect_invalid_arg_type(newdom, "attach_device", 'foo', 'bar') expect_fail(newdom, Libvirt::Error, "invalid XML", "attach_device", "hello") expect_fail(newdom, Libvirt::Error, "shut off domain", "attach_device", new_hostdev_xml) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 #expect_success(newdom, "hostdev XML", "attach_device", new_hostdev_xml) newdom.destroy # TESTGROUP: dom.detach_device newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "detach_device", 1, 2, 3) expect_too_few_args(newdom, "detach_device") expect_invalid_arg_type(newdom, "detach_device", 1) expect_invalid_arg_type(newdom, "detach_device", 'foo', 'bar') expect_fail(newdom, Libvirt::Error, "invalid XML", "detach_device", "hello") expect_fail(newdom, Libvirt::Error, "shut off domain", "detach_device", new_hostdev_xml) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 #expect_success(newdom, "hostdev XML", "detach_device", new_hostdev_xml) newdom.destroy # TESTGROUP: dom.update_device newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "update_device", 1, 2, 3) expect_too_few_args(newdom, "update_device") expect_invalid_arg_type(newdom, "update_device", 1) expect_invalid_arg_type(newdom, "update_device", 'foo', 'bar') expect_fail(newdom, Libvirt::Error, "invalid XML", "update_device", "hello") expect_fail(newdom, Libvirt::Error, "shut off domain", "update_device", new_hostdev_xml) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 #expect_success(newdom, "hostdev XML", "update_device", new_hostdev_xml) newdom.destroy # TESTGROUP: dom.free newdom = conn.define_domain_xml($new_dom_xml) newdom.undefine expect_too_many_args(newdom, "free", 1) expect_success(newdom, "free", "free") # TESTGROUP: dom.snapshot_create_xml newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "snapshot_create_xml", 1, 2, 3) expect_too_few_args(newdom, "snapshot_create_xml") expect_invalid_arg_type(newdom, "snapshot_create_xml", 1) expect_invalid_arg_type(newdom, "snapshot_create_xml", nil) expect_invalid_arg_type(newdom, "snapshot_create_xml", 'foo', 'bar') expect_success(newdom, "simple XML arg", "snapshot_create_xml", "") snaps = newdom.num_of_snapshots if snaps != 1 puts_fail "domain.snapshot_create_xml after one snapshot has #{snaps} snapshots" else puts_ok "domain.snapshot_create_xml after one snapshot has 1 snapshot" end newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.num_of_snapshots newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "num_of_snapshots", 1, 2) expect_invalid_arg_type(newdom, "num_of_snapshots", 'foo') expect_success(newdom, "no args", "num_of_snapshots") {|x| x == 0} newdom.snapshot_create_xml("") expect_success(newdom, "no args", "num_of_snapshots") {|x| x == 1} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.list_snapshots newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "list_snapshots", 1, 2) expect_invalid_arg_type(newdom, "list_snapshots", 'foo') expect_success(newdom, "no args", "list_snapshots") {|x| x.length == 0} newdom.snapshot_create_xml("") expect_success(newdom, "no args", "list_snapshots") {|x| x.length == 1} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.lookup_snapshot_by_name newdom = conn.define_domain_xml($new_dom_xml) newdom.snapshot_create_xml("foo") expect_too_many_args(newdom, "lookup_snapshot_by_name", 1, 2, 3) expect_too_few_args(newdom, "lookup_snapshot_by_name") expect_invalid_arg_type(newdom, "lookup_snapshot_by_name", 1) expect_invalid_arg_type(newdom, "lookup_snapshot_by_name", 'foo', 'bar') expect_success(newdom, "name arg", "lookup_snapshot_by_name", "foo") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.has_current_snapshot? newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "has_current_snapshot?", 1, 2) expect_invalid_arg_type(newdom, "has_current_snapshot?", 'foo') expect_success(newdom, "no args", "has_current_snapshot?") {|x| x == false} newdom.snapshot_create_xml("foo") expect_success(newdom, "no args", "has_current_snapshot?") {|x| x == true} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.revert_to_snapshot newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "revert_to_snapshot", 1, 2, 3) expect_too_few_args(newdom, "revert_to_snapshot") expect_invalid_arg_type(newdom, "revert_to_snapshot", 1) expect_invalid_arg_type(newdom, "revert_to_snapshot", nil) expect_invalid_arg_type(newdom, "revert_to_snapshot", 'foo') snap = newdom.snapshot_create_xml("foo") sleep 1 expect_invalid_arg_type(newdom, "revert_to_snapshot", snap, 'foo') expect_success(newdom, "snapshot arg", "revert_to_snapshot", snap) newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.current_snapshot newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "current_snapshot", 1, 2) expect_invalid_arg_type(newdom, "current_snapshot", 'foo') expect_fail(newdom, Libvirt::RetrieveError, "with no snapshots", "current_snapshot") newdom.snapshot_create_xml("foo") expect_success(newdom, "no args", "current_snapshot") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.job_info newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "job_info", 1) expect_fail(newdom, Libvirt::RetrieveError, "shutoff domain", "job_info") newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_success(newdom, "no args", "job_info") newdom.destroy # TESTGROUP: dom.abort_job newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "abort_job", 1) expect_fail(newdom, Libvirt::Error, "not running domain", "abort_job") newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) sleep 1 expect_fail(newdom, Libvirt::Error, "no active job", "abort_job") # FIXME: need to start long running job here #expect_success(newdom, "no args", "abort_job") newdom.destroy # TESTGROUP: dom.scheduler_type newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "scheduler_type", 1) expect_success(newdom, "no args", "scheduler_type") newdom.undefine # TESTGROUP: dom.scheduler_parameters newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "scheduler_parameters", 1, 1) expect_success(newdom, "no args", "scheduler_parameters") newdom.undefine # TESTGROUP: dom.scheduler_parameters= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "scheduler_parameters=", 1, 2) expect_too_few_args(newdom, "scheduler_parameters=") expect_invalid_arg_type(newdom, "scheduler_parameters=", 0) expect_success(newdom, "cpu shares arg", "scheduler_parameters=", {"cpu_shares" => 512}) newdom.undefine # TESTGROUP: dom.qemu_monitor_command new_test_xml = < fc4 EF86180145B911CB88E3AFBFE5370493 xen /boot/vmlinuz-2.6.15-1.43_FC5guest /boot/initrd-2.6.15-1.43_FC5guest.img /dev/sda1 ro selinux=0 3 261072 131072 1