package_availability_test.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import pytest
  2. from openshift_checks.package_availability import PackageAvailability
  3. @pytest.mark.parametrize('pkg_mgr,is_containerized,is_active', [
  4. ('yum', False, True),
  5. ('yum', True, False),
  6. ('dnf', True, False),
  7. ('dnf', False, False),
  8. ])
  9. def test_is_active(pkg_mgr, is_containerized, is_active):
  10. task_vars = dict(
  11. ansible_pkg_mgr=pkg_mgr,
  12. openshift=dict(common=dict(is_containerized=is_containerized)),
  13. )
  14. assert PackageAvailability.is_active(task_vars=task_vars) == is_active
  15. @pytest.mark.parametrize('task_vars,must_have_packages,must_not_have_packages', [
  16. (
  17. dict(openshift=dict(common=dict(service_type='openshift'))),
  18. set(),
  19. set(['openshift-master', 'openshift-node']),
  20. ),
  21. (
  22. dict(
  23. openshift=dict(common=dict(service_type='origin')),
  24. group_names=['masters'],
  25. ),
  26. set(['origin-master']),
  27. set(['origin-node']),
  28. ),
  29. (
  30. dict(
  31. openshift=dict(common=dict(service_type='atomic-openshift')),
  32. group_names=['nodes'],
  33. ),
  34. set(['atomic-openshift-node']),
  35. set(['atomic-openshift-master']),
  36. ),
  37. (
  38. dict(
  39. openshift=dict(common=dict(service_type='atomic-openshift')),
  40. group_names=['masters', 'nodes'],
  41. ),
  42. set(['atomic-openshift-master', 'atomic-openshift-node']),
  43. set(),
  44. ),
  45. ])
  46. def test_package_availability(task_vars, must_have_packages, must_not_have_packages):
  47. return_value = object()
  48. def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
  49. assert module_name == 'check_yum_update'
  50. assert 'packages' in module_args
  51. assert set(module_args['packages']).issuperset(must_have_packages)
  52. assert not set(module_args['packages']).intersection(must_not_have_packages)
  53. return return_value
  54. check = PackageAvailability(execute_module=execute_module)
  55. result = check.run(tmp=None, task_vars=task_vars)
  56. assert result is return_value