def add_revision(self, blueprint_id: uuid = None, CSAR: FileStorage = None, blueprint_path: Path = None, revision_msg: str = None, minor_to_increment: str = None): """ saves blueprint into database. One of (CSAR, blueprint_path) must not be None. If blueprint_token is None, it is generated and returned together with version_id if minor_to_increment not None, minor version of tag will be incremented, else, major version (of all tags) will be incremented """ token = blueprint_id or uuid.uuid4() path = Path( tempfile.mkdtemp()) if not blueprint_path else blueprint_path if CSAR is not None: workdir = Path(tempfile.mkdtemp()) CSAR_path = workdir / Path(CSAR.filename) workdir.mkdir(parents=True, exist_ok=True) CSAR.save(CSAR_path.open('wb')) try: csar_to_blueprint(csar=CSAR_path, dst=path) except shutil.ReadError as e: logger.error(str(e)) shutil.rmtree(str(workdir)) return None, str(e) shutil.rmtree(str(workdir)) try: validate_csar(path, raise_exceptions=True) except Exception as e: logger.error(str(e)) shutil.rmtree(str(path)) return None, str(e) elif blueprint_path is None: # both params cannot be None raise AttributeError('Both CSAR and blueprint path cannot be None') result = self.connection.save_CSAR( csar_path=path, csar_token=token, message=revision_msg, minor_to_increment=minor_to_increment) https_url = self.connection.get_repo_url(csar_token=token) users = self.connection.get_user_list(csar_token=token) if CSAR is not None: shutil.rmtree(str(path)) return { 'message': "Revision saved to GitDB", 'blueprint_id': result['token'], 'url': https_url, 'commit_sha': result['commit_sha'], 'version_id': result['version_tag'], 'users': users, 'timestamp': datetime_now_to_string() }, None
def test_no_meta_success(self, csar_unpacked): csar_path = csar_unpacked / 'CSAR-no-meta-ok' assert blueprint2CSAR.validate_csar(csar_path) # it should not fail blueprint2CSAR.validate_csar(csar_path, raise_exceptions=True)
def test_meta_section_missing_key(self, csar_unpacked): csar_path = csar_unpacked / 'CSAR-no-meta-missing-key' assert not blueprint2CSAR.validate_csar(csar_path) with pytest.raises(blueprint2CSAR.BrokenMetadataException): blueprint2CSAR.validate_csar(csar_path, raise_exceptions=True)
def test_no_meta_no_meta_section(self, csar_unpacked): csar_path = csar_unpacked / 'CSAR-no-meta-no-meta-section' assert not blueprint2CSAR.validate_csar(csar_path) with pytest.raises(blueprint2CSAR.NoMetadataException): blueprint2CSAR.validate_csar(csar_path, raise_exceptions=True)
def test_no_meta_no_entry_definitions(self, csar_unpacked): csar_path = csar_unpacked / 'CSAR-no-meta-no-entry-def' assert not blueprint2CSAR.validate_csar(csar_path) with pytest.raises(blueprint2CSAR.NoEntryDefinitionsFoundException): blueprint2CSAR.validate_csar(csar_path, raise_exceptions=True)
def test_not_meta_multiple_yaml(self, csar_unpacked): csar_path = csar_unpacked / 'CSAR-no-meta-multiple-yaml' assert not blueprint2CSAR.validate_csar(csar_path) with pytest.raises(blueprint2CSAR.MultipleDefinitionsFoundException): blueprint2CSAR.validate_csar(csar_path, raise_exceptions=True)
def test_no_other_definitions(self, csar_unpacked): csar_path = csar_unpacked / 'CSAR-no-other-def' assert not blueprint2CSAR.validate_csar(csar_path) with pytest.raises(blueprint2CSAR.NoOtherDefinitionsFoundException): blueprint2CSAR.validate_csar(csar_path, raise_exceptions=True)
def test_broken_metadata_file(self, csar_unpacked): csar_path = csar_unpacked / 'CSAR-broken-meta' assert not blueprint2CSAR.validate_csar(csar_path) with pytest.raises(blueprint2CSAR.BrokenMetadataException): blueprint2CSAR.validate_csar(csar_path, raise_exceptions=True)