コード例 #1
0
    def test_add_remove_file(self, workspace, project):
        project_path = project.project_root

        # create new text file inside the project
        file_path = os.path.join(project_path, 'sample.txt')
        with open(file_path, 'w') as open_file:
            open_file.write('sample text')
        assert os.path.isfile(file_path)

        # add to project.yml
        args = cli.parse_args([
            '-w', workspace, '-p',
            str(project_path), '--add',
            str(file_path), '--debug'
        ])
        cli.dispatch(args)
        project_yml_path = os.path.join(project_path, 'project.yml')
        with open(project_yml_path) as open_file:
            project_yml = yaml.load(open_file, Loader=yaml.FullLoader)
            project_files = [f['path'] for f in project_yml['files']]
            assert 'sample.txt' in project_files

        # remove sample.txt
        args = cli.parse_args([
            '-w', workspace, '-p',
            str(project.project_root), '--remove',
            os.path.join(project.project_root, 'sample.txt'), '--debug'
        ])
        project = cli.dispatch(args)

        # check if NSD was removed
        with open(project_yml_path) as open_file:
            project_yml = yaml.load(open_file, Loader=yaml.FullLoader)
            project_files = [f['path'] for f in project_yml['files']]
            assert 'sample.txt' not in project_files
コード例 #2
0
    def post(self):
        """Create a new project and generate descriptors with the given args"""
        args = project_parser.parse_args()
        log.info("POST to /projects with args: {}".format(args))

        # transform args into array passed to the descriptorgen cli
        # create a new UUID for each project (to avoid whitespaces)
        project_uuid = str(uuid.uuid4())
        dgn_args = ['-p', os.path.join('projects', project_uuid)]

        for k, v in args.items():
            # only add --tango/--osm if value=True
            if k == 'only_tango':
                if v:
                    dgn_args.append('--tango')
            elif k == 'only_osm':
                if v:
                    dgn_args.append('--osm')
            elif k == 'image_names' or k == 'image_types':
                dgn_args.append('--' + k)
                # split multiple image names/types and append all of them
                dgn_args.extend(v.split(' '))
            else:
                # convert #vnfs from int to str (CLI only accepts string)
                if k == 'vnfs':
                    v = str(v)
                # add '--' as prefix for each key to be consistent with CLI
                dgn_args.append('--' + k)
                dgn_args.append(v)
        log.debug("CLI args: {}".format(dgn_args))

        cli_args = cli.parse_args(dgn_args)
        project = cli.dispatch(cli_args)

        return {'uuid': project_uuid, "error_msg": project.error_msg}
コード例 #3
0
 def project(self, workspace):
     args = cli.parse_args([
         '-p', 'test-project', '-w', workspace, '--debug', '--author',
         'test.author', '--vendor', 'test.vendor', '--vnfs', '2'
     ])
     project = cli.dispatch(args)
     assert os.path.isdir('test-project')
     assert os.path.isfile(os.path.join('test-project', 'project.yml'))
     yield project
     shutil.rmtree('test-project')
コード例 #4
0
    def test_generate_osm_descriptors(self):
        args = cli.parse_args([
            '--osm',
            '-o', 'test-descriptorgen'
        ])
        dgn.generate(args)

        assert os.path.isfile(os.path.join('test-descriptorgen', 'osm_nsd.yml'))
        assert os.path.isfile(os.path.join('test-descriptorgen', 'osm_vnfd0.yml'))
        assert not os.path.isfile(os.path.join('test-descriptorgen', 'tango_nsd.yml'))
        assert not os.path.isfile(os.path.join('test-descriptorgen', 'tango_vnfd0.yml'))

        shutil.rmtree('test-descriptorgen')
コード例 #5
0
def generate(args=None):
    if args is None:
        args = cli.parse_args()

    if args.debug:
        coloredlogs.install(level='DEBUG')
    else:
        coloredlogs.install(level='INFO')

    # generate and save tango descriptors
    if not args.osm:
        descriptors = tango.generate_descriptors(args, log)
        save_descriptors(descriptors['nsd'], descriptors['vnfds'], 'tango', args.out_path)

    # generate and save osm descriptors
    if not args.tango:
        descriptors = osm.generate_descriptors(args, log)
        save_descriptors(descriptors['nsd'], descriptors['vnfds'], 'osm', args.out_path)
コード例 #6
0
ファイル: __init__.py プロジェクト: vcgato29/tng-sdk-project
def main(args=None):
    """Entry point of tng-project"""
    args = cli.parse_args(args)
    if args.debug:
        coloredlogs.install(level='DEBUG')
    else:
        coloredlogs.install(level='INFO')

    # dump Swagger REST API specification
    if args.dump_swagger:
        rest.dump_swagger()
        log.info("Dumped Swagger API spec to docs/rest_api.json")
        exit(0)

    # start service with REST API
    if args.service:
        # create the default workspace (required to serve)
        workspace.init_workspace(args)
        rest.serve_forever(args)
    # or use CLI
    else:
        cli.dispatch(args)
コード例 #7
0
    def test_generate_multiple_descriptors(self, num_vnfs):
        args = cli.parse_args([
            '--vnfs', str(num_vnfs),
            '-o', 'test-descriptorgen'
        ])
        dgn.generate(args)

        # check the NSDs
        with open(os.path.join('test-descriptorgen', 'tango_nsd.yml'), 'r') as f:
            tango_nsd = yaml.load(f, Loader=yaml.FullLoader)
            assert len(tango_nsd['network_functions']) == num_vnfs

        with open(os.path.join('test-descriptorgen', 'osm_nsd.yml'), 'r') as f:
            osm_nsd = yaml.load(f, Loader=yaml.FullLoader)
            assert len(osm_nsd['constituent-vnfd']) == num_vnfs

        # check all vnfd files exist
        for i in range(0, num_vnfs):
            assert os.path.isfile(os.path.join('test-descriptorgen', 'tango_vnfd{}.yml'.format(i)))
            assert os.path.isfile(os.path.join('test-descriptorgen', 'osm_vnfd{}.yml'.format(i)))

        shutil.rmtree('test-descriptorgen')
コード例 #8
0
    def test_generate_custom_descriptors(self):
        args = cli.parse_args([
            '--author', 'test.author',
            '--vendor', 'test.vendor',
            '--name', 'test.service',
            '--description', 'test.description',
            '-o', 'test-descriptorgen'
        ])
        dgn.generate(args)

        # check tango nsd and vnfd
        with open(os.path.join('test-descriptorgen', 'tango_nsd.yml'), 'r') as f:
            tango_nsd = yaml.load(f, Loader=yaml.FullLoader)
            assert tango_nsd['author'] == 'test.author'
            assert tango_nsd['vendor'] == 'test.vendor'
            assert tango_nsd['name'] == 'test.service'
            assert tango_nsd['description'] == 'test.description'
            assert len(tango_nsd['network_functions']) == 1

        with open(os.path.join('test-descriptorgen', 'tango_vnfd0.yml'), 'r') as f:
            tango_vnfd = yaml.load(f, Loader=yaml.FullLoader)
            assert tango_vnfd['author'] == 'test.author'
            assert tango_vnfd['vendor'] == 'test.vendor'

        # check osm nsd and vnfd
        with open(os.path.join('test-descriptorgen', 'osm_nsd.yml'), 'r') as f:
            osm_nsd = yaml.load(f, Loader=yaml.FullLoader)
            assert osm_nsd['vendor'] == 'test.vendor'
            assert osm_nsd['id'] == 'test.service'
            assert osm_nsd['name'] == 'test.service'
            assert osm_nsd['description'] == 'test.description'
            assert len(osm_nsd['constituent-vnfd']) == 1

        with open(os.path.join('test-descriptorgen', 'osm_vnfd0.yml'), 'r') as f:
            osm_vnfd = yaml.load(f, Loader=yaml.FullLoader)
            assert osm_vnfd['vnfd-catalog']['vnfd'][0]['vendor'] == 'test.vendor'

        # clean up: remove test folder again
        shutil.rmtree('test-descriptorgen')