Beispiel #1
0
def ping_pong_records(path_ping_image, path_pong_image, rsyslog_host, rsyslog_port):
    '''Fixture containing a set of generated ping and pong descriptors
    '''
    def md5sum(path):
        with open(path, mode='rb') as fd:
            md5 = hashlib.md5()
            for buf in iter(functools.partial(fd.read, 4096), b''):
                md5.update(buf)
        return md5.hexdigest()

    ping_md5sum = md5sum(path_ping_image)
    pong_md5sum = md5sum(path_pong_image)

    ex_userdata = None
    if rsyslog_host and rsyslog_port:
        ex_userdata = '''
rsyslog:
  - "$ActionForwardDefaultTemplate RSYSLOG_ForwardFormat"
  - "*.* @{host}:{port}"
        '''

    descriptors = ping_pong.generate_ping_pong_descriptors(
            pingcount=1,
            ping_md5sum=ping_md5sum,
            pong_md5sum=pong_md5sum,
            ex_ping_userdata=ex_userdata,
            ex_pong_userdata=ex_userdata,
    )

    return descriptors
Beispiel #2
0
    def publish_desciptors(self, num_external_vlrs=1, num_internal_vlrs=1, num_ping_vms=1):
        self.ping_vnfd, self.pong_vnfd, self.ping_pong_nsd = \
                ping_pong_nsd.generate_ping_pong_descriptors(
                        pingcount=1,
                        external_vlr_count=num_external_vlrs,
                        internal_vlr_count=num_internal_vlrs,
                        num_vnf_vms=2,
                        )

        # Publish ping_vnfd
        xpath = XPaths.vnfd(self.ping_vnfd_id)
        xpath_wild = XPaths.vnfd()
        for obj in self.ping_vnfd.descriptor.vnfd:
            self.log.debug("Publishing ping_vnfd path: %s - %s, type:%s, obj:%s",
                           xpath, xpath_wild, type(obj), obj)
            yield from self.publisher.publish(xpath_wild, xpath, obj)

        # Publish pong_vnfd
        xpath = XPaths.vnfd(self.pong_vnfd_id)
        xpath_wild = XPaths.vnfd()
        for obj in self.pong_vnfd.descriptor.vnfd:
            self.log.debug("Publishing pong_vnfd path: %s, wild_path: %s, obj:%s",
                           xpath, xpath_wild, obj)
            yield from self.publisher.publish(xpath_wild, xpath, obj)

        # Publish ping_pong_nsd
        xpath = XPaths.nsd(self.nsd_id)
        xpath_wild = XPaths.nsd()
        for obj in self.ping_pong_nsd.descriptor.nsd:
            self.log.debug("Publishing ping_pong nsd path: %s, wild_path: %s, obj:%s",
                           xpath, xpath_wild, obj)
            yield from self.publisher.publish(xpath_wild, xpath, obj)

        self.log.debug("DONE - publish_desciptors")
Beispiel #3
0
    def __init__(self,
                 log,
                 loop,
                 dts,
                 num_external_vlrs=1,
                 num_internal_vlrs=1,
                 num_ping_vms=1):
        self.log = log
        self.loop = loop
        self.dts = dts

        self.querier = ManoQuerier(self.log, self.dts)
        self.publisher = DescriptorPublisher(self.log, self.loop, self.dts)
        self.ping_vnfd, self.pong_vnfd, self.ping_pong_nsd = \
                ping_pong_nsd.generate_ping_pong_descriptors(
                        pingcount=1,
                        external_vlr_count=num_external_vlrs,
                        internal_vlr_count=num_internal_vlrs,
                        num_vnf_vms=2,
                        mano_ut=True,
                        use_scale_group=True,
                        use_mon_params=False,
                        )

        self.config_dir = os.path.join(os.getenv('RIFT_ARTIFACTS'),
                                       "launchpad/libs", self.ping_pong_nsd.id,
                                       "config")
Beispiel #4
0
    def generate_descriptors(self):
        '''Return a new set of ping and pong descriptors
        '''
        def md5sum(path):
            with open(path, mode='rb') as fd:
                md5 = hashlib.md5()
                for buf in iter(functools.partial(fd.read, 4096), b''):
                    md5.update(buf)
            return md5.hexdigest()

        ping_md5sum = md5sum(self.path_ping_image)
        pong_md5sum = md5sum(self.path_pong_image)

        ex_userdata = None
        if self.rsyslog_host and self.rsyslog_port:
            ex_userdata = '''
rsyslog:
  - "$ActionForwardDefaultTemplate RSYSLOG_ForwardFormat"
  - "*.* @{host}:{port}"
            '''.format(
                host=self.rsyslog_host,
                port=self.rsyslog_port,
            )

        descriptors = ping_pong.generate_ping_pong_descriptors(
            pingcount=1,
            ping_md5sum=ping_md5sum,
            pong_md5sum=pong_md5sum,
            ex_ping_userdata=ex_userdata,
            ex_pong_userdata=ex_userdata,
        )

        return descriptors
Beispiel #5
0
 def __init__(self):
     ping_vnfd, pong_vnfd, nsd = \
             ping_pong_nsd.generate_ping_pong_descriptors(
                 pingcount=1,
                 external_vlr_count=1,
                 internal_vlr_count=0,
                 num_vnf_vms=1,
                 ping_md5sum='1234567890abcdefg',
                 pong_md5sum='1234567890abcdefg',
                 mano_ut=False,
                 use_scale_group=True,
                 use_mon_params=True,
             )
     self.ping_pong_nsd = nsd.descriptor.nsd[0]
     self.ping_vnfd = ping_vnfd.descriptor.vnfd[0]
     self.pong_vnfd = pong_vnfd.descriptor.vnfd[0]
    def __init__(self, output_dir, log):
        ping_vnfd, pong_vnfd, nsd = \
                ping_pong_nsd.generate_ping_pong_descriptors(
                    fmt='yaml',
                    write_to_file=True,
                    out_dir=output_dir,
                    pingcount=1,
                    external_vlr_count=1,
                    internal_vlr_count=0,
                    num_vnf_vms=1,
                    ping_md5sum='1234567890abcdefg',
                    pong_md5sum='1234567890abcdefg',
                    mano_ut=False,
                    use_scale_group=True,
                    use_mon_params=True,
                    use_placement_group = False,
                )

        # Create the tar files in output dir
        def create_archive(desc):
            # Create checksum file
            cur_dir = os.path.join(output_dir, desc)
            flist = {}
            for root, dirs, files in os.walk(cur_dir):
                rel_dir = root.replace(cur_dir + '/', '')
                for f in files:
                    fpath = os.path.join(root, f)
                    flist[os.path.join(rel_dir, f)] = \
                                        ChecksumUtils.get_md5(fpath)
            log.debug(_("Files in {}: {}").format(cur_dir, flist))

            chksumfile = os.path.join(cur_dir, 'checksums.txt')
            with open(chksumfile, 'w') as c:
                for key in sorted(flist.keys()):
                    c.write("{}  {}\n".format(flist[key], key))

            # Create the tar archive
            tar_cmd = "tar zcvf {0}.tar.gz {0}"
            subprocess.check_call(tar_cmd.format(desc),
                                  shell=True,
                                  stdout=subprocess.DEVNULL)

        prevdir = os.getcwd()
        os.chdir(output_dir)
        for d in os.listdir(output_dir):
            create_archive(d)
        os.chdir(prevdir)
Beispiel #7
0
    def __init__(self, log, loop, dts, num_external_vlrs=1, num_internal_vlrs=1, num_ping_vms=1):
        self.log = log
        self.loop = loop
        self.dts = dts

        self.querier = ManoQuerier(self.log, self.dts)
        self.publisher = DescriptorPublisher(self.log, self.loop, self.dts)
        self.ping_vnfd, self.pong_vnfd, self.ping_pong_nsd = \
                ping_pong_nsd.generate_ping_pong_descriptors(
                        pingcount=1,
                        external_vlr_count=num_external_vlrs,
                        internal_vlr_count=num_internal_vlrs,
                        num_vnf_vms=2,
                        mano_ut=True,
                        use_scale_group=False,
                        use_mon_params=False,
                        )

        self.config_dir = os.path.join(os.getenv('RIFT_ARTIFACTS'),
                                       "launchpad/libs",
                                       self.ping_pong_nsd.id,
                                       "config")
Beispiel #8
0
def ping_pong_records(request):
    return ping_pong.generate_ping_pong_descriptors(pingcount=1)
    def test_onboard_descriptors(self, logger, vnfd_proxy, nsd_proxy,
                                 mgmt_session, scheme, cert,
                                 ping_pong_records):
        """Generates & On-boards the descriptors.
        """
        temp_dirs = []
        catalog = vnfd_proxy.get_config(
            '/rw-project:project[rw-project:name="default"]/vnfd-catalog')
        endpoint = "update"
        ping_vnfd, pong_vnfd, ping_pong_nsd = ping_pong_records
        """
        This upload routine can get called multiples times for upload API,
        depending on the combinations of 'cloud_account' & 'endpoint'
        fixtures. Since the records are cached at module level, we might end up
        uploading the same uuids multiple times, thus causing errors. So a
        simple work-around will be to skip the records when they are uploaded
        for the second time.
        """
        def onboard_ping_pong_vnfds(ping_vnfd_file, pong_vnfd_file):
            # On-board VNFDs
            for file_name in [ping_vnfd_file, pong_vnfd_file]:
                onboard_descriptor(mgmt_session.host, file_name, logger,
                                   endpoint, scheme, cert)

            catalog = vnfd_proxy.get_config(
                '/rw-project:project[rw-project:name="default"]/vnfd-catalog')
            vnfds = catalog.vnfd

            assert len(vnfds) == 2, "There should two vnfds"
            assert "ping_vnfd" in [vnfds[0].name, vnfds[1].name]
            assert "pong_vnfd" in [vnfds[0].name, vnfds[1].name]

        def delete_nsds():
            nsds = nsd_proxy.get(
                "/rw-project:project[rw-project:name='default']/nsd-catalog/nsd",
                list_obj=True)
            for nsd_record in nsds.nsd:
                xpath = "/rw-project:project[rw-project:name='default']/nsd-catalog/nsd[id={}]".format(
                    quoted_key(nsd_record.id))
                nsd_proxy.delete_config(xpath)

            time.sleep(5)
            nsds = nsd_proxy.get(
                "/rw-project:project[rw-project:name='default']/nsd-catalog/nsd",
                list_obj=True)
            assert nsds is None or len(nsds.nsd) == 0

        delete_nsds()

        def delete_vnfds():
            vnfds = vnfd_proxy.get(
                "/rw-project:project[rw-project:name='default']/vnfd-catalog/vnfd",
                list_obj=True)
            for vnfd_record in vnfds.vnfd:
                xpath = "/rw-project:project[rw-project:name='default']/vnfd-catalog/vnfd[id={}]".format(
                    quoted_key(vnfd_record.id))
                vnfd_proxy.delete_config(xpath)

            time.sleep(5)
            vnfds = vnfd_proxy.get(
                "/rw-project:project[rw-project:name='default']/vnfd-catalog/vnfd",
                list_obj=True)
            assert vnfds is None or len(vnfds.vnfd) == 0

        delete_vnfds()

        if catalog is not None and len(
                catalog.vnfd) == 2 and endpoint == "upload":
            return

        ping_vnfd, pong_vnfd, ping_pong_nsd = ping_pong_records

        if endpoint == "update":
            for vnfd_record in [ping_vnfd, pong_vnfd]:
                vnfd_record.descriptor.vnfd[0].description += "_update"
            ping_pong_nsd.descriptor.nsd[0].description += "_update"

        tmpdir2 = tempfile.TemporaryDirectory()
        temp_dirs.append(tmpdir2)
        ping_pong.generate_ping_pong_descriptors(
            pingcount=1,
            write_to_file=True,
            out_dir=tmpdir2.name,
            ping_fmt='json',
            pong_fmt='xml',
        )

        # On-board VNFDs without image
        ping_vnfd_file = os.path.join(tmpdir2.name,
                                      'ping_vnfd/vnfd/ping_vnfd.json')
        pong_vnfd_file = os.path.join(tmpdir2.name,
                                      'pong_vnfd/vnfd/pong_vnfd.xml')
        onboard_ping_pong_vnfds(ping_vnfd_file, pong_vnfd_file)
        delete_vnfds()

        tmpdir = tempfile.TemporaryDirectory()
        temp_dirs.append(tmpdir)

        ping_vnfd_file, pong_vnfd_file, pingpong_nsd_file = \
            generate_tar_files(tmpdir, ping_vnfd, pong_vnfd, ping_pong_nsd)

        # On-board VNFDs with image
        onboard_ping_pong_vnfds(ping_vnfd_file, pong_vnfd_file)

        # On-board NSD
        onboard_descriptor(mgmt_session.host, pingpong_nsd_file, logger,
                           endpoint, scheme, cert)

        catalog = nsd_proxy.get_config(
            '/rw-project:project[rw-project:name="default"]/nsd-catalog')
        nsds = catalog.nsd
        assert len(nsds) == 1, "There should only be a single nsd"
        assert nsds[0].name == "ping_pong_nsd"
    def test_onboard_descriptors(
            self,
            logger,
            vnfd_proxy,
            nsd_proxy,
            launchpad_session,
            scheme,
            cert,
            ping_pong_records):
        """Generates & On-boards the descriptors.
        """
        temp_dirs = []
        catalog = vnfd_proxy.get_config('/vnfd-catalog')
        endpoint = "update"
        ping_vnfd, pong_vnfd, ping_pong_nsd = ping_pong_records                

        """
        This upload routine can get called multiples times for upload API,
        depending on the combinations of 'cloud_account' & 'endpoint'
        fixtures. Since the records are cached at module level, we might end up
        uploading the same uuids multiple times, thus causing errors. So a
        simple work-around will be to skip the records when they are uploaded
        for the second time.
        """
        def onboard_ping_pong_vnfds(ping_vnfd_file, pong_vnfd_file):
            # On-board VNFDs
            for file_name in [ping_vnfd_file, pong_vnfd_file]:
                onboard_descriptor(
                        launchpad_session.host,
                        file_name,
                        logger,
                        endpoint,
                        scheme,
                        cert)

            catalog = vnfd_proxy.get_config('/vnfd-catalog')
            vnfds = catalog.vnfd

            assert len(vnfds) == 2, "There should two vnfds"
            assert "ping_vnfd" in [vnfds[0].name, vnfds[1].name]
            assert "pong_vnfd" in [vnfds[0].name, vnfds[1].name]

        def delete_nsds():
            nsds = nsd_proxy.get("/nsd-catalog/nsd", list_obj=True)
            for nsd_record in nsds.nsd:
                xpath = "/nsd-catalog/nsd[id='{}']".format(nsd_record.id)
                nsd_proxy.delete_config(xpath)

            time.sleep(5)
            nsds = nsd_proxy.get("/nsd-catalog/nsd", list_obj=True)
            assert nsds is None or len(nsds.nsd) == 0
        delete_nsds()

        def delete_vnfds():
            vnfds = vnfd_proxy.get("/vnfd-catalog/vnfd", list_obj=True)
            for vnfd_record in vnfds.vnfd:
                xpath = "/vnfd-catalog/vnfd[id='{}']".format(vnfd_record.id)
                vnfd_proxy.delete_config(xpath)

            time.sleep(5)
            vnfds = vnfd_proxy.get("/vnfd-catalog/vnfd", list_obj=True)
            assert vnfds is None or len(vnfds.vnfd) == 0

        delete_vnfds()

        if catalog is not None and len(catalog.vnfd) == 2 and endpoint == "upload":
            return

        ping_vnfd, pong_vnfd, ping_pong_nsd = ping_pong_records

        if endpoint == "update":
            for vnfd_record in [ping_vnfd, pong_vnfd]:
                vnfd_record.descriptor.vnfd[0].description += "_update"
            ping_pong_nsd.descriptor.nsd[0].description += "_update"

        tmpdir2 = tempfile.TemporaryDirectory()
        temp_dirs.append(tmpdir2)
        ping_pong.generate_ping_pong_descriptors(pingcount=1,
                                                  write_to_file=True,
                                                  out_dir=tmpdir2.name,
                                                  ping_fmt='json',
                                                  pong_fmt='xml',
                                                  )

        # On-board VNFDs without image
        ping_vnfd_file = os.path.join(tmpdir2.name, 'ping_vnfd/vnfd/ping_vnfd.json')
        pong_vnfd_file = os.path.join(tmpdir2.name, 'pong_vnfd/vnfd/pong_vnfd.xml')
        onboard_ping_pong_vnfds(ping_vnfd_file, pong_vnfd_file)
        delete_vnfds()

        tmpdir = tempfile.TemporaryDirectory()
        temp_dirs.append(tmpdir)

        ping_vnfd_file, pong_vnfd_file, pingpong_nsd_file = \
            generate_tar_files(tmpdir, ping_vnfd, pong_vnfd, ping_pong_nsd)

        # On-board VNFDs with image
        onboard_ping_pong_vnfds(ping_vnfd_file, pong_vnfd_file)


        # On-board NSD
        onboard_descriptor(
                launchpad_session.host,
                pingpong_nsd_file,
                logger,
                endpoint,
                scheme,
                cert)

        catalog = nsd_proxy.get_config('/nsd-catalog')
        nsds = catalog.nsd
        assert len(nsds) == 1, "There should only be a single nsd"
        assert nsds[0].name == "ping_pong_nsd"