aboutsummaryrefslogtreecommitdiffstats
path: root/services/api
diff options
context:
space:
mode:
Diffstat (limited to 'services/api')
-rw-r--r--services/api/api_checklist.py22
-rw-r--r--services/api/api_gitlab.py52
-rw-r--r--services/api/api_jenkins.py23
3 files changed, 50 insertions, 47 deletions
diff --git a/services/api/api_checklist.py b/services/api/api_checklist.py
index ef7b8a3..fda0730 100644
--- a/services/api/api_checklist.py
+++ b/services/api/api_checklist.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -47,6 +47,7 @@ from services.constants import Constants
from services.database.db_general import DBGeneral
from services.helper import Helper
from services.logging_service import LoggingServiceFactory
+from services.database.db_checklist import DBChecklist
logger = LoggingServiceFactory.get_logger()
@@ -208,12 +209,21 @@ class APIChecklist:
@staticmethod
def move_cl_to_closed(cl_uuid, vf_staff_emails):
api_checklist_obj = APIChecklist()
-
+ states = [Constants.ChecklistStates.PeerReview.TEXT,
+ Constants.ChecklistStates.Approval.TEXT,
+ Constants.ChecklistStates.Handoff.TEXT,
+ Constants.ChecklistStates.Closed.TEXT]
for i in range(len(vf_staff_emails)):
- logger.debug("Trying to jump state for %s [%s]" % (vf_staff_emails[i], i))
+ logger.debug(
+ "Trying to jump state for %s [%s]" % (vf_staff_emails[i], i))
+ DBChecklist.update_all_decisions_to_approve(cl_uuid)
api_checklist_obj.jump_state(cl_uuid, vf_staff_emails[i])
+ logger.debug("Checking state changed to %s" % states[i])
+ DBChecklist.state_changed("uuid", cl_uuid, states[i])
# Move CL to closed state.
- logger.debug("Trying to jump state 'closed' for %s" % vf_staff_emails[0])
+ logger.debug("Trying to jump state 'closed' for %s" %
+ vf_staff_emails[0])
api_checklist_obj.jump_state(cl_uuid, vf_staff_emails[0])
-
+ logger.debug("Checking state changed to %s" % states[-1])
+ DBChecklist.state_changed("uuid", cl_uuid, states[-1])
diff --git a/services/api/api_gitlab.py b/services/api/api_gitlab.py
index c7b25e0..6c5a2ff 100644
--- a/services/api/api_gitlab.py
+++ b/services/api/api_gitlab.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -56,6 +56,7 @@ from services.session import session
logger = LoggingServiceFactory.get_logger()
+
class APIGitLab:
@staticmethod
@@ -79,13 +80,13 @@ class APIGitLab:
headers['PRIVATE-TOKEN'] = settings.GITLAB_TOKEN
try:
r1 = requests.get(getURL, headers=headers, verify=False)
- Helper.internal_assert(r1.status_code, 200)
counter = 0
- while r1.content == b'[]' and counter <= Constants.GitLabConstants.RETRIES_NUMBER:
+ while r1.status_code == 404 or r1.content == b'[]' and counter <= Constants.GitLabConstants.RETRIES_NUMBER:
time.sleep(session.wait_until_time_pause)
r1 = requests.get(getURL, headers=headers, verify=False)
- Helper.internal_assert(r1.status_code, 200)
-
+ logger.debug(
+ "trying to get the git project, yet to succeed (try #%s)" % counter)
+ counter += 1
if r1.content == b'[]':
logger.error("Got an empty list as a response.")
raise
@@ -363,32 +364,15 @@ class APIGitLab:
@staticmethod
def is_gitlab_ready(user_content):
- counter = 1
- gettURL = settings.ICE_EM_URL + '/v1/engmgr/engagement/' + \
- user_content['engagement_uuid'] + '/checklist/new/'
- logger.debug(
- "Get URL to check if GitLab and Jenkins are ready: " + gettURL)
- # Validate with EL
- token = "token " + APIBridge.login_user(user_content['el_email'])
- headers = dict() # Create header for get request.
- headers['Content-type'] = 'application/json'
- headers['Authorization'] = token
- r1 = requests.get(gettURL, headers=headers, verify=False)
- while (r1.content == b'"Create New checklist is not ready yet"' and counter <=
- Constants.GitLabConstants.RETRIES_NUMBER):
- time.sleep(session.wait_until_time_pause_long)
- logger.debug(
- "GitLab and Jenkins are not ready yet, trying again (%s of %s)" %
- (counter, Constants.GitLabConstants.RETRIES_NUMBER))
- r1 = requests.get(gettURL, headers=headers, verify=False)
- counter += 1
- if r1.status_code != 200:
- if r1.content == "Create New checklist is not ready yet":
- raise Exception("Max retries exceeded, failing test...")
- else:
- raise Exception("Something went wrong while waiting for GitLab and Jenkins. %s %s" % (
- r1.status_code, r1.reason))
- return False
- elif r1.status_code == 200:
- logger.debug("Gitlab and Jenkins are ready to continue!")
+ path_with_namespace = user_content[
+ 'engagement_manual_id'] + "%2F" + user_content['vfName']
+ # If admin user is in project repo, it means the project exists as
+ # well.
+ cont = APIGitLab.validate_git_project_members(
+ path_with_namespace, Constants.Users.Admin.EMAIL)
+ if cont:
+ logger.debug("Gitlab is ready for action, git repo was found!")
return True
+ else:
+ raise Exception(
+ "Something went wrong while waiting for GitLab.")
diff --git a/services/api/api_jenkins.py b/services/api/api_jenkins.py
index e1e1f6e..b63cb66 100644
--- a/services/api/api_jenkins.py
+++ b/services/api/api_jenkins.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -37,26 +37,36 @@
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
from django.conf import settings
-import requests
from requests.auth import HTTPBasicAuth
-
from services.constants import Constants
from services.helper import Helper
-from services.logging_service import LoggingServiceFactory
+import logging
+import requests
+import time
+from services.session import session
+
+logger = logging.getLogger('ice-ci.logger')
-logger = LoggingServiceFactory.get_logger()
class APIJenkins:
@staticmethod
def get_jenkins_job(job_name):
r1 = None
+ counter = 0
getURL = settings.JENKINS_URL + "job/" + job_name
logger.debug("Get APIJenkins job URL: " + getURL)
try:
r1 = requests.get(getURL, auth=HTTPBasicAuth(
settings.JENKINS_USERNAME, settings.JENKINS_PASSWORD))
+ while r1.status_code != 200 and counter <= Constants.GitLabConstants.RETRIES_NUMBER:
+ r1 = requests.get(getURL, auth=HTTPBasicAuth(
+ settings.JENKINS_USERNAME, settings.JENKINS_PASSWORD))
+ time.sleep(session.wait_until_time_pause)
+ logger.debug(
+ "try to get jenkins job (try #%s)" % counter)
+ counter += 1
Helper.internal_assert(r1.status_code, 200)
logger.debug("Job was created on APIJenkins!")
except:
@@ -78,4 +88,3 @@ class APIJenkins:
if Constants.Dashboard.Checklist.JenkinsLog.Modal.Body.BUILD_IDENTIFIER in line:
parts = line.partition('jenkins')
return parts[2]
-