Best Python code snippet using autotest_python
constants.py
Source:constants.py
1#2# (c) Copyright 2015-2017 Hewlett Packard Enterprise Development Company LP3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15#.16from eon.hlm_facade import exception17COMMIT_MESSAGE = "[%s]: EON commit - %s"18# hlm facade endpoints19FACADE_BASE_URL = "/api/v1/hlm"20MODEL = "/model"21INPUT_MODEL_URL = FACADE_BASE_URL + MODEL22EXPANDED_INPUT_MODEL_URL = INPUT_MODEL_URL + "/expanded"23SERVERS_URL = FACADE_BASE_URL + MODEL + "/entities/servers"24INTERFACES_URL = FACADE_BASE_URL + MODEL + "/entities/interface-models"25CONTROLPLANES_URL = FACADE_BASE_URL + MODEL + "/entities/control-planes"26NETWORKS_URL = FACADE_BASE_URL + MODEL + "/entities/networks"27NETWORKS_GROUPS_URL = FACADE_BASE_URL + MODEL + "/entities/network-groups"28SERVER_GROUPS_URL = FACADE_BASE_URL + MODEL + "/entities/server-groups"29INTERFACES_URL = FACADE_BASE_URL + MODEL + "/entities/interface-models"30PASS_THROUGH_URL = FACADE_BASE_URL + MODEL + "/entities/pass-through"31EXPANDED_INPUT_MODEL_SERVERS = EXPANDED_INPUT_MODEL_URL + "/servers"32COMMIT_URL = FACADE_BASE_URL + MODEL + "/commit"33REVERT_URL = FACADE_BASE_URL + MODEL + "/changes"34CP_OUTPUT_SERVER_INFO = FACADE_BASE_URL + MODEL + "/cp_output/server_info_yml"35PLAYBOOKS = "/playbooks"36HLM_PLAYBOOKS = FACADE_BASE_URL + PLAYBOOKS37CONFIG_PROCESSOR_RUN = HLM_PLAYBOOKS + "/config_processor_run"38READY_DEPLOYMENT = HLM_PLAYBOOKS + "/ready_deployment"39SITE = HLM_PLAYBOOKS + "/site"40HLM_START = HLM_PLAYBOOKS + "/hlm_start"41HLM_STOP = HLM_PLAYBOOKS + "/hlm_stop"42HLM_STATUS = HLM_PLAYBOOKS + "/hlm_status"43PLAYS = FACADE_BASE_URL + "/plays"44PLAYBOOK_MAP = {'site': HLM_PLAYBOOKS + '/site',45 'hlm_start': HLM_PLAYBOOKS + '/hlm_start',46 'hlm_stop': HLM_PLAYBOOKS + '/hlm_stop',47 'hlm_status': HLM_PLAYBOOKS + '/hlm_status',48 'hlm_ssh_configure':49 HLM_PLAYBOOKS + '/hlm_ssh_configure',50 'hlm_post_deactivation':51 HLM_PLAYBOOKS + '/hlm_post_deactivation',52 'hlm_remove_cobbler_node':53 HLM_PLAYBOOKS + '/hlm_remove_cobbler_node',54 'osconfig': HLM_PLAYBOOKS + '/osconfig_run',55 'guard_deployment': HLM_PLAYBOOKS + '/guard_deployment',56 'wipe_disks': HLM_PLAYBOOKS + '/wipe_disks',57 'hlm_deploy': HLM_PLAYBOOKS + '/hlm_deploy',58 'monasca-deploy': HLM_PLAYBOOKS + '/monasca-deploy',59 'neutron-reconfigure': HLM_PLAYBOOKS + '/neutron-reconfigure',60 'nova-reconfigure': HLM_PLAYBOOKS + '/nova-reconfigure'}61OSINSTALL = FACADE_BASE_URL + "/osinstall"62# API retry constants63RETRY_COUNT = 7064MAX_INTERVAL = 6065ESX_TIMEOUT_PER_HOST = 90066HANDLED_EXCEPTIONS = [exception.GetException]67COMPLETE = "complete"68READY = "ready"69INSTALLING = "installing"70PWR_ERROR = "pwr_error"71REMOVE = "remove"72INTERMEDIATE_INSTALL_STATES = [READY, INSTALLING]...
automation.py
Source:automation.py
1from config import *2from utilities import *3import json4import yaml5import time6# LABS7def createLab(getTitle: str):8 title = getTitle9 endpoint = "/labs?title={}".format(title)10 URL = url(endpoint)11 print("Creating Lab with title '{}' ...".format(title))12 resp = req.post(URL, headers=headers, verify=False)13 idlab = resp.json()14 return idlab['id']15# NODES16def createNode(getId, data):17 id_labs = getId18 print("id lab: {}".format(id_labs))19 endpoint = "/labs/{}/nodes".format(id_labs)20 URL = url(endpoint)21 payload = json.dumps({22 "x": data['x'],23 "y": data['y'],24 "label": data['label'],25 "configuration": data['configuration'],26 "node_definition": data['node_definition'],27 "image_definition": data['image_definition'],28 "ram": None,29 "cpus": None,30 "cpu_limit": None,31 "data_volume": None,32 "boot_disk_size": None,33 "tags": [34 ""35 ]36 })37 print("Creating node in lab with id {}...".format(id_labs))38 resp = req.post(URL, headers=headers, data=payload, verify=False)39 return resp.text40def updateConfigNodes(getId, getNode, fileConfig):41 id_labs = getId42 print("id lab: {}".format(id_labs))43 node = getNode 44 config = fileConfig 45 f = open(config, 'r')46 payload = f.read()47 f.close()48 endpoint = "/labs/{}/nodes/{}/wipe_disks".format(id_labs, node)49 URL = url(endpoint)50 req.put(URL, headers=headers, verify=False)51 endpoint = "/labs/{}/nodes/{}/config".format(id_labs, node)52 URL = url(endpoint)53 headers['Content-Type'] = "text/plain"54 resp = req.put(URL, headers=headers, data=payload, verify=False)55 return resp.text56# INTERFACES57def createInterfaces(getId, data):58 id_labs = getId59 print("id lab: {}".format(id_labs))60 endpoint = "/labs/{}/nodes/{}/wipe_disks".format(id_labs, data['node'])61 URL = url(endpoint)62 req.put(URL, headers=headers, verify=False)63 endpoint = "/labs/{}/interfaces".format(id_labs)64 URL = url(endpoint)65 payload = json.dumps({66 'node': data['node'],67 'slot': data['slot']68 })69 print("Creating interface on node {} in lab with id {}...".format(data['node'],id_labs))70 resp = req.post(URL, headers=headers, data=payload, verify=False)71 return resp.text72# LINKS73def createLinks(getId, data):74 id_labs = getId75 print("id lab: {}".format(id_labs))76 endpoint = "/labs/{}/links".format(id_labs)77 URL = url(endpoint)78 payload = json.dumps({79 'src_int': data['src_int'],80 'dst_int': data['dst_int']81 })82 print("Creating links in lab with id {}...".format(id_labs))83 resp = req.post(URL, headers=headers, data=payload, verify=False)...
Nodes.py
Source:Nodes.py
1from config import *2from utilities import *3from Labs import getIdLab4import json5def createNode():6 id_labs = getIdLab('create node in')7 print("id lab: {}".format(id_labs))8 endpoint = "/labs/{}/nodes".format(id_labs)9 URL = url(endpoint)10 x = input("x: ")11 y = input("y: ")12 label = input('label: ')13 configuration = input('configuration: ')14 node_definition = input("node_definition: ")15 image_definition = input("image_definition: ")16 data = json.dumps({17 "x": int(x),18 "y": int(y),19 "label": label,20 "configuration": configuration,21 "node_definition": node_definition,22 "image_definition": image_definition,23 "ram": None,24 "cpus": None,25 "cpu_limit": None,26 "data_volume": None,27 "boot_disk_size": None,28 "tags": [29 ""30 ]31 })32 print("Creating node in lab with id {}...".format(id_labs))33 resp = req.post(URL, headers=headers, data=data, verify=False)34 print(resp.text)35def updateConfigNodes():36 id_labs = getIdLab('update configuration node in')37 print("id lab: {}".format(id_labs))38 node = input("node: ")39 config = input("config path file: ")40 f = open(config, 'r')41 payload = f.read()42 f.close()43 endpoint = "/labs/{}/nodes/{}/wipe_disks".format(id_labs, node)44 URL = url(endpoint)45 req.put(URL, headers=headers, verify=False)46 endpoint = "/labs/{}/nodes/{}/config".format(id_labs, node)47 URL = url(endpoint)48 headers['Content-Type'] = "text/plain"49 resp = req.put(URL, headers=headers, data=payload, verify=False)50 print(resp.text)51def deleteNode():52 id_labs = getIdLab('delete node in')53 print("id lab: {}".format(id_labs))54 node = input("node: ")55 endpoint = "/labs/{}/nodes/{}/wipe_disks".format(id_labs, node)56 URL = url(endpoint)57 req.put(URL, headers=headers, verify=False)58 endpoint = "/labs/{}/nodes/{}".format(id_labs, node)59 URL = url(endpoint)60 resp = req.delete(URL, headers=headers, verify=False)...
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!!