test_requirements.py 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import pytest
  2. import _requirements as requirements
  3. import lib.test_const as consts
  4. class TestRequirements(object):
  5. @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
  6. def test_cpu(self, test_size):
  7. max_cpu = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Cpu)
  8. min_cpu = consts.TestRequirementsConstants.MinCpu
  9. assert requirements.check_cpu(-1, test_size)
  10. assert requirements.check_cpu(min_cpu - 1, test_size)
  11. assert requirements.check_cpu("unknown", test_size)
  12. assert not requirements.check_cpu(1, test_size)
  13. assert not requirements.check_cpu(3, test_size)
  14. assert requirements.check_cpu(1000, test_size)
  15. if max_cpu != consts.TestRequirementsConstants.All:
  16. assert requirements.check_cpu(max_cpu + 1, test_size)
  17. assert requirements.check_cpu(max_cpu + 4, test_size)
  18. assert requirements.check_cpu(consts.TestRequirementsConstants.All, test_size)
  19. else:
  20. assert not requirements.check_cpu(consts.TestRequirementsConstants.All, test_size)
  21. @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
  22. def test_ram(self, test_size):
  23. max_ram = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Ram)
  24. min_ram = consts.TestRequirementsConstants.MinRam
  25. assert requirements.check_ram(-1, test_size)
  26. assert requirements.check_ram(min_ram - 1, test_size)
  27. assert requirements.check_ram(max_ram + 1, test_size)
  28. assert not requirements.check_ram(1, test_size)
  29. assert not requirements.check_ram(4, test_size)
  30. assert not requirements.check_ram(5, test_size)
  31. assert not requirements.check_ram(32, consts.TestSize.Large)
  32. assert requirements.check_ram(48, consts.TestSize.Large)
  33. assert not requirements.check_ram(1, test_size, is_kvm=True)
  34. assert not requirements.check_ram(4, test_size, is_kvm=True)
  35. assert not requirements.check_ram(16, test_size, is_kvm=True)
  36. assert requirements.check_ram(32, test_size, is_kvm=True)
  37. @pytest.mark.parametrize('test_size', consts.TestSize.sizes())
  38. def test_ram_disk(self, test_size):
  39. max_ram_disk = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.RamDisk)
  40. min_ram_disk = consts.TestRequirementsConstants.MinRamDisk
  41. assert requirements.check_ram_disk(-1, test_size)
  42. assert requirements.check_ram_disk(min_ram_disk - 1, test_size)
  43. assert requirements.check_ram_disk(max_ram_disk + 1, test_size)
  44. assert requirements.check_ram_disk(33, test_size)
  45. assert not requirements.check_ram_disk(32, test_size)
  46. assert not requirements.check_ram_disk(1, test_size)
  47. assert not requirements.check_ram_disk(4, test_size)
  48. assert not requirements.validate_ram_disk_requirement(
  49. 'ram_disk', '0', test_size, False, True, False, False, False, 1
  50. )
  51. assert not requirements.validate_ram_disk_requirement(
  52. 'ram_disk', '1', test_size, False, True, False, False, False, 1
  53. )
  54. assert not requirements.validate_ram_disk_requirement(
  55. 'ram_disk', '1', test_size, True, True, False, False, False, 0
  56. )
  57. assert not requirements.validate_ram_disk_requirement(
  58. 'ram_disk', '1', test_size, False, False, False, False, False, 0
  59. )
  60. if test_size != consts.TestSize.Large:
  61. assert requirements.validate_ram_disk_requirement(
  62. 'ram_disk', '1', test_size, False, True, False, False, False, 0
  63. )
  64. assert requirements.validate_ram_disk_requirement(
  65. 'ram_disk', '1', test_size, False, True, True, False, False, 0
  66. )
  67. assert requirements.validate_ram_disk_requirement(
  68. 'ram_disk', '1', test_size, False, True, False, True, False, 0
  69. )
  70. assert requirements.validate_ram_disk_requirement(
  71. 'ram_disk', '1', test_size, False, True, False, False, True, 0
  72. )
  73. else:
  74. assert not requirements.validate_ram_disk_requirement(
  75. 'ram_disk', '1', test_size, False, True, False, False, False, 0
  76. )
  77. assert not requirements.validate_ram_disk_requirement(
  78. 'ram_disk', '1', test_size, False, True, True, False, False, 0
  79. )
  80. assert not requirements.validate_ram_disk_requirement(
  81. 'ram_disk', '1', test_size, False, True, False, True, False, 0
  82. )
  83. assert not requirements.validate_ram_disk_requirement(
  84. 'ram_disk', '1', test_size, False, True, False, False, True, 0
  85. )