distcloud/distributedcloud/dccommon/tests/unit/test_utils.py
Victor Romano d4d548d7c6 Reformat dcmanager-audit to support dcagent
Before introducing the new dcagent several changes needed to be made
to dcmanager-audit. That is:

Refactor each individual audit (base audit, firmware, kubernetes,
kube rootca and software) to separate all subcloud client calls in
one single function (get_subcloud_audit_data, to be used by dcagent
periodic info gather loop) and another function to get the subcloud
sync status (get_subcloud_sync_status, to be used by dcagent to
process the data in the subcloud and return the sync status to
the system controller).

NOTES:
  - As patch and load audits will be deprecated in the next major
    release, no effort was made to refactor both patch and load audit.
  - All tests described below were executed applying [1] and [2] as
    well, to avoid retesting.

[1]: https://review.opendev.org/c/starlingx/distcloud/+/923350
[2]: https://review.opendev.org/c/starlingx/distcloud/+/923351

Test plan:
  - PASS: Run dcmanager audit with dcagent. Verify only one call is
          made to audit the subcloud and the response include the
          correct sync status.
  - PASS: Run dcmanager audit without dcagent. Verify the audit
          works as expected querying each individual endpoint.

Story: 2011106
Task: 50558

Change-Id: Ib955ff0c4f2035af2f59b6873f5779b71a8710ce
Signed-off-by: Victor Romano <victor.gluzromano@windriver.com>
2024-07-18 11:25:32 -03:00

52 lines
1.5 KiB
Python

#
# Copyright (c) 2022-2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from dccommon.exceptions import PlaybookExecutionTimeout
from dccommon.tests import base
from dccommon import utils
FAKE_SUBCLOUD_NAME = "subcloud1"
FAKE_LOG_FILE = "/dev/null"
class TestUtils(base.DCCommonTestCase):
def setUp(self):
super(TestUtils, self).setUp()
def tearDown(self):
super(TestUtils, self).tearDown()
def test_exec_playbook(self):
# no timeout:
testscript = ["dccommon/tests/unit/test_utils_script.sh", "1"]
ansible = utils.AnsiblePlaybook(FAKE_SUBCLOUD_NAME)
ansible.run_playbook(FAKE_LOG_FILE, testscript)
def test_exec_playbook_timeout(self):
testscript = ["dccommon/tests/unit/test_utils_script.sh", "30"]
ansible = utils.AnsiblePlaybook(FAKE_SUBCLOUD_NAME)
self.assertRaises(
PlaybookExecutionTimeout,
ansible.run_playbook,
FAKE_LOG_FILE,
testscript,
timeout=2,
)
def test_exec_playbook_timeout_requires_kill(self):
# This option ignores a regular TERM signal, and requires a
# kill -9 (KILL signal) to terminate. We're using this to simulate
# a hung process
script = ["dccommon/tests/unit/test_utils_script.sh", "30", "TERM"]
ansible = utils.AnsiblePlaybook(FAKE_SUBCLOUD_NAME)
self.assertRaises(
PlaybookExecutionTimeout,
ansible.run_playbook,
FAKE_LOG_FILE,
script,
timeout=2,
)