openshift_master_facts_bad_input_tests.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import copy
  2. import os
  3. import sys
  4. from ansible.errors import AnsibleError
  5. import pytest
  6. sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins"))
  7. from openshift_master_facts_default_predicates import LookupModule # noqa: E402
  8. class TestOpenShiftMasterFactsBadInput(object):
  9. lookup = LookupModule()
  10. default_facts = {
  11. 'openshift': {
  12. 'common': {}
  13. }
  14. }
  15. def test_missing_openshift_facts(self):
  16. with pytest.raises(AnsibleError):
  17. facts = {}
  18. self.lookup.run(None, variables=facts)
  19. def test_missing_deployment_type(self):
  20. with pytest.raises(AnsibleError):
  21. facts = copy.deepcopy(self.default_facts)
  22. facts['openshift']['common']['short_version'] = '10.10'
  23. self.lookup.run(None, variables=facts)
  24. def test_missing_short_version_and_missing_openshift_release(self):
  25. with pytest.raises(AnsibleError):
  26. facts = copy.deepcopy(self.default_facts)
  27. facts['openshift']['common']['deployment_type'] = 'origin'
  28. self.lookup.run(None, variables=facts)
  29. def test_unknown_deployment_types(self):
  30. with pytest.raises(AnsibleError):
  31. facts = copy.deepcopy(self.default_facts)
  32. facts['openshift']['common']['short_version'] = '1.1'
  33. facts['openshift']['common']['deployment_type'] = 'bogus'
  34. self.lookup.run(None, variables=facts)
  35. def test_unknown_origin_version(self):
  36. with pytest.raises(AnsibleError):
  37. facts = copy.deepcopy(self.default_facts)
  38. facts['openshift']['common']['short_version'] = '0.1'
  39. facts['openshift']['common']['deployment_type'] = 'origin'
  40. self.lookup.run(None, variables=facts)
  41. def test_unknown_ocp_version(self):
  42. with pytest.raises(AnsibleError):
  43. facts = copy.deepcopy(self.default_facts)
  44. facts['openshift']['common']['short_version'] = '0.1'
  45. facts['openshift']['common']['deployment_type'] = 'openshift-enterprise'
  46. self.lookup.run(None, variables=facts)