| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# |
| 3 |
# |
| 4 |
# Ansible is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# Ansible is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
|
| 18 |
from __future__ import annotations |
| 19 |
|
| 20 |
# for testing |
| 21 |
import unittest |
| 22 |
from unittest.mock import Mock, patch |
| 23 |
|
| 24 |
from ansible.module_utils.facts import collector |
| 25 |
from ansible.module_utils.facts import ansible_collector |
| 26 |
from ansible.module_utils.facts import namespace |
| 27 |
|
| 28 |
from ansible.module_utils.facts.other.facter import FacterFactCollector |
| 29 |
from ansible.module_utils.facts.other.ohai import OhaiFactCollector |
| 30 |
|
| 31 |
from ansible.module_utils.facts.system.apparmor import ApparmorFactCollector |
| 32 |
from ansible.module_utils.facts.system.caps import SystemCapabilitiesFactCollector |
| 33 |
from ansible.module_utils.facts.system.date_time import DateTimeFactCollector |
| 34 |
from ansible.module_utils.facts.system.env import EnvFactCollector |
| 35 |
from ansible.module_utils.facts.system.distribution import DistributionFactCollector |
| 36 |
from ansible.module_utils.facts.system.dns import DnsFactCollector |
| 37 |
from ansible.module_utils.facts.system.fips import FipsFactCollector |
| 38 |
from ansible.module_utils.facts.system.local import LocalFactCollector |
| 39 |
from ansible.module_utils.facts.system.lsb import LSBFactCollector |
| 40 |
from ansible.module_utils.facts.system.pkg_mgr import PkgMgrFactCollector, OpenBSDPkgMgrFactCollector |
| 41 |
from ansible.module_utils.facts.system.platform import PlatformFactCollector |
| 42 |
from ansible.module_utils.facts.system.python import PythonFactCollector |
| 43 |
from ansible.module_utils.facts.system.selinux import SelinuxFactCollector |
| 44 |
from ansible.module_utils.facts.system.service_mgr import ServiceMgrFactCollector |
| 45 |
from ansible.module_utils.facts.system.user import UserFactCollector |
| 46 |
|
| 47 |
# from ansible.module_utils.facts.hardware.base import HardwareCollector |
| 48 |
from ansible.module_utils.facts.network.base import NetworkCollector |
| 49 |
from ansible.module_utils.facts.virtual.base import VirtualCollector |
| 50 |
|
| 51 |
ALL_COLLECTOR_CLASSES = \ |
| 52 |
[PlatformFactCollector, |
| 53 |
DistributionFactCollector, |
| 54 |
SelinuxFactCollector, |
| 55 |
ApparmorFactCollector, |
| 56 |
SystemCapabilitiesFactCollector, |
| 57 |
FipsFactCollector, |
| 58 |
PkgMgrFactCollector, |
| 59 |
OpenBSDPkgMgrFactCollector, |
| 60 |
ServiceMgrFactCollector, |
| 61 |
LSBFactCollector, |
| 62 |
DateTimeFactCollector, |
| 63 |
UserFactCollector, |
| 64 |
LocalFactCollector, |
| 65 |
EnvFactCollector, |
| 66 |
DnsFactCollector, |
| 67 |
PythonFactCollector, |
| 68 |
# FIXME: re-enable when hardware doesn't Hardware() doesn't munge self.facts |
| 69 |
# HardwareCollector |
| 70 |
NetworkCollector, |
| 71 |
VirtualCollector, |
| 72 |
OhaiFactCollector, |
| 73 |
FacterFactCollector] |
| 74 |
|
| 75 |
|
| 76 |
def mock_module(gather_subset=None, |
| 77 |
filter=None): |
| 78 |
if gather_subset is None: |
| 79 |
gather_subset = ['all', '!facter', '!ohai'] |
| 80 |
if filter is None: |
| 81 |
filter = '*' |
| 82 |
mock_module = Mock() |
| 83 |
mock_module.params = {'gather_subset': gather_subset, |
| 84 |
'gather_timeout': 5, |
| 85 |
'filter': filter} |
| 86 |
mock_module.get_bin_path = Mock(return_value=None) |
| 87 |
return mock_module |
| 88 |
|
| 89 |
|
| 90 |
def _collectors(module, |
| 91 |
all_collector_classes=None, |
| 92 |
minimal_gather_subset=None): |
| 93 |
gather_subset = module.params.get('gather_subset') |
| 94 |
if all_collector_classes is None: |
| 95 |
all_collector_classes = ALL_COLLECTOR_CLASSES |
| 96 |
if minimal_gather_subset is None: |
| 97 |
minimal_gather_subset = frozenset([]) |
| 98 |
|
| 99 |
collector_classes = \ |
| 100 |
collector.collector_classes_from_gather_subset(all_collector_classes=all_collector_classes, |
| 101 |
minimal_gather_subset=minimal_gather_subset, |
| 102 |
gather_subset=gather_subset) |
| 103 |
|
| 104 |
collectors = [] |
| 105 |
for collector_class in collector_classes: |
| 106 |
collector_obj = collector_class() |
| 107 |
collectors.append(collector_obj) |
| 108 |
|
| 109 |
# Add a collector that knows what gather_subset we used so it it can provide a fact |
| 110 |
collector_meta_data_collector = \ |
| 111 |
ansible_collector.CollectorMetaDataCollector(gather_subset=gather_subset, |
| 112 |
module_setup=True) |
| 113 |
collectors.append(collector_meta_data_collector) |
| 114 |
|
| 115 |
return collectors |
| 116 |
|
| 117 |
|
| 118 |
ns = namespace.PrefixFactNamespace('ansible_facts', 'ansible_') |
| 119 |
|
| 120 |
|
| 121 |
# FIXME: this is brute force, but hopefully enough to get some refactoring to make facts testable |
| 122 |
class TestInPlace(unittest.TestCase): |
| 123 |
def _mock_module(self, gather_subset=None): |
| 124 |
return mock_module(gather_subset=gather_subset) |
| 125 |
|
| 126 |
def _collectors(self, module, |
| 127 |
all_collector_classes=None, |
| 128 |
minimal_gather_subset=None): |
| 129 |
return _collectors(module=module, |
| 130 |
all_collector_classes=all_collector_classes, |
| 131 |
minimal_gather_subset=minimal_gather_subset) |
| 132 |
|
| 133 |
def test(self): |
| 134 |
gather_subset = ['all'] |
| 135 |
mock_module = self._mock_module(gather_subset=gather_subset) |
| 136 |
all_collector_classes = [EnvFactCollector] |
| 137 |
collectors = self._collectors(mock_module, |
| 138 |
all_collector_classes=all_collector_classes) |
| 139 |
|
| 140 |
fact_collector = \ |
| 141 |
ansible_collector.AnsibleFactCollector(collectors=collectors, |
| 142 |
namespace=ns) |
| 143 |
|
| 144 |
res = fact_collector.collect(module=mock_module) |
| 145 |
self.assertIsInstance(res, dict) |
| 146 |
self.assertIn('env', res) |
| 147 |
self.assertIn('gather_subset', res) |
| 148 |
self.assertEqual(res['gather_subset'], ['all']) |
| 149 |
|
| 150 |
def test1(self): |
| 151 |
gather_subset = ['all'] |
| 152 |
mock_module = self._mock_module(gather_subset=gather_subset) |
| 153 |
collectors = self._collectors(mock_module) |
| 154 |
|
| 155 |
fact_collector = \ |
| 156 |
ansible_collector.AnsibleFactCollector(collectors=collectors, |
| 157 |
namespace=ns) |
| 158 |
|
| 159 |
res = fact_collector.collect(module=mock_module) |
| 160 |
self.assertIsInstance(res, dict) |
| 161 |
# just assert it's not almost empty |
| 162 |
# with run_command and get_file_content mock, many facts are empty, like network |
| 163 |
self.assertGreater(len(res), 20) |
| 164 |
|
| 165 |
def test_empty_all_collector_classes(self): |
| 166 |
mock_module = self._mock_module() |
| 167 |
all_collector_classes = [] |
| 168 |
|
| 169 |
collectors = self._collectors(mock_module, |
| 170 |
all_collector_classes=all_collector_classes) |
| 171 |
|
| 172 |
fact_collector = \ |
| 173 |
ansible_collector.AnsibleFactCollector(collectors=collectors, |
| 174 |
namespace=ns) |
| 175 |
|
| 176 |
res = fact_collector.collect() |
| 177 |
self.assertIsInstance(res, dict) |
| 178 |
# just assert it's not almost empty |
| 179 |
self.assertLess(len(res), 3) |
| 180 |
|
| 181 |
# def test_facts_class(self): |
| 182 |
# mock_module = self._mock_module() |
| 183 |
# Facts(mock_module) |
| 184 |
|
| 185 |
# def test_facts_class_load_on_init_false(self): |
| 186 |
# mock_module = self._mock_module() |
| 187 |
# Facts(mock_module, load_on_init=False) |
| 188 |
# # FIXME: assert something |
| 189 |
|
| 190 |
|
| 191 |
class TestCollectedFacts(unittest.TestCase): |
| 192 |
gather_subset = ['all', '!facter', '!ohai'] |
| 193 |
min_fact_count = 30 |
| 194 |
max_fact_count = 1000 |
| 195 |
|
| 196 |
# TODO: add ansible_cmdline, ansible_*_pubkey* back when TempFactCollector goes away |
| 197 |
expected_facts = ['date_time', |
| 198 |
'user_id', 'distribution', |
| 199 |
'gather_subset', 'module_setup', |
| 200 |
'env'] |
| 201 |
not_expected_facts = ['facter', 'ohai'] |
| 202 |
|
| 203 |
collected_facts: dict[str, str] = {} |
| 204 |
|
| 205 |
def _mock_module(self, gather_subset=None): |
| 206 |
return mock_module(gather_subset=self.gather_subset) |
| 207 |
|
| 208 |
@patch('platform.system', return_value='Linux') |
| 209 |
@patch('ansible.module_utils.facts.system.service_mgr.get_file_content', return_value='systemd') |
| 210 |
def setUp(self, mock_gfc, mock_ps): |
| 211 |
mock_module = self._mock_module() |
| 212 |
collectors = self._collectors(mock_module) |
| 213 |
|
| 214 |
fact_collector = \ |
| 215 |
ansible_collector.AnsibleFactCollector(collectors=collectors, |
| 216 |
namespace=ns) |
| 217 |
self.facts = fact_collector.collect(module=mock_module, |
| 218 |
collected_facts=self.collected_facts) |
| 219 |
|
| 220 |
def _collectors(self, module, |
| 221 |
all_collector_classes=None, |
| 222 |
minimal_gather_subset=None): |
| 223 |
return _collectors(module=module, |
| 224 |
all_collector_classes=all_collector_classes, |
| 225 |
minimal_gather_subset=minimal_gather_subset) |
| 226 |
|
| 227 |
def test_basics(self): |
| 228 |
self._assert_basics(self.facts) |
| 229 |
|
| 230 |
def test_expected_facts(self): |
| 231 |
self._assert_expected_facts(self.facts) |
| 232 |
|
| 233 |
def test_not_expected_facts(self): |
| 234 |
self._assert_not_expected_facts(self.facts) |
| 235 |
|
| 236 |
def _assert_basics(self, facts): |
| 237 |
self.assertIsInstance(facts, dict) |
| 238 |
# just assert it's not almost empty |
| 239 |
self.assertGreaterEqual(len(facts), self.min_fact_count) |
| 240 |
# and that is not huge number of keys |
| 241 |
self.assertLess(len(facts), self.max_fact_count) |
| 242 |
|
| 243 |
# everything starts with ansible_ namespace |
| 244 |
def _assert_ansible_namespace(self, facts): |
| 245 |
|
| 246 |
# FIXME: kluge for non-namespace fact |
| 247 |
facts.pop('module_setup', None) |
| 248 |
facts.pop('gather_subset', None) |
| 249 |
|
| 250 |
for fact_key in facts: |
| 251 |
self.assertTrue(fact_key.startswith('ansible_'), |
| 252 |
'The fact name "%s" does not startwith "ansible_"' % fact_key) |
| 253 |
|
| 254 |
def _assert_expected_facts(self, facts): |
| 255 |
|
| 256 |
facts_keys = sorted(facts.keys()) |
| 257 |
for expected_fact in self.expected_facts: |
| 258 |
self.assertIn(expected_fact, facts_keys) |
| 259 |
|
| 260 |
def _assert_not_expected_facts(self, facts): |
| 261 |
|
| 262 |
facts_keys = sorted(facts.keys()) |
| 263 |
for not_expected_fact in self.not_expected_facts: |
| 264 |
self.assertNotIn(not_expected_fact, facts_keys) |
| 265 |
|
| 266 |
|
| 267 |
class ProvidesOtherFactCollector(collector.BaseFactCollector): |
| 268 |
name = 'provides_something' |
| 269 |
_fact_ids = set(['needed_fact']) |
| 270 |
|
| 271 |
def collect(self, module=None, collected_facts=None): |
| 272 |
return {'needed_fact': 'THE_NEEDED_FACT_VALUE'} |
| 273 |
|
| 274 |
|
| 275 |
class RequiresOtherFactCollector(collector.BaseFactCollector): |
| 276 |
name = 'requires_something' |
| 277 |
|
| 278 |
def collect(self, module=None, collected_facts=None): |
| 279 |
collected_facts = collected_facts or {} |
| 280 |
fact_dict = {} |
| 281 |
fact_dict['needed_fact'] = collected_facts['needed_fact'] |
| 282 |
fact_dict['compound_fact'] = "compound-%s" % collected_facts['needed_fact'] |
| 283 |
return fact_dict |
| 284 |
|
| 285 |
|
| 286 |
class ConCatFactCollector(collector.BaseFactCollector): |
| 287 |
name = 'concat_collected' |
| 288 |
|
| 289 |
def collect(self, module=None, collected_facts=None): |
| 290 |
collected_facts = collected_facts or {} |
| 291 |
fact_dict = {} |
| 292 |
con_cat_list = [] |
| 293 |
for key, value in collected_facts.items(): |
| 294 |
con_cat_list.append(value) |
| 295 |
|
| 296 |
fact_dict['concat_fact'] = '-'.join(con_cat_list) |
| 297 |
return fact_dict |
| 298 |
|
| 299 |
|
| 300 |
class TestCollectorDepsWithFilter(unittest.TestCase): |
| 301 |
gather_subset = ['all', '!facter', '!ohai'] |
| 302 |
|
| 303 |
def _mock_module(self, gather_subset=None, filter=None): |
| 304 |
return mock_module(gather_subset=self.gather_subset, |
| 305 |
filter=filter) |
| 306 |
|
| 307 |
def setUp(self): |
| 308 |
self.mock_module = self._mock_module() |
| 309 |
self.collectors = self._collectors(mock_module) |
| 310 |
|
| 311 |
def _collectors(self, module, |
| 312 |
all_collector_classes=None, |
| 313 |
minimal_gather_subset=None): |
| 314 |
return [ProvidesOtherFactCollector(), |
| 315 |
RequiresOtherFactCollector()] |
| 316 |
|
| 317 |
def test_no_filter(self): |
| 318 |
_mock_module = mock_module(gather_subset=['all', '!facter', '!ohai']) |
| 319 |
|
| 320 |
facts_dict = self._collect(_mock_module) |
| 321 |
|
| 322 |
expected = {'needed_fact': 'THE_NEEDED_FACT_VALUE', |
| 323 |
'compound_fact': 'compound-THE_NEEDED_FACT_VALUE'} |
| 324 |
|
| 325 |
self.assertEqual(expected, facts_dict) |
| 326 |
|
| 327 |
def test_with_filter_on_compound_fact(self): |
| 328 |
_mock_module = mock_module(gather_subset=['all', '!facter', '!ohai'], |
| 329 |
filter='compound_fact') |
| 330 |
|
| 331 |
facts_dict = self._collect(_mock_module) |
| 332 |
|
| 333 |
expected = {'compound_fact': 'compound-THE_NEEDED_FACT_VALUE'} |
| 334 |
|
| 335 |
self.assertEqual(expected, facts_dict) |
| 336 |
|
| 337 |
def test_with_filter_on_needed_fact(self): |
| 338 |
_mock_module = mock_module(gather_subset=['all', '!facter', '!ohai'], |
| 339 |
filter='needed_fact') |
| 340 |
|
| 341 |
facts_dict = self._collect(_mock_module) |
| 342 |
|
| 343 |
expected = {'needed_fact': 'THE_NEEDED_FACT_VALUE'} |
| 344 |
|
| 345 |
self.assertEqual(expected, facts_dict) |
| 346 |
|
| 347 |
def test_with_filter_on_compound_gather_compound(self): |
| 348 |
_mock_module = mock_module(gather_subset=['!all', '!any', 'compound_fact'], |
| 349 |
filter='compound_fact') |
| 350 |
|
| 351 |
facts_dict = self._collect(_mock_module) |
| 352 |
|
| 353 |
expected = {'compound_fact': 'compound-THE_NEEDED_FACT_VALUE'} |
| 354 |
|
| 355 |
self.assertEqual(expected, facts_dict) |
| 356 |
|
| 357 |
def test_with_filter_no_match(self): |
| 358 |
_mock_module = mock_module(gather_subset=['all', '!facter', '!ohai'], |
| 359 |
filter='ansible_this_doesnt_exist') |
| 360 |
|
| 361 |
facts_dict = self._collect(_mock_module) |
| 362 |
|
| 363 |
expected = {} |
| 364 |
self.assertEqual(expected, facts_dict) |
| 365 |
|
| 366 |
def test_concat_collector(self): |
| 367 |
_mock_module = mock_module(gather_subset=['all', '!facter', '!ohai']) |
| 368 |
|
| 369 |
_collectors = self._collectors(_mock_module) |
| 370 |
_collectors.append(ConCatFactCollector()) |
| 371 |
|
| 372 |
fact_collector = \ |
| 373 |
ansible_collector.AnsibleFactCollector(collectors=_collectors, |
| 374 |
namespace=ns, |
| 375 |
filter_spec=_mock_module.params['filter']) |
| 376 |
|
| 377 |
collected_facts = {} |
| 378 |
facts_dict = fact_collector.collect(module=_mock_module, |
| 379 |
collected_facts=collected_facts) |
| 380 |
self.assertIn('concat_fact', facts_dict) |
| 381 |
self.assertIn('THE_NEEDED_FACT_VALUE', facts_dict['concat_fact']) |
| 382 |
|
| 383 |
def test_concat_collector_with_filter_on_concat(self): |
| 384 |
_mock_module = mock_module(gather_subset=['all', '!facter', '!ohai'], |
| 385 |
filter='concat_fact') |
| 386 |
|
| 387 |
_collectors = self._collectors(_mock_module) |
| 388 |
_collectors.append(ConCatFactCollector()) |
| 389 |
|
| 390 |
fact_collector = \ |
| 391 |
ansible_collector.AnsibleFactCollector(collectors=_collectors, |
| 392 |
namespace=ns, |
| 393 |
filter_spec=_mock_module.params['filter']) |
| 394 |
|
| 395 |
collected_facts = {} |
| 396 |
facts_dict = fact_collector.collect(module=_mock_module, |
| 397 |
collected_facts=collected_facts) |
| 398 |
self.assertIn('concat_fact', facts_dict) |
| 399 |
self.assertIn('THE_NEEDED_FACT_VALUE', facts_dict['concat_fact']) |
| 400 |
self.assertIn('compound', facts_dict['concat_fact']) |
| 401 |
|
| 402 |
def _collect(self, _mock_module, collected_facts=None): |
| 403 |
_collectors = self._collectors(_mock_module) |
| 404 |
|
| 405 |
fact_collector = \ |
| 406 |
ansible_collector.AnsibleFactCollector(collectors=_collectors, |
| 407 |
namespace=ns, |
| 408 |
filter_spec=_mock_module.params['filter']) |
| 409 |
facts_dict = fact_collector.collect(module=_mock_module, |
| 410 |
collected_facts=collected_facts) |
| 411 |
return facts_dict |
| 412 |
|
| 413 |
|
| 414 |
class ExceptionThrowingCollector(collector.BaseFactCollector): |
| 415 |
def collect(self, module=None, collected_facts=None): |
| 416 |
raise Exception('A collector failed') |
| 417 |
|
| 418 |
|
| 419 |
class TestExceptionCollectedFacts(TestCollectedFacts): |
| 420 |
|
| 421 |
def _collectors(self, module, |
| 422 |
all_collector_classes=None, |
| 423 |
minimal_gather_subset=None): |
| 424 |
collectors = _collectors(module=module, |
| 425 |
all_collector_classes=all_collector_classes, |
| 426 |
minimal_gather_subset=minimal_gather_subset) |
| 427 |
|
| 428 |
c = [ExceptionThrowingCollector()] + collectors |
| 429 |
return c |
| 430 |
|
| 431 |
|
| 432 |
class TestOnlyExceptionCollector(TestCollectedFacts): |
| 433 |
expected_facts = [] |
| 434 |
min_fact_count = 0 |
| 435 |
|
| 436 |
def _collectors(self, module, |
| 437 |
all_collector_classes=None, |
| 438 |
minimal_gather_subset=None): |
| 439 |
return [ExceptionThrowingCollector()] |
| 440 |
|
| 441 |
|
| 442 |
class NoneReturningCollector(collector.BaseFactCollector): |
| 443 |
def collect(self, module=None, collected_facts=None): |
| 444 |
return None |
| 445 |
|
| 446 |
|
| 447 |
class TestOnlyNoneCollector(TestCollectedFacts): |
| 448 |
expected_facts = [] |
| 449 |
min_fact_count = 0 |
| 450 |
|
| 451 |
def _collectors(self, module, |
| 452 |
all_collector_classes=None, |
| 453 |
minimal_gather_subset=None): |
| 454 |
return [NoneReturningCollector(namespace='ansible')] |
| 455 |
|
| 456 |
|
| 457 |
class TestMinimalCollectedFacts(TestCollectedFacts): |
| 458 |
gather_subset = ['!all'] |
| 459 |
min_fact_count = 1 |
| 460 |
max_fact_count = 10 |
| 461 |
expected_facts = ['gather_subset', |
| 462 |
'module_setup'] |
| 463 |
not_expected_facts = ['lsb'] |
| 464 |
|
| 465 |
|
| 466 |
class TestFacterCollectedFacts(TestCollectedFacts): |
| 467 |
gather_subset = ['!all', 'facter'] |
| 468 |
min_fact_count = 1 |
| 469 |
max_fact_count = 10 |
| 470 |
expected_facts = ['gather_subset', |
| 471 |
'module_setup'] |
| 472 |
not_expected_facts = ['lsb'] |
| 473 |
|
| 474 |
|
| 475 |
class TestOhaiCollectedFacts(TestCollectedFacts): |
| 476 |
gather_subset = ['!all', 'ohai'] |
| 477 |
min_fact_count = 1 |
| 478 |
max_fact_count = 10 |
| 479 |
expected_facts = ['gather_subset', |
| 480 |
'module_setup'] |
| 481 |
not_expected_facts = ['lsb'] |
| 482 |
|
| 483 |
|
| 484 |
class TestPkgMgrFacts(TestCollectedFacts): |
| 485 |
gather_subset = ['pkg_mgr'] |
| 486 |
min_fact_count = 1 |
| 487 |
max_fact_count = 20 |
| 488 |
expected_facts = ['gather_subset', |
| 489 |
'module_setup', |
| 490 |
'pkg_mgr'] |
| 491 |
collected_facts = { |
| 492 |
"ansible_distribution": "Fedora", |
| 493 |
"ansible_distribution_major_version": "28", |
| 494 |
"ansible_os_family": "RedHat" |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
class TestPkgMgrOSTreeFacts(TestPkgMgrFacts): |
| 499 |
@patch( |
| 500 |
'ansible.module_utils.facts.system.pkg_mgr.os.path.exists', |
| 501 |
side_effect=lambda x: x == '/run/ostree-booted') |
| 502 |
def _recollect_facts(self, distribution, version, mock_exists): |
| 503 |
self.collected_facts['ansible_distribution'] = distribution |
| 504 |
self.collected_facts['ansible_distribution_major_version'] = \ |
| 505 |
str(version) |
| 506 |
# Recollect facts |
| 507 |
self.setUp() |
| 508 |
self.assertIn('pkg_mgr', self.facts) |
| 509 |
self.assertEqual(self.facts['pkg_mgr'], 'atomic_container') |
| 510 |
|
| 511 |
def test_is_rhel_edge_ostree(self): |
| 512 |
self._recollect_facts('RedHat', 8) |
| 513 |
|
| 514 |
def test_is_fedora_ostree(self): |
| 515 |
self._recollect_facts('Fedora', 33) |
| 516 |
|
| 517 |
|
| 518 |
class TestOpenBSDPkgMgrFacts(TestPkgMgrFacts): |
| 519 |
def test_is_openbsd_pkg(self): |
| 520 |
self.assertIn('pkg_mgr', self.facts) |
| 521 |
self.assertEqual(self.facts['pkg_mgr'], 'openbsd_pkg') |
| 522 |
|
| 523 |
def setUp(self): |
| 524 |
self.patcher = patch('platform.system') |
| 525 |
mock_platform = self.patcher.start() |
| 526 |
mock_platform.return_value = 'OpenBSD' |
| 527 |
|
| 528 |
mock_module = self._mock_module() |
| 529 |
collectors = self._collectors(mock_module) |
| 530 |
|
| 531 |
fact_collector = \ |
| 532 |
ansible_collector.AnsibleFactCollector(collectors=collectors, |
| 533 |
namespace=ns) |
| 534 |
self.facts = fact_collector.collect(module=mock_module) |
| 535 |
|
| 536 |
def tearDown(self): |
| 537 |
self.patcher.stop() |