예제 #1
0
    def test_pack_project(self):
        session = db_session()
        project = session.query(Project).filter(
            Project.id == self.pjid).first()
        package_path = publishutil.pack_project(project)

        self.assertTrue(os.path.exists(package_path))
        self.assertTrue(os.path.isfile(package_path))

        # create another service in project
        request_dict = get_sample_ns("servicename", "vendorname", "0.1")
        response = self.app.post('/' + WORKSPACES + '/' + self.wsid + '/' +
                                 PROJECTS + '/' + str(self.pjid) + '/' +
                                 SERVICES + '/',
                                 data=json.dumps(request_dict),
                                 content_type='application/json')

        # should fail because the project name is invalid
        project = session.query(Project).filter(
            Project.id == self.pjid).first()
        try:
            publishutil.pack_project(project)
        except Exception as err:
            self.assertTrue(isinstance(err, PackException))

            # should fail as only one service can be packaged
            project = session.query(Project).filter(
                Project.id == self.pjid2).first()
            try:
                publishutil.pack_project(project)
            except Exception as err:
                self.assertTrue(isinstance(err, PackException))

        session.commit()
    def test_pack_project(self):
        session = db_session()
        project = session.query(Project).filter(Project.id == self.pjid).first()
        package_path = publishutil.pack_project(project)

        self.assertTrue(os.path.exists(package_path))
        self.assertTrue(os.path.isfile(package_path))

        # create another service in project
        request_dict = get_sample_ns("servicename", "vendorname", "0.1")
        response = self.app.post(
            '/' + WORKSPACES + '/' + self.wsid + '/' + PROJECTS + '/' + str(self.pjid) + '/' + SERVICES + '/',
            data=json.dumps(request_dict),
            content_type='application/json')

        # should fail because the project name is invalid
        project = session.query(Project).filter(Project.id == self.pjid).first()
        try:
            publishutil.pack_project(project)
        except Exception as err:
            self.assertTrue(isinstance(err, PackException))

            # should fail as only one service can be packaged
            project = session.query(Project).filter(Project.id == self.pjid2).first()
            try:
                publishutil.pack_project(project)
            except Exception as err:
                self.assertTrue(isinstance(err, PackException))

        session.commit()
예제 #3
0
def create_service_on_platform(ws_id, platform_id, service_data):
    """
    Deploys the service on the referenced Platform
    :param ws_id:
    :param platform_id:
    :param service_data:
    :return: A  message if the function was deployed successfully
    """
    service_id = int(service_data['id'])
    session = db_session()
    try:
        workspace = session.query(Workspace).filter(Workspace.id == ws_id).first()
        project = session.query(Project). \
            join(Service). \
            filter(Project.services.any(Service.id == service_id)). \
            filter(Project.workspace == workspace). \
            first()  # type: Project
        if not len(project.services) == 1:
            raise InvalidArgument(
                "Project must have exactly one service "
                "to push to platform. Number of services: {}".format(
                    len(project.services)))

        platform = session.query(Platform).filter(Platform.id == platform_id). \
            filter(Platform.workspace == workspace).first()
        package_path = pack_project(project)
        service_uuid = push_to_platform(package_path, platform)
        logger.info("Pushed to platform: " + str(service_uuid))
        # deploy to private catalogue
        service = project.services[0].as_dict()
        publish_private_nsfs(ws_id, service["descriptor"], is_vnf=False)
        publish_referenced_functions(ws_id, project.id, service["descriptor"])
        return {'message': 'Deployed successfully: {}'.format(str(service_uuid))}
    finally:
        session.commit()
예제 #4
0
def create_service_on_platform(ws_id, platform_id, service_data):
    """
    Deploys the service on the referenced Platform

    :param ws_id: The workspace ID
    :param platform_id: The platform ID
    :param service_data: The service descriptor data
    :return: A  message if the function was deployed successfully
    """
    # TODO test this!
    service_id = int(service_data['id'])
    session = db_session()
    try:
        workspace = session.query(Workspace).filter(
            Workspace.id == ws_id).first()
        project = session.query(Project). \
            join(Service). \
            filter(Project.services.any(Service.id == service_id)). \
            filter(Project.workspace == workspace). \
            first()  # type: Project
        if not len(project.services) == 1:
            raise InvalidArgument(
                "Project must have exactly one service "
                "to push to platform. Number of services: {}".format(
                    len(project.services)))

        platform = session.query(Platform).filter(Platform.id == platform_id). \
            filter(Platform.workspace == workspace).first()
        package_path = pack_project(project)
        service_uuid = push_to_platform(package_path, platform.workspace)
        logger.info("Pushed to platform: " + str(service_uuid))
        # deploy to private catalogue
        service = project.services[0].as_dict()
        publish_private_nsfs(ws_id, service["descriptor"], is_vnf=False)
        publish_referenced_functions(ws_id, project.id, service["descriptor"])
        return {
            'message': 'Deployed successfully: {}'.format(str(service_uuid))
        }
    finally:
        session.commit()