summaryrefslogtreecommitdiff
path: root/tests/unittests/test_vmware
diff options
context:
space:
mode:
authorxiaofengw-vmware <42736879+xiaofengw-vmware@users.noreply.github.com>2020-03-27 00:31:04 +0800
committerGitHub <noreply@github.com>2020-03-26 12:31:04 -0400
commit1fefeef92fd1881b21e124b83f2adefd3e014087 (patch)
treedbfc6177930df50a9bc800c3f286d48b052a83ae /tests/unittests/test_vmware
parentbacd63a782daf44937f23a1a33555cb579ae4fb5 (diff)
downloadvyos-cloud-init-1fefeef92fd1881b21e124b83f2adefd3e014087.tar.gz
vyos-cloud-init-1fefeef92fd1881b21e124b83f2adefd3e014087.zip
VMWware: support to update guest info gc status if enabled (#261)
Diffstat (limited to 'tests/unittests/test_vmware')
-rw-r--r--tests/unittests/test_vmware/test_guestcust_util.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/unittests/test_vmware/test_guestcust_util.py b/tests/unittests/test_vmware/test_guestcust_util.py
index b175a998..394bee9f 100644
--- a/tests/unittests/test_vmware/test_guestcust_util.py
+++ b/tests/unittests/test_vmware/test_guestcust_util.py
@@ -6,8 +6,11 @@
# This file is part of cloud-init. See LICENSE file for license information.
from cloudinit import util
+from cloudinit.sources.helpers.vmware.imc.config import Config
+from cloudinit.sources.helpers.vmware.imc.config_file import ConfigFile
from cloudinit.sources.helpers.vmware.imc.guestcust_util import (
get_tools_config,
+ set_gc_status,
)
from cloudinit.tests.helpers import CiTestCase, mock
@@ -69,4 +72,27 @@ class TestGuestCustUtil(CiTestCase):
get_tools_config('section', 'key', 'defaultVal'),
'e-f')
+ def test_set_gc_status(self):
+ """
+ This test is designed to verify the behavior of set_gc_status
+ """
+ # config is None, return None
+ self.assertEqual(set_gc_status(None, 'Successful'), None)
+
+ # post gc status is NO, return None
+ cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
+ conf = Config(cf)
+ self.assertEqual(set_gc_status(conf, 'Successful'), None)
+
+ # post gc status is YES, subp is called to execute command
+ cf._insertKey("MISC|POST-GC-STATUS", "YES")
+ conf = Config(cf)
+ with mock.patch.object(util, 'subp',
+ return_value=('ok', b'')) as mockobj:
+ self.assertEqual(
+ set_gc_status(conf, 'Successful'), ('ok', b''))
+ mockobj.assert_called_once_with(
+ ['vmware-rpctool', 'info-set guestinfo.gc.status Successful'],
+ rcs=[0])
+
# vi: ts=4 expandtab