How to use reboot_server method in tempest

Best Python code snippet using tempest_python

utility_restart_circuits.py

Source:utility_restart_circuits.py Github

copy

Full Screen

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:...

Full Screen

Full Screen

monitor.py

Source:monitor.py Github

copy

Full Screen

...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()...

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 tempest 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