예제 #1
0
    def __init__(self, deployment):
        if deployment:
            self.uuid = str(uuid.uuid4())
            self.deployment = deployment
            self.deployment_uuid = deployment.uuid
            self.storage_path = os.path.join(get_path(), self.__tablename__,
                                             self.uuid)
            self.plugin = None
            self.test_artifact = deployment.test_artifact

            plugins_available = ModuleLoader().load('plugins')
            for p in plugins_available:
                if p.plugin_type == self.test_artifact.plugin:
                    self.plugin = p

            if not self.plugin:
                raise LookupError(
                    f"Could not find matching plugin for '{self.test_artifact.plugin}'."
                )

            db_session.add(self)
            db_session.commit()

            if not os.path.exists(self.fq_storage_path):
                os.makedirs(self.fq_storage_path)
        else:
            raise Exception(f'Linked entities do not exist.')
예제 #2
0
    def create(cls, name, repository_url):
        # New Project
        if not Project.exists(name):
            import uuid
            new_uuid = str(uuid.uuid4())
            new_storage_path = path.join(Project.__tablename__, new_uuid)
            project = Project(new_uuid, name, repository_url, new_storage_path)
            current_app.logger.info('Project created: ' + str(project))

        # Existing Project
        else:
            project = Project.query.filter_by(name=name).first()
            if project.is_che_project:
                copytree(path.join(get_dir_prefix(),
                                   project.repository_src_url),
                         path.join(get_path(), project.storage_path),
                         dirs_exist_ok=True)
            else:
                git.Git(path.join(get_path(), project.storage_path)).pull()
            current_app.logger.info(f"Project {str(project)} updated.")

        return project
예제 #3
0
    def __init__(self, testartifact):
        self.uuid = str(uuid.uuid4())
        self.testartifact_uuid = testartifact.uuid
        self.storage_path = os.path.join(get_path(), self.__tablename__,
                                         self.uuid)
        self.__test_artifact = testartifact
        self.sut_hostname = 'localhost'
        self.ti_hostname = 'localhost'

        if testartifact:
            db_session.add(self)
            db_session.commit()
        else:
            raise Exception(f'Linked entities do not exist.')

        if not os.path.exists(self.storage_path):
            os.makedirs(self.storage_path)
예제 #4
0
    def __init__(self, project, sut_tosca_path, sut_inputs_path,
                 ti_tosca_path, ti_inputs_path, tmp_dir, policy, plugin):
        self.uuid = str(uuid.uuid4())
        self.project_uuid = project.uuid
        self.storage_path = os.path.join(get_path(), self.__tablename__, self.uuid)
        self.policy = policy
        self.plugin = plugin

        if not os.path.exists(self.fq_storage_path):
            os.makedirs(self.fq_storage_path)

        self.commit_hash = project.commit_hash

        # Copy repository excluding the '.git' directory
        src_dir = project.fq_storage_path
        if os.path.isdir(src_dir) and os.path.isdir(self.fq_storage_path):
            copytree(src_dir, self.fq_storage_path, ignore=ignore_patterns('.git'), dirs_exist_ok=True)

        # Set default paths for the artifacts and copy them into the testartifact folder in the RepoDir of RadonCTT
        self.sut_tosca_path = os.path.join(RepoDir, TestArtifact.sut_default_file_name)
        sut_tosca_path_fq = os.path.join(self.fq_storage_path, self.sut_tosca_path)
        os.makedirs(os.path.dirname(sut_tosca_path_fq), exist_ok=True)
        copy(sut_tosca_path, sut_tosca_path_fq)

        self.ti_tosca_path = os.path.join(RepoDir, TestArtifact.ti_default_file_name)
        ti_tosca_path_fq = os.path.join(self.fq_storage_path, self.ti_tosca_path)
        os.makedirs(os.path.dirname(ti_tosca_path_fq), exist_ok=True)
        copy(ti_tosca_path, ti_tosca_path_fq)

        if sut_inputs_path:
            self.sut_inputs_path = os.path.join(RepoDir, TestArtifact.sut_inputs_default_file_name)
            sut_inputs_path_fq = os.path.join(self.fq_storage_path, self.sut_inputs_path)
            os.makedirs(os.path.dirname(sut_inputs_path_fq), exist_ok=True)
            copy(sut_inputs_path, sut_inputs_path_fq)

        if ti_inputs_path:
            self.ti_inputs_path = os.path.join(RepoDir, TestArtifact.ti_inputs_default_file_name)
            ti_inputs_path_fq = os.path.join(self.fq_storage_path, self.ti_inputs_path)
            os.makedirs(os.path.dirname(ti_inputs_path_fq), exist_ok=True)
            copy(ti_inputs_path, ti_inputs_path_fq)

        db_session.add(self)
        db_session.commit()

        rmtree(tmp_dir, ignore_errors=True)
예제 #5
0
 def fq_storage_path(self):
     return os.path.join(get_path(), self.storage_path)
예제 #6
0
 def storage_path(self):
     return os.path.join(get_path(), self.__tablename__, self.uuid)
예제 #7
0
import os

from sqlalchemy import create_engine, event
from sqlalchemy.engine import Engine
from sqlalchemy.pool import SingletonThreadPool
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

from util.configuration import get_path, DBFile, DefaultDirectoryPrefix

os.makedirs(get_path(), exist_ok=True)
db_path = os.path.join(get_path(), DBFile)

engine = create_engine('sqlite:///' + db_path,
                       convert_unicode=True,
                       poolclass=SingletonThreadPool)
db_session = scoped_session(
    sessionmaker(autocommit=False, autoflush=False, bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()


def init_db():
    from models import project, testartifact, deployment, execution, result
    Base.metadata.create_all(bind=engine)


# Explicitly enable ForeignKey support for SQLite
# https://docs.sqlalchemy.org/en/13/dialects/sqlite.html#foreign-key-support
@event.listens_for(Engine, "connect")