diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api/migrations/0003_auto_20190102_1956.py | 18 | ||||
-rw-r--r-- | src/api/models.py | 6 | ||||
-rw-r--r-- | src/booking/migrations/0002_booking_pdf.py | 18 | ||||
-rw-r--r-- | src/booking/models.py | 1 | ||||
-rw-r--r-- | src/booking/views.py | 2 | ||||
-rw-r--r-- | src/templates/workflow/confirm.html | 6 | ||||
-rw-r--r-- | src/workflow/models.py | 91 | ||||
-rw-r--r-- | src/workflow/resource_bundle_workflow.py | 9 |
8 files changed, 133 insertions, 18 deletions
diff --git a/src/api/migrations/0003_auto_20190102_1956.py b/src/api/migrations/0003_auto_20190102_1956.py new file mode 100644 index 0000000..2ea5d70 --- /dev/null +++ b/src/api/migrations/0003_auto_20190102_1956.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1 on 2019-01-02 19:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_remove_job_delta'), + ] + + operations = [ + migrations.AlterField( + model_name='accessconfig', + name='delta', + field=models.TextField(default='{}'), + ), + ] diff --git a/src/api/models.py b/src/api/models.py index b6bd79f..cc25f82 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -343,7 +343,7 @@ class AccessConfig(TaskConfig): user = models.ForeignKey(User, on_delete=models.CASCADE) revoke = models.BooleanField(default=False) context = models.TextField(default="") - delta = models.TextField() + delta = models.TextField(default="{}") def to_dict(self): d = {} @@ -691,12 +691,12 @@ class JobFactory(object): config = AccessConfig() config.access_type = access_type config.user = user - if context: - config.set_context(context) config.save() relation.config = config relation.save() config.clear_delta() + if context: + config.set_context(context) config.set_access_type(access_type) config.set_revoke(revoke) config.set_user(user) diff --git a/src/booking/migrations/0002_booking_pdf.py b/src/booking/migrations/0002_booking_pdf.py new file mode 100644 index 0000000..53232c9 --- /dev/null +++ b/src/booking/migrations/0002_booking_pdf.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1 on 2018-11-09 16:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('booking', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='booking', + name='pdf', + field=models.TextField(blank=True, default=''), + ), + ] diff --git a/src/booking/models.py b/src/booking/models.py index d0c77b4..74b766d 100644 --- a/src/booking/models.py +++ b/src/booking/models.py @@ -57,6 +57,7 @@ class Booking(models.Model): config_bundle = models.ForeignKey(ConfigBundle, on_delete=models.SET_NULL, null=True) project = models.CharField(max_length=100, default="", blank=True, null=True) lab = models.ForeignKey(Lab, null=True, on_delete=models.SET_NULL) + pdf = models.TextField(blank=True, default="") class Meta: db_table = 'booking' diff --git a/src/booking/views.py b/src/booking/views.py index ab43519..29b53e2 100644 --- a/src/booking/views.py +++ b/src/booking/views.py @@ -112,7 +112,7 @@ def booking_detail_view(request, booking_id): { 'title': 'Booking Details', 'booking': booking, - 'pdf': ResourceManager().makePDF(booking.resource), + 'pdf': booking.pdf, 'user_id': user.id }) diff --git a/src/templates/workflow/confirm.html b/src/templates/workflow/confirm.html index 277c305..2510204 100644 --- a/src/templates/workflow/confirm.html +++ b/src/templates/workflow/confirm.html @@ -114,9 +114,9 @@ function fixVlans() { req.onerror = function() { alert("problem submitting form"); } req.onreadystatechange = function() { //replaces current page with response if(req.readyState === 4 ) { - document.open(); - document.write(req.responseText); - document.close(); + var d = document.getElementById("vlan_warning").innerHTML = ""; + document.getElementById("confirm_button").disabled = false; + document.getElementById("cancel_button").disabled = false; } } req.send(formData); diff --git a/src/workflow/models.py b/src/workflow/models.py index 66b1739..495ce07 100644 --- a/src/workflow/models.py +++ b/src/workflow/models.py @@ -27,13 +27,11 @@ from booking.models import Booking class BookingAuthManager(): LFN_PROJECTS = ["opnfv"] # TODO - def parse_url(self, info_url): - """ - will return the PTL in the INFO file on success, or None - """ + def parse_github_url(self, url): + project_leads = [] try: - parts = info_url.split("/") - if parts[0].find("http") > -1: # the url include http(s):// + parts = url.split("/") + if "http" in parts[0]: # the url include http(s):// parts = parts[2:] if parts[-1] != "INFO.yaml": return None @@ -48,13 +46,84 @@ class BookingAuthManager(): info_file = requests.get(url, timeout=15).text info_parsed = yaml.load(info_file) ptl = info_parsed.get('project_lead') - if not ptl: + if ptl: + project_leads.append(ptl) + sub_ptl = info_parsed.get("subproject_lead") + if sub_ptl: + project_leads.append(sub_ptl) + + except Exception: + pass + + return project_leads + + def parse_gerrit_url(self, url): + project_leads = [] + try: + parts = url.split("/") + if "http" in parts[0]: # the url include http(s):// + parts = parts[2:] + if "f=INFO.yaml" not in parts[-1].split(";"): return None - return ptl + if "gerrit.opnfv.org" not in parts[0]: + return None + # now to download and parse file + url = "https://" + "/".join(parts) + info_file = requests.get(url, timeout=15).text + info_parsed = yaml.load(info_file) + ptl = info_parsed.get('project_lead') + if ptl: + project_leads.append(ptl) + sub_ptl = info_parsed.get("subproject_lead") + if sub_ptl: + project_leads.append(sub_ptl) except Exception: return None + return project_leads + + def parse_opnfv_git_url(self, url): + project_leads = [] + try: + parts = url.split("/") + if "http" in parts[0]: # the url include http(s):// + parts = parts[2:] + if "INFO.yaml" not in parts[-1]: + return None + if "git.opnfv.org" not in parts[0]: + return None + if parts[-2] == "tree": + parts[-2] = "plain" + # now to download and parse file + url = "https://" + "/".join(parts) + info_file = requests.get(url, timeout=15).text + info_parsed = yaml.load(info_file) + ptl = info_parsed.get('project_lead') + if ptl: + project_leads.append(ptl) + sub_ptl = info_parsed.get("subproject_lead") + if sub_ptl: + project_leads.append(sub_ptl) + + except Exception: + return None + + return project_leads + + def parse_url(self, info_url): + """ + will return the PTL in the INFO file on success, or None + """ + if "github" in info_url: + return self.parse_github_url(info_url) + + if "gerrit.opnfv.org" in info_url: + return self.parse_gerrit_url(info_url) + + if "git.opnfv.org" in info_url: + return self.parse_opnfv_git_url(info_url) + def booking_allowed(self, booking, repo): """ This is the method that will have to change whenever the booking policy changes in the Infra @@ -485,6 +554,12 @@ class Repository(): booking.collaborators.add(collaborator) try: + booking.pdf = ResourceManager().makePDF(booking.resource) + booking.save() + except Exception as e: + return "BOOK, failed to create Pod Desriptor File: " + str(e) + + try: JobFactory.makeCompleteJob(booking) except Exception as e: return "BOOK, serializing for api generated exception: " + str(e) + " CODE:0xFFFF" diff --git a/src/workflow/resource_bundle_workflow.py b/src/workflow/resource_bundle_workflow.py index 712c92b..4858ebe 100644 --- a/src/workflow/resource_bundle_workflow.py +++ b/src/workflow/resource_bundle_workflow.py @@ -131,9 +131,12 @@ class Define_Hardware(WorkflowStep): try: self.form = HardwareDefinitionForm(request.POST) if self.form.is_valid(): - self.update_models(self.form.cleaned_data) - self.update_confirmation() - self.metastep.set_valid("Step Completed") + if len(json.loads(self.form.cleaned_data['filter_field'])['labs']) != 1: + self.metastep.set_invalid("Please select one lab") + else: + self.update_models(self.form.cleaned_data) + self.update_confirmation() + self.metastep.set_valid("Step Completed") else: self.metastep.set_invalid("Please complete the fields highlighted in red to continue") pass |