How to use _verify_package_result method in lisa

Best Python code snippet using lisa_python

operating_system.py

Source:operating_system.py Github

copy

Full Screen

...1091 # replace $releasever to 8 for 8.x1092 if major == 8:1093 sed = self._node.tools[Sed]1094 sed.substitute("$releasever", "8", "/etc/yum.repos.d/epel*.repo", sudo=True)1095 def _verify_package_result(self, result: ExecutableResult, packages: Any) -> None:1096 # yum returns exit_code=1 if DNF handled an error with installation.1097 # We do not want to fail if exit_code=1, but warn since something may1098 # potentially have gone wrong.1099 if result.exit_code == 1:1100 self._log.debug(f"DNF handled error with installation of {packages}")1101 elif result.exit_code == 0:1102 self._log.debug(f"{packages} is/are installed successfully.")1103 else:1104 raise LisaException(1105 f"Failed to install {packages}. exit_code: {result.exit_code}"1106 )1107 def group_install_packages(self, group_name: str) -> None:1108 # trigger to run _initialize_package_installation1109 self._get_package_list(group_name)1110 result = self._node.execute(f'yum -y groupinstall "{group_name}"', sudo=True)1111 self._verify_package_result(result, group_name)1112 def _get_information(self) -> OsInformation:1113 cmd_result = self._node.execute(1114 # Typical output of 'cat /etc/fedora-release' is -1115 # Fedora release 22 (Twenty Two)1116 cmd="cat /etc/fedora-release",1117 no_error_log=True,1118 expected_exit_code=0,1119 expected_exit_code_failure_message="error on get os information",1120 )1121 full_version = cmd_result.stdout1122 if "Fedora" not in full_version:1123 raise LisaException("OS version information not found")1124 vendor = "Fedora"1125 release = get_matched_str(full_version, self._fedora_release_pattern_version)1126 codename = get_matched_str(full_version, self._distro_codename_pattern)1127 information = OsInformation(1128 version=self._parse_version(release),1129 vendor=vendor,1130 release=release,1131 codename=codename,1132 full_version=full_version,1133 )1134 return information1135class Redhat(Fedora):1136 # Red Hat Enterprise Linux Server release 6.9 (Santiago)1137 # CentOS release 6.9 (Final)1138 # CentOS Linux release 8.3.20111139 __legacy_redhat_information_pattern = re.compile(1140 r"^(?P<vendor>.*?)?(?: Enterprise Linux Server)?(?: Linux)?"1141 r"(?: release)? (?P<version>[0-9\.]+)(?: \((?P<codename>.*).*\))?$"1142 )1143 # Oracle Linux Server1144 # Red Hat Enterprise Linux Server1145 # Red Hat Enterprise Linux1146 __vendor_pattern = re.compile(1147 r"^(?P<vendor>.*?)?(?: Enterprise)?(?: Linux)?(?: Server)?$"1148 )1149 @classmethod1150 def name_pattern(cls) -> Pattern[str]:1151 return re.compile("^rhel|Red|AlmaLinux|Rocky|Scientific|acronis|Actifio$")1152 def replace_boot_kernel(self, kernel_version: str) -> None:1153 # Redhat kernel is replaced when installing RPM. For source code1154 # installation, it's implemented in source code installer.1155 ...1156 def capture_system_information(self, saved_path: Path) -> None:1157 super().capture_system_information(saved_path)1158 self._node.shell.copy_back(1159 self._node.get_pure_path("/etc/redhat-release"),1160 saved_path / "redhat-release.txt",1161 )1162 @retry(tries=10, delay=5)1163 def _initialize_package_installation(self) -> None:1164 information = self._get_information()1165 # We may hit issue when run any yum command, caused by out of date1166 # rhui-microsoft-azure-rhel package.1167 # Use below command to update rhui-microsoft-azure-rhel package from microsoft1168 # repo to resolve the issue.1169 # Details please refer https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/redhat/redhat-rhui#azure-rhui-infrastructure # noqa: E5011170 if "Red Hat" == information.vendor:1171 self._node.execute(1172 "yum update -y --disablerepo='*' --enablerepo='*microsoft*' ",1173 sudo=True,1174 expected_exit_code=0,1175 )1176 def _install_packages(1177 self,1178 packages: List[str],1179 signed: bool = True,1180 timeout: int = 600,1181 extra_args: Optional[List[str]] = None,1182 ) -> None:1183 add_args = self._process_extra_package_args(extra_args)1184 command = f"yum install {add_args} -y {' '.join(packages)}"1185 if not signed:1186 command += " --nogpgcheck"1187 install_result = self._node.execute(1188 command, shell=True, sudo=True, timeout=timeout1189 )1190 # RedHat will fail package installation is a single missing package is1191 # detected, therefore we check the output to see if we were missing1192 # a package. If so, fail. Otherwise we will warn in verify package result.1193 if install_result.exit_code == 1:1194 missing_packages = []1195 for line in install_result.stdout.splitlines():1196 if line.startswith("No match for argument:"):1197 package = line.split(":")[1].strip()1198 missing_packages.append(package)1199 if missing_packages:1200 raise MissingPackagesException(missing_packages)1201 super()._verify_package_result(install_result, packages)1202 def _package_exists(self, package: str) -> bool:1203 command = f"yum list installed {package}"1204 result = self._node.execute(command, sudo=True)1205 if result.exit_code == 0:1206 return True1207 return False1208 def _is_package_in_repo(self, package: str) -> bool:1209 command = f"yum --showduplicates list {package}"1210 result = self._node.execute(command, sudo=True, shell=True)1211 return 0 == result.exit_code1212 def _get_information(self) -> OsInformation:1213 # The higher version above 7.0 support os-version.1214 try:1215 information = super(Fedora, self)._get_information()...

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