aboutsummaryrefslogtreecommitdiffstats
path: root/services/api
diff options
context:
space:
mode:
Diffstat (limited to 'services/api')
-rw-r--r--services/api/__init__.py4
-rw-r--r--services/api/api_bridge.py15
-rw-r--r--services/api/api_checklist.py66
-rw-r--r--services/api/api_gitlab.py107
-rw-r--r--services/api/api_jenkins.py15
-rw-r--r--services/api/api_rados.py85
-rw-r--r--services/api/api_user.py64
-rw-r--r--services/api/api_virtual_function.py117
8 files changed, 288 insertions, 185 deletions
diff --git a/services/api/__init__.py b/services/api/__init__.py
index 30d7152..32b601a 100644
--- a/services/api/__init__.py
+++ b/services/api/__init__.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
diff --git a/services/api/api_bridge.py b/services/api/api_bridge.py
index 8926a1d..d8cb46c 100644
--- a/services/api/api_bridge.py
+++ b/services/api/api_bridge.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -36,11 +36,15 @@
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
+
class APIBridge:
"""
- This class helps to use functions inside classes with circular import (dependencies).
- Use this class only when there is circular import in one of the API services.
+ This class helps to use functions inside
+ classes with circular import (dependencies).
+ Use this class only when there is circular
+ import in one of the API services.
"""
@staticmethod
@@ -63,7 +67,8 @@ class APIBridge:
@staticmethod
def create_engagement(wait_for_gitlab=True):
- """create_engagement: Originally can be found under APIVirtualFunction class."""
+ """create_engagement: Originally can be found under
+ APIVirtualFunction class."""
from services.api.api_virtual_function import APIVirtualFunction
return APIVirtualFunction.create_engagement(wait_for_gitlab)
diff --git a/services/api/api_checklist.py b/services/api/api_checklist.py
index fda0730..02ab311 100644
--- a/services/api/api_checklist.py
+++ b/services/api/api_checklist.py
@@ -37,7 +37,6 @@
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
import datetime
-import logging
import requests
@@ -56,7 +55,12 @@ logger = LoggingServiceFactory.get_logger()
class APIChecklist:
@staticmethod
- def create_checklist(user_content, files=["file0", "file1"], return_negative_response=False):
+ def create_checklist(
+ user_content,
+ files=[
+ "file0",
+ "file1"],
+ return_negative_response=False):
r1 = None
postURL = Constants.Default.URL.Checklist.TEXT + \
user_content['engagement_uuid'] + '/checklist/new/'
@@ -69,11 +73,13 @@ class APIChecklist:
data['checkListName'] = "checklistAPI" + \
Helper.rand_string('randomString')
data['checkListTemplateUuid'] = DBGeneral.select_where(
- "uuid", "ice_checklist_template", "name", Constants.Template.Heat.TEXT, 1)
+ "uuid", "ice_checklist_template", "name",
+ Constants.Template.Heat.TEXT, 1)
try:
if not APIGitLab.is_gitlab_ready(user_content):
raise Exception(
- "Gitlab is not ready and because of that the test is failed.")
+ "Gitlab is not ready and because " +
+ "of that the test is failed.")
r1 = requests.post(postURL, json=data,
headers=headers, verify=False)
@@ -82,15 +88,19 @@ class APIChecklist:
logger.debug("Checklist was created successfully!")
cl_content = r1.json()
return cl_content
- except:
+ except BaseException:
if return_negative_response:
return r1
if r1 is None:
logger.error(
- "Failed to create checklist for VF " + user_content['vfName'])
+ "Failed to create checklist for VF " +
+ user_content['vfName'])
else:
- logger.error("Failed to create checklist for VF " + user_content[
- 'vfName'] + ", see response >>> %s %s.\nContent: %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "Failed to create checklist for VF " +
+ user_content['vfName'] +
+ ", see response >>> %s %s.\nContent: %s" %
+ (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
raise
@staticmethod
@@ -107,7 +117,8 @@ class APIChecklist:
data['checkListName'] = "UpdateChecklistAPI" + \
Helper.rand_string('randomString')
data['checkListTemplateUuid'] = DBGeneral.select_where(
- "uuid", "ice_checklist_template", "name", Constants.Template.Heat.TEXT, 1)
+ "uuid", "ice_checklist_template", "name",
+ Constants.Template.Heat.TEXT, 1)
try:
r1 = requests.put(
postURL, json=data, headers=headers, verify=False)
@@ -115,13 +126,17 @@ class APIChecklist:
logger.debug("DBChecklist was created successfully!")
cl_content = r1.json()
return cl_content['uuid']
- except:
+ except BaseException:
if r1 is None:
logger.error(
- "Failed to create checklist for VF " + user_content['vfName'])
+ "Failed to create checklist for VF " +
+ user_content['vfName'])
else:
- logger.error("Failed to create checklist for VF " + user_content[
- 'vfName'] + ", see response >>> %s %s.\nContent: %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "Failed to create checklist for VF " +
+ user_content['vfName'] +
+ ", see response >>> %s %s.\nContent: %s" %
+ (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
raise
@staticmethod
@@ -141,13 +156,16 @@ class APIChecklist:
postURL, json=data, headers=headers, verify=False)
Helper.internal_assert_boolean(r1.status_code, 200)
logger.debug("Audit log was added successfully!")
- except:
+ except BaseException:
if r1 is None:
logger.error(
"Failed to add audit log for checklist uuid: " + cl_uuid)
else:
- logger.error("Failed to add audit log for checklist uuid: " + cl_uuid +
- ", see response >>> %s %s.\nContent: %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "Failed to add audit log for checklist uuid: " +
+ cl_uuid +
+ ", see response >>> %s %s.\nContent: %s" %
+ (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
raise
@staticmethod
@@ -175,13 +193,16 @@ class APIChecklist:
logger.debug("Next step was added successfully!")
ns_uuid = r1.json()
return ns_uuid[0]['uuid']
- except:
+ except BaseException:
if r1 is None:
logger.error(
"Failed to add next step for checklist uuid: " + cl_uuid)
else:
- logger.error("Failed to add next step for checklist uuid: " + cl_uuid +
- ", see response >>> %s %s.\nContent: %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "Failed to add next step for checklist uuid: " +
+ cl_uuid +
+ ", see response >>> %s %s.\nContent: %s" %
+ (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
raise
@staticmethod
@@ -202,8 +223,8 @@ class APIChecklist:
logger.debug("go_to_next_state put request result status: %s" %
r.status_code)
else:
- logger.error(
- "PUT request failed to change checklist state >>> " + str(r.status_code) + " " + r.reason)
+ logger.error("PUT request failed to change checklist state >>> " +
+ str(r.status_code) + " " + r.reason)
raise Exception("PUT request failed to change checklist state")
@staticmethod
@@ -215,7 +236,8 @@ class APIChecklist:
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))
+ "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])
diff --git a/services/api/api_gitlab.py b/services/api/api_gitlab.py
index 6c5a2ff..639f67e 100644
--- a/services/api/api_gitlab.py
+++ b/services/api/api_gitlab.py
@@ -36,7 +36,6 @@
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-import logging
import os
import subprocess
import sys
@@ -63,7 +62,7 @@ class APIGitLab:
def display_output(p):
while True:
out = p.stderr.read(1)
- if out == b'' and p.poll() != None:
+ if out == b'' and p.poll() is not None:
break
if out != '':
sys.stdout.write(str(out.decode()))
@@ -81,31 +80,42 @@ class APIGitLab:
try:
r1 = requests.get(getURL, headers=headers, verify=False)
counter = 0
- while r1.status_code == 404 or 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)
logger.debug(
- "trying to get the git project, yet to succeed (try #%s)" % counter)
+ "trying to get the git project, " +
+ "yet to succeed (try #%s)" % counter)
counter += 1
+ Helper.internal_assert(r1.status_code, 200)
if r1.content == b'[]':
logger.error("Got an empty list as a response.")
raise
logger.debug("Project exists on APIGitLab!")
content = r1.json() # Change it from list to dict.
return content
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to get project from APIGitLab.")
else:
- logger.error("Failed to get project from APIGitLab, see response >>> %s %s \n %s"
- % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "Failed to get project from APIGitLab, " +
+ "see response >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
- def are_all_list_users_registered_as_project_members(self, users_emails_list, project_path_with_namespace):
+ def are_all_list_users_registered_as_project_members(
+ self, users_emails_list, project_path_with_namespace):
for email in users_emails_list:
- if not self.validate_git_project_members(project_path_with_namespace, email):
+ if not self.validate_git_project_members(
+ project_path_with_namespace, email):
raise Exception(
- "Couldn't find the invited users: " + email + " in GitLab.")
+ "Couldn't find the invited users: " +
+ email +
+ " in GitLab.")
logger.debug(
"Invited user: " + email + " found in GitLab.")
@@ -121,7 +131,9 @@ class APIGitLab:
headers['Content-type'] = 'application/json'
headers['PRIVATE-TOKEN'] = settings.GITLAB_TOKEN
counter = 0
- while (r1 is None or r1.content == b'[]' or r1.status_code != 200) and counter <= Constants.GitLabConstants.RETRIES_NUMBER:
+ while (r1 is None or r1.content == b'[]' or r1.status_code !=
+ 200) and counter <= Constants.GitLabConstants.\
+ RETRIES_NUMBER:
logger.debug(
"try to get git project members (try #%s)" % counter)
time.sleep(session.wait_until_time_pause)
@@ -130,8 +142,11 @@ class APIGitLab:
counter += 1
except Exception as e:
if counter >= Constants.GitLabConstants.RETRIES_NUMBER:
- logger.error("Failed to get project's team members from APIGitLab, see response >>> %s %s \n %s %s"
- % (r1.status_code, r1.reason, str(r1.content, 'utf-8'), e.message))
+ logger.error(
+ "Failed to get project's team members from " +
+ "APIGitLab, see response >>> %s %s \n %s %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8'), e.message))
return False
if r1.content == b'[]':
logger.error("Got an empty list as a response.")
@@ -144,7 +159,8 @@ class APIGitLab:
return True
@staticmethod
- def negative_validate_git_project_member(path_with_namespace, user_email, git_user_id):
+ def negative_validate_git_project_member(
+ path_with_namespace, user_email, git_user_id):
if settings.DATABASE_TYPE != 'local':
r1 = None
headers = dict()
@@ -154,7 +170,9 @@ class APIGitLab:
headers['Content-type'] = 'application/json'
headers['PRIVATE-TOKEN'] = settings.GITLAB_TOKEN
counter = 0
- while r1 is None or str.encode(user_email) not in r1.content and counter <= Constants.GitLabConstants.RETRIES_NUMBER:
+ while r1 is None or str.encode(
+ user_email) not in r1.content and counter <= Constants.\
+ GitLabConstants.RETRIES_NUMBER:
logger.debug(
"try to get git project members (try #%s)" % counter)
time.sleep(session.wait_until_time_pause)
@@ -163,8 +181,11 @@ class APIGitLab:
counter += 1
except Exception as e:
if counter >= Constants.GitLabConstants.RETRIES_NUMBER:
- logger.error("Failed to get project's team members from APIGitLab, see response >>> %s %s \n %s %s"
- % (r1.status_code, r1.reason, str(r1.content, 'utf-8'), e.message))
+ logger.error(
+ "Failed to get project's team members from " +
+ "APIGitLab, see response >>> %s %s \n %s %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8'), e.message))
return False
if r1.content == b'[]':
@@ -193,7 +214,9 @@ class APIGitLab:
counter = 0
while r1.content == b'[]' and counter <= 60:
logger.info(
- "Will try to get gitlab user until will be response... #%s" % counter)
+ "Will try to get gitlab user until " +
+ "will be response... #%s" %
+ counter)
time.sleep(session.wait_until_time_pause_long)
r1 = requests.get(getURL, headers=headers, verify=False)
Helper.internal_assert(r1.status_code, 200)
@@ -207,12 +230,15 @@ class APIGitLab:
(r1.status_code, r1.reason, r1.content))
content = r1.json()
return content[0]
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to get user from APIGitLab.")
else:
- logger.error("Failed to get user from APIGitLab, see response >>> %s %s \n %s"
- % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "Failed to get user from APIGitLab, see response " +
+ ">>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -235,19 +261,24 @@ class APIGitLab:
content = r1.json() # Change it from list to dict.
gitPubKey = content[0]['key']
return gitPubKey
- except:
+ except BaseException:
if r1 is None:
- logger.error("Failed to get user's public key from APIGitLab.")
+ logger.error("Failed to get user's public key " +
+ "from APIGitLab.")
else:
- logger.error("Failed to get user's public key from APIGitLab, see response >>> %s %s \n %s"
- % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "Failed to get user's public key from APIGitLab, " +
+ "see response >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
def git_clone_push(user_content):
if settings.DATABASE_TYPE != 'local':
logger.debug(
- "About to push files into project's repository on the local folder(not over origin).")
+ "About to push files into project's repository on the " +
+ "local folder(not over origin).")
try:
user_content['session_token'] = "token " + \
APIBridge.login_user(Constants.Users.Admin.EMAIL)
@@ -267,7 +298,8 @@ class APIGitLab:
counter = 0
git_user_pub_key = None
- while user_pub_key != git_user_pub_key and counter < Constants.GitLabConstants.RETRIES_NUMBER:
+ while user_pub_key != git_user_pub_key and counter < \
+ Constants.GitLabConstants.RETRIES_NUMBER:
try:
git_user_pub_key = APIGitLab.get_git_user_ssh_key(
git_user['id'])
@@ -279,17 +311,20 @@ class APIGitLab:
# Check that the SSH key was added to user on APIGitLab.
if user_pub_key != git_user_pub_key:
- raise Exception("The SSH Key received does not equal to the"
- " one provided! The key from"
- "APIGitLab:\n %s ==<>== %s"
- % (git_user_pub_key, user_pub_key))
+ raise Exception(
+ "The SSH Key received does not equal to the"
+ " one provided! The key from"
+ "APIGitLab:\n %s ==<>== %s" %
+ (git_user_pub_key, user_pub_key))
gitRepoURL = "git@gitlab:%s/%s.git" % (
- user_content['engagement_manual_id'], user_content['vfName'])
+ user_content['engagement_manual_id'],
+ user_content['vfName'])
logger.debug("Clone repo from: " + gitRepoURL)
APIGitLab.is_gitlab_ready(user_content)
cmd = 'cd ' + repo_dir + \
- '; git config --global user.email \"' + Constants.Users.Admin.EMAIL + \
+ '; git config --global user.email \"' + Constants.\
+ Users.Admin.EMAIL + \
'\"; git config --global user.name \"' + \
Constants.Users.Admin.FULLNAME + '\";'
# Commit all changes.
@@ -358,9 +393,11 @@ class APIGitLab:
"All edited files were commited and pushed to APIGitLab.")
except Exception as e:
logger.error(
- "_-_-_-_-_- Unexpected error in git_push_commit : " + str(e))
+ "_-_-_-_-_- Unexpected error in git_push_commit : " +
+ str(e))
raise Exception(
- "Something went wrong on git_push_commit function, please check logs.")
+ "Something went wrong on git_push_commit " +
+ "function, please check logs.")
@staticmethod
def is_gitlab_ready(user_content):
diff --git a/services/api/api_jenkins.py b/services/api/api_jenkins.py
index b63cb66..0b57b00 100644
--- a/services/api/api_jenkins.py
+++ b/services/api/api_jenkins.py
@@ -40,10 +40,10 @@ from django.conf import settings
from requests.auth import HTTPBasicAuth
from services.constants import Constants
from services.helper import Helper
+from services.session import session
import logging
import requests
import time
-from services.session import session
logger = logging.getLogger('ice-ci.logger')
@@ -60,7 +60,8 @@ class APIJenkins:
try:
r1 = requests.get(getURL, auth=HTTPBasicAuth(
settings.JENKINS_USERNAME, settings.JENKINS_PASSWORD))
- while r1.status_code != 200 and counter <= Constants.GitLabConstants.RETRIES_NUMBER:
+ 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)
@@ -69,14 +70,15 @@ class APIJenkins:
counter += 1
Helper.internal_assert(r1.status_code, 200)
logger.debug("Job was created on APIJenkins!")
- except:
+ except BaseException:
msg = None
if r1 is None:
msg = "APIJenkins didn't create job for %s" % job_name
else:
- msg = "APIJenkins didn't create job for %s, see response >>> %s %s" % (
- job_name, r1.status_code, r1.reason)
+ msg = "APIJenkins didn't create job for %s, " +\
+ "see response >>> %s %s" % (
+ job_name, r1.status_code, r1.reason)
logger.error(msg)
raise Exception(msg)
@@ -85,6 +87,7 @@ class APIJenkins:
def find_build_num_out_of_jenkins_log(log):
lines_array = log.splitlines()
for line in lines_array:
- if Constants.Dashboard.Checklist.JenkinsLog.Modal.Body.BUILD_IDENTIFIER in line:
+ if Constants.Dashboard.Checklist.JenkinsLog.\
+ Modal.Body.BUILD_IDENTIFIER in line:
parts = line.partition('jenkins')
return parts[2]
diff --git a/services/api/api_rados.py b/services/api/api_rados.py
index 61cfa5c..cdad7d4 100644
--- a/services/api/api_rados.py
+++ b/services/api/api_rados.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -36,7 +36,6 @@
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-import logging
import time
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
@@ -50,6 +49,7 @@ from services.session import session
logger = LoggingServiceFactory.get_logger()
+
class APIRados:
@staticmethod
@@ -75,77 +75,56 @@ class APIRados:
@staticmethod
def get_bucket_grants(bucket_name):
"""Return the Grants."""
- counter = 1
- bucket = APIRados.get_bucket(bucket_name)
- while not bucket and counter <= Constants.RGWAConstants.BUCKET_RETRIES_NUMBER:
- logger.error("Bucket not found. Retry #%s" % counter)
- time.sleep(session.wait_until_time_pause_long)
+ for counter in range(Constants.RGWAConstants.BUCKET_RETRIES_NUMBER):
bucket = APIRados.get_bucket(bucket_name)
- counter += 1
- if not bucket:
+ if bucket:
+ break
+ logger.error("Bucket not found. Retry #%s" % counter+1)
+ time.sleep(session.wait_until_time_pause_long)
+ else:
raise TimeoutError("Max retries exceeded, failing test...")
grants = bucket.list_grants()
- print("***********grants=", grants)
return grants
@staticmethod
def is_bucket_ready(bucket_id):
- counter = 1
- bucket = APIRados.get_bucket(bucket_id)
- while (bucket == None and counter <=
- Constants.RGWAConstants.BUCKET_RETRIES_NUMBER):
- time.sleep(session.wait_until_time_pause_long)
- logger.debug(
- "bucket are not ready yet, trying again (%s of 180)" % counter)
+ for counter in range(Constants.RGWAConstants.BUCKET_RETRIES_NUMBER):
bucket = APIRados.get_bucket(bucket_id)
- counter += 1
- print("****_+__+bucket= ", str(bucket))
- time.sleep(session.wait_until_time_pause_long)
- if bucket == None:
+ if bucket:
+ break
+ logger.debug(
+ "bucket are not ready yet, trying again (%s of %s)" % (
+ counter+1, Constants.RGWAConstants.BUCKET_RETRIES_NUMBER))
+ time.sleep(session.wait_until_time_pause_long)
+ else:
raise TimeoutError("Max retries exceeded, failing test...")
- elif bucket != None:
- logger.debug("bucket are ready to continue!")
- return True
+ logger.debug("bucket are ready to continue!")
+ return True
@staticmethod
def users_of_bucket_ready_after_complete(bucket_id, user_name):
- grants = APIRados.get_bucket_grants(bucket_id)
- count = 0
- counter = 1
- while (count != 0 and counter <=
- Constants.RGWAConstants.BUCKET_RETRIES_NUMBER):
+ for counter in range(Constants.RGWAConstants.BUCKET_RETRIES_NUMBER):
grants = APIRados.get_bucket_grants(bucket_id)
+ if not any(user_name == g.id for g in grants):
+ break
time.sleep(session.wait_until_time_pause_long)
- for g in grants:
- if g.id == user_name:
- count = +1
- time.sleep(session.wait_until_time_pause_long)
- if count != 0:
+ else:
raise Exception("Max retries exceeded, failing test...")
return False
- elif count == 0:
- logger.debug("users_of_bucket are ready to continue!")
- return True
+ logger.debug("users_of_bucket are ready to continue!")
+ return True
@staticmethod
- def users_of_bucket_ready_after_created(bucket_id, user_name):
- grants = APIRados.get_bucket_grants(bucket_id)
- count = 0
- counter = 1
- while (count == 0 and counter <=
- Constants.RGWAConstants.BUCKET_RETRIES_NUMBER):
+ def users_of_bucket_ready_after_created(bucket_id, user_uuid):
+ for counter in range(Constants.RGWAConstants.BUCKET_RETRIES_NUMBER):
grants = APIRados.get_bucket_grants(bucket_id)
+ if any(user_uuid == g.id for g in grants):
+ break
time.sleep(session.wait_until_time_pause_long)
- for g in grants:
- if g.id == user_name:
- count = +1
- time.sleep(session.wait_until_time_pause_long)
- if count == 0:
+ else:
raise Exception("Max retries exceeded, failing test...")
- return False
- elif count > 0:
- logger.debug("users_of_bucket are ready to continue!")
- return True
+ logger.debug("users_of_bucket are ready to continue!")
+ return True
@staticmethod
def specific_client(access_key_id, secret_access_key):
diff --git a/services/api/api_user.py b/services/api/api_user.py
index 3e38fd2..963280e 100644
--- a/services/api/api_user.py
+++ b/services/api/api_user.py
@@ -1,5 +1,5 @@
-
-# ============LICENSE_START==========================================
+
+# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
@@ -50,13 +50,14 @@ from services.logging_service import LoggingServiceFactory
logger = LoggingServiceFactory.get_logger()
+
class APIUser:
@staticmethod
# Update account API - only adds new SSH key!
def update_account(user_content):
r1 = None
- token = APIUser.login_user(user_content['email'])
+ token = APIUser.login_user(user_content['email'])
user_content['session_token'] = 'token ' + token
sshKey = Helper.generate_sshpub_key()
putURL = settings.ICE_EM_URL + '/v1/engmgr/users/account'
@@ -82,16 +83,20 @@ class APIUser:
putURL, json=put_data, headers=headers, verify=False)
Helper.internal_assert(r1.status_code, 200)
logger.debug(
- "SSH Key was added successfully to user " + user_content['full_name'])
+ "SSH Key was added successfully to user " +
+ user_content['full_name'])
if not APIBridge.is_gitlab_ready(user_content):
raise
return sshKey
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to add public SSH key to user.")
else:
- logger.error("PUT request failed to add SSH key to user, see response >>> %s %s \n %s" % (
- r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "PUT request failed to add SSH key to user, see " +
+ "response >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -125,12 +130,15 @@ class APIUser:
if not APIBridge.is_gitlab_ready(user_content):
raise
return True
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to add public SSH key to user.")
else:
- logger.error("PUT request failed to add SSH key to user, see response >>> %s %s \n %s" % (
- r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "PUT request failed to add SSH key to user, " +
+ "see response >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -168,7 +176,7 @@ class APIUser:
logger.debug(str(r.status_code) + " " + r.reason)
decoded_response = r.json()
return decoded_response['token']
- except:
+ except BaseException:
logger.debug("Failed to login.")
raise
@@ -195,12 +203,14 @@ class APIUser:
if not APIBridge.is_gitlab_ready(user_content):
raise
return sshKey
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to add public SSH key.")
else:
logger.error(
- "POST request failed to add SSH key to user, see response >>> %s %s" % (r1.status_code, r1.reason))
+ "POST request failed to add SSH key to user, " +
+ "see response >>> %s %s" %
+ (r1.status_code, r1.reason))
raise
@staticmethod
@@ -214,11 +224,11 @@ class APIUser:
data = {
"company": company,
"full_name": Helper.rand_string("randomString"),
- "email": Helper.rand_string("randomString") + "@" + email_domain,
+ "email": Helper.rand_string("randomString") +
+ "@" + email_domain,
"phone_number": Constants.Default.Phone.TEXT,
"password": Constants.Default.Password.TEXT,
- "regular_email_updates": "True"
- }
+ "regular_email_updates": "True"}
return data
# If failed - count the failure and add the error to list of errors.
@@ -237,10 +247,19 @@ class APIUser:
return True
else:
raise Exception(
- "Failed to activate user >>> %s %s" % (r1.status_code, r1.reason))
+ "Failed to activate user >>> %s %s" %
+ (r1.status_code, r1.reason))
@staticmethod
- def signup_invited_user(company, invited_email, invite_token, invite_url, user_content, is_contact_user="false", activate=False, wait_for_gitlab=True):
+ def signup_invited_user(
+ company,
+ invited_email,
+ invite_token,
+ invite_url,
+ user_content,
+ is_contact_user="false",
+ activate=False,
+ wait_for_gitlab=True):
r1 = None
postURL = settings.ICE_EM_URL + '/v1/engmgr/signup'
logger.debug("Post signup URL: " + postURL)
@@ -279,12 +298,15 @@ class APIUser:
if not APIBridge.is_gitlab_ready(user_content):
raise
return post_data
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to sign up the invited team member.")
else:
- logger.error("POST request failed to sign up the invited team member, see response >>> %s %s \n %s" % (
- r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "POST request failed to sign up the invited " +
+ "team member, see response >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
diff --git a/services/api/api_virtual_function.py b/services/api/api_virtual_function.py
index 46610e8..193d6e2 100644
--- a/services/api/api_virtual_function.py
+++ b/services/api/api_virtual_function.py
@@ -43,7 +43,6 @@ import time
from django.conf import settings
import requests
-from services.api.api_gitlab import APIGitLab
from services.api.api_user import APIUser
from services.constants import Constants, ServiceProvider
from services.database.db_general import DBGeneral
@@ -67,7 +66,7 @@ class APIVirtualFunction:
headers['Authorization'] = user_content['session_token']
data = dict() # Create JSON data for post request.
files_list = list()
- if type(files) is list:
+ if isinstance(files, list):
for file in files:
files_list.append(file)
else:
@@ -85,13 +84,16 @@ class APIVirtualFunction:
logger.debug("Next step was added to the engagement!")
ns_uuid = r1.json()
return ns_uuid[0]['uuid']
- except:
+ except BaseException:
if r1 is None:
logger.error(
"Failed to add next step to VF " + user_content['vfName'])
else:
- logger.error("Failed to add next step to VF " + user_content[
- 'vfName'] + ", see response >>> %s %s.\nContent: %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error("Failed to add next step to VF " +
+ user_content['vfName'] +
+ ", see response >>> %s %s.\nContent: %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -104,12 +106,15 @@ class APIVirtualFunction:
headers = dict() # Create header for post request.
headers['Content-type'] = 'application/json'
headers['Authorization'] = 'token ' + token
- jdata = [{"virtual_function": Helper.rand_string("randomString"),
- "version": Helper.rand_string("randomString") + Helper.rand_string("randomNumber"),
- "target_lab_entry_date": time.strftime("%Y-%m-%d"),
- "target_aic_uuid": targetVersion,
- "ecomp_release": ecompRelease,
- "is_service_provider_internal": False}]
+ jdata = [
+ {
+ "virtual_function": Helper.rand_string("randomString"),
+ "version": Helper.rand_string("randomString") +
+ Helper.rand_string("randomNumber"),
+ "target_lab_entry_date": time.strftime("%Y-%m-%d"),
+ "target_aic_uuid": targetVersion,
+ "ecomp_release": ecompRelease,
+ "is_service_provider_internal": False}]
try:
r1 = requests.post(
postUrl, json=jdata, headers=headers, verify=False)
@@ -117,12 +122,14 @@ class APIVirtualFunction:
logger.debug("Virtual Function created successfully!")
content = r1.content[1:-1]
return content
- except:
+ except BaseException:
if r1 is None:
logger.debug("Failed to create VF >>> request failed!")
else:
logger.debug(
- "Failed to create VF >>> %s %s \n %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ "Failed to create VF >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -140,13 +147,15 @@ class APIVirtualFunction:
logger.debug("Retrieved the Engagement successfully!")
content = r1.content
return json.loads(content)
- except:
+ except BaseException:
if r1 is None:
logger.debug(
"Failed to Retrieve the Engagement >>> request failed!")
else:
logger.debug(
- "Failed to Retrieve the Engagement >>> %s %s \n %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ "Failed to Retrieve the Engagement >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -168,18 +177,25 @@ class APIVirtualFunction:
postURL, json=list_data, headers=headers, verify=False)
Helper.internal_assert_boolean(r1.status_code, 200)
logger.debug("Invite sent successfully to email " + data['email'])
- invite_token = DBGeneral.select_where_and("invitation_token", "ice_invitation", "email", data[
- 'email'], "engagement_uuid", user_content['engagement_uuid'], 1)
- invite_url = settings.ICE_PORTAL_URL + "/#/signUp?invitation=" + invite_token + \
- "&email=" + data['email']
+ invite_token = DBGeneral.select_where_and(
+ "invitation_token",
+ "ice_invitation",
+ "email",
+ data['email'],
+ "engagement_uuid",
+ user_content['engagement_uuid'],
+ 1)
+ invite_url = settings.ICE_PORTAL_URL + "/#/signUp?invitation=" + \
+ invite_token + "&email=" + data['email']
logger.debug("Invitation URL is: " + invite_url)
return data['email'], invite_token, invite_url
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to invite team member.")
else:
logger.error(
- "POST request failed to invite team member, see response >>> %s %s" % (r1.status_code, r1.reason))
+ "POST request failed to invite team member, " +
+ "see response >>> %s %s" % (r1.status_code, r1.reason))
raise
@staticmethod
@@ -202,21 +218,30 @@ class APIVirtualFunction:
postURL, json=data, headers=headers, verify=False)
Helper.internal_assert_boolean(r1.status_code, 200)
logger.debug("Invite sent successfully to email " + data['email'])
- invite_token = DBGeneral.select_where_and("invitation_token", "ice_invitation", "email", data[
- 'email'], "engagement_uuid", user_content['engagement_uuid'], 1)
- invite_url = settings.ICE_PORTAL_URL + "/#/signUp?invitation=" + invite_token + \
- "&email=" + data['email'] + "&full_name=" + data['full_name'] + \
- "&phone_number=" + \
- data['phone_number'] + "&company=" + \
+ invite_token = DBGeneral.select_where_and(
+ "invitation_token",
+ "ice_invitation",
+ "email",
+ data['email'],
+ "engagement_uuid",
+ user_content['engagement_uuid'],
+ 1)
+ invite_url = settings.ICE_PORTAL_URL + "/#/signUp?invitation=" +\
+ invite_token + "&email=" + data['email'] +\
+ "&full_name=" + data['full_name'] + \
+ "&phone_number=" + data['phone_number'] + "&company=" + \
data['company'] + "&is_contact_user=true"
logger.debug("Invitation URL is: " + invite_url)
return data['email'], invite_token, invite_url
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to invite vendor contact.")
else:
- logger.error("POST request failed to invite vendor contact, see response >>> %s %s \n %s" % (
- r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ logger.error(
+ "POST request failed to invite vendor contact, " +
+ "see response >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -239,12 +264,16 @@ class APIVirtualFunction:
postURL, json=data, headers=headers, verify=False)
Helper.internal_assert_boolean(r1.status_code, 202)
logger.debug("Next step was edited successfully!")
- except:
+ except BaseException:
if r1 is None:
logger.error("Failed to edit next step uuid: " + ns_uuid)
else:
- logger.error("Failed to edit next step uuid: " + ns_uuid +
- ", see response >>> %s %s" % (r1.status_code, r1.reason))
+ logger.error(
+ "Failed to edit next step uuid: " +
+ ns_uuid +
+ ", see response >>> %s %s" %
+ (r1.status_code,
+ r1.reason))
raise
@staticmethod
@@ -259,7 +288,8 @@ class APIVirtualFunction:
return r1.content
else:
raise Exception(
- "Failed to activate user >>> %s %s" % (r1.status_code, r1.reason))
+ "Failed to activate user >>> %s %s" %
+ (r1.status_code, r1.reason))
return False
@staticmethod
@@ -314,15 +344,19 @@ class APIVirtualFunction:
putUrl, headers=headers, verify=False)
Helper.internal_assert(r1.status_code, 202)
logger.debug(
- "Engagement stage was successfully changed to " + str(requested_stage) + "!")
+ "Engagement stage was successfully changed to " +
+ str(requested_stage) +
+ "!")
content = r1.content[1:-1]
return content
- except:
+ except BaseException:
if r1 is None:
logger.debug("Failed to set eng stage >>> request failed!")
else:
logger.debug(
- "Failed to set eng stage >>> %s %s \n %s" % (r1.status_code, r1.reason, str(r1.content, 'utf-8')))
+ "Failed to set eng stage >>> %s %s \n %s" %
+ (r1.status_code, r1.reason, str(
+ r1.content, 'utf-8')))
raise
@staticmethod
@@ -338,7 +372,7 @@ class APIVirtualFunction:
r1 = requests.put(putURL, headers=headers, verify=False)
Helper.internal_assert_boolean(r1.status_code, 200)
logger.debug("AIC version has changed!")
- except:
+ except BaseException:
if r1 is None:
msg = "Failed to edit AIC version"
else:
@@ -359,10 +393,11 @@ class APIVirtualFunction:
r1 = requests.put(putURL, headers=headers, verify=False)
Helper.internal_assert_boolean(r1.status_code, 200)
logger.debug("AIC version has changed!")
- except:
+ except BaseException:
if r1 is None:
msg = "Failed to update ECOMP release"
else:
- msg = "Failed to update ECOMP release, see response >>> %s %s" % (
- r1.status_code, r1.reason)
+ msg = "Failed to update ECOMP release," +\
+ " see response >>> %s %s" % (
+ r1.status_code, r1.reason)
raise msg