def given_space_created(_context): global spaceID spaceID = helpers.getSpaceID() spaceID | should_not.be_none().desc("Space ID") global lb lb = LaunchBooster()
def given_space_created(_context): global spaceID spaceID = helpers.getSpaceID() spaceID | should_not.be_none().desc("Space ID exists.") global ib ib = ImportBooster()
def checkCodebases(self, maxAttempts=10): serverUrl = os.getenv("SERVER_ADDRESS") spaceId = helpers.getSpaceID() codebasesUrl = '{}/api/spaces/{}/codebases'.format(serverUrl, spaceId) theToken = helpers.get_user_tokens().split(";")[0] authHeader = 'Bearer {}'.format(theToken) headers = {'Accept': 'application/json', 'Authorization': authHeader, 'X-App': 'osio', 'X-Git-Provider': 'GitHub', 'Content-Type': 'application/x-www-form-urlencoded'} global boosterImported for i in range(1, int(maxAttempts) + 1): r = requests.get( codebasesUrl, headers=headers ) helpers.printToJson('Attempt to get codebases #{}:'.format(i), r) responseJson = r.json() data = responseJson['data'] cbCount = len(data) print('Codebases found: {}'.format(cbCount)) if cbCount > 0: boosterImported = True return True time.sleep(1) boosterImported = False return False
def importGithubRepo(self, gitRepo): ############################################### # Environment variables # # Note: Pipelines = https://forge.api.openshift.io/api/services/jenkins/pipelines # Tokens are stored in a form of "<access_token>;<refresh_token>(;<username>)" theToken = helpers.get_user_tokens().split(";")[0] projectName = os.getenv('PROJECT_NAME') pipeline = os.getenv('PIPELINE') spaceId = helpers.getSpaceID() authHeader = 'Bearer {}'.format(theToken) print('Starting test.....') ############################################### # Import the booster headers = {'Accept': 'application/json', 'Authorization': authHeader, 'X-App': 'osio', 'X-Git-Provider': 'GitHub', 'Content-Type': 'application/x-www-form-urlencoded'} data = {'gitRepository': gitRepo, 'projectName': projectName, 'pipeline': pipeline, 'space': spaceId} forgeApi = os.getenv("FORGE_API") print('Making request to import...') try: r = requests.post( '{}/api/osio/import'.format(forgeApi), headers=headers, data=data ) # print('request results = {}'.format(r.text)) helpers.printToJson('Import booster request response', r) result = r.text if re.search('uuid', result): return 'Success' else: return 'Fail' except Exception as e: print('Unexpected booster import exception found: {}'.format(e)) print('Raw text of request/response: [{}]'.format(r.text))
def getCodebaseUrl(self, maxAttempts=10): serverUrl = os.getenv("SERVER_ADDRESS") spaceId = helpers.getSpaceID() codebasesUrl = '{}/api/spaces/{}/codebases'.format(serverUrl, spaceId) theToken = helpers.get_user_tokens().split(";")[0] authHeader = 'Bearer {}'.format(theToken) headers = { 'Accept': 'application/json', 'Authorization': authHeader, 'X-App': 'OSIO', 'X-Git-Provider': 'GitHub', 'Content-Type': 'application/x-www-form-urlencoded' } for i in range(1, 2): r = requests.get(codebasesUrl, headers=headers) helpers.printToJson('Attempt to get codebases #{}:'.format(i), r) responseJson = r.json() data = responseJson['data'][0]['attributes']['url'] time.sleep(5) return data
def given_space_created(_context): _context.spaceID = helpers.getSpaceID() _context.spaceID | should_not.be_none().desc("Space ID exists.") _context.ib = ImportBooster()
def when_create_workspace(_context): spaceID = helpers.getSpaceID() workspace = Workspace() workspaceID = workspace.createWorkspaceForSpace(spaceID) helpers.setWorkspaceID(workspaceID)
def launch(self, projectName, mission="rest-http", runtime="vert.x", version="redhat", pipeline="maven-releasestageapproveandpromote", blankBooster="false"): ############################################### # Environment variables # Tokens are stored in a form of "<access_token>;<refresh_token>(;<username>)" theToken = helpers.get_user_tokens().split(";")[0] spaceId = helpers.getSpaceID() spaceName = helpers.getSpaceName() authHeader = 'Bearer {}'.format(theToken) gitRepo = '{}-{}'.format(spaceName, projectName) helpers.setGithubRepo(gitRepo) print('Starting test.....') ############################################### # Launch the booster headers = { 'Accept': 'application/json', 'Authorization': authHeader, 'X-App': 'OSIO', 'X-Git-Provider': 'GitHub', 'Content-Type': 'application/x-www-form-urlencoded' } data = { 'emptyGitRepository': blankBooster, # true for blank booster 'mission': mission, 'runtime': runtime, 'runtimeVersion': version, 'pipeline': pipeline, 'projectName': projectName, 'projectVersion': '1.0.0', 'gitRepository': gitRepo, 'groupId': 'io.openshift.booster', 'artifactId': projectName, 'spacePath': spaceName, 'space': spaceId } forgeApi = os.getenv("FORGE_API") print('Making request to launch...') try: r = requests.post('{}/api/osio/launch'.format(forgeApi), headers=headers, data=data) # print('request results = {}'.format(r.text)) helpers.printToJson('Launch booster request response', r) result = r.text if re.search('GITHUB_PUSHED', result): return 'Success' else: return 'Fail' except Exception as e: print('Unexpected booster launch exception found: {}'.format(e)) print('Raw text of request/response: [{}]'.format(r.text))
def then_space_created(_context): spaceID = helpers.getSpaceID() spaceID | should_not.be_none().desc("Space created. Space ID is set.")
def then_space_created(_context): spaceID = helpers.getSpaceID() spaceID | should_not.be_none().desc("Created space ID")