How to use verify_ifcfg_eth0 method in lisa

Best Python code snippet using lisa_python

BVT-VERIFY-VHD-PREREQUISITES.py

Source:BVT-VERIFY-VHD-PREREQUISITES.py Github

copy

Full Screen

...119 else:120 RunLog.error("File not present")121 print(distro+"_TEST_NETWORK_FILE_ERROR")122 return False123def verify_ifcfg_eth0(distro):124 RunLog.info("Verifying contents of ifcfg-eth0 file")125 if distro == "CENTOS" or distro == "ORACLELINUX" or distro == "REDHAT" or distro == "FEDORA":126 i_out = Run("cat /etc/sysconfig/network-scripts/ifcfg-eth0")127 i_out = i_out.replace('"', '')128 #if "DEVICE=eth0" in i_out and "ONBOOT=yes" in i_out and "BOOTPROTO=dhcp" in i_out and "DHCP=yes" in i_out:129 if "DEVICE=eth0" in i_out and "ONBOOT=yes" in i_out and "BOOTPROTO=dhcp" in i_out :130 RunLog.info("all required parameters exists.")131 print(distro+"_TEST_IFCFG_ETH0_FILE_SUCCESS")132 return True133 else:134 if "DEVICE=eth0" not in i_out:135 RunLog.error("DEVICE=eth0 not present in ifcfg-eth0")136 if "ONBOOT=yes" not in i_out:137 RunLog.error("ONBOOT=yes not present in ifcfg-eth0")138 if "BOOTPROTO=dhcp" not in i_out:139 RunLog.error("BOOTPROTO=dhcp not present in ifcfg-eth0")140 #if "DHCP=yes" not in i_out:141 # RunLog.error("DHCP=yes not present in ifcfg-eth0")142 print(distro+"_TEST_IFCFG_ETH0_FILE_ERROR")143 return False144def verify_udev_rules(distro):145 import os.path146 RunLog.info("Verifying if udev rules are moved to /var/lib/waagent/")147 if distro == "CENTOS" or distro == "ORACLELINUX" or distro == "REDHAT" or distro == "FEDORA":148 if not os.path.isfile("/lib/udev/rules.d/75-persistent-net-generator.rules") and not os.path.isfile("/etc/udev/rules.d/70-persistent-net.rules"):149 RunLog.info("rules are moved.")150 print(distro+"_TEST_UDEV_RULES_SUCCESS")151 return True152 else:153 if os.path.isfile("/lib/udev/rules.d/75-persistent-net-generator.rules"):154 RunLog.error("/lib/udev/rules.d/75-persistent-net-generator.rules file present")155 if os.path.isfile("/etc/udev/rules.d/70-persistent-net.rules"):156 RunLog.error("/etc/udev/rules.d/70-persistent-net.rules file present")157 print(distro+"_TEST_UDEV_RULES_ERROR")158 return False159 if distro == "COREOS":160 if not os.path.isfile("/usr/lib64/udev/rules.d/75-persistent-net-generator.rules") and not os.path.isfile("/usr/lib64/udev/rules.d/70-persistent-net.rules"):161 RunLog.info("rules are moved.")162 print(distro+"_TEST_UDEV_RULES_SUCCESS")163 return True164 else:165 if os.path.isfile("/usr/lib64/udev/rules.d/75-persistent-net-generator.rules"):166 RunLog.error("/usr/lib64/udev/rules.d/75-persistent-net-generator.rules file present")167 if os.path.isfile("/usr/lib64/udev/rules.d/70-persistent-net.rules"):168 RunLog.error("/usr/lib64/udev/rules.d/70-persistent-net.rules file present")169 print(distro+"_TEST_UDEV_RULES_ERROR")170 return False171if distro == "UBUNTU":172 RunLog.info("DISTRO PROVIDED : "+distro)173 #Test 1 : verify that hv-kvp-daemon-init is installed or not, it's optional not strict.174 RunLog.info("Checking if hv-kvp-daemon-init is installed or not..")175 #kvp_install_status = Run("dpkg -s hv-kvp-daemon-init")176 kvp_install_status = Run("pgrep -lf hv_kvp_daemon")177 matchCount = 0178 if "hv_kvp_daemon" in kvp_install_status:179 matchCount = matchCount + 1180 if matchCount == 1:181 print(distro+"_TEST_KVP_INSTALLED")182 else:183 print(distro+"_TEST_KVP_NOT_INSTALLED")184 #Test 2 : Make sure that repositories are installed.185 RunLog.info("Checking if repositories are installed or not..")186 repository_out = Run("apt-get update")187 if "security.ubuntu.com" in repository_out and "azure.archive.ubuntu.com" in repository_out and "Hit" in repository_out:188 print(distro+"_TEST_REPOSITORIES_AVAILABLE")189 else:190 print(distro+"_TEST_REPOSITORIES_ERROR")191 #Test 3 : Make sure to have console=ttyS0 rootdelay=300 in /etc/default/grub.192 result = verify_grub(distro)193 #Test 4 : Make sure that default targetpw is commented in /etc/sudoers file.194 result = verify_default_targetpw(distro)195if distro == "DEBIAN":196 RunLog.info("DISTRO PROVIDED : "+distro)197 #Test 1 : verify that hv-kvp-daemon-init is installed or not, it's optional not strict.198 RunLog.info("Checking if hv-kvp-daemon-init is installed or not..")199 kvp_install_status = Run("pgrep -lf hv_kvp_daemon")200 matchCount = 0201 if "hv_kvp_daemon" in kvp_install_status:202 matchCount = matchCount + 1203 if matchCount == 1:204 print(distro+"_TEST_KVP_INSTALLED")205 else:206 print(distro+"_TEST_KVP_NOT_INSTALLED")207 #Test 2 : Make sure that repositories are installed.208 RunLog.info("Checking if repositories are installed or not..")209 repository_out = Run("apt-get update")210 if ( "deb.debian.org" in repository_out or "debian-archive.trafficmanager.net" in repository_out ) and "Hit" in repository_out:211 print(distro+"_TEST_REPOSITORIES_AVAILABLE")212 else:213 print(distro+"_TEST_REPOSITORIES_ERROR")214 #Test 3 : Make sure that default targetpw is commented in /etc/sudoers file.215 result = verify_default_targetpw(distro)216 217if distro == "SUSE":218 #Make sure that distro contains Cloud specific repositories219 RunLog.info("Verifying Cloud specific repositories")220 Oss_repo_count = Run("zypper lr | grep -vi debug | grep -vi non | grep Oss | wc -l | tr -d '\n'")221 Update_repo_count = Run("zypper lr | grep -vi debug | grep -vi non | grep Update | wc -l | tr -d '\n'")222 Oss_repo_enable_refresh = Run("zypper lr | grep -vi debug | grep -vi non | grep Oss | grep -o Yes | wc -l | tr -d '\n'")223 Update_repo_enable_refresh = Run("zypper lr | grep -vi debug | grep -vi non | grep Update | grep -o Yes | wc -l | tr -d '\n'")224 if int(Oss_repo_count) > 0 and int(Update_repo_count) > 0:225 RunLog.info("All expected repositories are present")226 if int(Oss_repo_enable_refresh) >= 2 and int(Update_repo_enable_refresh) >= 2:227 RunLog.info("All expected repositories are enabled and refreshed")228 print(distro+"_TEST_REPOSITORIES_AVAILABLE")229 else:230 RunLog.error("One or more expected repositories are not enabled/refreshed.")231 print(distro+"_TEST_REPOSITORIES_ERROR")232 else:233 RunLog.error("One or more expected repositories are not present")234 print(distro+"_TEST_REPOSITORIES_ERROR")235 236 #Verify Grub237 result = verify_grub(distro)238 #Test : Make sure that default targetpw is commented in /etc/sudoers file.239 result = verify_default_targetpw(distro)240if distro == "CENTOS":241 #Test 1 : Make sure Network Manager is not installed242 result = verify_network_manager(distro)243 result = verify_network_file_in_sysconfig(distro)244 result = verify_ifcfg_eth0(distro)245 result = verify_udev_rules(distro)246 #Verify repositories247 r_out = Run("yum repolist")248 if "base" in r_out and "updates" in r_out:249 RunLog.info("Expected repositories are present")250 print(distro+"_TEST_REPOSITORIES_AVAILABLE")251 else:252 if "base" not in r_out:253 RunLog.error("Base repository not present")254 if "updates" not in r_out:255 RunLog.error("Updates repository not present")256 print(distro+"_TEST_REPOSITORIES_ERROR")257 #Verify etc/yum.conf258 y_out = Run("cat /etc/yum.conf")259 # check http_caching=packages in yum.conf for CentOS 6.x260 version_release = Run("cat /etc/system-release | grep -Eo '[0-9].?[0-9]?' | head -1 | tr -d '\n'")261 if float(version_release) < 6.6:262 if "http_caching=packages" in y_out:263 RunLog.info("http_caching=packages present in /etc/yum.conf")264 print(distro+"_TEST_YUM_CONF_SUCCESS")265 else:266 RunLog.error("http_caching=packages not present in /etc/yum.conf")267 print(distro+"_TEST_YUM_CONF_ERROR")268 else:269 print(distro+"_TEST_YUM_CONF_SUCCESS")270 result = verify_grub(distro)271if distro == "REDHAT" or distro == "FEDORA":272 #Test 1 : Make sure Network Manager is not installed273 result = verify_default_targetpw(distro)274 result = verify_network_manager(distro)275 result = verify_network_file_in_sysconfig(distro)276 result = verify_ifcfg_eth0(distro)277 result = verify_udev_rules(distro)278 #Verify repositories279 r_out = Run("yum repolist")280 if "base" in r_out and "updates" in r_out:281 RunLog.info("Expected repositories are present")282 print(distro+"_TEST_REPOSITORIES_AVAILABLE")283 else:284 if "base" not in r_out:285 RunLog.error("Base repository not present")286 if "updates" not in r_out:287 RunLog.error("Updates repository not present")288 print(distro+"_TEST_REPOSITORIES_ERROR")289 if distro == "REDHAT":290 ra_out = Run("yum repolist all | grep 'rhui-rhel-' | wc -l")291 if(ra_out > 5):292 RunLog.info("yum repolist all status: Success, repo count = %s", ra_out)293 print(distro+"_TEST_RHUIREPOSITORIES_AVAILABLE")294 else:295 RunLog.error("yum repolist all status: Fail, repo count = %s", ra_out)296 print(distro+"_TEST_RHUIREPOSITORIES_ERROR")297 #Verify etc/yum.conf298 version_release = Run("cat /etc/system-release | grep -Eo '[0-9].?[0-9]?' | head -1 | tr -d '\n'")299 if float(version_release) < 6.6:300 if "http_caching=packages" in y_out:301 RunLog.info("http_caching=packages present in /etc/yum.conf")302 print(distro+"_TEST_YUM_CONF_SUCCESS")303 else:304 RunLog.error("http_caching=packages not present in /etc/yum.conf")305 print(distro+"_TEST_YUM_CONF_ERROR")306 else:307 print(distro+"_TEST_YUM_CONF_SUCCESS")308 result = verify_grub(distro)309if distro == "ORACLELINUX":310 #Test 1 : Make sure Network Manager is not installed311 result = verify_network_manager(distro)312 result = verify_network_file_in_sysconfig(distro)313 result = verify_ifcfg_eth0(distro)314 result = verify_udev_rules(distro)315 #Verify repositories316 r_out = Run("yum repolist")317 if "latest" in r_out:318 RunLog.info("Expected latest repositories are present")319 print(distro+"_TEST_REPOSITORIES_AVAILABLE")320 else:321 RunLog.error("Expected latest repository not present")322 print(distro+"_TEST_REPOSITORIES_ERROR")323 # no need to verify yum.conf since http_caching is not required for Oracle Linux.324 result = verify_grub(distro)325if distro == "SLES":326 #Verify Repositories..327 r_out = Run("zypper lr")...

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