def load_json_data(self, data): try: return json.loads(data) except json.decoder.JSONDecodeError: logger.error( 'Unable to convert following data to json: \n{}'.format(data)) sys.exit(1)
def set_power_state(self, state): """ Set power state to passed state """ attempts = 0 while attempts < 5: try: ipmi_object = self.initialize_ipmi_session() ipmi_object.set_power(state) break except IpmiException as iex: logger.error("Error sending command: %s" % str(iex)) logger.warning( "IPMI command failed, retrying after 15 seconds...") sleep(15) attempts = attempts + 1
def set_power_state(self, state): """ Set power state to passed state """ attempts = 0 ipmi_object = None while attempts < 5: try: ipmi_object = self.initialize_ipmi_session() response = ipmi_object.set_power(state) status = True break except IpmiException as iex: logger.error("Error sending command: %s" % str(iex)) logger.warning( "IPMI command failed, retrying after 15 seconds...") if ipmi_object: ipmi_object.ipmi_session.logout() sleep(15) attempts = attempts + 1 status = False return response, status
def get_openstack_token(self): """ Get openstack token """ logger.info('Get openstack token started') data_template = Template(OPENSTACK_TOKEN) data = data_template.substitute(self.auth) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } url = self.auth['auth_url'] + '/auth/tokens' response = requests.post(url, headers=headers, data=data, verify=False) self.token = response.headers.get('X-Subject-Token', None) response_dict = self.load_json_data(response.text) # Handle error in case token fails if response.status_code == 201: self.tenant_id = response_dict['token']['project']['id'] logger.info('Get openstack token completed successfully') else: logger.error('Get openstack token failed') return self.token
if __name__ == "__main__": inputs = sys.argv auth = ast.literal_eval(inputs[1]) component = inputs[2] duration = int(inputs[3]) count = int(inputs[4]) if inputs[5]: nodes = ast.literal_eval(inputs[5]) else: nodes = [] if inputs[6]: extra_args = ast.literal_eval(inputs[6]) else: extra_args = [] if inputs[7]: pod_labels = ast.literal_eval(inputs[7]) else: pod_labels = [] run = Runner() logger.info('Starting with test case execution') testcases = json.loads(open("testcases.json", "r").read()) testcases[component]["duration"] = duration testcases[component]["repeat"] = count try: run.execute(auth, testcases[component], nodes, extra_args, pod_labels) except Exception as e: logger.error("%s: %s" % (e.__class__.__name__, e)) logger.error(traceback.print_exc())