2ac784ad9c87e34b68a167ee951666c5ea701274
3 # Copyright 2016 RIFT.IO Inc
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
25 import rift
.tasklets
.rwnsmtasklet
.cloud
as cloud
26 import rift
.tasklets
.rwnsmtasklet
.openmano_nsm
as openmano_nsm
27 from rift
.mano
.utils
.project
import ManoProject
31 gi
.require_version('RwDts', '1.0')
32 from gi
.repository
import (
33 RwLaunchpadYang
as launchpadyang
,
35 RwProjectVnfdYang
as RwVnfdYang
,
38 RwProjectNsdYang
as RwNsdYang
,
43 class DescriptorPublisher(object):
44 def __init__(self
, log
, dts
, loop
):
49 self
._registrations
= []
52 def publish(self
, w_path
, path
, desc
):
53 ready_event
= asyncio
.Event(loop
=self
.loop
)
56 def on_ready(regh
, status
):
57 self
.log
.debug("Create element: %s, obj-type:%s obj:%s",
58 path
, type(desc
), desc
)
59 with self
.dts
.transaction() as xact
:
60 regh
.create_element(path
, desc
, xact
.xact
)
61 self
.log
.debug("Created element: %s, obj:%s", path
, desc
)
64 handler
= rift
.tasklets
.DTS
.RegistrationHandler(
68 self
.log
.debug("Registering path: %s, obj:%s", w_path
, desc
)
69 reg
= yield from self
.dts
.register(
72 flags
=rwdts
.Flag
.PUBLISHER | rwdts
.Flag
.NO_PREP_READ
74 self
._registrations
.append(reg
)
75 self
.log
.debug("Registered path : %s", w_path
)
76 yield from ready_event
.wait()
80 def unpublish_all(self
):
81 self
.log
.debug("Deregistering all published descriptors")
82 for reg
in self
._registrations
:
85 class RoAccountDtsTestCase(rift
.test
.dts
.AbstractDTSTest
):
87 def configure_schema(cls
):
88 return launchpadyang
.get_schema()
91 def configure_timeout(cls
):
94 def configure_test(self
, loop
, test_id
):
95 self
.log
.debug("STARTING - %s", test_id
)
96 self
.tinfo
= self
.new_tinfo(str(test_id
))
97 self
.dts
= rift
.tasklets
.DTS(self
.tinfo
, self
.schema
, self
.loop
)
98 self
.project
= ManoProject(self
.log
)
100 self
.tinfo_sub
= self
.new_tinfo(str(test_id
) + "_sub")
101 self
.dts_sub
= rift
.tasklets
.DTS(self
.tinfo_sub
, self
.schema
, self
.loop
)
103 self
.publisher
= DescriptorPublisher(self
.log
, self
.dts
, self
.loop
)
108 @rift.test
.dts
.async_test
109 def test_orch_account_create(self
):
110 orch
= cloud
.ROAccountPluginSelector(self
.dts
, self
.log
, self
.loop
, self
.project
, None)
112 yield from orch
.register()
114 # Test if we have a default plugin in case no RO is specified.
115 assert type(orch
.ro_plugin
) is cloud
.RwNsPlugin
116 mock_orch_acc
= launchpadyang
.ResourceOrchestrator
.from_dict(
117 {'name': 'rift-ro', 'account_type': 'rift_ro', 'rift_ro': {'rift_ro': True}})
119 # Test rift-ro plugin CREATE
120 w_xpath
= self
.project
.add_project("C,/rw-launchpad:resource-orchestrator")
122 yield from self
.publisher
.publish(w_xpath
, xpath
, mock_orch_acc
)
123 yield from asyncio
.sleep(5, loop
=self
.loop
)
125 assert type(orch
.ro_plugin
) is cloud
.RwNsPlugin
127 # Test Openmano plugin CREATE
128 mock_orch_acc
= launchpadyang
.ResourceOrchestrator
.from_dict(
130 'account_type': 'openmano',
131 'openmano': {'tenant_id': "abc",
133 "host": "10.64.11.77"}})
134 yield from self
.publisher
.publish(w_xpath
, xpath
, mock_orch_acc
)
135 yield from asyncio
.sleep(5, loop
=self
.loop
)
137 assert type(orch
.ro_plugin
) is openmano_nsm
.OpenmanoNsPlugin
138 assert orch
.ro_plugin
._cli
_api
._port
== mock_orch_acc
.openmano
.port
139 assert orch
.ro_plugin
._cli
_api
._host
== mock_orch_acc
.openmano
.host
142 mock_orch_acc
.openmano
.port
= 9789
143 mock_orch_acc
.openmano
.host
= "10.64.11.78"
144 yield from self
.dts
.query_update(w_xpath
,
145 rwdts
.XactFlag
.ADVISE
, mock_orch_acc
)
146 assert orch
.ro_plugin
._cli
_api
._port
== mock_orch_acc
.openmano
.port
147 assert orch
.ro_plugin
._cli
_api
._host
== mock_orch_acc
.openmano
.host
149 # Test update when a live instance exists
150 # Exception should be thrown
151 orch
.handle_nsr(None, rwdts
.QueryAction
.CREATE
)
152 mock_orch_acc
.openmano
.port
= 9788
154 with self
.assertRaises(Exception):
155 yield from self
.dts
.query_update(w_xpath
,
156 rwdts
.XactFlag
.ADVISE
, mock_orch_acc
)
159 yield from self
.dts
.query_delete(w_xpath
,
160 flags
=rwdts
.XactFlag
.ADVISE
)
161 assert orch
.ro_plugin
== None
164 def main(argv
=sys
.argv
[1:]):
166 # The unittest framework requires a program name, so use the name of this
167 # file instead (we do not want to have to pass a fake program name to main
168 # when this is called from the interpreter).
170 argv
=[__file__
] + argv
,
171 testRunner
=None#xmlrunner.XMLTestRunner(output=os.environ["RIFT_MODULE_TEST"])
174 if __name__
== '__main__':