def configure_test(self, loop, test_id):
        self.log.debug("STARTING - %s", test_id)
        self.tinfo = self.new_tinfo(str(test_id))
        self.dts = rift.tasklets.DTS(self.tinfo, self.schema, self.loop)
        self.project = ManoProject(self.log, name=DEFAULT_PROJECT)

        self.job_handler = pkg_publisher.DownloadStatusPublisher(
            self.log, self.dts, self.loop, self.project)
示例#2
0
    def configure_test(self, loop, test_id):
        self.log.debug("STARTING - %s", test_id)
        self.tinfo = self.new_tinfo(str(test_id))
        self.dts = rift.tasklets.DTS(self.tinfo, self.schema, self.loop)
        self.project = ManoProject(self.log)

        self.tinfo_sub = self.new_tinfo(str(test_id) + "_sub")
        self.dts_sub = rift.tasklets.DTS(self.tinfo_sub, self.schema,
                                         self.loop)

        self.publisher = DescriptorPublisher(self.log, self.dts, self.loop)
示例#3
0
 def __init__(self, *args, **kwargs):
     self._loop = asyncio.get_event_loop()
     self._log = logging.getLogger(__file__)
     self._project = ManoProject(self._log, name=DEFAULT_PROJECT)
     self._project._loop = self._loop
     ImageMockMixin.__init__(self, self._log)
     unittest.TestCase.__init__(self, *args, **kwargs)
class SubscriberStoreDtsTestCase(rift.test.dts.AbstractDTSTest):
    @classmethod
    def configure_schema(cls):
        return RwPkgMgmtYang.get_schema()

    @classmethod
    def configure_timeout(cls):
        return 240

    def configure_test(self, loop, test_id):
        self.log.debug("STARTING - %s", test_id)
        self.tinfo = self.new_tinfo(str(test_id))
        self.dts = rift.tasklets.DTS(self.tinfo, self.schema, self.loop)
        self.publisher = DescriptorPublisher(self.log, self.dts, self.loop)
        self.project = ManoProject(self.log, name=DEFAULT_PROJECT)

    def tearDown(self):
        super().tearDown()

    @rift.test.dts.async_test
    def test_download_status_handler(self):

        mock_msg = RwPkgMgmtYang.YangData_RwProject_Project_DownloadJobs_Job.from_dict(
            {
                "url": "http://foo/bar",
                "package_id": "123",
                "download_id": str(uuid.uuid4())
            })

        w_xpath = self.project.add_project(
            "D,/rw-pkg-mgmt:download-jobs/rw-pkg-mgmt:job")
        xpath = "{}[download-id={}]".format(w_xpath,
                                            quoted_key(mock_msg.download_id))

        mock_called = False

        def mock_cb(msg, status):
            nonlocal mock_called
            assert msg == mock_msg
            mock_called = True

        sub = pkg_subscriber.DownloadStatusSubscriber(self.log,
                                                      self.dts,
                                                      self.loop,
                                                      self.project,
                                                      callback=mock_cb)

        yield from sub.register()
        yield from asyncio.sleep(1, loop=self.loop)

        yield from self.publisher.publish(w_xpath, xpath, mock_msg)
        yield from asyncio.sleep(1, loop=self.loop)

        assert mock_called is True
    def configure_test(self, loop, test_id):
        self.log.debug("STARTING - %s", self.id())
        self.tinfo = self.new_tinfo(self.id())

        self.project = ManoProject(self.log, name=DEFAULT_PROJECT)
        self.project._dts = rift.tasklets.DTS(self.tinfo, self.schema,
                                              self.loop)
        self.project.cloud_accounts = {'mock'}

        self.task_creator_mock = create_upload_task_creator_mock()
        self.job_controller_mock = create_job_controller_mock()
        self.rpc_handler = tasklet.ImageDTSRPCHandler(self.project, object(),
                                                      self.task_creator_mock,
                                                      self.job_controller_mock)
        self.show_handler = tasklet.ImageDTSShowHandler(
            self.project, self.job_controller_mock)

        self.tinfo_c = self.new_tinfo(self.id() + "_client")
        self.dts_c = rift.tasklets.DTS(self.tinfo_c, self.schema, self.loop)

        self._upload_mixin = utest_image_upload.UploadTaskMixin(
            self.log, self.loop)
        self._image_mock_mixin = utest_image_upload.ImageMockMixin(self)
示例#6
0
    def setUp(self):
        # Reduce the sample interval so that test run quickly
        NfviMetrics.SAMPLE_INTERVAL = 0.1

        self.loop = asyncio.get_event_loop()
        self.logger = logging.getLogger('test-logger')
        self.project = ManoProject(self.logger, name=DEFAULT_PROJECT)
        self.config = InstanceConfiguration()
        self.monitor = Monitor(self.loop, self.logger, self.config, self.project)

        self.account = RwcalYang.YangData_RwProject_Project_CloudAccounts_CloudAccountList(
                name='test-cloud-account',
                account_type="mock",
                )
示例#7
0
    def wait_until_complete(self):
        """ Wait until the upload job reaches a terminal state

        Raises:
            UploadJobError: A generic exception occured in the upload job
            UploadJobFailed: The upload job failed
            UploadJobCancelled: The upload job was cancelled
        """
        self._log.debug("waiting for upload job %s to complete", self._job_id)
        xpath = ManoProject.prefix_project(
            "D,/rw-image-mgmt:upload-jobs/" +
            "rw-image-mgmt:job[rw-image-mgmt:id={}]".format(
                quoted_key(str(self._job_id))),
            project=self._project,
            log=self._log)

        while True:
            query_iter = yield from self._dts.query_read(xpath)
            job_status_msg = None
            for fut_resp in query_iter:
                job_status_msg = (yield from fut_resp).result
                break

            if job_status_msg is None:
                raise UploadJobError(
                    "did not get a status response for job_id: %s",
                    self._job_id)

            if job_status_msg.status == "COMPLETED":
                msg = "upload job %s completed successfully" % self._job_id
                self._log.debug(msg)
                return

            elif job_status_msg.status == "FAILED":
                msg = "upload job %s as not successful: %s" % (
                    self._job_id, job_status_msg.status)
                self._log.error(msg)
                raise UploadJobFailed(msg)

            elif job_status_msg.status == "CANCELLED":
                msg = "upload job %s was cancelled" % self._job_id
                self._log.error(msg)
                raise UploadJobCancelled(msg)

            yield from asyncio.sleep(.5, loop=self._loop)
class TestCase(rift.test.dts.AbstractDTSTest):
    @classmethod
    def configure_schema(cls):
        return RwPkgMgmtYang.get_schema()

    @classmethod
    def configure_timeout(cls):
        return 240

    def configure_test(self, loop, test_id):
        self.log.debug("STARTING - %s", test_id)
        self.tinfo = self.new_tinfo(str(test_id))
        self.dts = rift.tasklets.DTS(self.tinfo, self.schema, self.loop)
        self.project = ManoProject(self.log, name=DEFAULT_PROJECT)

        self.job_handler = pkg_publisher.DownloadStatusPublisher(
            self.log, self.dts, self.loop, self.project)

    def tearDown(self):
        super().tearDown()

    @asyncio.coroutine
    def get_published_xpaths(self):
        published_xpaths = set()

        res_iter = yield from self.dts.query_read("D,/rwdts:dts")
        for i in res_iter:
            res = (yield from i).result
            for member in res.member:
                published_xpaths |= {
                    reg.keyspec
                    for reg in member.state.registration
                    if reg.flags == "publisher"
                }

        return published_xpaths

    @asyncio.coroutine
    def read_xpath(self, xpath):
        itr = yield from self.dts.query_read(xpath)

        result = None
        for fut in itr:
            result = yield from fut
            return result.result

    @rift.test.dts.async_test
    def test_download_publisher(self):
        yield from self.job_handler.register()
        published_xpaths = yield from self.get_published_xpaths()
        assert self.job_handler.xpath() in published_xpaths

    @rift.test.dts.async_test
    def test_publish(self):
        """
        Asserts:
            1. Verify if an update on_download_progess & on_download_finished
               triggers a DTS update
            2. Verify if the internal store is updated
        """
        yield from self.job_handler.register()

        mock_msg = RwPkgMgmtYang.YangData_RwProject_Project_DownloadJobs_Job.from_dict(
            {
                "url": "http://foo/bar",
                "package_id": "123",
                "download_id": str(uuid.uuid4())
            })

        yield from self.job_handler._dts_publisher(mock_msg)
        yield from asyncio.sleep(5, loop=self.loop)

        xpath = self.project.add_project(
            "/download-jobs/job[download-id={}]".format(
                quoted_key(mock_msg.download_id)))
        itr = yield from self.dts.query_read(xpath)

        result = None
        for fut in itr:
            result = yield from fut
            result = result.result

        self.log.debug("Mock msg: {}".format(mock_msg))
        assert result == mock_msg

        # Modify the msg
        mock_msg.url = "http://bar/foo"
        yield from self.job_handler._dts_publisher(mock_msg)
        yield from asyncio.sleep(5, loop=self.loop)

        itr = yield from self.dts.query_read(xpath)

        result = None
        for fut in itr:
            result = yield from fut
            result = result.result
        assert result == mock_msg

    @rift.test.dts.async_test
    def test_url_download(self):
        """
        Integration Test:
            Test the updates with download/url.py
        """
        yield from self.job_handler.register()

        proxy = mock.MagicMock()

        url = "http://sharedfiles/common/unittests/plantuml.jar"
        url_downloader = downloader.PackageFileDownloader(
            url, "1", "/", "VNFD", "SCRIPTS", "VNF_CONFIG", proxy)

        download_id = yield from self.job_handler.register_downloader(
            url_downloader)
        assert download_id is not None

        # Waiting for 5 secs to be sure that the file is downloaded
        yield from asyncio.sleep(10, loop=self.loop)
        xpath = self.project.add_project(
            "/download-jobs/job[download-id={}]".format(
                quoted_key(download_id)))
        result = yield from self.read_xpath(xpath)
        self.log.debug("Test result before complete check - %s", result)
        assert result.status == "COMPLETED"
        assert len(self.job_handler.tasks) == 0

    @rift.test.dts.async_test
    def test_url_download_unreachable_ip(self):
        """
        Integration Test:
            Ensure that a bad IP does not block forever
        """
        yield from self.job_handler.register()

        proxy = mock.MagicMock()

        # Here, we are assuming that there is no HTTP server at 10.1.2.3
        url = "http://10.1.2.3/common/unittests/plantuml.jar"
        url_downloader = downloader.PackageFileDownloader(
            url, "1", "/", "VNFD", "SCRIPTS", "VNF_CONFIG", proxy)
        self.log.debug("Downloader url: {}".format(url_downloader))

        download_id = yield from self.job_handler.register_downloader(
            url_downloader)
        self.log.debug("Download id: {}".format(download_id))
        assert download_id is not None

        # Waiting for 60 secs to be sure all reconnect attempts have been exhausted
        yield from asyncio.sleep(60, loop=self.loop)
        xpath = self.project.add_project(
            "/download-jobs/job[download-id={}]".format(
                quoted_key(download_id)))
        result = yield from self.read_xpath(xpath)
        self.log.debug("Test result before complete check - %s", result)
        assert result.status == "FAILED"
        assert len(self.job_handler.tasks) == 0

    @rift.test.dts.async_test
    def test_cancelled(self):
        """
        Integration Test:
            1. Test the updates with downloader.py
            2. Verifies if cancel triggers the job status to move to cancelled
        """
        yield from self.job_handler.register()

        proxy = mock.MagicMock()
        url = "http://sharedfiles/common/unittests/Fedora-x86_64-20-20131211.1-sda-ping.qcow2"
        url_downloader = downloader.PackageFileDownloader(
            url, "1", "/", "VNFD", "SCRIPTS", "VNF_CONFIG", proxy)

        download_id = yield from self.job_handler.register_downloader(
            url_downloader)
        assert download_id is not None
        xpath = self.project.add_project(
            "/download-jobs/job[download-id={}]".format(
                quoted_key(download_id)))

        # wait long enough to have the state be in IN_PROGRESS
        yield from asyncio.sleep(0.2, loop=self.loop)

        result = yield from self.read_xpath(xpath)
        self.log.debug("Test result before in_progress check - %s", result)
        assert result.status == "IN_PROGRESS"

        yield from self.job_handler.cancel_download(download_id)
        yield from asyncio.sleep(3, loop=self.loop)
        result = yield from self.read_xpath(xpath)
        self.log.debug("Test result before cancel check - %s", result)
        assert result.status == "CANCELLED"
        assert len(self.job_handler.tasks) == 0
class RwImageRPCTestCase(rift.test.dts.AbstractDTSTest):
    @classmethod
    def configure_schema(cls):
        return RwImageMgmtYang.get_schema()

    @classmethod
    def configure_timeout(cls):
        return 240

    def configure_test(self, loop, test_id):
        self.log.debug("STARTING - %s", self.id())
        self.tinfo = self.new_tinfo(self.id())

        self.project = ManoProject(self.log, name=DEFAULT_PROJECT)
        self.project._dts = rift.tasklets.DTS(self.tinfo, self.schema,
                                              self.loop)
        self.project.cloud_accounts = {'mock'}

        self.task_creator_mock = create_upload_task_creator_mock()
        self.job_controller_mock = create_job_controller_mock()
        self.rpc_handler = tasklet.ImageDTSRPCHandler(self.project, object(),
                                                      self.task_creator_mock,
                                                      self.job_controller_mock)
        self.show_handler = tasklet.ImageDTSShowHandler(
            self.project, self.job_controller_mock)

        self.tinfo_c = self.new_tinfo(self.id() + "_client")
        self.dts_c = rift.tasklets.DTS(self.tinfo_c, self.schema, self.loop)

        self._upload_mixin = utest_image_upload.UploadTaskMixin(
            self.log, self.loop)
        self._image_mock_mixin = utest_image_upload.ImageMockMixin(self)

    @async_test
    def test_create_job(self):
        yield from self.rpc_handler.register()
        yield from self.show_handler.register()

        account = self._image_mock_mixin.account
        with self._upload_mixin.create_upload_task(account) as upload_task:
            self.task_creator_mock.create_tasks_from_onboarded_create_rpc.return_value = [
                upload_task
            ]
            self.job_controller_mock.create_job.return_value = 2
            type(self.job_controller_mock).pb_msg = unittest.mock.PropertyMock(
                return_value=RwImageMgmtYang.
                YangData_RwProject_Project_UploadJobs.from_dict({
                    "job": [{
                        "id": 2,
                        "upload_tasks": [upload_task.pb_msg],
                        "status": "COMPLETED"
                    }]
                }))

            create_job_msg = RwImageMgmtYang.YangInput_RwImageMgmt_CreateUploadJob.from_dict(
                {
                    "cloud_account": [upload_task.cloud_account],
                    "onboarded_image": {
                        "image_name": upload_task.image_name,
                        "image_checksum": upload_task.image_checksum,
                    },
                    "project_name": self.project.name,
                })

            query_iter = yield from self.dts_c.query_rpc(
                "I,/rw-image-mgmt:create-upload-job",
                0,
                create_job_msg,
            )

            for fut_resp in query_iter:
                rpc_result = (yield from fut_resp).result

            self.assertEqual(2, rpc_result.job_id)

            self.assertTrue(self.task_creator_mock.
                            create_tasks_from_onboarded_create_rpc.called)

            query_iter = yield from self.dts_c.query_read(
                self.project.add_project("D,/rw-image-mgmt:upload-jobs"), )

            for fut_resp in query_iter:
                rpc_result = (yield from fut_resp).result
                self.assertEqual(1, len(rpc_result.job))
                self.assertEqual(2, rpc_result.job[0].id)
                self.assertEqual(1, len(rpc_result.job[0].upload_tasks))
 def _get_project(cls, project_name):
     if cls.project is None:
         cls.project = ManoProject(cls.log, project_name)
     return cls.project
示例#11
0
class RoAccountDtsTestCase(rift.test.dts.AbstractDTSTest):
    @classmethod
    def configure_schema(cls):
        return roaccountyang.get_schema()

    @classmethod
    def configure_timeout(cls):
        return 240

    def configure_test(self, loop, test_id):
        self.log.debug("STARTING - %s", test_id)
        self.tinfo = self.new_tinfo(str(test_id))
        self.dts = rift.tasklets.DTS(self.tinfo, self.schema, self.loop)
        self.project = ManoProject(self.log)

        self.tinfo_sub = self.new_tinfo(str(test_id) + "_sub")
        self.dts_sub = rift.tasklets.DTS(self.tinfo_sub, self.schema,
                                         self.loop)

        self.publisher = DescriptorPublisher(self.log, self.dts, self.loop)

    def tearDown(self):
        super().tearDown()

    @rift.test.dts.async_test
    def test_orch_account_create(self):
        ro_cfg_sub = cloud.ROAccountConfigSubscriber(self.dts, self.log,
                                                     self.loop, self.project,
                                                     None)
        yield from ro_cfg_sub.register()

        ro_plugin = ro_cfg_sub.get_ro_plugin(account_name=None)
        # Test if we have a default plugin in case no RO is specified.
        assert type(ro_plugin) is rwnsmplugin.RwNsPlugin

        # Test rift-ro plugin CREATE
        w_xpath = self.project.add_project(
            "C,/rw-ro-account:ro-account/rw-ro-account:account")
        xpath = w_xpath + "[rw-ro-account:name='openmano']"

        # Test Openmano plugin CREATE
        mock_orch_acc = roaccountyang.YangData_RwProject_Project_RoAccount_Account.from_dict(
            {
                'name': 'openmano',
                'ro_account_type': 'openmano',
                'openmano': {
                    'tenant_id': "abc",
                    "port": 9999,
                    "host": "10.64.11.77"
                }
            })

        yield from self.publisher.publish(w_xpath, xpath, mock_orch_acc)
        yield from asyncio.sleep(5, loop=self.loop)

        ro_plugin = ro_cfg_sub.get_ro_plugin(account_name='openmano')
        assert type(ro_plugin) is openmano_nsm.OpenmanoNsPlugin

        # Test update
        mock_orch_acc.openmano.port = 9789
        mock_orch_acc.openmano.host = "10.64.11.78"
        yield from self.publisher.update(xpath, mock_orch_acc)
        yield from asyncio.sleep(5, loop=self.loop)

        #Since update means delete followed by a insert get the new ro_plugin.
        ro_plugin = ro_cfg_sub.get_ro_plugin(account_name='openmano')
        assert ro_plugin._cli_api._port == mock_orch_acc.openmano.port
        assert ro_plugin._cli_api._host == mock_orch_acc.openmano.host
 def __init__(self):
     self.log = logging.getLogger()
     self.projects = {}
     project = ManoProject(self.log, name=DEFAULT_PROJECT)
     project.publisher = None
     self.projects[project.name] = project
示例#13
0
 def setUp(self):
     project = ManoProject(logger)
     self.substitute_input_parameters = rwnsmtasklet.InputParameterSubstitution(logger, project)