Esempio n. 1
0
 def create(cls, *args, **kwargs):
     # OpenEdXInstance constructor accepts either a 'sub_domain' or 'instance_lms_domain' value. Only generate a
     # random value for 'internal_lms_domain' if neither 'sub_domain' nor 'internal_lms_domain' are provided.
     if 'sub_domain' not in kwargs and 'internal_lms_domain' not in kwargs:
         kwargs = kwargs.copy()
         random_id = str(uuid.uuid4())[:8]
         sub_domain = '{}.integration'.format(random_id)
         kwargs['internal_lms_domain'] = generate_internal_lms_domain(sub_domain)
     return super(OpenEdXInstanceFactory, cls).create(*args, **kwargs)
Esempio n. 2
0
 def create(cls, *args, **kwargs):
     # OpenEdXInstance constructor accepts either a 'sub_domain' or 'instance_lms_domain' value. Only generate a
     # random value for 'internal_lms_domain' if neither 'sub_domain' nor 'internal_lms_domain' are provided.
     if 'sub_domain' not in kwargs and 'internal_lms_domain' not in kwargs:
         kwargs = kwargs.copy()
         random_id = str(uuid.uuid4())[:8]
         sub_domain = '{}.integration'.format(random_id)
         kwargs['internal_lms_domain'] = generate_internal_lms_domain(sub_domain)
     return super(OpenEdXInstanceFactory, cls).create(*args, **kwargs)
Esempio n. 3
0
    def clean(self):
        """
        Verify that the subdomain has not already been taken by any running instance.

        We can't do this in a regular validator, since we have to allow the subdomain of the
        instance associated with this application.
        """
        generated_domain = generate_internal_lms_domain(self.subdomain)
        if self.instance is not None and self.instance.internal_lms_domain == generated_domain:
            return
        if OpenEdXInstance.objects.filter(internal_lms_domain=generated_domain).exists():
            subdomain_error = ValidationError(
                message='This domain is already taken.',
                code='unique',
            )
            raise ValidationError({'subdomain': [subdomain_error]})
Esempio n. 4
0
    def clean(self):
        """
        Verify that the subdomain has not already been taken by any running instance.

        We can't do this in a regular validator, since we have to allow the subdomain of the
        instance associated with this application.
        """
        generated_domain = generate_internal_lms_domain(self.subdomain)
        if self.instance is not None and self.instance.internal_lms_domain == generated_domain:
            return
        if OpenEdXInstance.objects.filter(internal_lms_domain=generated_domain).exists():
            subdomain_error = ValidationError(
                message='This domain is already taken.',
                code='unique',
            )
            raise ValidationError({'subdomain': [subdomain_error]})
Esempio n. 5
0
    def update_instance_from_pr(self, pr):
        """
        Update/create the associated sandbox instance with settings from the given pull request.

        This will not spawn a new AppServer.
        This method will automatically save this WatchedPullRequest's 'instance' field.
        """
        # The following fields should never change:
        assert self.github_pr_url == pr.github_pr_url
        assert self.fork_name == pr.fork_name
        assert self.branch_name == pr.branch_name
        # Create an instance if necessary:
        instance = self.instance or OpenEdXInstance()
        instance.internal_lms_domain = generate_internal_lms_domain('pr{number}.sandbox'.format(number=pr.number))
        instance.edx_platform_repository_url = self.repository_url
        instance.edx_platform_commit = self.get_branch_tip()
        instance.name = (
            'PR#{pr.number}: {pr.truncated_title} ({pr.username}) - {i.reference_name} ({commit_short_id})'
            .format(pr=pr, i=self, commit_short_id=instance.edx_platform_commit[:7])
        )
        instance.configuration_extra_settings = pr.extra_settings
        instance.use_ephemeral_databases = pr.use_ephemeral_databases(instance.domain)
        instance.configuration_source_repo_url = pr.get_extra_setting(
            'edx_ansible_source_repo', default=instance.configuration_source_repo_url
        )
        instance.configuration_version = pr.get_extra_setting(
            'configuration_version', default=instance.configuration_version
        )
        # Save atomically. (because if the instance gets created but self.instance failed to
        # update, then any subsequent call to update_instance_from_pr() would try to create
        # another instance, which would fail due to unique domain name constraints.)
        with transaction.atomic():
            instance.save()
            if not self.instance:
                self.instance = instance
                self.save(update_fields=["instance"])  # pylint: disable=no-member