2022-11-20 12:47:58 +00:00
|
|
|
import os, sys,time
|
2022-11-20 10:57:48 +00:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
|
|
|
|
from myOpenstackApp.logger import log
|
|
|
|
|
|
|
|
|
|
|
|
import myOpenstackApp
|
|
|
|
testProjectName="SmokeTest"
|
|
|
|
testProjectExists=False
|
|
|
|
testProject=""
|
2022-11-20 11:41:29 +00:00
|
|
|
testNetwork=""
|
|
|
|
testSubnet=""
|
2022-11-20 12:47:58 +00:00
|
|
|
timingText=""
|
2022-11-20 11:41:29 +00:00
|
|
|
|
2022-11-20 10:57:48 +00:00
|
|
|
cleanupResourcesOnCompletion=True
|
|
|
|
|
|
|
|
y=myOpenstackApp.OSC
|
|
|
|
y.initalise()
|
2022-11-20 11:41:29 +00:00
|
|
|
y.ks.getCatalog()
|
2022-11-20 10:57:48 +00:00
|
|
|
# print(y.something())
|
|
|
|
# print(y._keystone)
|
|
|
|
log.info("Starting")
|
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
tic = time.perf_counter()
|
2022-11-20 10:57:48 +00:00
|
|
|
|
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
allProjects=y.ks.getAllProjects()
|
|
|
|
toc = time.perf_counter()
|
|
|
|
timingText +=(f"Queried keystone in {toc - tic:0.4f} seconds\n")
|
2022-11-20 10:57:48 +00:00
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
def sendFailureNotice(e,timingText):
|
|
|
|
log.error("JOB FAILED\n\n" + str(e))
|
|
|
|
log.error(timingText)
|
|
|
|
exit()
|
2022-11-20 10:57:48 +00:00
|
|
|
|
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
def cleanUp():
|
|
|
|
log.info("Cleaning up")
|
|
|
|
log.info("Deleting project")
|
|
|
|
y.ks.deleteProject(testProject['id'])
|
|
|
|
#Delete VM
|
|
|
|
#Delete router
|
|
|
|
#Delete Network
|
|
|
|
#Delete project
|
|
|
|
pass
|
2022-11-20 11:41:29 +00:00
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
try:
|
|
|
|
#Does my test project ID already exist?
|
|
|
|
for _project in allProjects['projects']:
|
|
|
|
if _project['name']==testProjectName:
|
|
|
|
testProject=_project
|
|
|
|
testProjectExists=True
|
2022-11-20 11:41:29 +00:00
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
if testProjectExists:
|
|
|
|
log.error("Test project already exists with ID " + testProject['id'])
|
2022-11-20 11:41:29 +00:00
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
else:
|
|
|
|
# Create test project
|
|
|
|
log.info("{} project does not exist, creating".format(testProjectName))
|
|
|
|
testProject=y.ks.createProject(testProjectName,"Description goes here")['project']
|
|
|
|
log.info("Test project created with ID " + testProject['id'])
|
2022-11-20 11:41:29 +00:00
|
|
|
|
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
toc = time.perf_counter()
|
|
|
|
timingText +=(f"Queried projects in {toc - tic:0.4f} seconds\n")
|
|
|
|
except Exception as e:
|
|
|
|
log.error("Error managing project" + str(e))
|
|
|
|
cleanUp()
|
|
|
|
sendFailureNotice(e,timingText)
|
|
|
|
|
|
|
|
try:
|
|
|
|
#Does my test network exist?
|
|
|
|
allNetworks=y.neutron.getAllNetworks(testProject['id'])
|
|
|
|
log.info(allNetworks)
|
|
|
|
|
|
|
|
#Does my test network ID already exist?
|
|
|
|
for _network in allNetworks['networks']:
|
|
|
|
if _network['name']==testProjectName+"_network":
|
|
|
|
testNetwork=_network
|
|
|
|
|
|
|
|
if testNetwork != "":
|
|
|
|
log.info("Test network already exists with ID " + testNetwork['id'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Create test network
|
|
|
|
log.info("{} network does not exist, creating".format(testProjectName))
|
|
|
|
testNetwork=y.neutron.createNetwork(testProjectName+"_network",testProject['id'],"Test network description")['network']
|
|
|
|
log.info("Test network created with ID " + testNetwork['id'])
|
|
|
|
|
|
|
|
#Create subnet
|
|
|
|
log.info("Creating new subnet")
|
|
|
|
testSubnet=y.neutron.createSubnet(testProjectName + "_subnet",testNetwork['id'])
|
|
|
|
log.debug(testSubnet)
|
|
|
|
|
|
|
|
#Create a test router
|
|
|
|
log.info("Creating new router")
|
|
|
|
testRouter=y.neutron.createRouter(testProjectName + "_router",os.getenv("EXTERNAL_NETWORK_ID"))
|
|
|
|
log.debug(testRouter)
|
|
|
|
toc = time.perf_counter()
|
|
|
|
timingText +=(f"Queried neutron in {toc - tic:0.4f} seconds")
|
|
|
|
except Exception as e:
|
|
|
|
log.error("Error managing network" + str(e))
|
|
|
|
toc = time.perf_counter()
|
|
|
|
timingText +=(f"Neutron failed after {toc - tic:0.4f} seconds\n")
|
2022-11-20 11:41:29 +00:00
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
cleanUp()
|
|
|
|
sendFailureNotice(e,timingText)
|
2022-11-20 11:41:29 +00:00
|
|
|
|
|
|
|
#Create
|
|
|
|
#Project
|
|
|
|
#Network
|
|
|
|
#Subnet
|
|
|
|
#Router
|
|
|
|
#bind router to network
|
|
|
|
#Volume from image
|
|
|
|
#Vm from volume
|
2022-11-20 10:57:48 +00:00
|
|
|
|
2022-11-20 12:47:58 +00:00
|
|
|
|
2022-11-20 10:57:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
if cleanupResourcesOnCompletion:
|
|
|
|
cleanUp()
|
2022-11-20 12:47:58 +00:00
|
|
|
|
|
|
|
toc = time.perf_counter()
|
|
|
|
log.info(f"Total runtime {toc - tic:0.4f} seconds")
|