diff options
author | Edan Binshtok <eb578m@intl.att.com> | 2017-11-19 11:42:55 +0200 |
---|---|---|
committer | Edan Binshtok <eb578m@intl.att.com> | 2017-11-19 11:43:15 +0200 |
commit | a9ef6f094a2bcf1fd7a0b7c2aaf814841db558ec (patch) | |
tree | 81a3f8436f9e6af07c3070c74f3a0543c2ca5eff /django/validationmanager | |
parent | c169d08d437ccb62fd79ade759077b874f00b1c3 (diff) |
Pep8 more fixes
Update base files to pass pep8 strict standarts.
Issue-ID: VVP-25
Change-Id: If9ef80abf7fbc33ea181dfc2eb73c27ddd6ddc3e
Signed-off-by: Edan Binshtok <eb578m@intl.att.com>
Diffstat (limited to 'django/validationmanager')
33 files changed, 431 insertions, 209 deletions
diff --git a/django/validationmanager/__init__.py b/django/validationmanager/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/__init__.py +++ b/django/validationmanager/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/admin.py b/django/validationmanager/admin.py index aa2eeab..a0b8a8b 100644 --- a/django/validationmanager/admin.py +++ b/django/validationmanager/admin.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/apps.py b/django/validationmanager/apps.py index 8576af0..552f98c 100644 --- a/django/validationmanager/apps.py +++ b/django/validationmanager/apps.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -39,6 +39,9 @@ # To avoid the server reloading this class twice, run it with --noreload flag from django.apps import AppConfig +from engagementmanager.service.logging_service import LoggingServiceFactory + +logger = LoggingServiceFactory.get_logger() class ValidationmanagerConfig(AppConfig): @@ -48,4 +51,7 @@ class ValidationmanagerConfig(AppConfig): def ready(self): # This otherwise unused import causes the signal receivers # to register themselves at the appropriate time. Do not remove. + # We use logger.debug to ignore flake8's warning about unused import. import validationmanager.em_integration.vm_api + logger.debug( + validationmanager.em_integration.vm_api.config_xml_content) diff --git a/django/validationmanager/em_integration/__init__.py b/django/validationmanager/em_integration/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/em_integration/__init__.py +++ b/django/validationmanager/em_integration/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/em_integration/em_client.py b/django/validationmanager/em_integration/em_client.py index 5620c0c..5fff71a 100644 --- a/django/validationmanager/em_integration/em_client.py +++ b/django/validationmanager/em_integration/em_client.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/em_integration/vm_api.py b/django/validationmanager/em_integration/vm_api.py index 1650fa1..6fb422b 100644 --- a/django/validationmanager/em_integration/vm_api.py +++ b/django/validationmanager/em_integration/vm_api.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -44,14 +44,17 @@ from django.forms.models import model_to_dict from django.template.loader import render_to_string import requests from engagementmanager.decorator.retry import retry_connection -from engagementmanager.models import Engagement, IceUserProfile, Role, Checklist, \ - ChecklistDecision, ChecklistLineItem, CheckListState, ChecklistTemplate, VF +from engagementmanager.models import Engagement, IceUserProfile, \ + Role, Checklist,\ + ChecklistDecision, ChecklistLineItem, CheckListState, \ + ChecklistTemplate, VF from engagementmanager.serializers import VFModelSerializerForSignal from engagementmanager.utils.constants import Roles, EngagementStage, \ - CheckListLineType, JenkinsBuildParametersNames, RGWApermission + CheckListLineType, JenkinsBuildParametersNames, RGWApermission, CheckListCategory from engagementmanager.utils.cryptography import CryptographyText from engagementmanager.utils.validator import logEncoding -from mocks.gitlab_mock.rest.gitlab_files_respons_rest import GitlabFilesResultsREST +from mocks.gitlab_mock.rest.gitlab_files_respons_rest import \ + GitlabFilesResultsREST from mocks.jenkins_mock.rest.jenkins_tests_validation_rest import \ JenkinsTestsResultsREST @@ -59,6 +62,7 @@ from rgwa_mock.services.rgwa_keys_service import RGWAKeysService from validationmanager.rados.rgwa_client_factory import RGWAClientFactory from validationmanager.utils.clients import get_jenkins_client, \ get_gitlab_client +from validationmanager.tasks import request_scan from engagementmanager.service.logging_service import LoggingServiceFactory logger = LoggingServiceFactory.get_logger() @@ -101,11 +105,16 @@ def cl_from_pending_to_automation_callback(vf, checklist): logger.debug( "Engagement Manager has signaled that a checklist state was " + "changed from pending to automation") - get_jenkins_client().build_job( - vf.jenkins_job_name(), { - 'checklist_uuid': checklist.uuid, - 'git_repo_url': vf.git_repo_url, - }) + if checklist.template and checklist.template.category == CheckListCategory.glance.name: + logger.debug("Triggering image scan") + request_scan(vf, checklist) + elif checklist.template and checklist.template.category == CheckListCategory.heat.name: + logger.debug("Triggering heat template validation") + get_jenkins_client().build_job( + vf.jenkins_job_name(), { + 'checklist_uuid': checklist.uuid, + 'git_repo_url': vf.git_repo_url, + }) def provision_new_vf_callback(vf): @@ -134,10 +143,8 @@ def provision_new_vf_callback(vf): def get_list_of_repo_files_callback(vf): """Given a vf, return its file list. - This function will either succeed (and return a list), or throw an exception. - """ logger.debug( "Engagement Manager has signaled that there is a need " + @@ -159,10 +166,8 @@ def get_list_of_repo_files_callback(vf): def ssh_key_created_or_updated_callback(user): if not settings.IS_SIGNAL_ENABLED: return None - logger.debug("Engagement Manager has signaled that a user has " + "created or updated an ssh key") - user_dict = model_to_dict(user) gitlab = get_gitlab_client() gitlab_user = gitlab.get_user_by_email(user.email) @@ -173,9 +178,7 @@ def ssh_key_created_or_updated_callback(user): if 'id' not in gitlab_user: err_msg = "coudln't get gitlab user %s " % user.uuid raise ValueError(err_msg) - update_user_ssh_keys(user_dict, gitlab, gitlab_user) - logger.debug( "Successfuly created/updated user in the git in " + "key_created_or_updated signal") @@ -228,7 +231,7 @@ def ensure_checklists(vf): @retry_connection def ensure_jenkins_job(vf): - """Given a vf, ensure that its jenkins/TestEngine job exists. + """Given a vf, ensure that its jenkins/TestEngine jobs exist. This function will either succeed (and return None), or throw an exception. @@ -241,16 +244,19 @@ def ensure_jenkins_job(vf): jenkins = get_jenkins_client() job_name = vf.jenkins_job_name() - # FIXME test-then-set can cause a race condition, so maybe better - # to attempt to create and ignore "already exists" error. - if jenkins.job_exists(job_name): - logger.debug( - "TestEngine job %s for VF %s already provisioned, skipping.", - job_name, vf.name) - return None + for namesuffix, xml in config_xml_content.items(): + name = job_name + namesuffix - logger.debug("creating TestEngine job %s for VF %s", job_name, vf.name) - jenkins.create_job(job_name, config_xml_content) + # FIXME test-then-set can cause a race condition, so maybe better + # to attempt to create and ignore "already exists" error. + if jenkins.job_exists(name): + logger.debug( + "TestEngine job %s for VF %s already provisioned, skipping.", + name, vf.name) + continue + + logger.debug("creating TestEngine job %s for VF %s", name, vf.name) + jenkins.create_job(name, xml) @retry_connection @@ -261,7 +267,8 @@ def get_jenkins_build_log(vf, checklistUuid): """ if not settings.IS_SIGNAL_ENABLED: - return jenkins_mock_object.get(vf.engagement.engagement_manual_id, vf.name) + return jenkins_mock_object.get( + vf.engagement.engagement_manual_id, vf.name) logger.debug("Retrieving VF's(%s) last Jenkins build log " % (vf.name)) jenkins = get_jenkins_client() job_name = vf.jenkins_job_name() @@ -271,35 +278,43 @@ def get_jenkins_build_log(vf, checklistUuid): logs = '' for build in vf_builds['builds']: for parameter in build['actions'][0]['parameters']: - if parameter['name'] == JenkinsBuildParametersNames.CHECKLIST_UUID: + if parameter['name'] == \ + JenkinsBuildParametersNames.CHECKLIST_UUID: if parameter['value'] == checklistUuid: logger.debug( - "I have succeeded to match the given checklist uuid to one of the VF's builds' checklist_uuid") + "I have succeeded to match the given checklist uuid \ + to one of the VF's builds' checklist_uuid") build_num = build['number'] if build_num < 0: logger.error( - "Failed to match the given checklist uuid to one of the VF's builds' checklist_uuid") + "Failed to match the given checklist uuid to one of the VF's \ + builds' checklist_uuid") else: logs = jenkins.server.get_build_console_output(job_name, build_num) return logs def get_jenkins_job_config(): - """Return the XML configuration for a Jenkins/TestEngine build job. + """Return the XML configurations for the Jenkins/TestEngine build job and + the Jenkins/Imagescanner results processing job. - The configuration is templated, and the context provided will - include the appropriate webhook endpoint for its notification - callbacks. It is not cached; do that from a higher level caller. + The configurations are templated, and the context provided will include the + appropriate webhook endpoint for its notification callbacks. It is not + cached; do that from a higher level caller. """ # replacing auth in the view name 'jenkins-notification-endpoint' # (url.py) and appending it to the url from settings - webhook_endpoint = "http://%s%s" % ( - settings.API_DOMAIN, - reverse('jenkins-notification-endpoint', - kwargs={'auth_token': settings.WEBHOOK_TOKEN})) - return render_to_string('jenkins_job_config.xml', - {'notification_endpoint': webhook_endpoint}) + context = { + 'notification_endpoint': "http://%s%s" % ( + settings.API_DOMAIN, + reverse( + 'jenkins-notification-endpoint', + kwargs={'auth_token': settings.WEBHOOK_TOKEN}))} + return { + '': render_to_string('jenkins_job_config.xml', context), + '_scanner': render_to_string('imagescanner_job_config.xml', context), + } @retry_connection @@ -633,14 +648,14 @@ def ensure_rgwa_entities(vf): """ formated_vf = VFModelSerializerForSignal(vf).data engagement_stage = formated_vf['engagement']['engagement_stage'] + bucket_name = vf.engagement.engagement_manual_id + "_" + vf.name.lower() if engagement_stage == EngagementStage.Active.name: - bucket_name = vf.engagement.engagement_manual_id+"_"+vf.name.lower() bucket = get_or_create_bucket(bucket_name) add_bucket_users(bucket, vf) elif engagement_stage == EngagementStage.Validated.name or\ engagement_stage == EngagementStage.Completed.name or\ engagement_stage == EngagementStage.Archived.name: - bucket = get_or_create_bucket(vf.engagement.engagement_manual_id) + bucket = get_or_create_bucket(bucket_name) remove_bucket_users_grants(bucket, vf) @@ -649,13 +664,18 @@ def create_user_rgwa(user): logger.debug("Engagement Manager has signaled that a user has " + "created an rgwa") rgwa = RGWAClientFactory.admin() - rgwa_user = rgwa.get_user(user.full_name) + rgwa_user = rgwa.get_user(user.uuid) if rgwa_user is None: logger.debug( user.full_name + "User does not exist, a new one is created!") try: rgwa_user = rgwa.create_user( - uid=user.full_name, display_name='User "%s"' % user.full_name) + uid=user.uuid, + display_name=user.full_name, + # admin will create and own the buckets users use. note: + # radosgw treats 0 as "unlimited", -1 as "none" + max_buckets=-1, + ) user = IceUserProfile.objects.get(uuid=user.uuid) access_key = rgwa_user['keys'][0]['access_key'] secret_key = CryptographyText.encrypt( @@ -669,20 +689,21 @@ def create_user_rgwa(user): str(rgwa_user)) except Exception as e: logger.error(str(e)) - err_msg = "coudln't get rgwa user %s " % user.full_name + err_msg = "coudln't get rgwa user %s " % user.uuid raise ValueError(err_msg) else: rgwa_user = RGWAKeysService().mock_create_user( - uid=user.full_name, display_name='User "%s"' % user.full_name) + uid=user.uuid, display_name=user.full_name) user = IceUserProfile.objects.get(uuid=user.uuid) user.rgwa_access_key = rgwa_user['access_key'] - user.rgwa_secret_key = CryptographyText.encrypt(rgwa_user['secret_key']) + user.rgwa_secret_key = CryptographyText.encrypt( + rgwa_user['secret_key']) user.save() -def validate_rgwa_user(full_name, uuid): +def validate_rgwa_user(uuid): rgwa = RGWAClientFactory.admin() - rgwa_user = rgwa.get_user(full_name) + rgwa_user = rgwa.get_user(uuid) if rgwa_user is None: create_user_rgwa(IceUserProfile.objects.get(uuid=uuid)) @@ -695,14 +716,14 @@ def add_bucket_users(bucket, vf): def add_bucket_user(user, bucket): try: - validate_rgwa_user(user.full_name, user.uuid) + validate_rgwa_user(user.uuid) bucket_acl = bucket.get_acl() grants = set((grant.id, grant.permission) for grant in bucket_acl.acl.grants) for permission in [RGWApermission.READ, RGWApermission.WRITE]: - if (user.full_name, permission) in grants: + if (user.uuid, permission) in grants: continue - bucket_acl.acl.add_user_grant(permission, user.full_name) + bucket_acl.acl.add_user_grant(permission, user.uuid) bucket.set_acl(bucket_acl) except Exception as e: err_msg = "Failed: Engagement team user with uuid " + \ @@ -735,5 +756,6 @@ def remove_bucket_users_grants(bucket, vf): def remove_bucket_user_grants(bucket, user): bucket_acl = bucket.get_acl() bucket_acl.acl.grants = [ - grant for grant in bucket_acl.acl.grants if not grant.id == user.full_name] + grant for grant in bucket_acl.acl.grants if not grant.id == + user.uuid] bucket.set_acl(bucket_acl) diff --git a/django/validationmanager/git/__init__.py b/django/validationmanager/git/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/git/__init__.py +++ b/django/validationmanager/git/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/git/gitlab_client.py b/django/validationmanager/git/gitlab_client.py index 66d4177..4cce73a 100644 --- a/django/validationmanager/git/gitlab_client.py +++ b/django/validationmanager/git/gitlab_client.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -104,12 +104,14 @@ class GitlabClient(object): def create_project(self, name, **kwargs): """ - Function creates a new project with specified parameters. The following parameters are - understood: + Function creates a new project with specified parameters. + The following parameters are understood: name: The name of the new project - path: Custom repository name for new project. default: based on name - namespace_id: Namespace for the new project. default: current user's namespace + path: Custom repository name for new project. + default: based on name + namespace_id: Namespace for the new project. + default: current user's namespace description issues_enabled merge_requests_enabled @@ -132,9 +134,12 @@ class GitlabClient(object): # filter kwargs to known parameters and non-optional args parameters = dict({k: kwargs[k] for k in kwargs if k in [ - 'path', 'namespace_id', 'description', 'issues_enabled', 'merge_requests_enabled', - 'builds_enabled', 'wiki_enabled', 'snippets_enabled', 'container_registry_enabled', - 'shared_runners_enabled', 'public', 'visibility_level', 'import_url', + 'path', 'namespace_id', 'description', + 'issues_enabled', 'merge_requests_enabled', + 'builds_enabled', 'wiki_enabled', + 'snippets_enabled', 'container_registry_enabled', + 'shared_runners_enabled', 'public', + 'visibility_level', 'import_url', 'public_builds', 'only_allow_merge_if_build_succeeds', 'only_allow_merge_if_all_discussions_are_resolved', 'lfs_enabled', 'request_access_enabled', @@ -206,7 +211,8 @@ class GitlabClient(object): logger.info("didnt find project: %s", logEncoding(resp.content)) else: for project in resp.json(): - if (project_name == project['name'] and group_id == project['namespace']['id']): + if (project_name == project['name'] and + group_id == project['namespace']['id']): project_found = project break @@ -219,7 +225,8 @@ class GitlabClient(object): email = email.lower() url = "%s?username=%s" % (self.users_url, str(username)) resp = requests.get(url, headers=self.headers) - # logger.debug("get_user_by_email response: %s" % resp.content+". Response code: %s" % resp.status_code) + # logger.debug("get_user_by_email response: %s" % resp.content+". + # Response code: %s" % resp.status_code) if not resp.json(): logger.info("didnt find user: %s", logEncoding(resp.content)) else: @@ -300,7 +307,8 @@ class GitlabClient(object): else: user_created = resp.json() -# logger.debug("create_user response: %s" % resp.content + ", Response code: %s" % resp.status_code) +# logger.debug("create_user response: %s" % resp.content + ", +# Response code: %s" % resp.status_code) return user_created @@ -322,7 +330,8 @@ class GitlabClient(object): """ Function removes a user from a gitlab project, using a given user id """ - url = self.projects_url + '/' + str(project_id) + '/members/' + str(int(uid)) + url = self.projects_url + '/' + \ + str(project_id) + '/members/' + str(int(uid)) return requests.delete(url, headers=self.headers) def list_users(self): @@ -469,22 +478,28 @@ class GitlabClient(object): def get_repository_files(self, project_id): """ - Function retrieves all files for a given repository by project id (In ICE projectId is 1:1 with repo_id) + Function retrieves all files for a given repository by project id + (In VVP projectId is 1:1 with repo_id) GET /projects/:id/repository/tree Doc: https://docs.gitlab.com/ce/api/repositories.html """ -# endpoint = self.url+self.BASE_CTX+"projects/"+str(project_id)+"/repository/tree" +# endpoint = self.url+self.BASE_CTX+"projects/"+str(project_id)+ +# "/repository/tree" endpoint = "%s%sprojects/%s/repository/tree" % ( self.url, self.BASE_CTX, str(project_id)) logger.debug("get_repository_files endpoint=" + endpoint) resp = requests.get(endpoint, headers=self.headers) - if resp.status_code == 404 and resp.json()['message'] == '404 Tree Not Found': - # When no initial commit has been created and there are no files in the repo, the - # response is not an empty list but "404 Tree Not Found." Intercept this and return + if resp.status_code == 404 and resp.json()['message'] == \ + '404 Tree Not Found': + # When no initial commit has been created and there are + # no files in the repo, the response is not an empty list + # but "404 Tree Not Found." Intercept this and return # empty list instead. - logger.info("get_repository_files: Looks like there are no associated file to project %s. Response : %s, status = %s", logEncoding( - project_id), logEncoding(resp.content), 404) + logger.info("get_repository_files: Looks like there are" + + "no associated file to project %s." + + "Response : %s, status = %s", logEncoding( + project_id), logEncoding(resp.content), 404) return [] return resp.json() @@ -534,8 +549,9 @@ class GitlabClient(object): https://docs.gitlab.com/ce/api/projects.html """ parameters = dict({k: kwargs[k] for k in kwargs if k in [ - 'push_events', 'issues_events', 'merge_requests_events', 'tag_push_events', - 'note_events', 'build_events', 'pipeline_events', 'wiki_events', + 'push_events', 'issues_events', 'merge_requests_events', + 'tag_push_events', 'note_events', 'build_events', + 'pipeline_events', 'wiki_events', 'enable_ssl_verification', 'token']}, id=project_id, url=url, @@ -544,13 +560,15 @@ class GitlabClient(object): if hook_id is None: # New hook endpoint = "%s/api/v3/projects/%s/hooks" % (self.url, project_id) - return requests.post(endpoint, json=parameters, headers=self.headers) + return requests.post(endpoint, json=parameters, + headers=self.headers) else: # Update existing hook parameters['hook_id'] = hook_id endpoint = "%s/api/v3/projects/%s/hooks/%s" % ( self.url, project_id, hook_id) - return requests.put(endpoint, json=parameters, headers=self.headers) + return requests.put(endpoint, json=parameters, + headers=self.headers) def delete_project_hook(self, project_id, hook_id): endpoint = "%s/api/v3/projects/%s/hooks/%s" % ( diff --git a/django/validationmanager/jenkins/__init__.py b/django/validationmanager/jenkins/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/jenkins/__init__.py +++ b/django/validationmanager/jenkins/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/jenkins/jenkins_client.py b/django/validationmanager/jenkins/jenkins_client.py index d8d383e..9ee929b 100644 --- a/django/validationmanager/jenkins/jenkins_client.py +++ b/django/validationmanager/jenkins/jenkins_client.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/migrations/0001_initial.py b/django/validationmanager/migrations/0001_initial.py index 4cb1430..15de079 100644 --- a/django/validationmanager/migrations/0001_initial.py +++ b/django/validationmanager/migrations/0001_initial.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -58,11 +58,18 @@ class Migration(migrations.Migration): migrations.CreateModel( name='ActiveJob', fields=[ - ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('uuid', models.UUIDField( + default=uuid.uuid4, editable=False, + primary_key=True, serialize=False)), ('url', models.URLField( - help_text=b' The jenkins job URL, which should uniquely identify one\n execution of the TestEngine.')), - ('checklist', models.ForeignKey(help_text=b' The checklist associated with this job.', - on_delete=django.db.models.deletion.CASCADE, to='engagementmanager.Checklist')), + help_text=b' The jenkins job URL, which should \ + uniquely identify one\n \ + execution of the TestEngine.')), + ('checklist', models.ForeignKey( + help_text=b' \ + The checklist associated with this job.', + on_delete=django.db.models.deletion.CASCADE, + to='engagementmanager.Checklist')), ], options={ 'db_table': 'ice_vm_active_job', @@ -71,10 +78,13 @@ class Migration(migrations.Migration): migrations.CreateModel( name='ValidationTest', fields=[ - ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('uuid', models.UUIDField(default=uuid.uuid4, + editable=False, + primary_key=True, serialize=False)), ('name', models.CharField(max_length=128)), ('line_items', models.ManyToManyField( - to='engagementmanager.ChecklistLineItem', verbose_name=b'Satisfies Line Items')), + to='engagementmanager.ChecklistLineItem', + verbose_name=b'Satisfies Line Items')), ], options={ 'db_table': 'ice_vm_validation_test', diff --git a/django/validationmanager/migrations/0002_auto_20161019_2056.py b/django/validationmanager/migrations/0002_auto_20161019_2056.py index 653f5f4..d2213c7 100644 --- a/django/validationmanager/migrations/0002_auto_20161019_2056.py +++ b/django/validationmanager/migrations/0002_auto_20161019_2056.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/migrations/0003_auto_20170423_0531.py b/django/validationmanager/migrations/0003_auto_20170423_0531.py index bcc716a..6707a10 100644 --- a/django/validationmanager/migrations/0003_auto_20170423_0531.py +++ b/django/validationmanager/migrations/0003_auto_20170423_0531.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -53,6 +53,8 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='validationtest', name='line_items', - field=models.ManyToManyField(to='engagementmanager.ChecklistLineItem', verbose_name='Satisfies Line Items'), + field=models.ManyToManyField( + to='engagementmanager.ChecklistLineItem', + verbose_name='Satisfies Line Items'), ), ] diff --git a/django/validationmanager/migrations/__init__.py b/django/validationmanager/migrations/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/migrations/__init__.py +++ b/django/validationmanager/migrations/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/models.py b/django/validationmanager/models.py index dab60ce..03ef18f 100644 --- a/django/validationmanager/models.py +++ b/django/validationmanager/models.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -52,7 +52,8 @@ class ValidationTest(models.Model): as the first word in the TAP description. """ - uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, + editable=False) name = models.CharField(max_length=128) line_items = models.ManyToManyField(ChecklistLineItem, verbose_name="Satisfies Line Items") diff --git a/django/validationmanager/rados/__init__.py b/django/validationmanager/rados/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/rados/__init__.py +++ b/django/validationmanager/rados/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/rados/rgwa_client.py b/django/validationmanager/rados/rgwa_client.py index 232b900..9b72290 100644 --- a/django/validationmanager/rados/rgwa_client.py +++ b/django/validationmanager/rados/rgwa_client.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -94,11 +94,12 @@ class RGWAClient(object): """ valid_args = { - 'quota_type': ['user', 'bucket'], - 'key_type': ['s3', 'swift'], - }, + 'quota_type': ['user', 'bucket'], + 'key_type': ['s3', 'swift'], + }, - def __init__(self, base_url, access_key=None, secret_key=None, verify='/etc/ssl/certs/ca-certificates.crt', + def __init__(self, base_url, access_key=None, secret_key=None, + verify='/etc/ssl/certs/ca-certificates.crt', return_raw_response=False): """ @@ -259,7 +260,8 @@ class RGWAClient(object): # http://docs.ceph.com/docs/master/radosgw/adminops/ # - def get_usage(self, uid=None, start=None, end=None, show_entries=False, show_summary=False): + def get_usage(self, uid=None, start=None, end=None, show_entries=False, + show_summary=False): """Request bandwidth usage information. Note: this feature is disabled by default, can be enabled by setting @@ -353,7 +355,8 @@ class RGWAClient(object): purge_data=purge_data, ) - def create_subuser(self, uid, subuser=None, secret_key=None, access_key=None, + def create_subuser(self, uid, subuser=None, + secret_key=None, access_key=None, key_type=None, access=None, generate_secret=False): """Create a new subuser. @@ -374,8 +377,8 @@ class RGWAClient(object): generate_secret=generate_secret, ) - def modify_subuser(self, uid, subuser, secret=None, key_type='swift', access=None, - generate_secret=False): + def modify_subuser(self, uid, subuser, secret=None, + key_type='swift', access=None, generate_secret=False): """Modify an existing subuser.""" return self._request( 'post', 'user', 'subuser', @@ -569,7 +572,8 @@ class RGWAClient(object): def get_user_quota(self, uid): return self.get_quota(uid=uid, quota_type='user') - def set_user_quota(self, uid, max_size_kb=None, max_objects=None, enabled=None): + def set_user_quota(self, uid, max_size_kb=None, + max_objects=None, enabled=None): return self.set_quota( uid=uid, quota_type='user', @@ -581,7 +585,8 @@ class RGWAClient(object): def get_user_bucket_quota(self, uid): return self.get_quota(uid=uid, quota_type='bucket') - def set_user_bucket_quota(self, uid, bucket, max_size_kb=None, max_objects=None, + def set_user_bucket_quota(self, uid, bucket, + max_size_kb=None, max_objects=None, enabled=None): return self.set_quota( uid=uid, diff --git a/django/validationmanager/rados/rgwa_client_factory.py b/django/validationmanager/rados/rgwa_client_factory.py index ff29897..ba29b32 100644 --- a/django/validationmanager/rados/rgwa_client_factory.py +++ b/django/validationmanager/rados/rgwa_client_factory.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/rest/__init__.py b/django/validationmanager/rest/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/rest/__init__.py +++ b/django/validationmanager/rest/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/rest/git_webhook_endpoint.py b/django/validationmanager/rest/git_webhook_endpoint.py index 4aeb5d4..1931e7d 100644 --- a/django/validationmanager/rest/git_webhook_endpoint.py +++ b/django/validationmanager/rest/git_webhook_endpoint.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/rest/http_response_custom.py b/django/validationmanager/rest/http_response_custom.py index 0a22551..d6f69b5 100644 --- a/django/validationmanager/rest/http_response_custom.py +++ b/django/validationmanager/rest/http_response_custom.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -52,7 +52,8 @@ class InvalidGitlabEventException(APIException): class InvalidJenkinsPhaseException(APIException): status_code = HTTP_400_BAD_REQUEST - default_detail = 'Jenkins job build notification phase was missing or invalid.' + default_detail = 'Jenkins job build notification phase \ + was missing or invalid.' class InvalidPayloadException(APIException): diff --git a/django/validationmanager/rest/jenkins_webhook_endpoint.py b/django/validationmanager/rest/jenkins_webhook_endpoint.py index 21b3760..6b0f312 100644 --- a/django/validationmanager/rest/jenkins_webhook_endpoint.py +++ b/django/validationmanager/rest/jenkins_webhook_endpoint.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -272,18 +272,23 @@ class JenkinsWebhookEndpoint(APIView): }} logger.debug('sending test_finished with payload %s', payload) - # The Validation Engine suite will always include a successful result with the description - # "test_this_sentinel_always_succeeds'. If it is not present, we assume something has gone + # The Validation Engine suite will always include a successful + # result with the description. + # "test_this_sentinel_always_succeeds'. If it is not present, + # we assume something has gone # wrong with the Validation Engine itself. # if 'test_this_sentinel_always_succeeds' not in test_results: - # logger.error('Validation Engine failed to include sentinel. Assuming it failed. Full log: %s', + # logger.error('Validation Engine failed to include sentinel. + # Assuming it failed. Full log: %s', # logEncoding(request.data['build']['log'])) - # payload['checklist']['error'] = 'The Validation Engine encountered an error.' - # # If possible, identify what specifically went wrong and provide a message to return to - # # the user. - # if 'fatal: Could not read from remote repository' in request.data['build']['log']: - # payload['checklist']['error'] += " There was a problem cloning a git repository." - + # payload['checklist']['error'] = 'The Validation Engine \ + # encountered an error.' + # If possible, identify what specifically went wrong and + # provide a message to return to the user. + # if 'fatal: Could not read from remote repository' + # in request.data['build']['log']: + # payload['checklist']['error'] += " There was a problem \ + # cloning a git repository." # Send Signal em_client.test_finished(checklist_test_results=payload['checklist']) diff --git a/django/validationmanager/tasks.py b/django/validationmanager/tasks.py new file mode 100644 index 0000000..5d7b0d2 --- /dev/null +++ b/django/validationmanager/tasks.py @@ -0,0 +1,49 @@ +from celery import Celery +from django.conf import settings +from engagementmanager.models import CheckListState + +celery_app = Celery( + broker='redis://redis', + backend='redis://redis', + ) + +# Celery signatures allow us to invoke the imagescanner celery task without +# importing or depending upon imagescanner's code here. (Because doing so would +# make all of imagescanner's dependencies get added to this Django project.) +# +# FIXME for some reason, requests submitted in this way do not show their +# arguments in the simple frontend's "Executing" and "Pending" lists. It +# appears only as "()" +_request_scan = celery_app.signature( + 'imagescanner.tasks.request_scan', + queue='scans', + ignore_result=True) + + +def request_scan(vf, checklist): + """Issue a request (using Celery and Redis) for the imagescanner to run. + + This function issues the request asynchronously and returns quickly. + + vf: + the VF corresponding to the image to be scanned. we use this to + determine the radosgw bucket name to search for images and the jenkins + job name to trigger with the image scan results. + + checklist: + the checklist to be updated with the results of the scan. + """ + # we can't necessarily look this up from the vf because there might be two + # available at the time this method runs (the new one, and the old one + # which will get changed to archive state) + + return _request_scan.delay( + source="https://%s/%s_%s/" % ( + settings.AWS_S3_HOST, vf.engagement.engagement_manual_id, vf.name), + path='', + recipients=[], + # this suffix should match the one in + # validationmanager.em_integration.vm_api.get_jenkins_job_config + jenkins_job_name=vf.jenkins_job_name() + '_scanner', + checklist_uuid=checklist.uuid, + ) diff --git a/django/validationmanager/templates/imagescanner_job_config.xml b/django/validationmanager/templates/imagescanner_job_config.xml new file mode 100644 index 0000000..19d5eb5 --- /dev/null +++ b/django/validationmanager/templates/imagescanner_job_config.xml @@ -0,0 +1,54 @@ +<?xml version='1.0' encoding='UTF-8'?> +<project> + <actions/> + <description>Handler for ImageScanner results</description> + <keepDependencies>false</keepDependencies> + <properties> + <com.tikal.hudson.plugins.notification.HudsonNotificationProperty plugin="notification@1.11"> + <endpoints> + <com.tikal.hudson.plugins.notification.Endpoint> + <protocol>HTTP</protocol> + <format>JSON</format> + <url>{{ notification_endpoint }}</url> + <event>finalized</event> + <timeout>30000</timeout> + <loglines>-1</loglines> + </com.tikal.hudson.plugins.notification.Endpoint> + </endpoints> + </com.tikal.hudson.plugins.notification.HudsonNotificationProperty> + <hudson.model.ParametersDefinitionProperty> + <parameterDefinitions> + <hudson.model.StringParameterDefinition> + <name>checklist_uuid</name> + <description>The UUID of the checklist to be validated.</description> + <defaultValue></defaultValue> + </hudson.model.StringParameterDefinition> + <hudson.model.StringParameterDefinition> + <name>status</name> + <description>The UNIX exit status of the scanner (0=success)</description> + <defaultValue></defaultValue> + </hudson.model.StringParameterDefinition> + <hudson.model.StringParameterDefinition> + <name>logurl</name> + <description>A URL to the imagescanner log file, which will be retrieved and parsed</description> + <defaultValue></defaultValue> + </hudson.model.StringParameterDefinition> + </parameterDefinitions> + </hudson.model.ParametersDefinitionProperty> + </properties> + <scm class="hudson.scm.NullSCM"/> + <canRoam>true</canRoam> + <disabled>false</disabled> + <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> + <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> + <triggers/> + <concurrentBuild>false</concurrentBuild> + <builders> + <hudson.tasks.Shell> + <command><![CDATA[#!/bin/sh +exec imagescanner-results-processor]]></command> + </hudson.tasks.Shell> + </builders> + <publishers/> + <buildWrappers/> +</project> diff --git a/django/validationmanager/tests/__init__.py b/django/validationmanager/tests/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/tests/__init__.py +++ b/django/validationmanager/tests/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/tests/testFinishedSignal.py b/django/validationmanager/tests/testFinishedSignal.py index bca44c1..5c1bd48 100644 --- a/django/validationmanager/tests/testFinishedSignal.py +++ b/django/validationmanager/tests/testFinishedSignal.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -42,7 +42,8 @@ from uuid import uuid4 from django.conf import settings from rest_framework.status import HTTP_200_OK -from engagementmanager.models import Vendor, ChecklistSection, ChecklistDecision, ChecklistLineItem +from engagementmanager.models import Vendor, ChecklistSection, \ + ChecklistDecision, ChecklistLineItem from engagementmanager.tests.test_base_entity import TestBaseEntity from engagementmanager.utils.constants import CheckListLineType,\ CheckListDecisionValue, Constants @@ -51,46 +52,67 @@ from engagementmanager.utils.constants import CheckListLineType,\ class TestTestFinishedSignalCase(TestBaseEntity): def childSetup(self): - self.createVendors([Constants.service_provider_company_name, 'Amdocs']) + self.createVendors([Constants.service_provider_company_name, + 'Amdocs']) self.createDefaultRoles() self.el_user = self.creator.createUser(Vendor.objects.get( name=Constants.service_provider_company_name), - self.randomGenerator("main-vendor-email"), '55501000199', 'el user', self.el, True) + self.randomGenerator("main-vendor-email"), '55501000199', + 'el user', self.el, True) self.user = self.creator.createUser(Vendor.objects.get( name=Constants.service_provider_company_name), - self.randomGenerator("main-vendor-email"), '55501000199', 'user', self.standard_user, True) + self.randomGenerator("main-vendor-email"), '55501000199', 'user', + self.standard_user, True) self.peer_reviewer = self.creator.createUser(Vendor.objects.get( name=Constants.service_provider_company_name), - self.randomGenerator("main-vendor-email"), '55501000199', 'peer-reviewer user', self.el, True) + self.randomGenerator("main-vendor-email"), '55501000199', + 'peer-reviewer user', self.el, True) token = settings.WEBHOOK_TOKEN self.urlStr = "/v/hook/test-complete/" + token self.req = dict() self.token = self.loginAndCreateSessionToken(self.el_user) self.template = self.creator.createDefaultCheckListTemplate() - self.engagement = self.creator.createEngagement('just-a-fake-uuid', 'Validation', None) + self.engagement = self.creator.createEngagement( + 'just-a-fake-uuid', 'Validation', None) self.engagement.engagement_team.add(self.el_user, self.user) self.checklist = self.creator.createCheckList( - 'some-checklist', 'Automation', 1, '{}', self.engagement, self.template, self.el_user, self.peer_reviewer) - self.section = ChecklistSection.objects.create(uuid=uuid4(), name=self.randomGenerator("randomString"), weight=1.0, description=self.randomGenerator( - "randomString"), validation_instructions=self.randomGenerator("randomString"), template=self.template) - self.line_item = ChecklistLineItem.objects.create(uuid=uuid4(), name=self.randomGenerator("randomString"), weight=1.0, description=self.randomGenerator( - "randomString"), line_type=CheckListLineType.auto.name, validation_instructions=self.randomGenerator("randomString"), template=self.template, section=self.section) # @UndefinedVariable + 'some-checklist', 'Automation', 1, '{}', self.engagement, + self.template, self.el_user, self.peer_reviewer) + self.section = ChecklistSection.objects.create( + uuid=uuid4(), name=self.randomGenerator("randomString"), + weight=1.0, description=self.randomGenerator( + "randomString"), + validation_instructions=self.randomGenerator("randomString"), + template=self.template) + self.line_item = ChecklistLineItem.objects.create( + uuid=uuid4(), name=self.randomGenerator("randomString"), + weight=1.0, description=self.randomGenerator( + "randomString"), line_type=CheckListLineType.auto.name, + validation_instructions=self.randomGenerator("randomString"), + template=self.template, section=self.section) self.decision = ChecklistDecision.objects.create( - uuid=uuid4(), checklist=self.checklist, template=self.template, lineitem=self.line_item) - self.vendor = Vendor.objects.get(name=Constants.service_provider_company_name) + uuid=uuid4(), checklist=self.checklist, template=self.template, + lineitem=self.line_item) + self.vendor = Vendor.objects.get( + name=Constants.service_provider_company_name) self.deploymentTarget = self.creator.createDeploymentTarget( - self.randomGenerator("randomString"), self.randomGenerator("randomString")) - self.vf = self.creator.createVF(self.randomGenerator("randomString"), - self.engagement, self.deploymentTarget, False, self.vendor) + self.randomGenerator("randomString"), + self.randomGenerator("randomString")) + self.vf = self.creator.createVF( + self.randomGenerator("randomString"), + self.engagement, + self.deploymentTarget, + False, self.vendor) def initBody(self): self.req['checklist'] = dict() self.req['checklist']['checklist_uuid'] = str(self.checklist.uuid) decisionData = dict() decisionData['line_item_id'] = str(self.line_item.uuid) - decisionData['value'] = CheckListDecisionValue.approved.name # @UndefinedVariable + # @UndefinedVariable + decisionData['value'] = CheckListDecisionValue.approved.name decisionData['audit_log_text'] = "audiot text blah blaj" self.req['checklist']['decisions'] = [decisionData] self.req['build'] = dict() @@ -98,14 +120,14 @@ class TestTestFinishedSignalCase(TestBaseEntity): self.req['build']['url'] = "http://samplejob" self.req['build']['log'] = "Jenkins Log Example" - ### TESTS ### def testFinishedSignalPositive(self): if not settings.IS_SIGNAL_ENABLED: return self.initBody() datajson = json.dumps(self.req, ensure_ascii=False) - response = self.c.post(self.urlStr, datajson, content_type='application/json', + response = self.c.post(self.urlStr, datajson, + content_type='application/json', **{'HTTP_AUTHORIZATION': "token " + self.token}) print('Got response : ' + str(response.status_code) + diff --git a/django/validationmanager/tests/test_git_push.py b/django/validationmanager/tests/test_git_push.py index e3798f3..acbb8f3 100644 --- a/django/validationmanager/tests/test_git_push.py +++ b/django/validationmanager/tests/test_git_push.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -44,7 +44,8 @@ from rest_framework.status import HTTP_200_OK from engagementmanager.models import Vendor, ChecklistSection, Checklist from engagementmanager.tests.test_base_entity import TestBaseEntity -from engagementmanager.utils.constants import CheckListState, EngagementType, Constants +from engagementmanager.utils.constants import CheckListState, \ + EngagementType, Constants class TestGitPushSignalCase(TestBaseEntity): @@ -57,33 +58,48 @@ class TestGitPushSignalCase(TestBaseEntity): self.fileAdded = "CHANGELOG" self.fileModified = "app/controller/application.rb" # self.associatedFiles = [self.fileAdded, self.fileModified] - self.associatedFiles = "[\"" + self.fileAdded + "\",\"" + self.fileModified + "\"]" + self.associatedFiles = "[\"" + self.fileAdded + \ + "\",\"" + self.fileModified + "\"]" # Create full engagement: - self.createVendors([Constants.service_provider_company_name, 'Amdocs']) + self.createVendors([Constants.service_provider_company_name, + 'Amdocs']) self.createDefaultRoles() self.el_user = self.creator.createUser(Vendor.objects.get( name=Constants.service_provider_company_name), - self.randomGenerator("main-vendor-email"), '55501000199', 'el user', self.el, True) + self.randomGenerator("main-vendor-email"), '55501000199', + 'el user', self.el, True) self.user = self.creator.createUser(Vendor.objects.get( name=Constants.service_provider_company_name), - self.randomGenerator("main-vendor-email"), '55501000199', 'user', self.standard_user, True) + self.randomGenerator("main-vendor-email"), '55501000199', + 'user', self.standard_user, True) self.peer_reviewer = self.creator.createUser(Vendor.objects.get( name=Constants.service_provider_company_name), - self.randomGenerator("main-vendor-email"), '55501000199', 'peer-reviewer user', self.el, True) + self.randomGenerator("main-vendor-email"), '55501000199', + 'peer-reviewer user', self.el, True) self.template = self.creator.createDefaultCheckListTemplate() self.engagement = self.creator.createEngagement( - 'just-a-fake-uuid', EngagementType.Validation.name, None) # @UndefinedVariable + 'just-a-fake-uuid', EngagementType.Validation.name, None) self.engagement.engagement_team.add(self.el_user, self.user) - self.checklist = self.creator.createCheckList('some-checklist', CheckListState.review.name, 1, - self.associatedFiles, self.engagement, self.template, self.el_user, self.el_user) # @UndefinedVariable - self.section = ChecklistSection.objects.create(uuid=uuid4(), name=self.randomGenerator("randomString"), weight=1.0, description=self.randomGenerator( - "randomString"), validation_instructions=self.randomGenerator("randomString"), template=self.template) - self.vendor = Vendor.objects.get(name=Constants.service_provider_company_name) + self.checklist = self.creator.createCheckList( + 'some-checklist', CheckListState.review.name, 1, + self.associatedFiles, self.engagement, self.template, + self.el_user, self.el_user) + self.section = ChecklistSection.objects.create( + uuid=uuid4(), name=self.randomGenerator("randomString"), + weight=1.0, + description=self.randomGenerator( + "randomString"), validation_instructions=self.randomGenerator( + "randomString"), template=self.template) + self.vendor = Vendor.objects.get( + name=Constants.service_provider_company_name) self.deploymentTarget = self.creator.createDeploymentTarget( - self.randomGenerator("randomString"), self.randomGenerator("randomString")) + self.randomGenerator("randomString"), self.randomGenerator( + "randomString")) self.vf = self.creator.createVF("TestVF-GitPush", self.engagement, - self.deploymentTarget, False, self.vendor, git_repo_url=self.gitRepoURL) + self.deploymentTarget, False, + self.vendor, + git_repo_url=self.gitRepoURL) def initBody(self): # Create JSON for body REST request. self.data['object_kind'] = "push" @@ -101,13 +117,13 @@ class TestGitPushSignalCase(TestBaseEntity): commitsData['modified'] = [self.fileModified] commitsData['removed'] = [] commitsList.append(commitsData) - for a in commitsData.values(): # Count number of commits in commitsData. + # Count number of commits in commitsData. + for a in commitsData.values(): if a != []: totalCommits += 1 self.data['commits'] = commitsList self.data['total_commits_count'] = totalCommits - ### TESTS ### def test_git_push_event_positive(self): if not settings.IS_SIGNAL_ENABLED: return @@ -119,11 +135,14 @@ class TestGitPushSignalCase(TestBaseEntity): print(datajson) headers = {'HTTP_X_GITLAB_EVENT': "Push Hook"} - response = self.c.post(self.urlStr, datajson, content_type='application/json', **headers) + response = self.c.post(self.urlStr, datajson, + content_type='application/json', **headers) print("Got response: " + str(response.status_code) + ", Expecting 200. Response body: " + response.reason_phrase) self.assertEqual(response.status_code, HTTP_200_OK) checklistState = Checklist.objects.get(uuid=self.checklist.uuid) - print("Checklist state (final, should be 'archive'): " + checklistState.state) - self.assertEqual(checklistState.state, CheckListState.archive.name) # @UndefinedVariable + print("Checklist state (final, should be 'archive'): " + + checklistState.state) + # @UndefinedVariable + self.assertEqual(checklistState.state, CheckListState.archive.name) diff --git a/django/validationmanager/tests/test_rgwa_client_factory.py b/django/validationmanager/tests/test_rgwa_client_factory.py index 0280fd0..dc38aa5 100644 --- a/django/validationmanager/tests/test_rgwa_client_factory.py +++ b/django/validationmanager/tests/test_rgwa_client_factory.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -40,7 +40,9 @@ from boto.s3.connection import S3Connection from engagementmanager.tests.test_base_entity import TestBaseEntity from validationmanager.rados.rgwa_client import RGWAClient -from validationmanager.rados.rgwa_client_factory import RGWAClientFactory as RGWAClientFactorySing +from validationmanager.rados.rgwa_client_factory import \ + RGWAClientFactory as RGWAClientFactorySing + class TestRGWAClientFactory(TestBaseEntity): def childSetup(self): @@ -52,4 +54,5 @@ class TestRGWAClientFactory(TestBaseEntity): def testStandardClientCreation(self): client = RGWAClientFactorySing.standard() - self.assertTrue(client is not None and isinstance(client, S3Connection)) + self.assertTrue( + client is not None and isinstance(client, S3Connection)) diff --git a/django/validationmanager/urls.py b/django/validationmanager/urls.py index 5c6edb8..50ec791 100644 --- a/django/validationmanager/urls.py +++ b/django/validationmanager/urls.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -38,12 +38,15 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. from django.conf.urls import url -from validationmanager.rest import git_webhook_endpoint, jenkins_webhook_endpoint +from validationmanager.rest import git_webhook_endpoint,\ + jenkins_webhook_endpoint urlpatterns = [ url(r'^hook/test-complete(?:/(?P<auth_token>[^/]+)/?)?$', - jenkins_webhook_endpoint.JenkinsWebhookEndpoint.as_view(), name='jenkins-notification-endpoint'), + jenkins_webhook_endpoint.JenkinsWebhookEndpoint.as_view(), + name='jenkins-notification-endpoint'), url(r'^hook/git-push(?:/(?P<auth_token>[^/]+)/?)?$', - git_webhook_endpoint.GitWebhookEndpoint.as_view(), name='git-push-endpoint'), + git_webhook_endpoint.GitWebhookEndpoint.as_view(), + name='git-push-endpoint'), ] diff --git a/django/validationmanager/utils/__init__.py b/django/validationmanager/utils/__init__.py index 1726c13..16f81cb 100644 --- a/django/validationmanager/utils/__init__.py +++ b/django/validationmanager/utils/__init__.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/utils/clients.py b/django/validationmanager/utils/clients.py index 0a6a34d..766f1b7 100644 --- a/django/validationmanager/utils/clients.py +++ b/django/validationmanager/utils/clients.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/utils/constants.py b/django/validationmanager/utils/constants.py index b110f23..32bf95d 100644 --- a/django/validationmanager/utils/constants.py +++ b/django/validationmanager/utils/constants.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. diff --git a/django/validationmanager/utils/keyawaredefaultdict.py b/django/validationmanager/utils/keyawaredefaultdict.py index b9a8254..2d0e6a2 100644 --- a/django/validationmanager/utils/keyawaredefaultdict.py +++ b/django/validationmanager/utils/keyawaredefaultdict.py @@ -1,5 +1,5 @@ -# -# ============LICENSE_START========================================== +# +# ============LICENSE_START========================================== # org.onap.vvp/engagementmgr # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -40,14 +40,16 @@ from collections import defaultdict class KeyAwareDefaultDict(defaultdict): - """A defaultdict whose missing-key factory is passed the missing key as its only argument. + """A defaultdict whose missing-key factory + is passed the missing key as its only argument. See https://docs.python.org/3/library/collections.html#defaultdict-objects """ def __missing__(self, key): - # This code is modified copypasta from help(collections.defaultdict.__missing__). + # This code is modified copypasta from help + # (collections.defaultdict.__missing__). # Unfortunately there is no simpler way to override its behavior. if self.default_factory is None: raise KeyError((key,)) |