Commit Graph

440 Commits

Author SHA1 Message Date
Ghanshyam Mann 83dc573004 Retire os-win: remove repo content
Winstackers project has been retired
- https://review.opendev.org/c/openstack/governance/+/886880

this commit remove the content of os-win
deliverables of this project

Depends-On: https://review.opendev.org/c/openstack/project-config/+/894407/1
Change-Id: Ia157731a558dc66e7fc944d8e42938b2eff8afa7
2023-09-09 12:25:13 -07:00
Thomas Goirand 318b1052d3 Python 3.11: use getfullargspec, not getargspec
In Python 3.11, inspect.getargspec. We shall use getfullargspec from now
on instead. This patch was added to Debian. See Debian bug:

https://bugs.debian.org/1025112

Change-Id: Ib7982470958377d9454446dab326aaa9e782ad69
2022-12-01 10:25:43 +01:00
Stefan Chivu 248d4f1e57 Added function for enabling AllowFullSCSICommandSet
By default, Hyper-V filters some of the SCSI commands received from
the VMs. This change allows disabling the filter.

Signed-off-by: Stefan Chivu <schivu@cloudbasesolutions.com>
Change-Id: I1b0fc8e7e75a6c5395aedd5b8e94b3bd000e1843
2022-11-22 16:10:47 +02:00
Takashi Natsume 3be4e4a684 Use daemon property instead of setDaemon method
The setDaemon method of the threading.Thread was deprecated
in Python 3.10 (*).
Replace the setDaemon method with the daemon property.

*: https://docs.python.org/3.10/library/threading.html#threading.Thread.setDaemon

Change-Id: I34c7753ae1ba3704a1c2ec1a9b5a9905b6bcb8f5
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2022-09-25 16:23:42 +09:00
Takashi Natsume a4effc7e54 Fix wrong assertion methods
Replcae 'has_calls' with 'assert_has_calls' or
remove 'has_calls'.

Change-Id: I65f9a761af75d94052362056fe1c9ba152f6449e
Closes-Bug: 1989280
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2022-09-12 20:38:19 +09:00
Felipe Reyes c672101e60 Drop collections.Iterable in favor of collections.abc.Iterable
Python3 has deprecated (and recently dropped) collections.Iterable in
favor of using the collections.abc module. This change fixes the import.

Closes-Bug: #1966442
Change-Id: I76ed972890a2fe0bedebd0364276590d5aa90f29
2022-03-25 10:06:40 -03:00
Takashi Kajinami d571260d41 Use importlib instead of imp
... because the imp module is deprecated since Python 3.4 .

Closes-Bug: #1937904
Change-Id: Ib8f06ee629753faec73cf3a2f41e7c743b6e0b04
2021-07-24 22:42:25 +09:00
Lucian Petrut cce95b44a9 Allow setting VHD GUIDs
Hyper-V exposes the VHD GUIDs to guests, which can be used to
easily identify attached disks.

This change will allow setting the VHD GUID for new as well as
existing images.

Worth mentioning that the Kubernetes Openstack provider will
benefit from this. Without it, k8s Persistent Volumes can't be
identified by some guests.

http://paste.openstack.org/raw/801011/

Change-Id: Ied73997e6f5f3ded9827703867f059ef3dfca159
2020-12-15 11:38:05 +02:00
Lucian Petrut fa9061f31d Avoid propagating wmi exceptions for soft shutdown
The soft shutdown operation is expected to fail while the VM is
still booting. The issue is that in some cases, os-win will
propagate a wmi exception that Nova cannot handle:

http://paste.openstack.org/raw/800833/

That's because of Msvm_ShutdownComponent.InitiateShutdown, an
asynchronous WMI method that can sometimes throw a wmi exception
right away.

For now, we're taking care of this specific WMI call only. If needed,
we may consider handling all async WMI methods by introducing a new
decorator or helper function.

Change-Id: I9263b14c3c343db6453645152cb9274e38864b48
Closes-Bug: #1907270
2020-12-09 15:20:21 +02:00
Claudiu Belu 78414e7160 vmutils: Adds the ability to modify the VM's chassis asset tag
The Msvm_VirtualSystemSettingData object associated with a VM has a
field named "ChassisAssetTag". The value set in this field is reflected
in Linux VMs in /sys/class/dmi/id/chassis-asset-tag. This value is
checked by cloud-init in order to figure out if it is currently running
inside an OpenStack VM.

The verification above has been introduced in cloud-init [1] in order to
avoid costly metadata probes that aren't needed in non-OpenStack VMs.

Setting the ChassisAssetTag will allow us to pass these checks.

Partially-Fixes: #1895976

[1] 1efa8a0a03

Change-Id: I50dd761b3df9f2d243ca295f02d20422f6af965e
2020-09-21 14:58:42 +03:00
Dirk Mueller 066c1c49b5 Switch from unittest2 compat methods to Python 3.x methods
With the removal of Python 2.x we can remove the unittest2 compat
wrappers and switch to assertCountEqual instead of assertItemsEqual

We have been able to use them since then, because
testtools required unittest2, which still included it. With testtools
removing Python 2.7 support [3][4], we will lose support for
assertItemsEqual, so we should switch to use assertCountEqual.

[1] - https://bugs.python.org/issue17866
[2] - https://hg.python.org/cpython/rev/d9921cb6e3cd
[3] - testing-cabal/testtools#286
[4] - testing-cabal/testtools#277^

Change-Id: I4fd20ef857846117b50e8d17fdf98fa4aa117262
2020-06-23 14:21:25 +02:00
Lucian Petrut 94046df43a Fix case sensitive path comparisons
While Windows paths are case insensitive, a few os-win checks are
case sensitive and are addressed by this patch.

Change-Id: I60c0d3e12501d7b2f62df8f95a3d3f328de83817
Closes-Bug: #1878588
2020-05-14 13:23:25 +03:00
Sean McGinnis 8be89e1076
Remove monotonic usage
The monotonic package was needed for monotonic time operations when
running under Python runtimes older than 3.3. Since we now only support
versions higher than this, this third party package requirement can now
be removed.

Change-Id: I809de2f6fe257c80de7c81f9e08499a919f52ff8
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-05-04 17:23:36 -05:00
Sean McGinnis c995a87873
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.

Change-Id: I24c8926bc7a571b45af77c497f0791d101ebbc12
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-18 11:56:56 -05:00
Zuul e486ee0faf Merge "Cleanup py27 support" 2020-04-13 10:37:57 +00:00
Andreas Jaeger bb4934a240 Cleanup py27 support
This repo is now testing only with Python 3, so let's make
a few cleanups:
- Remove python 2.7 stanza from setup.py
- Add requires on python >= 3.6 to setup.cfg so that pypi and pip
  know about the requirement
- Remove obsolete sections from setup.cfg
- Update classifiers
- Switch to using sphinx-build
- Cleanup doc/source/conf.py to remove now obsolete content.
- Use newer openstackdocstheme version
- Remove install_command from tox.ini, the default is fine
- Remove old python compatiblity test code

Change-Id: If7296703fc4848a16dd10d904ba3f49f19054546
2020-04-13 10:12:53 +00:00
Andreas Jaeger d3ad80a436 Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found.

Update local hacking checks for new flake8.

Change-Id: I7c6896dd25d76dc02145f4d09a4d09de35a4afb1
2020-04-13 13:04:48 +03:00
Zuul 4ec8809541 Merge "Fix Windows support for the unit tests" 2020-02-18 10:05:38 +00:00
Zuul acaa2323c7 Merge "Add configurable timeout for in-use files" 2020-02-18 09:59:03 +00:00
Lucian Petrut 229cf8bb46 Fix Windows support for the unit tests
We've been running the unit tests mostly on Linux as part of the
CI test jobs.

On Windows, some of the tests fail mostly due to the WMI lib not
being mocked correctly. This issue is addressed by this change.

Change-Id: Ib4de3d262a7cf98a552f6234f6561d6c87b2067d
2020-02-18 11:18:41 +02:00
Lucian Petrut a30eeb8ed9 Trivial: Fix test_get_cluster_group_type on x86 or Win32
One unit test is using the wrong type, unsigned long long instead of
long, for which reason it will fail on Linux x86 or Windows, where
the size of those types do not match.

Change-Id: If49e57ada8d367f537710974ea59728d20720275
Closes-Bug: 1850770
2020-02-17 17:14:05 +02:00
Lucian Petrut 4f7118d81a Add configurable timeout for in-use files
In some cases, Hyper-V locks on VHD images persist for a few seconds
even after the instances are deleted (not sure if that's due to
Hyper-V or the filesystem). In order to mitigate this, we're
already performing some retries when deleting instance files.

We've encountered similar issues with 3rd party backup tools
that kept open file handles.

This change adds a configurable timeout that will be used when waiting
for in-use fles. The default value is 15 seconds, slightly more than
the current hardcoded value. At the same time, this timeout will
also be used when deleting individual files or renaming folders or
files.

Change-Id: I49307146b79a20089190e1ce8bde73d656d37c6d
2020-02-11 15:51:47 +02:00
Lucian Petrut b6ce9b33dd Wait for cluster node to be available
After a reboot, the Failover Cluster WMI provider may be unavailable.
This change will wait for it when initializing clusterutils, having
a configurable timeout defaulting to infinite.

Closes-Bug: #1841779

Change-Id: Id7f2d65cb0307bc952f1e6a2724295ea524835f3
2019-08-28 16:14:00 +03:00
Lucian Petrut dc9f6b9aeb Fix VHD detach
Attempting to disconnect a VHD from the local host may fail if the
image is in-use by a different host, even though it's not actually
mounted on the local host.

The reason is that the detach API requires a handle, which we may
fail to obtain if the file is in-use.

This change will try to figure out if the image is actually attached
to the local host before erroring out. This check is a bit more
complicated than it should, again due to file locks. We'll use
two approaches:
* the preffered way, using virtdisk.dll:GetVirtualDiskInformation,
  which may fail due to file locks
* the slower way, used as a fallback, which involves getting a full
  list of attached images and comparing file and volume ids as
  the file may be accessible through multiple paths

Closes-Bug: #1840954
Change-Id: Ib5bf0070c0ba4cb18e98c1cb983c641eaae582bf
2019-08-21 20:31:54 +03:00
jacky06 ec959ea8bc Update hacking version
Use latest release 1.1.0 and compatible changes w.r.t pep8

It's worth noting that the pep8 package has been renamed to
pycodestyle. New hacking packages no longer install the old pep8
package automatically.

Change-Id: Ibbad8b42188ade597d9a3032389e930c2f5fe2d0
2019-03-15 13:12:00 +02:00
Zuul 7ed1f4db45 Merge "Add mutex class" 2019-02-01 13:19:36 +00:00
Lucian Petrut 5c3f7cd15e Add mutex class
This will expose Windows mutexes. We usually rely on file locks
when synchronizing multiple processes, mostly for portability
reasons.

Some times, file locks may not be an option, in which case a
named mutex can be useful. We intend to use this in Glance when
ensuring that only one scrubber can run at a time.

Change-Id: I4a2a51e2164c6f5816f2af2641d41d1db7870600
2019-02-01 14:15:27 +02:00
Zuul 7fa5db4de9 Merge "Cleanup utilsfactory map" 2019-01-16 14:01:23 +00:00
Zuul 2223f3c7fa Merge "Add pipe helpers" 2019-01-16 14:01:22 +00:00
Lucian Petrut 0857a0eb81 Cleanup utilsfactory map
This change cleans up the utilsfactory map, making it easier to add
new classes.

Most classes have 6.2 as a minimum version, without having a maximum
version cap. For this reason, this change sets those versions as
defaults so that we don't have to be explicit every time.

At the same time, we're now using a list for each class type, instead
of a dict that uses the class name as a key (which is redundant). So,
something like this:

'networkutils': {
    'NetworkUtils': {
        'min_version': 6.2,
        'max_version': 6.3,
        'path': 'os_win.utils.network.networkutils.NetworkUtils'},
    'NetworkUtilsR2': {
        'min_version': 6.3,
        'max_version': None,
        'path': 'os_win.utils.network.networkutils.NetworkUtilsR2'}},

... becomes

'networkutils': [
    {'max_version': 6.3,
     'path': 'os_win.utils.network.networkutils.NetworkUtils'},
    {'min_version': 6.3,
     'path': 'os_win.utils.network.networkutils.NetworkUtilsR2'},
],

Change-Id: I7919617166b2e872f1b50c0a0f40196fc90e9a82
2019-01-16 14:41:43 +02:00
Lucian Petrut d139d77167 Add pipe helpers
This change adds a few helpers that will allow creating and consuming
pipes. While similar functions are already provided by the built-in
os module, the handle inherit flags do not work on Windows.

We intend to use those helpers in Glance when dealing with
subprocesses.

Change-Id: I6ed456b5f95b5691da555e36846de4286ad96f15
2019-01-16 14:41:00 +02:00
Zuul 1ceb2bcaf5 Merge "Silently continue when disconnecting missing vhds" 2019-01-16 09:42:44 +00:00
Lucian Petrut 593152d8d8 Silently continue when disconnecting missing vhds
os-win should silently pass when requested to disconnect a vhd that's missing.
At the moment, it's erroring out, which prevents some Nova instances from being
cleaned up.

This change checks if the image to be disconnected actually exists before
attempting to open it.

Change-Id: Ic734d38e1939165a89a79842d37e98b4cbbcb3bf
Closes-Bug: #1810927
2019-01-08 13:29:31 +02:00
Zuul 3bbe2e4a50 Merge "Logging multiple WMI job errors" 2018-11-22 13:55:55 +00:00
Daniel Vincze e1c83c86bc Logging multiple WMI job errors
WMI jobs may return multiple errors, but only one of them
would be logged.

This change ensures that we're fetching all of them, calling the
Msvm_ConcreteJob.GetErrorEx method.

Change-Id: I7311e63e4f95c4e1d17357d28fdd1c7425362270
Closes-Bug: 1748208
2018-11-22 12:41:13 +00:00
Lucian Petrut 030df4e310 Disable wmi object caching by default
Due to the known issues related to WMI object caching, it's safer
if we just disable it by default.

Change-Id: If859917af9a185fc612231002d252c9e0ac6ddd3
Related-Bug: #1801701
2018-11-09 09:25:28 +00:00
Lucian Petrut 21a2fe8758 Trivial: Fix flaky unit test
One cluster listener daemon isn't properly mocked, for which reason
it's running in a separate thread and calling mocked methods,
affecting other test cases and their assertions.

http://paste.openstack.org/raw/734339/

This change mocks it properly, ensuring that other test cases will
not be affected by it.

Change-Id: I2e9d2b98457bac280bf7a19afc12dc822a83eb0f
2018-11-07 10:14:20 +02:00
Zuul 728ddeb4f4 Merge "Limit Failover Cluster WMI provider usage" 2018-10-26 10:56:48 +00:00
Lucian Petrut 6c6955f9f2 Limit Failover Cluster WMI provider usage
The Failover Cluster WMI provider is quite unreliable, especially
in recent Windows Server 2016 versions.

After failovers, some valid WMI queries fail with "Invalid Property"
errors, which really looks like a WMI provider bug. Event listeners
are affected as well, for which reason we're missing VM failover events.

This change refactors "clusterutils", switching to the underlying
C library.

The new failover event listener cannot provide the source of the
migrated instances, so we're keeping the old one as well for backwards
compatibility, for now.

The only other places in which we're still using WMI are the methods
that add or destroy VM cluster roles.

The reason is that we'd have to explicitly create the the cluster
resources and group, probably set some resource dependencies and
properties. For now, it's easier/safer to just stick with the WMI
method (which really shouldn't fail).

Also, destroying VM cluster groups using clusapi's DestroyClusterGroup
function behaves strange. VMs get recreated asyncronuously and put in
suspended state, breaking everything. We're avoiding it for now.

Closes-Bug: #1798069

Change-Id: I63d1aa3a6f9fb12d08478eb41fe973b1582b540c
2018-10-25 11:49:55 +03:00
Zuul 5d7c91e627 Merge "Ignore events for unnamed VM vNICs" 2018-10-03 10:32:05 +00:00
Zuul 68d763f4c3 Merge "Allow enabling metrics per virtual disk" 2018-10-01 09:41:13 +00:00
Zuul d0acdadf4b Merge "Add method for retrieving VM nics" 2018-10-01 09:41:08 +00:00
Zuul 617cab6735 Merge "Fix port metrics" 2018-10-01 09:41:08 +00:00
Lucian Petrut 42cfab1081 Ignore events for unnamed VM vNICs
VM vNIC names are mandatory. Still, we'll getting events for unnamed ports,
breaking os-win consumers.

We'll ignore those events, logging a warning.

Change-Id: I58a408b33a590b9c1ca3d8f32fa3c4d027f43381
Closes-Bug: #1761748
2018-09-28 16:08:27 +03:00
maaktweluit 91eb56c8ac Add getter for MemorySettingsData
This will allow fetching various VM memory information, such as
dynamic memory limits and reserved amount.

Change-Id: Ifa9649e490a851090cdf3f8a0390e4ab7d5a6373
2018-09-28 13:41:02 +03:00
Lucian Petrut a0b64b6544 Allow enabling metrics per virtual disk
This change will allow enabling metrics for individual virtual disks.
The Nova Hyper-V driver will use it when attaching Cinder volumes.

Note that Hyper-V does not support collecting metrics for passthrough
disks at the moment.

Change-Id: Iaba32ca94b2c09661f150fa4b12b2c7eb83ff6d9
Partial-Bug: #1794456
2018-09-27 19:40:48 +03:00
Lucian Petrut c73b074042 Add method for retrieving VM nics
We need a way to retrieve VM nic names. This will allow the Nova
Hyper-V driver to enable port metrics when receiving instance power
on events.

It's safer to query Hyper-V directly rather than relying on Nova's port
cache.

Change-Id: Ibe7409b392b91204f0cea2bdd32c86ec03d06b67
Partial-Bug: #1794456
2018-09-27 18:59:59 +03:00
Lucian Petrut 865c1cfaa0 Fix port metrics
At the moment, port metrics are not enabled. The reason is that we're
using the wrong switch port WMI class.

This issue went more or less unnoticed, especially due to the fact that
we're currently ignoring the according WMI method return code.

This change ensures that port metrics are properly enabled and that an
exception will be raised when failing to do so.

Closes-Bug: #1794291

Change-Id: I8086e7dd9e134749760b05469f5b2c8bcfdcdbde
2018-09-26 16:05:20 +03:00
Lucian Petrut 1f8200ef79 Fix incorrect numeric comparisons
In a few places, we're using "is" or "is not", when comparing
numeric variables.

This is incorrect and will give unexpected results when the types
do not match (for example, if one of the variables is a long int):
http://paste.openstack.org/raw/730618/

This change fixes those comparisons.

Closes-Bug: #1794068

Change-Id: Ibf28778879050cfdfa82ef4f9b587170dde6203f
2018-09-24 14:09:16 +03:00
Lucian Petrut 11e28563d4 Add wmi job terminate timeout cfg opt
We're using a hardcoded 15 seconds timeout when canceling WMI jobs.

Some jobs may not be cancelable, some may take longer to stop. For
example, Nova instances may end up in error state after attempting
to delete them as this hardcoded timeout gets exceeded.

That being considered, we're now adding a config option for this,
also increasing the default timeout to 2 minutes.

Ideally, Nova should pass a timeout here. Still, by adding a config
option at the os-win level, it's easier to backport this to older
releases, also providing a default for any kind of WMI job.

Change-Id: I797366c40a3a4bb74fe925bd10697f227e22915c
Closes-Bug: #1790890
2018-09-06 09:56:14 +03:00