Best Python code snippet using lisa_python
platform_.py
Source:platform_.py
...1891 def _get_sig_os_disk_size(self, shared_image: SharedImageGallerySchema) -> int:1892 found_image = self._get_sig_info(shared_image)1893 assert found_image.storage_profile.os_disk_image.size_in_gb1894 return int(found_image.storage_profile.os_disk_image.size_in_gb)1895 def _get_normalized_vm_sizes(1896 self, name: str, location: str, log: Logger1897 ) -> List[str]:1898 split_vm_sizes: List[str] = [x.strip() for x in name.split(",")]1899 for index, vm_size in enumerate(split_vm_sizes):1900 split_vm_sizes[index] = self._get_normalized_vm_size(vm_size, location, log)1901 return [x for x in split_vm_sizes if x]1902 def _get_normalized_vm_size(self, name: str, location: str, log: Logger) -> str:1903 # find predefined vm size on all available's.1904 location_info: AzureLocation = self.get_location_info(location, log)1905 matched_score: float = 01906 matched_name: str = ""1907 matcher = SequenceMatcher(None, name.lower(), "")1908 for vm_size in location_info.capabilities:1909 matcher.set_seq2(vm_size.lower())1910 if name.lower() in vm_size.lower() and matched_score < matcher.ratio():1911 matched_name = vm_size1912 matched_score = matcher.ratio()1913 return matched_name1914 def _get_capabilities(1915 self, vm_sizes: List[str], location: str, use_max_capability: bool, log: Logger1916 ) -> List[AzureCapability]:1917 candidate_caps: List[AzureCapability] = []1918 caps = self.get_location_info(location, log).capabilities1919 for vm_size in vm_sizes:1920 # force to use max capability to run test cases as much as possible,1921 # or force to support non-exists vm size.1922 if use_max_capability:1923 candidate_caps.append(self._generate_max_capability(vm_size, location))1924 continue1925 if vm_size in caps:1926 candidate_caps.append(caps[vm_size])1927 return candidate_caps1928 def _get_matched_capability(1929 self,1930 requirement: schema.NodeSpace,1931 candidate_capabilities: List[AzureCapability],1932 ) -> Optional[schema.NodeSpace]:1933 matched_cap: Optional[schema.NodeSpace] = None1934 # filter allowed vm sizes1935 for azure_cap in candidate_capabilities:1936 check_result = requirement.check(azure_cap.capability)1937 if check_result.result:1938 min_cap = self._generate_min_capability(1939 requirement, azure_cap, azure_cap.location1940 )1941 matched_cap = min_cap1942 break1943 return matched_cap1944 def _get_matched_capabilities(1945 self, location: str, nodes_requirement: List[schema.NodeSpace], log: Logger1946 ) -> Tuple[List[Union[schema.NodeSpace, bool]], str]:1947 # capability or if it's able to wait.1948 caps: List[Union[schema.NodeSpace, bool]] = [False] * len(nodes_requirement)1949 # one of errors for all requirements. It's enough for troubleshooting.1950 error: str = ""1951 # get allowed vm sizes. Either it's from the runbook defined, or1952 # from subscription supported .1953 for req_index, req in enumerate(nodes_requirement):1954 candidate_caps, sub_error = self._get_allowed_capabilities(1955 req, location, log1956 )1957 if sub_error:1958 # no candidate found, so try next one.1959 error = sub_error1960 continue1961 # filter vm sizes and return two list. 1st is deployable, 2nd is1962 # wait able for released resource.1963 (1964 available_capabilities,1965 awaitable_capabilities,1966 ) = self._parse_cap_availabilities(candidate_caps)1967 # sort vm sizes to match1968 available_capabilities = self.get_sorted_vm_sizes(1969 available_capabilities, log1970 )1971 # match vm sizes by capability or use the predefined vm sizes.1972 candidate_cap = self._get_matched_capability(req, available_capabilities)1973 if candidate_cap:1974 caps[req_index] = candidate_cap1975 else:1976 # the error will be overwritten, if there is vm sizes without1977 # quota.1978 error = f"no available vm size found on '{location}'."1979 if not candidate_cap:1980 # check if there is awaitable VMs1981 candidate_cap = self._get_matched_capability(1982 req, awaitable_capabilities1983 )1984 if candidate_cap:1985 # True means awaitable.1986 caps[req_index] = True1987 error = f"no quota found on '{location}'"1988 return caps, error1989 def _get_allowed_capabilities(1990 self, req: schema.NodeSpace, location: str, log: Logger1991 ) -> Tuple[List[AzureCapability], str]:1992 node_runbook = req.get_extended_runbook(AzureNodeSchema, AZURE)1993 error: str = ""1994 if node_runbook.vm_size:1995 # find the vm_size1996 allowed_vm_sizes = self._get_normalized_vm_sizes(1997 name=node_runbook.vm_size, location=location, log=log1998 )1999 # Some preview vm size may not be queried from the list.2000 # Force to add.2001 if not allowed_vm_sizes:2002 log.debug(2003 f"no vm size matched '{node_runbook.vm_size}' on location "2004 f"'{location}', using the raw string as vm size name."2005 )2006 allowed_vm_sizes = [node_runbook.vm_size]2007 else:2008 location_info = self.get_location_info(location, log)2009 allowed_vm_sizes = [key for key, _ in location_info.capabilities.items()]2010 # build the capability of vm sizes. The information is useful to...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!