4 # Copyright 2016 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
31 gi
.require_version('RwDts', '1.0')
32 gi
.require_version('RwPkgMgmtYang', '1.0')
33 from gi
.repository
import (
37 from rift
.tasklets
.rwpkgmgr
.proxy
import filesystem
39 import rift
.tasklets
.rwpkgmgr
.publisher
as pkg_publisher
40 import rift
.tasklets
.rwpkgmgr
.rpc
as rpc
43 TEST_STRING
= "foobar"
45 class TestCase(rift
.test
.dts
.AbstractDTSTest
):
47 def configure_schema(cls
):
48 return RwPkgMgmtYang
.get_schema()
51 def configure_timeout(cls
):
54 def configure_test(self
, loop
, test_id
):
55 self
.log
.debug("STARTING - %s", test_id
)
56 self
.tinfo
= self
.new_tinfo(str(test_id
))
57 self
.dts
= rift
.tasklets
.DTS(self
.tinfo
, self
.schema
, self
.loop
)
62 def create_mock_package(self
):
63 uid
= str(uuid
.uuid4())
65 os
.getenv('RIFT_ARTIFACTS'),
66 "launchpad/packages/vnfd",
69 package_path
= os
.path
.join(path
, "pong_vnfd")
71 os
.makedirs(package_path
)
72 open(os
.path
.join(path
, "pong_vnfd.xml"), "wb").close()
73 open(os
.path
.join(path
, "logo.png"), "wb").close()
77 @rift.test
.dts
.async_test
78 def test_endpoint_discovery(self
):
80 Verifies the following:
81 The endpoint RPC returns a URL
83 proxy
= filesystem
.FileSystemProxy(self
.loop
, self
.log
)
84 endpoint
= rpc
.EndpointDiscoveryRpcHandler(self
.log
, self
.dts
, self
.loop
, proxy
)
85 yield from endpoint
.register()
87 ip
= RwPkgMgmtYang
.YangInput_RwPkgMgmt_GetPackageEndpoint
.from_dict({
88 "package_type": "VNFD",
89 "package_id": "BLAHID"})
91 rpc_out
= yield from self
.dts
.query_rpc(
92 "I,/get-package-endpoint",
97 result
= yield from itr
98 assert result
.result
.endpoint
== 'https://127.0.0.1:4567/api/package/vnfd/BLAHID'
100 @rift.test
.dts
.async_test
101 def test_schema_rpc(self
):
103 Verifies the following:
104 The schema RPC return the schema structure
106 proxy
= filesystem
.FileSystemProxy(self
.loop
, self
.log
)
107 endpoint
= rpc
.SchemaRpcHandler(self
.log
, self
.dts
, self
.loop
, proxy
)
108 yield from endpoint
.register()
110 ip
= RwPkgMgmtYang
.YangInput_RwPkgMgmt_GetPackageSchema
.from_dict({
111 "package_type": "VNFD"})
113 rpc_out
= yield from self
.dts
.query_rpc(
114 "I,/get-package-schema",
115 rwdts
.XactFlag
.TRACE
,
119 result
= yield from itr
120 assert "charms" in result
.result
.schema
122 @rift.test
.dts
.async_test
123 def test_file_proxy_rpc(self
):
125 1. The file RPC returns a valid UUID thro' DTS
127 assert_uid
= str(uuid
.uuid4())
130 def register_downloader(self
, *args
):
133 uid
, path
= self
.create_mock_package()
135 proxy
= filesystem
.FileSystemProxy(self
.loop
, self
.log
)
136 endpoint
= rpc
.PackageOperationsRpcHandler(
142 yield from endpoint
.register()
144 ip
= RwPkgMgmtYang
.YangInput_RwPkgMgmt_PackageFileAdd
.from_dict({
145 "package_type": "VNFD",
147 "external_url": "https://raw.githubusercontent.com/RIFTIO/RIFT.ware/master/rift-shell",
148 "package_path": "script/rift-shell"})
150 rpc_out
= yield from self
.dts
.query_rpc(
151 "I,/rw-pkg-mgmt:package-file-add",
152 rwdts
.XactFlag
.TRACE
,
156 result
= yield from itr
157 assert result
.result
.task_id
== assert_uid
161 @rift.test
.dts
.async_test
162 def test_file_add_workflow(self
):
165 1. Verify the end to end flow of package ADD (NO MOCKS)
167 uid
, path
= self
.create_mock_package()
169 proxy
= filesystem
.FileSystemProxy(self
.loop
, self
.log
)
170 publisher
= pkg_publisher
.DownloadStatusPublisher(self
.log
, self
.dts
, self
.loop
)
171 endpoint
= rpc
.PackageOperationsRpcHandler(
178 yield from publisher
.register()
179 yield from endpoint
.register()
181 ip
= RwPkgMgmtYang
.YangInput_RwPkgMgmt_PackageFileAdd
.from_dict({
182 "package_type": "VNFD",
184 "external_url": "https://raw.githubusercontent.com/RIFTIO/RIFT.ware/master/rift-shell",
185 "package_path": "icons/rift-shell"})
187 rpc_out
= yield from self
.dts
.query_rpc(
188 "I,/rw-pkg-mgmt:package-file-add",
189 rwdts
.XactFlag
.TRACE
,
192 yield from asyncio
.sleep(5, loop
=self
.loop
)
193 filepath
= os
.path
.join(path
, ip
.package_path
)
194 assert os
.path
.isfile(filepath
)
195 mode
= oct(os
.stat(filepath
)[stat
.ST_MODE
])
196 assert str(mode
) == "0o100664"
201 @rift.test
.dts
.async_test
202 def test_file_delete_workflow(self
):
205 1. Verify the end to end flow of package ADD (NO MOCKS)
207 uid
, path
= self
.create_mock_package()
209 proxy
= filesystem
.FileSystemProxy(self
.loop
, self
.log
)
210 endpoint
= rpc
.PackageDeleteOperationsRpcHandler(
216 yield from endpoint
.register()
218 ip
= RwPkgMgmtYang
.YangInput_RwPkgMgmt_PackageFileDelete
.from_dict({
219 "package_type": "VNFD",
221 "package_path": "logo.png"})
223 assert os
.path
.isfile(os
.path
.join(path
, ip
.package_path
))
225 rpc_out
= yield from self
.dts
.query_rpc(
226 "I,/rw-pkg-mgmt:package-file-delete",
227 rwdts
.XactFlag
.TRACE
,
230 yield from asyncio
.sleep(5, loop
=self
.loop
)
231 assert not os
.path
.isfile(os
.path
.join(path
, ip
.package_path
))
236 runner
= xmlrunner
.XMLTestRunner(output
=os
.environ
["RIFT_MODULE_TEST"])
238 parser
= argparse
.ArgumentParser()
239 parser
.add_argument('-v', '--verbose', action
='store_true')
240 parser
.add_argument('-n', '--no-runner', action
='store_true')
241 args
, unittest_args
= parser
.parse_known_args()
245 logging
.basicConfig(format
='TEST %(message)s')
246 logging
.getLogger().setLevel(logging
.DEBUG
)
249 unittest
.main(testRunner
=runner
, argv
=[sys
.argv
[0]] + unittest_args
)
251 if __name__
== '__main__':