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.
29 gi
.require_version('RwDts', '1.0')
30 gi
.require_version('RwStagingMgmtYang', '1.0')
31 from gi
.repository
import (
35 import rift
.tasklets
.rwstagingmgr
.publisher
as publisher
37 from rift
.mano
.utils
.project
import ManoProject
39 class TestProject(ManoProject
):
40 def __init__(self
, log
, dts
, loop
):
46 class TestCase(rift
.test
.dts
.AbstractDTSTest
):
48 def configure_schema(cls
):
49 return RwStagingMgmtYang
.get_schema()
52 def configure_timeout(cls
):
55 def configure_test(self
, loop
, test_id
):
56 self
.log
.debug("STARTING - %s", test_id
)
57 self
.tinfo
= self
.new_tinfo(str(test_id
))
58 self
.dts
= rift
.tasklets
.DTS(self
.tinfo
, self
.schema
, self
.loop
)
59 self
.project
= TestProject(self
.log
, self
.dts
, self
.loop
)
61 self
.job_handler
= publisher
.StagingStorePublisher(self
.project
)
67 def get_published_xpaths(self
):
68 published_xpaths
= set()
70 res_iter
= yield from self
.dts
.query_read("D,/rwdts:dts")
72 res
= (yield from i
).result
73 for member
in res
.member
:
74 published_xpaths |
= {reg
.keyspec
for reg
in member
.state
.registration
if reg
.flags
== "publisher"}
76 return published_xpaths
79 def read_xpath(self
, xpath
):
80 itr
= yield from self
.dts
.query_read(xpath
)
84 result
= yield from fut
87 @rift.test
.dts
.async_test
88 def test_download_publisher(self
):
89 yield from self
.job_handler
.register()
90 yield from asyncio
.sleep(2, loop
=self
.loop
)
91 published_xpaths
= yield from self
.get_published_xpaths()
92 assert self
.job_handler
.xpath() in published_xpaths
93 self
.job_handler
.deregister()
95 @rift.test
.dts
.async_test
96 def test_publish(self
):
99 yield from self
.job_handler
.register()
101 mock_msg
= RwStagingMgmtYang
.StagingArea
.from_dict({
104 self
.job_handler
.on_staging_area_create(mock_msg
)
105 yield from asyncio
.sleep(5, loop
=self
.loop
)
107 xpath
= self
.project
.add_project("/staging-areas/staging-area[area-id='{}']".
108 format(mock_msg
.area_id
))
109 itr
= yield from self
.dts
.query_read(xpath
)
114 result
= yield from fut
115 result
= result
.result
118 assert result
== mock_msg
119 self
.job_handler
.deregister()
122 runner
= xmlrunner
.XMLTestRunner(output
=os
.environ
["RIFT_MODULE_TEST"])
124 parser
= argparse
.ArgumentParser()
125 parser
.add_argument('-v', '--verbose', action
='store_true')
126 parser
.add_argument('-n', '--no-runner', action
='store_true')
127 args
, unittest_args
= parser
.parse_known_args()
131 TestCase
.log_level
= logging
.DEBUG
if args
.verbose
else logging
.WARN
133 unittest
.main(testRunner
=runner
, argv
=[sys
.argv
[0]] + unittest_args
)
135 if __name__
== '__main__':