Best Python code snippet using tempest_python
utility_restart_circuits.py
Source: utility_restart_circuits.py
1# -*- coding: utf-8 -*-2# pragma pylint: disable=unused-argument, no-self-use3# This function will restart Resilient Circuits.4# File: utility_restart_circuits.py5# Date: 04/26/2019 - Modified: 04/11/20206# Author: Jared F7"""Function implementation"""8# @function -> utility_restart_resilient_circuits9# @params -> boolean: reboot_server10# @return -> boolean: results['was_successful']11import os12import time13import shutil14import logging15import datetime16from resilient_circuits import ResilientComponent, function, handler, StatusMessage, FunctionResult, FunctionError17import utilities.util.selftest as selftest18class FunctionComponent(ResilientComponent):19 """Component that implements Resilient function 'utility_restart_resilient_circuits"""20 def __init__(self, opts):21 """constructor provides access to the configuration options"""22 super(FunctionComponent, self).__init__(opts)23 self.options = opts.get("utilities", {})24 @handler("reload")25 def _reload(self, event, opts):26 """Configuration options have changed, save new values"""27 self.options = opts.get("utilities", {})28 @function("utility_restart_resilient_circuits")29 def _utility_restart_resilient_circuits_function(self, event, *args, **kwargs):30 results = {}31 results["was_successful"] = False32 try:33 # Get the function parameters:34 reboot_server = kwargs.get("reboot_server") # boolean35 if os.path.exists('/home/integrations/.resilient/rc_restarted.lock') is False:36 open('/home/integrations/.resilient/rc_restarted.lock', 'w+').close()37 if os.path.exists('/home/integrations/.resilient/rc_restarted.lock') is False: raise IOError38 if reboot_server is True:39 yield StatusMessage('[INFO] Rebooting the Resilient integrations server...')40 os.system('reboot')41 else:42 yield StatusMessage('[INFO] Restarting the Resilient Circuits service...')43 os.system("sudo systemctl restart resilient_circuits.service") # Modify as needed44 else:45 os.remove('/home/integrations/.resilient/rc_restarted.lock')46 if reboot_server is True: yield StatusMessage('[SUCCESS] Reboot completed!')47 else: yield StatusMessage('[SUCCESS] Restart completed!')48 except Exception as err: # Catch all exceptions and abort49 try: os.remove('/home/integrations/.resilient/rc_restarted.lock')50 except: pass51 yield StatusMessage('[FATAL ERROR] Encountered: ' + str(err))52 yield StatusMessage('[FAILURE] Fatal error caused exit!')53 # Produce a FunctionResult with the results54 yield FunctionResult(results)55 except Exception:...
monitor.py
Source: monitor.py
...19 body = 'Make sure the server restarted and it is back up'20 msg = f'Subject: {subject}\n\n{body}'21 # logging.info('Sending Email...')22 smtp.sendmail(EMAIL_ADDRESS, 'INSERT_RECEIVER_ADDRESS', msg)23def reboot_server():24 client = LinodeClient(LINODE_TOKEN)25 my_server = client.load(Instance, 376715)26 my_server.reboot()27 # logging.info('Attempting to reboot server...')28try:29 r = requests.get('https://example.com', timeout=5)30 if r.status_code != 200:31 # logging.info('Website is DOWN!')32 notify_user()33 reboot_server()34 else:35 # logging.info('Website is UP')36except Exception as e:37 # logging.info('Website is DOWN!')38 notify_user()...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!