_requirements.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import _test_const as consts
  2. def check_cpu(suite_cpu_requirements, test_size, is_kvm=False):
  3. min_cpu_requirements = consts.TestRequirementsConstants.MinCpu
  4. max_cpu_requirements = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Cpu)
  5. if isinstance(suite_cpu_requirements, str):
  6. if all(consts.TestRequirementsConstants.is_all_cpu(req) for req in (max_cpu_requirements, suite_cpu_requirements)):
  7. return None
  8. return "Wrong 'cpu' requirements: {}, should be in [{}..{}] for {}-size tests".format(suite_cpu_requirements, min_cpu_requirements, max_cpu_requirements, test_size)
  9. if not isinstance(suite_cpu_requirements, int):
  10. return "Wrong 'cpu' requirements: {}, should be integer".format(suite_cpu_requirements)
  11. if suite_cpu_requirements < min_cpu_requirements or suite_cpu_requirements > consts.TestRequirementsConstants.get_cpu_value(max_cpu_requirements):
  12. return "Wrong 'cpu' requirement: {}, should be in [{}..{}] for {}-size tests".format(suite_cpu_requirements, min_cpu_requirements, max_cpu_requirements, test_size)
  13. return None
  14. # TODO: Remove is_kvm param when there will be guarantees on RAM
  15. def check_ram(suite_ram_requirements, test_size, is_kvm=False):
  16. if not isinstance(suite_ram_requirements, int):
  17. return "Wrong 'ram' requirements: {}, should be integer".format(suite_ram_requirements)
  18. min_ram_requirements = consts.TestRequirementsConstants.MinRam
  19. max_ram_requirements = consts.MAX_RAM_REQUIREMENTS_FOR_KVM if is_kvm else consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.Ram)
  20. if suite_ram_requirements < min_ram_requirements or suite_ram_requirements > max_ram_requirements:
  21. err_msg = "Wrong 'ram' requirements: {}, should be in [{}..{}] for {}-size tests".format(suite_ram_requirements, min_ram_requirements, max_ram_requirements, test_size)
  22. if is_kvm:
  23. err_msg += ' with kvm requirements'
  24. return err_msg
  25. return None
  26. def check_ram_disk(suite_ram_disk, test_size, is_kvm=False):
  27. min_ram_disk = consts.TestRequirementsConstants.MinRamDisk
  28. max_ram_disk = consts.TestSize.get_max_requirements(test_size).get(consts.TestRequirements.RamDisk)
  29. if isinstance(suite_ram_disk, str):
  30. if all(consts.TestRequirementsConstants.is_all_ram_disk(req) for req in (max_ram_disk, suite_ram_disk)):
  31. return None
  32. return "Wrong 'ram_disk' requirements: {}, should be in [{}..{}] for {}-size tests".format(suite_ram_disk, 0, max_ram_disk, test_size)
  33. if not isinstance(suite_ram_disk, int):
  34. return "Wrong 'ram_disk' requirements: {}, should be integer".format(suite_ram_disk)
  35. if suite_ram_disk < min_ram_disk or suite_ram_disk > consts.TestRequirementsConstants.get_ram_disk_value(max_ram_disk):
  36. return "Wrong 'ram_disk' requirement: {}, should be in [{}..{}] for {}-size tests".format(suite_ram_disk, min_ram_disk, max_ram_disk, test_size)
  37. return None