def test_file_proxy_rpc(self):
        """
            1. The file RPC returns a valid UUID thro' DTS
        """
        assert_uid = str(uuid.uuid4())

        uid, path = self.create_mock_package(DEFAULT_PROJECT)

        proxy = filesystem.FileSystemProxy(self.loop, self.log, self.dts)
        endpoint = rpc.PackageOperationsRpcHandler(
            self.log, self.dts, self.loop, proxy,
            MockTasklet(self.log, uid=assert_uid))
        yield from endpoint.register()

        ip = RwPkgMgmtYang.YangInput_RwPkgMgmt_PackageFileAdd.from_dict({
            "package_type":
            "VNFD",
            "package_id":
            uid,
            "external_url":
            "https://raw.githubusercontent.com/RIFTIO/RIFT.ware/master/rift-shell",
            "package_path":
            "script/rift-shell",
            "project_name":
            DEFAULT_PROJECT
        })

        rpc_out = yield from self.dts.query_rpc(
            "I,/rw-pkg-mgmt:package-file-add", rwdts.XactFlag.TRACE, ip)

        for itr in rpc_out:
            result = yield from itr
            assert result.result.task_id == assert_uid

        shutil.rmtree(path)
    def test_endpoint_discovery(self):
        """
        Verifies the following:
            The endpoint RPC returns a URL
        """
        proxy = filesystem.FileSystemProxy(self.loop, self.log, self.dts)
        endpoint = rpc.EndpointDiscoveryRpcHandler(self.log, self.dts,
                                                   self.loop, proxy)
        yield from endpoint.register()

        ip = RwPkgMgmtYang.YangInput_RwPkgMgmt_GetPackageEndpoint.from_dict({
            "package_type":
            "VNFD",
            "package_id":
            "BLAHID",
            "project_name":
            DEFAULT_PROJECT
        })

        rpc_out = yield from self.dts.query_rpc("I,/get-package-endpoint",
                                                rwdts.XactFlag.TRACE, ip)

        for itr in rpc_out:
            result = yield from itr
            assert result.result.endpoint == 'https://127.0.0.1:8008/mano/api/package/vnfd/{}/BLAHID'.format(
                DEFAULT_PROJECT)
    def test_file_add_workflow(self):
        """
            Integration test:
                1. Verify the end to end flow of package ADD (NO MOCKS)
        """
        uid, path = self.create_mock_package(DEFAULT_PROJECT)

        proxy = filesystem.FileSystemProxy(self.loop, self.log, self.dts)
        tasklet = MockTasklet(self.log, uid=uid)
        project = tasklet.projects[DEFAULT_PROJECT]
        publisher = pkg_publisher.DownloadStatusPublisher(
            self.log, self.dts, self.loop, project)
        project.job_handler = publisher
        endpoint = rpc.PackageOperationsRpcHandler(self.log, self.dts,
                                                   self.loop, proxy, tasklet)

        yield from publisher.register()
        yield from endpoint.register()

        ip = RwPkgMgmtYang.YangInput_RwPkgMgmt_PackageFileAdd.from_dict({
            "package_type":
            "VNFD",
            "package_id":
            uid,
            "external_url":
            "https://raw.githubusercontent.com/RIFTIO/RIFT.ware/master/rift-shell",
            "project_name":
            DEFAULT_PROJECT,
            "vnfd_file_type":
            "ICONS",
            "package_path":
            "rift-shell"
        })

        rpc_out = yield from self.dts.query_rpc(
            "I,/rw-pkg-mgmt:package-file-add", rwdts.XactFlag.TRACE, ip)

        yield from asyncio.sleep(5, loop=self.loop)
        filepath = os.path.join(path, ip.vnfd_file_type.lower(),
                                ip.package_path)
        self.log.debug("Filepath: {}".format(filepath))
        assert os.path.isfile(filepath)
        mode = oct(os.stat(filepath)[stat.ST_MODE])
        assert str(mode) == "0o100664"

        shutil.rmtree(path)
    def test_schema_rpc(self):
        """
        Verifies the following:
            The schema RPC return the schema structure
        """
        proxy = filesystem.FileSystemProxy(self.loop, self.log, self.dts)
        endpoint = rpc.SchemaRpcHandler(self.log, self.dts, self.loop, proxy)
        yield from endpoint.register()

        ip = RwPkgMgmtYang.YangInput_RwPkgMgmt_GetPackageSchema.from_dict({
            "package_type":
            "VNFD",
            "project_name":
            DEFAULT_PROJECT
        })

        rpc_out = yield from self.dts.query_rpc("I,/get-package-schema",
                                                rwdts.XactFlag.TRACE, ip)

        for itr in rpc_out:
            result = yield from itr
            assert "charms" in result.result.schema
    def test_file_delete_workflow(self):
        """
            Integration test:
                1. Verify the end to end flow of package ADD (NO MOCKS)
        """
        uid, path = self.create_mock_package(DEFAULT_PROJECT)

        proxy = filesystem.FileSystemProxy(self.loop, self.log, self.dts)
        endpoint = rpc.PackageDeleteOperationsRpcHandler(
            self.log, self.dts, self.loop, proxy)

        yield from endpoint.register()

        ip = RwPkgMgmtYang.YangInput_RwPkgMgmt_PackageFileDelete.from_dict({
            "package_type":
            "VNFD",
            "package_id":
            uid,
            "package_path":
            "logo.png",
            "vnfd_file_type":
            "ICONS",
            "project_name":
            DEFAULT_PROJECT
        })

        assert os.path.isfile(
            os.path.join(path, ip.vnfd_file_type.lower(), ip.package_path))

        rpc_out = yield from self.dts.query_rpc(
            "I,/rw-pkg-mgmt:package-file-delete", rwdts.XactFlag.TRACE, ip)

        yield from asyncio.sleep(5, loop=self.loop)
        assert not os.path.isfile(
            os.path.join(path, ip.vnfd_file_type.lower(), ip.package_path))

        shutil.rmtree(path)