import uuid
import xmlrunner
+# Setting RIFT_VAR_ROOT if not already set for unit test execution
+if "RIFT_VAR_ROOT" not in os.environ:
+ os.environ['RIFT_VAR_ROOT'] = os.path.join(os.environ['RIFT_INSTALL'], 'var/rift/unittest')
+
import gi
gi.require_version('RwDts', '1.0')
gi.require_version('RwPkgMgmtYang', '1.0')
import rift.tasklets.rwpkgmgr.publisher as pkg_publisher
import rift.tasklets.rwpkgmgr.rpc as rpc
import rift.test.dts
+from rift.mano.utils.project import ManoProject, DEFAULT_PROJECT
TEST_STRING = "foobar"
+
+class MockPublisher(object):
+ def __init__(self, uid):
+ self.assert_uid = uid
+
+ @asyncio.coroutine
+ def register_downloader(self, *args):
+ return self.assert_uid
+
+
+class MockProject(ManoProject):
+ def __init__(self, log, uid=None):
+ super().__init__(log, name=DEFAULT_PROJECT)
+ self.job_handler = MockPublisher(uid)
+
+
+class MockTasklet:
+ def __init__(self, log, uid=None):
+ self.log = log
+ self.projects = {}
+ project = MockProject(self.log,
+ uid=uid)
+ project.publisher = None
+ self.projects[project.name] = project
+
+
class TestCase(rift.test.dts.AbstractDTSTest):
@classmethod
def configure_schema(cls):
def tearDown(self):
super().tearDown()
- def create_mock_package(self):
+ def create_mock_package(self, project):
uid = str(uuid.uuid4())
path = os.path.join(
- os.getenv('RIFT_ARTIFACTS'),
+ os.getenv('RIFT_VAR_ROOT'),
"launchpad/packages/vnfd",
+ project,
uid)
asset_path = os.path.join(path, "icons")
Verifies the following:
The endpoint RPC returns a URL
"""
- proxy = filesystem.FileSystemProxy(self.loop, self.log)
+ 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"})
+ "package_id": "BLAHID",
+ "project_name": DEFAULT_PROJECT})
rpc_out = yield from self.dts.query_rpc(
"I,/get-package-endpoint",
for itr in rpc_out:
result = yield from itr
- assert result.result.endpoint == 'https://127.0.0.1:4567/api/package/vnfd/BLAHID'
+ assert result.result.endpoint == 'https://127.0.0.1:8008/mano/api/package/vnfd/{}/BLAHID'.format(DEFAULT_PROJECT)
@rift.test.dts.async_test
def test_schema_rpc(self):
Verifies the following:
The schema RPC return the schema structure
"""
- proxy = filesystem.FileSystemProxy(self.loop, self.log)
+ 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"})
+ "package_type": "VNFD",
+ "project_name": DEFAULT_PROJECT})
rpc_out = yield from self.dts.query_rpc(
"I,/get-package-schema",
1. The file RPC returns a valid UUID thro' DTS
"""
assert_uid = str(uuid.uuid4())
- class MockPublisher:
- @asyncio.coroutine
- def register_downloader(self, *args):
- return assert_uid
- uid, path = self.create_mock_package()
+ uid, path = self.create_mock_package(DEFAULT_PROJECT)
- proxy = filesystem.FileSystemProxy(self.loop, self.log)
+ proxy = filesystem.FileSystemProxy(self.loop, self.log, self.dts)
endpoint = rpc.PackageOperationsRpcHandler(
self.log,
self.dts,
self.loop,
proxy,
- MockPublisher())
+ 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"})
+ "package_path": "script/rift-shell",
+ "project_name": DEFAULT_PROJECT})
rpc_out = yield from self.dts.query_rpc(
"I,/rw-pkg-mgmt:package-file-add",
Integration test:
1. Verify the end to end flow of package ADD (NO MOCKS)
"""
- uid, path = self.create_mock_package()
+ uid, path = self.create_mock_package(DEFAULT_PROJECT)
- proxy = filesystem.FileSystemProxy(self.loop, self.log)
- publisher = pkg_publisher.DownloadStatusPublisher(self.log, self.dts, self.loop)
+ 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,
- publisher)
+ tasklet)
yield from publisher.register()
yield from endpoint.register()
"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"})
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"
Integration test:
1. Verify the end to end flow of package ADD (NO MOCKS)
"""
- uid, path = self.create_mock_package()
+ uid, path = self.create_mock_package(DEFAULT_PROJECT)
- proxy = filesystem.FileSystemProxy(self.loop, self.log)
+ proxy = filesystem.FileSystemProxy(self.loop, self.log, self.dts)
endpoint = rpc.PackageDeleteOperationsRpcHandler(
self.log,
self.dts,
ip = RwPkgMgmtYang.YangInput_RwPkgMgmt_PackageFileDelete.from_dict({
"package_type": "VNFD",
"package_id": uid,
+ "package_path": "logo.png",
"vnfd_file_type": "ICONS",
- "package_path": "logo.png"})
+ "project_name": DEFAULT_PROJECT})
assert os.path.isfile(os.path.join(path, ip.vnfd_file_type.lower(), ip.package_path))