Best Python code snippet using lisa_python
platform_.py
Source:platform_.py
...1086 # no validate_operation returned, the message may include1087 # some errors, so check details1088 error_messages = self._parse_detail_errors(identifier.error)1089 error_message = "\n".join(error_messages)1090 plugin_manager.hook.azure_deploy_failed(error_message=error_message)1091 raise LisaException(error_message)1092 def _deploy(1093 self, location: str, deployment_parameters: Dict[str, Any], log: Logger1094 ) -> None:1095 resource_group_name = deployment_parameters[AZURE_RG_NAME_KEY]1096 storage_account_name = get_storage_account_name(self.subscription_id, location)1097 check_or_create_storage_account(1098 self.credential,1099 self.subscription_id,1100 storage_account_name,1101 self._azure_runbook.shared_resource_group_name,1102 location,1103 log,1104 )1105 log.info(f"resource group '{resource_group_name}' deployment is in progress...")1106 deployment_operation: Any = None1107 deployments = self._rm_client.deployments1108 try:1109 deployment_operation = deployments.begin_create_or_update(1110 **deployment_parameters1111 )1112 wait_operation(deployment_operation, failure_identity="deploy")1113 except HttpResponseError as identifier:1114 # Some errors happens underlying, so there is no detail errors from API.1115 # For example,1116 # azure.core.exceptions.HttpResponseError:1117 # Operation returned an invalid status 'OK'1118 assert identifier.error, f"HttpResponseError: {identifier}"1119 error_message = "\n".join(self._parse_detail_errors(identifier.error))1120 if (1121 self._azure_runbook.ignore_provisioning_error1122 and "OSProvisioningTimedOut: OS Provisioning for VM" in error_message1123 ):1124 # Provisioning timeout causes by waagent is not ready.1125 # In smoke test, it still can verify some information.1126 # Eat information here, to run test case any way.1127 #1128 # It may cause other cases fail on assumptions. In this case, we can1129 # define a flag in config, to mark this exception is ignorable or not.1130 log.error(1131 f"provisioning time out, try to run case. "1132 f"Exception: {error_message}"1133 )1134 elif self._azure_runbook.ignore_provisioning_error and get_matched_str(1135 error_message, AZURE_INTERNAL_ERROR_PATTERN1136 ):1137 # Similar situation with OSProvisioningTimedOut1138 # Some OSProvisioningInternalError caused by it doesn't support1139 # SSH key authentication1140 # e.g. hpe hpestoreoncevsa hpestoreoncevsa-3187 3.18.71141 # After passthrough this exception,1142 # actually the 22 port of this VM is open.1143 log.error(1144 f"provisioning failed for an internal error, try to run case. "1145 f"Exception: {error_message}"1146 )1147 else:1148 plugin_manager.hook.azure_deploy_failed(error_message=error_message)1149 raise LisaException(error_message)1150 def _parse_detail_errors(self, error: Any) -> List[str]:1151 # original message may be a summary, get lowest level details.1152 if hasattr(error, "details") and error.details:1153 errors: List[str] = []1154 for detail in error.details:1155 errors.extend(self._parse_detail_errors(detail))1156 else:1157 try:1158 # it returns serialized json string in message sometime1159 parsed_error = json.loads(1160 error.message, object_hook=lambda x: SimpleNamespace(**x)1161 )1162 errors = self._parse_detail_errors(parsed_error.error)...
hooks.py
Source:hooks.py
...10 plugin_manager,11)12class AzureHookSpec:13 @hookspec14 def azure_deploy_failed(self, error_message: str) -> None:15 """16 It can be used to skipped some by design failed deployment, such as deploy gen117 image on gen2 vm_size.18 """19 ...20 @hookspec21 def azure_update_arm_template(22 self, template: Any, environment: Environment23 ) -> None:24 """25 Implement it to update loaded arm_template.26 Args:27 template: the dict object, which is loaded from the arm_template.json.28 environment: the deploying environment.29 """30 ...31class AzureHookSpecDefaultImpl:32 __error_maps: List[Tuple[str, Pattern[str], Any]] = [33 (34 "gen1 image shouldn't run on gen2 vm size",35 re.compile(36 "^BadRequest: The selected VM size '.+?' "37 "cannot boot Hypervisor Generation '1'\\."38 ),39 SkippedException,40 ),41 (42 # QuotaExceeded: Operation could not be completed as it results in43 # exceeding approved standardMSFamily Cores quota. Additional44 # details - Deployment Model: Resource Manager, Location: westus2,45 # Current Limit: 1000, Current Usage: 896, Additional Required: 128,46 # (Minimum) New Limit Required: 1024. Submit a request for Quota47 # increase at48 # https://aka.ms/ProdportalCRP/#blade/Microsoft_Azure_Capacity/...........49 # by specifying parameters listed in the âDetailsâ section for50 # deployment to succeed. Please read more about quota limits at51 # https://docs.microsoft.com/en-us/azure/azure-supportability/per-vm-quota-requests52 "",53 # If current usage is 0, it means current limit cannot fit the54 # deployment. So, the deployment won't pass without larger limit.55 # For example, limit is 100, but the environment needs 128. It's56 # impossible to wait for enough.57 re.compile(58 r"Additional details - Deployment Model: .* Current Usage: (?!0).+, "59 r"Additional Required: \d+,"60 ),61 ResourceAwaitableException,62 ),63 (64 # AllocationFailed: Allocation failed. We do not have sufficient65 # capacity for the requested VM size in this region. Read more about66 # improving likelihood of allocation success at67 # http://aka.ms/allocation-guidance68 "",69 re.compile(r"^AllocationFailed: Allocation failed."),70 partial(ResourceAwaitableException, "vm size"),71 ),72 ]73 @hookimpl74 def azure_deploy_failed(self, error_message: str) -> None:75 for message, pattern, exception_type in self.__error_maps:76 if pattern.findall(error_message):77 raise exception_type(f"{message}. {error_message}")78plugin_manager.add_hookspecs(AzureHookSpec)...
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!!