Debian Codegraph @

test/units/module_utils/facts/virtual/test_hpux.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright: Contributors to the Ansible project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 from __future__ import annotations
6
7 import pytest
8
9 from ansible.module_utils.facts.virtual.hpux import HPUXVirtual
10
11
12 class MockVirtualSysctl(HPUXVirtual):
13 def __init__(self, module):
14 self.module = module
15
16
17 def mock_path_exists_vecheck(filename):
18 return filename in ("/usr/sbin/vecheck",)
19
20
21 def mock_path_exists_hpvminfo(filename):
22 return filename in ("/opt/hpvm/bin/hpvminfo",)
23
24
25 def mock_path_exists_parstatus(filename):
26 return filename in ("/usr/sbin/parstatus",)
27
28
29 @pytest.mark.parametrize(
30 ("mock_method", "expected_type", "mock_output", "expected_guest"),
31 [
32 pytest.param(
33 mock_path_exists_vecheck,
34 "guest",
35 "",
36 "HP vPar",
37 id="HP vPar",
38 ),
39 pytest.param(
40 mock_path_exists_hpvminfo,
41 "guest",
42 "Running HPVM vPar",
43 "HPVM vPar",
44 id="HPVM vPar",
45 ),
46 pytest.param(
47 mock_path_exists_hpvminfo,
48 "guest",
49 "Running HPVM guest",
50 "HPVM IVM",
51 id="HPVM IVM",
52 ),
53 pytest.param(
54 mock_path_exists_hpvminfo,
55 "host",
56 "Running HPVM host",
57 "HPVM",
58 id="HPVM",
59 ),
60 pytest.param(
61 mock_path_exists_parstatus,
62 "guest",
63 "",
64 "HP nPar",
65 id="HP nPar",
66 ),
67 ],
68 )
69 def test_get_virtual_facts_hpvpar(mocker, mock_method, expected_type, mock_output, expected_guest):
70 mocker.patch("os.path.exists", side_effect=mock_method)
71 module = mocker.Mock()
72 module.run_command.return_value = (0, mock_output, "")
73 mixin = MockVirtualSysctl(module=module)
74 guest_facts = mixin.get_virtual_facts()
75 expected = {
76 "virtualization_role": expected_guest,
77 "virtualization_tech_guest": set([expected_guest]),
78 "virtualization_tech_host": set(),
79 "virtualization_type": expected_type,
80 }
81
82 assert guest_facts == expected