Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix virt update when cpu and memory are changed #58465

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
# Special Thanks to Michael Dehann, many of the concepts, and a few structures
# of his in the virt func module have been used

# Import python libs

import base64
import copy
Expand All @@ -91,10 +90,7 @@
from xml.etree import ElementTree
from xml.sax import saxutils

# Import third party libs
import jinja2.exceptions

# Import salt libs
import salt.utils.data
import salt.utils.files
import salt.utils.json
Expand Down Expand Up @@ -2616,8 +2612,8 @@ def _set_with_mib_unit(node, value):
data = {k: v for k, v in locals().items() if bool(v)}
if boot_dev:
data["boot_dev"] = {i + 1: dev for i, dev in enumerate(boot_dev.split())}
need_update = need_update or salt.utils.xmlutil.change_xml(
desc, data, params_mapping
need_update = (
salt.utils.xmlutil.change_xml(desc, data, params_mapping) or need_update
)

# Update the XML definition with the new disks and diff changes
Expand Down
23 changes: 18 additions & 5 deletions tests/unit/modules/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# pylint: disable=3rd-party-module-not-gated

# Import python libs

import datetime
import os
Expand All @@ -15,16 +14,12 @@
import salt.modules.config as config
import salt.modules.virt as virt
import salt.syspaths

# Import salt libs
import salt.utils.yaml
from salt._compat import ElementTree as ET
from salt.exceptions import CommandExecutionError, SaltInvocationError

# pylint: disable=import-error
from salt.ext.six.moves import range # pylint: disable=redefined-builtin

# Import Salt Testing libs
from tests.support.helpers import dedent
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch
Expand Down Expand Up @@ -1858,6 +1853,24 @@ def test_update(self):
virt.update("my_vm"),
)

# mem + cpu case
define_mock.reset_mock()
domain_mock.setMemoryFlags.return_value = 0
domain_mock.setVcpusFlags.return_value = 0
self.assertEqual(
{
"definition": True,
"disk": {"attached": [], "detached": [], "updated": []},
"interface": {"attached": [], "detached": []},
"mem": True,
"cpu": True,
},
virt.update("my_vm", mem=2048, cpu=2),
)
setxml = ET.fromstring(define_mock.call_args[0][0])
self.assertEqual("2", setxml.find("vcpu").text)
self.assertEqual("2048", setxml.find("memory").text)

# Same parameters passed than in default virt.defined state case
self.assertEqual(
{
Expand Down