Beispiel #1
0
    def submit(self, allow_invalid=False):

        self.db_desc = Descriptor()

        self.db_desc.is_public = self.is_public
        self.db_desc.user_id = self.user

        file = create_temporary_file(self.container.get_data())

        if (isinstance(self.container, DescriptorDataCandidateURLContainer)):
            self.db_desc.data_url = self.container.get_url()
            self.db_desc.automatic_updating = self.automatic_updating
        else:
            self.db_desc.data_url = ""

        filename = uuid.uuid4().hex
        self.db_desc.data_file.save(filename,
                                    ContentFile(self.container.get_data()))

        self.db_desc.md5 = calculate_MD5(self.container.get_data())

        if (self.carmin_platform):
            self.db_desc.carmin_platform = self.carmin_platform

        # Validation
        try:
            bosh.validate(file.name)
            self.validated = True
        except Exception as exc:
            self.validated = False
            file.close()
            if (not allow_invalid):
                # An invalid descriptor is allowed on submission only if the 'allow_invalid' argument is set
                return False
            # Add error message to desc
            self.db_desc.execution_status = EXECUTION_STATUS_ERROR
            self.db_desc.error_message = str(exc).replace('\n', '<br>')
            self.db_desc.last_updated = datetime.date.today()
            self.db_desc.save()
            return True

        self.db_desc.execution_status = EXECUTION_STATUS_UNCHECKED

        desc_JSON = json.loads(file.read())

        self.db_desc.tool_name = desc_JSON["name"]
        self.db_desc.version = desc_JSON["tool-version"]

        self.db_desc.last_updated = datetime.date.today()

        self.db_desc.save()

        # Generate all the test profiles.
        desc_entry = DescriptorEntry(self.db_desc)
        desc_entry.generate_tests()

        return True
Beispiel #2
0
    def update(self, scheduled=False):
        
        self.unset_erroneous()                            
        user = self.db_car.user
        is_public = self.db_car.is_public
        
        data_getter = CarminPlatformCandidate(self.db_car.root_url, self.db_car.api_key)
        valid = data_getter.validate()
        if (not valid):

            self.set_erroneous(data_getter.get_message())

            # Check if the platform is not valid due to the fact that its absent of any boutiques descriptors
            if (not data_getter.is_empty()):
                # Otherwise its a platform error and we should propagate it to all the descriptor entries pertaining to this platform
                self.propagate_error()

            else:
                
                # Fetch all the descriptors and delete them
                for db_desc in self.get_descriptors().all():
                    desc = desc_utils.DescriptorEntry(db_desc)
                    desc.delete()
            return
        # No problems with the carmin platform, and we know there is at least one boutiques descriptor
        fetched_descriptors = data_getter.get_raw_descriptors()
        fetched_md5 = {}
        for fetched_descriptor in fetched_descriptors:
            md5 = calculate_MD5(fetched_descriptor)
            fetched_md5[md5] = fetched_descriptor
            
        current_md5 = {}
        for db_descriptor in self.get_descriptors():
            current_md5[db_descriptor.md5] = desc_utils.DescriptorEntry(db_descriptor)
        

        # Add the new descriptors to database
        # If the update is performed in the context of testing scheduling, show those newly created descriptors as being scheduled for testing.
        #print(current_md5)
        for fetched in fetched_md5:
            if (not current_md5.get(fetched)):
                data = self._generate_descriptor(fetched_md5[fetched])
                if (scheduled and data.is_valid()):
                    desc = desc_utils.DescriptorEntry(data.get_db())
                    desc.set_scheduled()
            
                
                
        
        # Remove descriptors that are not part of the fetched set
        # Additionaly, for descriptors that do belong, show them as being scheduled for testing.
        for current in current_md5:
            if (not fetched_md5.get(current)):
                current_md5[current].delete()
            else:
                current_md5[current].update(force_static_validation=True, scheduled=scheduled)
Beispiel #3
0
 def get_MD5(self):
     if (self.container.is_medium_erroneous()):
         return "0"
     return calculate_MD5(self.container.get_data())
Beispiel #4
0
                 "boutiques_descriptors/tests_bad_b.json")).read()
VALID_UNSUCC_DESC_C = open(
    os.path.join(os.path.dirname(root_path),
                 "boutiques_descriptors/tests_bad_c.json")).read()

INVALID_DESC_A = open(
    os.path.join(os.path.dirname(root_path),
                 "boutiques_descriptors/tests_invalid_a.json")).read()
INVALID_DESC_B = open(
    os.path.join(os.path.dirname(root_path),
                 "boutiques_descriptors/tests_invalid_b.json")).read()
INVALID_DESC_C = open(
    os.path.join(os.path.dirname(root_path),
                 "boutiques_descriptors/tests_invalid_c.json")).read()

VALID_SUCC_DESC_A_MD5 = calculate_MD5(VALID_SUCC_DESC_A.encode())
VALID_SUCC_DESC_B_MD5 = calculate_MD5(VALID_SUCC_DESC_B.encode())
VALID_SUCC_DESC_C_MD5 = calculate_MD5(VALID_SUCC_DESC_C.encode())
VALID_SUCC_DESC_D_MD5 = calculate_MD5(VALID_SUCC_DESC_D.encode())

VALID_UNSUCC_DESC_A_MD5 = calculate_MD5(VALID_UNSUCC_DESC_A.encode())
VALID_UNSUCC_DESC_B_MD5 = calculate_MD5(VALID_UNSUCC_DESC_B.encode())
VALID_UNSUCC_DESC_C_MD5 = calculate_MD5(VALID_UNSUCC_DESC_C.encode())

INVALID_DESC_A_MD5 = calculate_MD5(INVALID_DESC_A.encode())
INVALID_DESC_B_MD5 = calculate_MD5(INVALID_DESC_B.encode())
INVALID_DESC_C_MD5 = calculate_MD5(INVALID_DESC_C.encode())

VALID_MULTIPLE_TESTS_DESC = open(
    os.path.join(os.path.dirname(root_path),
                 "boutiques_descriptors/tests_multiple.json")).read()