Skip to content

Commit

Permalink
openSUSE-3000 virt-defined-states (#222)
Browse files Browse the repository at this point in the history
* Create virt.pool_defined state out of virt.pool_running

Users may want to use states to ensure a virtual storage pool is defined
and not enforce it to be running. Extract the code that performs the
pool definition / update from virt.pool_running state into a
virt.pool_defined.

Obviously the virt.pool_running state calls the virt.pool_defined one.
In such a case no additionnal test is needed for virt.pool_defined since
this is already tested with virt.pool_running.

* Add virt.update test parameter

In order to allow running dry-runs of virt.update module add a test
parameter. This will later be used by the virt states.

* Extract virt.defined state from virt.running

In order to ensure a virtual guest is defined independently of its
status, extract the corresponding code from the virt.running state.

This commit also handles the __opts__['test'] for the running state.
Since the update call only performs changes if needed, deprecate the
update parameter.

* Extract virt.network_defined from virt.network_running

Just like domains and storage pools, users may want to ensure a network
is defined without influencing it's status. Extract the code from
network_running state defining the network into a network_defined state.

While at it, support __opt__['test'] == True in these states. Updating
the network definition in the pool_defined state will come in a future
PR.

* Fix virt.update to handle None mem and cpu

virt.running state now may call virt.update with None mem and cpu
parameters. This was not handled in _gen_xml(). Also add some more tests
cases matching this for virt.update.
  • Loading branch information
cbosdo authored and meaksh committed Mar 24, 2020
1 parent cfd60f4 commit 900fdc4
Show file tree
Hide file tree
Showing 4 changed files with 1,665 additions and 396 deletions.
16 changes: 11 additions & 5 deletions salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,7 @@ def update(name,
graphics=None,
live=True,
boot=None,
test=False,
**kwargs):
'''
Update the definition of an existing domain.
Expand Down Expand Up @@ -1835,6 +1836,10 @@ def update(name,
.. versionadded:: 3000
:param test: run in dry-run mode if set to True
.. versionadded:: sodium
:return:
Returns a dictionary indicating the status of what has been done. It is structured in
Expand Down Expand Up @@ -1880,8 +1885,8 @@ def update(name,
boot = _handle_remote_boot_params(boot)

new_desc = ElementTree.fromstring(_gen_xml(name,
cpu,
mem,
cpu or 0,
mem or 0,
all_disks,
_get_merged_nics(hypervisor, nic_profile, interfaces),
hypervisor,
Expand Down Expand Up @@ -1973,11 +1978,12 @@ def update(name,
if changes['disk']:
for idx, item in enumerate(changes['disk']['sorted']):
source_file = all_disks[idx]['source_file']
if item in changes['disk']['new'] and source_file and not os.path.isfile(source_file):
if item in changes['disk']['new'] and source_file and not os.path.isfile(source_file) and not test:
_qemu_image_create(all_disks[idx])

try:
conn.defineXML(salt.utils.stringutils.to_str(ElementTree.tostring(desc)))
if not test:
conn.defineXML(salt.utils.stringutils.to_str(ElementTree.tostring(desc)))
status['definition'] = True
except libvirt.libvirtError as err:
conn.close()
Expand Down Expand Up @@ -2010,7 +2016,7 @@ def update(name,

for cmd in commands:
try:
ret = getattr(domain, cmd['cmd'])(*cmd['args'])
ret = getattr(domain, cmd['cmd'])(*cmd['args']) if not test else 0
device_type = cmd['device']
if device_type in ['cpu', 'mem']:
status[device_type] = not bool(ret)
Expand Down
Loading

0 comments on commit 900fdc4

Please sign in to comment.