Esempio n. 1
0
def package_upload(values, tenant_id):
    """Upload a package with new application

       :param values: parameters describing the new package
       :returns: detailed information about new package, dict
    """
    session = db_session.get_session()
    package = models.Package()

    composite_attr_to_func = {
        'categories': _get_categories,
        'tags': _get_tags,
        'class_definitions': _get_class_definitions
    }
    is_public = values.get('is_public', False)

    if is_public:
        public_lock = db_session.get_lock("public_packages", session)
    else:
        public_lock = None
    tenant_lock = db_session.get_lock("classes_of_" + tenant_id, session)
    try:
        _check_for_existing_classes(session,
                                    values.get('class_definitions'),
                                    tenant_id,
                                    check_public=is_public)
        if is_public:
            _check_for_public_packages_with_fqn(
                session, values.get('fully_qualified_name'))
        for attr, func in six.iteritems(composite_attr_to_func):
            if values.get(attr):
                result = func(values[attr], session)
                setattr(package, attr, result)
                del values[attr]
        package.update(values)
        package.owner_id = tenant_id
        package.save(session)
        tenant_lock.commit()
        if public_lock is not None:
            public_lock.commit()
    except Exception:
        tenant_lock.rollback()
        if public_lock is not None:
            public_lock.rollback()
        raise

    return package
Esempio n. 2
0
File: api.py Progetto: ovo-6/murano
def package_upload(values, tenant_id):
    """Upload a package with new application
       :param values: parameters describing the new package
       :returns: detailed information about new package, dict
    """
    session = db_session.get_session()
    package = models.Package()

    composite_attr_to_func = {'categories': _get_categories,
                              'tags': _get_tags,
                              'class_definitions': _get_class_definitions}
    with session.begin():
        for attr, func in composite_attr_to_func.iteritems():
            if values.get(attr):
                result = func(values[attr], session)
                setattr(package, attr, result)
                del values[attr]

        package.update(values)
        package.owner_id = tenant_id
        package.save(session)
    return package
Esempio n. 3
0
    def setUp(self):
        super(TestManage, self).setUp()

        session = db_session.get_session()
        # Create environment.
        self.test_environment = models.Environment(name=b'test_environment',
                                                   tenant_id=b'test_tenant_id',
                                                   version=1)
        # Create categories.
        self.test_categories = [
            models.Category(name=b'test_category_1'),
            models.Category(name=b'test_category_2')
        ]
        # Create tags.
        self.test_tags = [
            models.Tag(name=b'test_tag_1'),
            models.Tag(name=b'test_tag_2')
        ]
        # Add environment, categories and tags to DB.
        with session.begin():
            session.add(self.test_environment)
            session.add_all(self.test_categories)
            session.add_all(self.test_tags)
        # Create package.
        self.test_package = models.Package(
            fully_qualified_name=b'test_fqn',
            name=b'test_name',
            logo=b'test_logo',
            supplier_logo=b'test_supplier_logo',
            type=b'test_type',
            description=b'test_desc',
            is_public=True,
            archive=b'test_archive',
            ui_definition=b'test_ui_definition',
            categories=self.test_categories,
            tags=self.test_tags,
            owner_id=self.test_environment.tenant_id,
        )
        # Add the package to the DB.
        with session.begin():
            session.add(self.test_package)
        # Create class definitions and assign their FKs to test_package.id.
        self.test_class_definitions = [
            models.Class(name=b'test_class_definition_1',
                         package_id=self.test_package.id),
            models.Class(name=b'test_class_definition_2',
                         package_id=self.test_package.id)
        ]
        # Add the class definitions to the DB and update the FK reference for
        # test_package.class_definitions.
        with session.begin():
            session.add_all(self.test_class_definitions)
            self.test_package.class_definitions = self.test_class_definitions
            session.add(self.test_package)
        # Create mock object that resembles loaded package from
        # load_utils.load_from_dir
        self.mock_loaded_package = mock.MagicMock(
            full_name=self.test_package.fully_qualified_name,
            display_name=self.test_package.name,
            package_type=self.test_package.type,
            author=self.test_package.author,
            supplier=self.test_package.supplier,
            description=self.test_package.description,
            tags=[tag.name for tag in self.test_package.tags],
            classes=[cls.name for cls in self.test_package.class_definitions],
            logo=self.test_package.logo,
            supplier_logo=self.test_package.supplier_logo,
            ui=self.test_package.ui_definition,
            blob=self.test_package.archive)