Commit Graph

108 Commits

Author SHA1 Message Date
Simon Hensel 406d590a36 Always delete NVRAM files when deleting instances
When deleting an instance, always send VIR_DOMAIN_UNDEFINE_NVRAM to
delete the NVRAM file, regardless of whether the image is of type UEFI.
This prevents a bug when rebuilding an instance from an UEFI image to a
non-UEFI image.

Closes-Bug: #1997352

Change-Id: I24648f5b7895bf5d093f222b6c6e364becbb531f
Signed-off-by: Simon Hensel <simon.hensel@inovex.de>
2024-01-23 16:16:17 +01:00
Dan Smith 1ed02d57c0 Detach disks using alias when possible
This makes us attempt to first look up a disk device by alias using
the volume_uuid, before falling back to the old method of using the
guest target device name.

Related to blueprint libvirt-dev-alias

Change-Id: I1dfe4ad3df81bc810835af9b09cfc6c06e9a5388
2023-11-15 07:07:19 -08:00
Zuul df8e0335fa Merge "Handle "no RAM info was set" migration case" 2022-10-06 23:49:17 +00:00
Brett Milford 9fea934c71 Handle "no RAM info was set" migration case
This handles the case where the live migration monitoring thread may
race and call jobStats() after the migration has completed resulting in
the following error:

    libvirt.libvirtError: internal error: migration was active, but no
    RAM info was set

Closes-Bug: #1982284
Change-Id: I77fdfa9cffbd44b2889f49f266b2582bcc6a4267
2022-08-29 11:05:20 +10:00
Sean Mooney 6f1c7ab2e7 Add source dev parsing for vdpa interfaces
This change extends the guest xml parsing such that
the source device path can be extreacted from interface
elements of type vdpa.

This is required to identify the interface to remove when
detaching a vdpa port from a domain.

This change fixes a latent bug in the libvirt fixutre
related to the domain xml generation for vdpa interfaces.

Change-Id: I5f41170e7038f4b872066de4b1ad509113034960
2022-08-22 14:57:21 +01:00
Stephen Finucane 89ef050b8c Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib. Most of this
is autogenerated, as described below, but there is one manual change
necessary:

nova/tests/functional/regressions/test_bug_1781286.py
  We need to avoid using 'fixtures.MockPatch' since fixtures is using
  'mock' (the library) under the hood and a call to 'mock.patch.stop'
  found in that test will now "stop" mocks from the wrong library. We
  have discussed making this configurable but the option proposed isn't
  that pretty [1] so this is better.

The remainder was auto-generated with the following (hacky) script, with
one or two manual tweaks after the fact:

  import glob

  for path in glob.glob('nova/tests/**/*.py', recursive=True):
      with open(path) as fh:
          lines = fh.readlines()
      if 'import mock\n' not in lines:
          continue
      import_group_found = False
      create_first_party_group = False
      for num, line in enumerate(lines):
          line = line.strip()
          if line.startswith('import ') or line.startswith('from '):
              tokens = line.split()
              for lib in (
                  'ddt', 'six', 'webob', 'fixtures', 'testtools'
                  'neutron', 'cinder', 'ironic', 'keystone', 'oslo',
              ):
                  if lib in tokens[1]:
                      create_first_party_group = True
                      break
              if create_first_party_group:
                  break
              import_group_found = True
          if not import_group_found:
              continue
          if line.startswith('import ') or line.startswith('from '):
              tokens = line.split()
              if tokens[1] > 'unittest':
                  break
              elif tokens[1] == 'unittest' and (
                  len(tokens) == 2 or tokens[4] > 'mock'
              ):
                  break
          elif not line:
              break
      if create_first_party_group:
          lines.insert(num, 'from unittest import mock\n\n')
      else:
          lines.insert(num, 'from unittest import mock\n')
      del lines[lines.index('import mock\n')]
      with open(path, 'w+') as fh:
          fh.writelines(lines)

Note that we cannot remove mock from our requirements files yet due to
importing pypowervm unit test code in nova unit tests. This library
still uses the mock lib, and since we are importing test code and that
lib (correctly) only declares mock in its test-requirements.txt, mock
would not otherwise be installed and would cause errors while loading
nova unit test code.

[1] https://github.com/testing-cabal/fixtures/pull/49

Change-Id: Id5b04cf2f6ca24af8e366d23f15cf0e5cac8e1cc
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2022-08-01 17:46:26 +02:00
Stephen Finucane 33be6d4b56 tests: Move libvirt-specific fixtures
These were left to last since there's a bit of cleanup necessary to move
everything across.

Change-Id: I921c812ac03f7d32eec31200772020c17f292851
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-05-24 11:00:29 +01:00
Zuul 48b5bf94a3 Merge "Remove references to 'sys.version_info'" 2021-05-03 14:21:56 +00:00
Stephen Finucane bab3c8f3cb Remove references to 'sys.version_info'
We support Python 3.6 as a minimum now, making these checks no-ops.

Change-Id: I5ca2439c948687022f8d88df978bc7ee77199fcc
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-04-21 12:02:27 +01:00
Balazs Gibizer 52d6cd941c Move the guest.get_disk test to test_guest
As a follow up of I86153d31b02e6b74b42d53a6800297cbd0e5cbb4 the two
get_disk test that was mistakenly added to test_driver is now moved to
test_guest where they belong.

Change-Id: I17bd591ffb96b9b296bea04c87e286a83d40570e
Related-Bug: #1882521
2021-04-18 08:28:37 +00:00
Balazs Gibizer e56cc4f439 Replace blind retry with libvirt event waiting in detach
Nova so far applied a retry loop that tried to periodically detach the
device from libvirt while the device was visible in the domain xml. This
could lead to an issue where an already progressing detach on the
libvirt side is interrupted by nova re-sending the detach request for
the same device. See bug #1882521 for more information.

Also if there was both a persistent and a live domain the nova tried the
detach from both at the same call. This lead to confusion about the
result when such call failed. Was the detach failed partially?

We can do better, at least for the live detach case. Based on the
libvirt developers detaching from the persistent domain always
succeeds and it is a synchronous process. Detaching from the live
domain can be both synchronous or asynchronous depending on the guest
OS and the load on the hypervisor. But for live detach libvirt always
sends an event [1] nova can wait for.

So this patch does two things.

1) Separates the detach from the persistent domain from the detach from
   the live domain to make the error cases clearer.

2) Changes the retry mechanism.

   Detaching from the persistent domain is not retried. If libvirt
   reports device not found, while both persistent and live detach
   is needed, the error is ignored, and the process continues with
   the live detach. In any other case the error considered as fatal.

   Detaching from the live domain is changed to always wait for the
   libvirt event. In case of timeout, the live detach is retried.
   But a failure event from libvirt considered fatal, based on the
   information from the libvirt developers, so in this case the
   detach is not retried.

Related-Bug: #1882521

[1]https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventDeviceRemovedCallback

Change-Id: I7f2b6330decb92e2838aa7cee47fb228f00f47da
2021-04-18 10:24:08 +02:00
Lee Yarwood 0a7d3794c6 libvirt: Ignore device already in the process of unplug errors
At present QEMU will raise an error to libvirt when a device_del request
is made for a device that has already partially detached through a
previous request. This is outlined in more detail in the following
downstream Red Hat QEMU bug report:

Get libvirtError "Device XX is already in the process of unplug" [..]
https://bugzilla.redhat.com/show_bug.cgi?id=1878659

Within Nova we can actually ignore this error and allow our existing
retry logic to attempt again after a short wait, hopefully allowing the
original request to complete removing the device from the domain.

This change does this and should result in one of the following
device_del requests raising a VIR_ERR_DEVICE_MISSING error from libvirt.
_try_detach_device should then translate that libvirt error into a
DeviceNotFound exception which is itself then ignored by all
detach_device_with_retry callers and taken to mean that the device has
detached successfully.

Closes-Bug: #1923206
Change-Id: I0e068043d8267ab91535413d950a3e154c2234f7
2021-04-09 18:22:04 +01:00
Zuul f0cfa3ca6d Merge "libvirt: allow querying devices from the persistent domain" 2021-03-02 19:41:12 +00:00
Balazs Gibizer a634103b15 libvirt: allow querying devices from the persistent domain
This patch adds from_persistent_config kwargs to get_interface_by_cfg()
and get_disk() so that the caller can specify which domain config the
devices is read from. Currently, if there was both a live domain and a
persistent domain then nova only reads from the live domain. In a later
patch during device detach these calls will be used to detach from the
persistent domain separately from the live domain.

Change-Id: I86153d31b02e6b74b42d53a6800297cbd0e5cbb4
Related-Bug: #1882521
2021-02-22 16:05:20 +01:00
Nobuhiro MIKI 838370a490
libvirt: add IP address to libvirt guest metadata
Libvirt XML contains useful configuration information such as instance names,
flavors and images as metadata. This change extends this metadata to include
the IP addresses of the instances.

Example:
<metadata>
  <nova:instance xmlns:nova="http://openstack.org/xmlns/libvirt/nova/1.1">
    ...
    <nova:ports>
      <nova:port uuid="567a4527-b0e4-4d0a-bcc2-71fda37897f7">
        <nova:ip type="fixed" address="192.168.1.1" ipVersion="4"/>
        <nova:ip type="fixed" address="fe80::f95c:b030:7094" ipVersion="6"/>
        <nova:ip type="floating" address="11.22.33.44" ipVersion="4"/>
      </nova:port>
    </nova:ports>
    ...
  </nova:instance>
</metadata>

Change-Id: I45f1df4935905170957c2ea2496c8a698a7464a2
blueprint: libvirt-driver-ip-metadata
Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp>
2021-02-18 16:05:01 +09:00
Lee Yarwood 0aff191514 libvirt: Remove MIN_LIBVIRT_VIR_ERR_DEVICE_MISSING
Introduced by I32908b77c18f8ec08211dd67be49bbf903611c34 this was then
missed by the clean up of I8e349849db0b1a540d295c903f1470917b82fd97 that
actually bumped MIN_LIBVIRT_VERSION to 5.0.0 past the required 4.1.0 for
the original change. It's safe to remove this now ahead of another bump.

Change-Id: I181b3bf433b0fcef92ef4d430e9858506f24153c
2021-01-22 10:05:35 +00:00
Takashi Natsume 1cf2431f4b Remove six.text_type (2/2)
Replace six.text_type with str.
This patch completes six removal.

Change-Id: I779bd1446dc1f070fa5100ccccda7881fa508d79
Implements: blueprint six-removal
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2020-12-13 11:26:35 +00:00
Federico Ressi 73cc85d910 Log stack trace when fails launching a defined domain
Change-Id: I5165cebf8928c2214e28c61231baca7793bb421e
2020-09-23 12:18:12 +00:00
Balazs Gibizer 1361ea5ad1 Support SRIOV interface attach and detach
For attach:
* Generates InstancePciRequest for SRIOV interfaces attach requests
* Claims and allocates a PciDevice for such request

For detach:
* Frees PciDevice and deletes the InstancePciRequests

On the libvirt driver side the following small fixes was necessar:
* Fixes PCI address generation to avoid double 0x prefixes in LibvirtConfigGuestHostdevPCI
* Adds support for comparing LibvirtConfigGuestHostdevPCI objects
* Extends the comparison of LibvirtConfigGuestInterface to support
  macvtap interfaces where target_dev is only known by libvirt but not
  nova
* generalize guest.get_interface_by_cfg() to work with both
  LibvirtConfigGuest[Inteface|HostdevPCI] objects

Implements: blueprint sriov-interface-attach-detach

Change-Id: I67504a37b0fe2ae5da3cba2f3122d9d0e18b9481
2020-09-10 18:44:53 +01:00
Lee Yarwood 1bb8ee95d4 libvirt: Provide VIR_MIGRATE_PARAM_PERSIST_XML during live migration
The VIR_MIGRATE_PARAM_PERSIST_XML parameter was introduced in libvirt
v1.3.4 and is used to provide the new persistent configuration for the
destination during a live migration:

https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_MIGRATE_PARAM_PERSIST_XML

Without this parameter the persistent configuration on the destination
will be the same as the original persistent configuration on the source
when the VIR_MIGRATE_PERSIST_DEST flag is provided.

As Nova does not currently provide the VIR_MIGRATE_PARAM_PERSIST_XML
param but does provide the VIR_MIGRATE_PERSIST_DEST flag this means that
a soft reboot by Nova of the instance after a live migration can revert
the domain back to the original persistent configuration from the
source.

Note that this is only possible in Nova as a soft reboot actually
results in the virDomainShutdown and virDomainLaunch libvirt APIs being
called that recreate the domain using the persistent configuration.
virDomainReboot does not result in this but is not called at this time.

The impact of this on the instance after the soft reboot is pretty
severe, host devices referenced in the original persistent configuration
on the source may not exist or could even be used by other users on the
destination. CPU and NUMA affinity could also differ drastically between
the two hosts resulting in the instance being unable to start etc.

As MIN_LIBVIRT_VERSION is now > v1.3.4 this change simply includes the
VIR_MIGRATE_PARAM_PERSIST_XML param using the same updated XML for the
destination as is already provided to VIR_MIGRATE_PARAM_DEST_XML.

Co-authored-by: Tadayoshi Hosoya <tad-hosoya@wr.jp.nec.com>
Closes-Bug: #1890501
Change-Id: Ia3f1d8e83cbc574ce5cb440032e12bbcb1e10e98
2020-08-25 16:00:10 +01:00
Lee Yarwood bc96af5659 libvirt: Do not reference VIR_ERR_DEVICE_MISSING when libvirt is < v4.1.0
I7eb86edc130d186a66c04b229d46347ec5c0b625 introduced
VIR_ERR_DEVICE_MISSING into the hot unplug libvirt error code list
within detach_device_with_retry. While the change correctly referenced
that the error code was introduced in v4.1.0 it made no attempt to
handle versions prior to this. With MIN_LIBVIRT_VERSION currently pinned
to v4.0.0 we need to handle libvirt < v4.1.0 to avoid referencing the
non-existent error code within the libvirt module.

Closes-Bug: #1891547
Change-Id: I32908b77c18f8ec08211dd67be49bbf903611c34
2020-08-18 20:10:38 +01:00
Takashi Natsume 28ed0c5c9a Remove six.PY2 and six.PY3
Remove six.PY2 and six.PY3.
Subsequent patches will replace other six usages.

Change-Id: Iccce0ab50eee515e533ab36c8e7adc10cb3f7019
Implements: blueprint six-removal
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2020-08-15 07:45:23 +00:00
Lee Yarwood 902f09af25 libvirt: Handle VIR_ERR_DEVICE_MISSING when detaching devices
Introduced in libvirt v4.1.0 [1] this error code replaces the previously
raised VIR_ERR_INVALID_ARG, VIR_ERR_OPERATION_FAILED and
VIR_ERR_INVALID_ARG codes [2][3].

VIR_ERR_OPERATION_FAILED was introduced and tested as an
active/live/hot unplug config device detach error code in
I131aaf28d2f5d5d964d4045e3d7d62207079cfb0.

VIR_ERR_INTERNAL_ERROR was introduced and tested as an
active/live/hot unplug config device detach error code in
I3055cd7641de92ab188de73733ca9288a9ca730a.

VIR_ERR_INVALID_ARG was introduced and tested as an
inactive/persistent/cold unplug config device detach error code in
I09230fc47b0950aa5a3db839a070613c9c817576.

This change introduces support for the new VIR_ERR_DEVICE_MISSING error
code while also retaining coverage for these codes until
MIN_LIBVIRT_VERSION is bumped past v4.1.0.

The majority of this change is test code motion with the existing tests
being modified to run against either the active or inactive versions of
the above  error codes for the time being.

test_detach_device_with_retry_operation_internal and
test_detach_device_with_retry_invalid_argument_no_live have been removed
as they duplicate the logic within the now refactored
_test_detach_device_with_retry_second_detach_failure.

[1] https://libvirt.org/git/?p=libvirt.git;a=commit;h=bb189c8e8c93f115c13fa3bfffdf64498f3f0ce1
[2] https://libvirt.org/git/?p=libvirt.git;a=commit;h=126db34a81bc9f9f9710408f88cceaa1e34bbbd7
[3] https://libvirt.org/git/?p=libvirt.git;a=commit;h=2f54eab7c7c618811de23c60a51e910274cf30de

Closes-Bug: #1887946
Change-Id: I7eb86edc130d186a66c04b229d46347ec5c0b625
2020-07-22 08:33:19 +00:00
Stephen Finucane 969a6d49e5 libvirt: Simplify '_create_domain' function
This is actually two functions, one of which takes an XML string and
another than takes an existing domain. Neither return a domain but
rather a Guest object, and while the first actually creates a new domain
along with the new Guest, the latter simply creates the new Guest and
resumes the existing domain. Simplify the function by ensuring it only
focuses on the former case, creation of new domains as part of the new
Guest object. The revised function is renamed, along with a related
function, '_create_domain_and_network', to reflect what it actually
returns. The other cases are replaced by simple call to
'Guest.resume()', which is all the latter case was really doing.

While we're here, we also update the function signature of the later to
make the 'block_device_info' argument mandatory, since all callers were
passing this anyway. All of this has some test impact but nothing
serious.

We also move some of the tests from 'test_driver' to 'test_guest', since
they were actually testing things from 'virt.libvirt.guest' but clearly
just weren't moved when that module was introduced many cycles ago.

Finally, we rename the '_prepare_domain_for_snapshot' and
'_snapshot_domain' functions to reflect what they're actually doing,
namely suspending and then resuming the domain before and after a
(cold) snapshot, respectively.

Part of blueprint add-emulated-virtual-tpm

Change-Id: I2489bf16dabc8a83b2044139247f4245ae29adb1
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2020-07-16 17:46:55 +01:00
Lee Yarwood b1b0f1be18 libvirt: Always provide the size in bytes when calling virDomainBlockResize
Since 0.9.11 virDomainBlockResize has accepted the size argument in
bytes when the VIR_DOMAIN_BLOCK_RESIZE_BYTES flag is provided.

This change switches all callers over to using bytes to simplify the
required call, avoiding the need to divide by units.Ki etc.

Change-Id: Ib8d9318596186acd86a738ceea187420698645e6
2020-04-01 15:28:32 +01:00
Stephen Finucane 783d4cb246 libvirt: Remove 'enable_hairpin'
This was only used with nova-network.

Change-Id: Ia9dea804717d7afa9cf83f9689a018888987955d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2019-11-29 17:20:02 +00:00
melanie witt 738774b942 Avoid logging traceback when detach device not found
We use the oslo.utils save_and_reraise_exception context manager in our
detach device code and catch specific exceptions that mean 'not found'
and raise DeviceNotFound instead. When we do that, the
save_and_reraise_exception context manager logs an ERROR traceback of
the original exception, for informational purposes. This is misleading
when trying to debug other issues, as it makes it look like the caught
exception caused a problem.

This passes the reraise=False keyword arg to the context manager and
sets the 'reraise' attribute to True only if we are not going to raise
a different exception.

Related-Bug: #1836212

Change-Id: Icce1e31fe3ebcbf9e4897bbfa57b7f3d1fba67a3
2019-07-19 00:04:37 +00:00
Stephen Finucane 231908a7f4 hacking: Resolve W503 (line break occurred before a binary operator)
Change-Id: I6381365ff882cf23808e8dabfce41143c5e35192
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2019-06-24 14:24:06 -05:00
Chris Friesen 2a8ee40fcc Add missing libvirt exception during device detach
It turns out that when detaching a device libvirt can raise a
libvirt.VIR_ERR_INTERNAL_ERROR exception with an error log of
"unable to execute QEMU command 'device_del': Device <foo> not found".

Add this exception to the existing "not found" case which currently
handles only libvirt.VIR_ERR_OPERATION_FAILED.

Change-Id: I3055cd7641de92ab188de73733ca9288a9ca730a
Closes-Bug: #1815949
Signed-off-by: Chris Friesen <chris.friesen@windriver.com>
2019-03-07 00:04:48 +00:00
arches a19c38a6ab Skip checking of target_dev for vhostuser
Nova skips detaching of ovs dpdk interfaces
thinking that it's already detached because
get_interface_by_cfg() return no inteface.
This is due to _set_config_VIFVHostUser()
not setting target_dev in configuration while
LibvirtConfigGuestInterface sets target_dev
if tag "target" is found in the interface.

As target_dev is not a valid value for
vhostuser interface, it will not be checked
for vhostuser type.

Change-Id: Iaf185b98c236df47e44cda0732ee0aed1fd6323d
Closes-Bug: #1807340
2019-01-24 15:26:17 +00:00
melanie witt fded752b16 Use SleepFixture instead of mocking _ThreadingEvent.wait
Recently, the _ThreadingEvent class in oslo.service was removed [1] and
our unit test patching is preventing us from moving to a newer version
of oslo.service [2].

We have patching of the _ThreadingEvent.wait method to bypass the sleep
time in the looping call of RetryDecorator, which adds several seconds
to the run time of unit tests.

This changes things to use the new SleepFixture from oslo.service
instead.

Depends-On: https://review.openstack.org/616371

[1] I62e9f1a7cde8846be368fbec58b8e0825ce02079
[2] https://review.openstack.org/615676

Change-Id: I45dd7602068eb0ce1331cfefd5a0cf6418bc8e88
2018-11-08 16:50:39 -05:00
Doug Hellmann 32082ebcfc remove mocks of oslo.service private members
We need to completely remove the mocks for oslo.service private members
in order to decouple nova from the requirements updates and be able to
update the constraint for oslo.service to a new version that has a
fixture for managing the sleep call being mocked (applied in the
following patch).

Change-Id: I0bbd2d7f9d6eb13d97587d867ef4d651809a7dd4
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-11-08 16:50:17 -05:00
Zuul e2a39bb30f Merge "Revert "libvirt: add method to configure migration speed"" 2018-09-18 22:49:49 +00:00
Zuul 63f9f0c696 Merge "libvirt: guest: introduce blockStats instead of domain.blockStats" 2018-09-03 09:30:37 +00:00
Matt Riedemann 79a74d8185 Revert "libvirt: add method to configure migration speed"
This reverts commit 23446a9552.

With change Ibf2b5eeafd962e93ae4ab6290015d58c33024132 there
is nothing using the migrate_configure_max_speed method any
longer and can be removed. An additional mock, added after
the change being reverted, is also removed.

Change-Id: I90d6e14bf9383bf71d65d2180474ba228db2feab
Related-Bug: #1786346
2018-08-29 15:38:13 -04:00
melanie witt f046d8b540 Handle unicode characters in migration params
There can be unicode characters in the params for live migration, for
example, the guest domain name in the destination XML. We need to
convert those to bytes when we call migrateToURI3 under python2.

The existing code was just calling str() for this, but that will fail
with the error:

  UnicodeEncodeError: 'ascii' codec can't encode characters...

We need to encode the unicode characters to do conversion.

The existing unit test wasn't using any unicode characters in its test
data, so this scenario wasn't covered.

Closes-Bug: #1768807

Change-Id: I4b34139a3c5e3e2b7cf7cbe50bdf3da3131b9b1c
2018-08-10 20:35:24 +00:00
Zuul 4d8d813ae7 Merge "Grease some more tests hitting RetryDecorator" 2018-08-07 11:08:59 +00:00
Zuul 76a946b6da Merge "In Python3.7 async is a keyword [1]" 2018-08-03 00:58:06 +00:00
Eric Fried 63fae18528 Grease some more tests hitting RetryDecorator
That's "grease" in the sense of "lubricate", or "make faster". Not in
the sense of "kill with an M3 submachine gun".

Similar optimizations to [1] in libvirt/test_guest (RetryDecorator in
detach_device_with_retry) and disk/mount/test_api (RetryDecorator in
Mount.map_dev).

[1] I60d11fc9a9e8569b1663c7319a5c25b921c5de1a

Change-Id: Ic7ad60ce89c93c0f03c040e244f8191c963c08f3
2018-08-02 20:55:03 +00:00
Chen Hanxiao f1e937e6a6 libvirt: guest: introduce blockStats instead of domain.blockStats
We should use nova.virt.libvirt.Guest instead of call from
a virDomain object.

Change-Id: Ifa8fe1b19980cc9e986d26b284d2fb093466d30c
Signed-off-by: Chen Hanxiao <chenhx@certusnet.com.cn>
2018-08-02 15:35:37 +00:00
Kashyap Chamarthy 4b3e877210 libvirt: Remove usage of migrateToURI{2} APIs
The recently updated minimum required libvirt version (1.3.1; in commit
403320b -- libvirt: Bump MIN_{LIBVIRT,QEMU}_VERSION for "Rocky") brings
in the newer libvirt migration API, migrateToURI3().  The newer API was
explicitly designed[*] to be backward compatible with the older variant.

So remove the usage of the older variants:

    migrateToURI()
    migrateToURI2()

And just stick to the newer API -- migrateToURI3().

Clean up the following:

 - Add the 'migrate_disks' and 'destination_xml' paramters, and remove
   the no longer needed 'domain_xml' from the Nova migrate() method.

 - Remove or fix various unit tests to use migrateToURI3().

 - Stub nova.virt.libvirt.guest.Guest.migrate() correctly in
   nova/tests/unit/virt/test_virt_drivers.py.

[*] https://libvirt.org/git/?p=libvirt.git;a=commit;h=4bf62f4 --
    Extensible migration APIs

Change-Id: Id9ee1feeadf612fa79c3d280cee3a614a74a00a7
Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
2018-07-31 18:57:28 +02:00
Lee Yarwood 636c7461de libvirt: Remove reference to transient domain when detaching devices
When detaching a device from a domain we first attempt to remove the
device from both the persistent and live configs before looping to
ensure the device has really been detached from the running live config.

Previously when this failed we logged an error message that suggested
that this was due to issues detaching the device from a transient
domain, however this is not the case as the domain is persistent.

This change simply updates the error and associated comments to only
reference the live config of the domain.

Additionally a DEBUG line claiming that a device has been successfully
detached is now only logged once the device is removed from the live
config, hopefully avoiding any confusion from this line been logged
each time an attempt is made to detach the device.

Change-Id: If869470216600c303d47cf79f12c4fc88abcf813
2018-07-23 12:34:27 +01:00
Corey Bryant 2d532963fa In Python3.7 async is a keyword [1]
Change all instances of "async" to "async_"

[1] https://docs.python.org/3/whatsnew/3.7.html

Change-Id: I974b1177ba8313ac502910ca358cf386ef00bc02
Closes-Bug: #1782746
2018-07-20 12:21:34 -04:00
Zuul d70325d8ce Merge "libvirt: add method to configure migration speed" 2017-10-19 03:36:53 +00:00
Sahid Orentino Ferdjaoui 23446a9552 libvirt: add method to configure migration speed
In this commit we are enhancing guest object to control the maximum bw
to perform migration.

Related-Bug: #1414559
Change-Id: I35470773b8c467449ed71217fdb4b6c82f455e33
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@redhat.com>
2017-10-02 06:09:47 -04:00
Matthew Booth 8fa97d91c0 Make etree.tostring() emit unicode everywhere
etree.tostring() returns bytes by default in python3, and a string by
default in python2. For sanity, we make it explicitly emit unicode
everywhere. This requires a python2 fix in guest, as the libvirt
bindings for python2 don't accept a unicode string to migrateToURI3()'s
'param' argument, whereas the python3 bindings do.

Change-Id: I85cd9a903fba310b5ae7bedeed118ca4ea98dff6
2017-09-28 10:08:05 +01:00
Sahid Orentino Ferdjaoui c212ad27b0 libvirt: bandwidth param should be set in guest migrate
The bandwidth param set outside of the method "migrate" from guest
object have to be done inside that to avoid duplicating that option.

Change-Id: I8a37753dea8eca7b26466f17dfbdc184c48c24c5
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@redhat.com>
2017-09-21 09:48:45 -04:00
Michael Still 0952f80d01 Move execs of tee to privsep.
Instead of calling tee to write to files as root, we should just
write to files as root.

Change-Id: Ic48087fdf283b3ba503294a944be91be0c338132
2017-09-12 05:38:26 +10:00
Jenkins 7615b52dac Merge "Trim the fat from InstanceInfo" 2017-09-06 15:34:04 +00:00
melanie witt d39934ad6a Detach device from live domain even if not found on persistent
In a past attempt to fix a bug [1], we started raising DeviceNotFound
if a device wasn't found on the persistent domain. This was to address
a scenario where the guest ignored the detach from the live domain
because it was busy and we wanted to avoid failing a later detach
request to the user (compute handles DeviceNotFound).

Unfortunately, in the above case, a later detach request won't fail to
the user but it also won't detach from the live domain. It sees the
device already detached from the persistent domain and doesn't attempt
to detach from the live domain.

This is a serious problem because it's possible for a volume to be
attached to two live domains and data corruption can occur.

This adds an attempt to detach from the live domain even if we had
already detached from the persistent domain in the past.

Closes-Bug: #1707238

[1] https://review.openstack.org/386257

Change-Id: I8cd056fa17184a98c31547add0e9fb2d363d0908
2017-08-01 20:17:46 +00:00