How to use _check_has_resource_disk method in lisa

Best Python code snippet using lisa_python

features.py

Source:features.py Github

copy

Full Screen

...805 ),806 "data_disk_size",807 )808 result.merge(809 self._check_has_resource_disk(810 self.has_resource_disk, capability.has_resource_disk811 ),812 "has_resource_disk",813 )814 result.merge(815 search_space.check_countspace(816 self.max_data_disk_count, capability.max_data_disk_count817 ),818 "max_data_disk_count",819 )820 return result821 def _call_requirement_method(self, method_name: str, capability: Any) -> Any:822 assert isinstance(823 capability, AzureDiskOptionSettings824 ), f"actual: {type(capability)}"825 assert (826 capability.disk_type827 ), "capability should have at least one disk type, but it's None"828 value = AzureDiskOptionSettings()829 super_value = schema.DiskOptionSettings._call_requirement_method(830 self, method_name, capability831 )832 set_filtered_fields(super_value, value, ["data_disk_count"])833 cap_disk_type = capability.disk_type834 if isinstance(cap_disk_type, search_space.SetSpace):835 assert (836 len(cap_disk_type) > 0837 ), "capability should have at least one disk type, but it's empty"838 elif isinstance(cap_disk_type, schema.DiskType):839 cap_disk_type = search_space.SetSpace[schema.DiskType](840 is_allow_set=True, items=[cap_disk_type]841 )842 else:843 raise LisaException(844 f"unknown disk type on capability, type: {cap_disk_type}"845 )846 value.disk_type = getattr(search_space, f"{method_name}_setspace_by_priority")(847 self.disk_type, capability.disk_type, schema.disk_type_priority848 )849 # below values affect data disk only.850 if self.data_disk_count is not None or capability.data_disk_count is not None:851 value.data_disk_count = getattr(search_space, f"{method_name}_countspace")(852 self.data_disk_count, capability.data_disk_count853 )854 if (855 self.max_data_disk_count is not None856 or capability.max_data_disk_count is not None857 ):858 value.max_data_disk_count = getattr(859 search_space, f"{method_name}_countspace"860 )(self.max_data_disk_count, capability.max_data_disk_count)861 # The Ephemeral doesn't support data disk, but it needs a value. And it862 # doesn't need to calculate on intersect863 value.data_disk_iops = 0864 value.data_disk_size = 0865 if method_name == RequirementMethod.generate_min_capability:866 assert isinstance(867 value.disk_type, schema.DiskType868 ), f"actual: {type(value.disk_type)}"869 disk_type_iops = _disk_size_iops_map.get(value.disk_type, None)870 # ignore unsupported disk type like Ephemeral. It supports only os871 # disk. Calculate for iops, if it has value. If not, try disk size872 if disk_type_iops:873 if isinstance(self.data_disk_iops, int) or (874 self.data_disk_iops != search_space.IntRange(min=0)875 ):876 req_disk_iops = search_space.count_space_to_int_range(877 self.data_disk_iops878 )879 cap_disk_iops = search_space.count_space_to_int_range(880 capability.data_disk_iops881 )882 min_iops = max(req_disk_iops.min, cap_disk_iops.min)883 max_iops = min(req_disk_iops.max, cap_disk_iops.max)884 value.data_disk_iops = min(885 iops886 for iops, _ in disk_type_iops887 if iops >= min_iops and iops <= max_iops888 )889 value.data_disk_size = self._get_disk_size_from_iops(890 value.data_disk_iops, disk_type_iops891 )892 elif self.data_disk_size:893 req_disk_size = search_space.count_space_to_int_range(894 self.data_disk_size895 )896 cap_disk_size = search_space.count_space_to_int_range(897 capability.data_disk_size898 )899 min_size = max(req_disk_size.min, cap_disk_size.min)900 max_size = min(req_disk_size.max, cap_disk_size.max)901 value.data_disk_iops = min(902 iops903 for iops, disk_size in disk_type_iops904 if disk_size >= min_size and disk_size <= max_size905 )906 value.data_disk_size = self._get_disk_size_from_iops(907 value.data_disk_iops, disk_type_iops908 )909 else:910 # if req is not specified, query minimum value.911 cap_disk_size = search_space.count_space_to_int_range(912 capability.data_disk_size913 )914 value.data_disk_iops = min(915 iops916 for iops, _ in disk_type_iops917 if iops >= cap_disk_size.min and iops <= cap_disk_size.max918 )919 value.data_disk_size = self._get_disk_size_from_iops(920 value.data_disk_iops, disk_type_iops921 )922 elif method_name == RequirementMethod.intersect:923 value.data_disk_iops = search_space.intersect_countspace(924 self.data_disk_iops, capability.data_disk_iops925 )926 value.data_disk_size = search_space.intersect_countspace(927 self.data_disk_size, capability.data_disk_size928 )929 # all caching types are supported, so just take the value from requirement.930 value.data_disk_caching_type = self.data_disk_caching_type931 check_result = self._check_has_resource_disk(932 self.has_resource_disk, capability.has_resource_disk933 )934 if not check_result.result:935 raise NotMeetRequirementException("capability doesn't support requirement")936 value.has_resource_disk = capability.has_resource_disk937 return value938 def _get_disk_size_from_iops(939 self, data_disk_iops: int, disk_type_iops: List[Tuple[int, int]]940 ) -> int:941 return next(942 disk_size for iops, disk_size in disk_type_iops if iops == data_disk_iops943 )944 def _check_has_resource_disk(945 self, requirement: Optional[bool], capability: Optional[bool]946 ) -> search_space.ResultReason:947 result = search_space.ResultReason()948 # if requirement is none, capability can be either of True or False949 # else requirement should match capability950 if requirement is not None:951 if capability is None:952 result.add_reason(953 "if requirements isn't None, capability shouldn't be None"954 )955 else:956 if requirement != capability:957 result.add_reason(958 "requirement is a truth value, capability should be exact "...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful