5 import concurrent
.futures
14 gi
.require_version('RwLog', '1.0')
16 import rift
.tasklets
.rwmonitor
.core
as core
17 import rift
.mano
.cloud
as cloud
19 from gi
.repository
import RwCloudYang
, RwLog
, RwVnfrYang
23 def update(loop
, log
, executor
, account
, plugin
, vim_id
):
24 """Update the NFVI metrics for the associated VDUR
26 This coroutine will request new metrics from the data-source and update
31 # Make the request to the plugin in a separate thread and do
32 # not exceed the timeout
33 _
, metrics
= yield from asyncio
.wait_for(
44 except asyncio
.TimeoutError
:
45 msg
= "timeout on request for nfvi metrics (vim-id = {})"
46 log
.warning(msg
.format(vim_id
))
49 except Exception as e
:
54 # Create uninitialized metric structure
55 vdu_metrics
= RwVnfrYang
.YangData_Vnfr_VnfrCatalog_Vnfr_Vdur_NfviMetrics()
58 vdu_metrics
.vcpu
.total
= 5
59 vdu_metrics
.vcpu
.utilization
= metrics
.vcpu
.utilization
62 vdu_metrics
.memory
.used
= metrics
.memory
.used
63 vdu_metrics
.memory
.total
= 5000
64 vdu_metrics
.memory
.utilization
= 100 * vdu_metrics
.memory
.used
/ vdu_metrics
.memory
.total
68 vdu_metrics
.storage
.used
= metrics
.storage
.used
69 utilization
= 100 * vdu_metrics
.storage
.used
/ vdu_metrics
.storage
.total
73 vdu_metrics
.storage
.utilization
= utilization
75 except ZeroDivisionError:
76 vdu_metrics
.storage
.utilization
= 0
79 vdu_metrics
.network
.incoming
.packets
= metrics
.network
.incoming
.packets
80 vdu_metrics
.network
.incoming
.packet_rate
= metrics
.network
.incoming
.packet_rate
81 vdu_metrics
.network
.incoming
.bytes
= metrics
.network
.incoming
.bytes
82 vdu_metrics
.network
.incoming
.byte_rate
= metrics
.network
.incoming
.byte_rate
85 vdu_metrics
.network
.outgoing
.packets
= metrics
.network
.outgoing
.packets
86 vdu_metrics
.network
.outgoing
.packet_rate
= metrics
.network
.outgoing
.packet_rate
87 vdu_metrics
.network
.outgoing
.bytes
= metrics
.network
.outgoing
.bytes
88 vdu_metrics
.network
.outgoing
.byte_rate
= metrics
.network
.outgoing
.byte_rate
91 vdu_metrics
.external_ports
.total
= 5
94 vdu_metrics
.internal_ports
.total
= 5
98 except Exception as e
:
102 class TestUploadProgress(unittest
.TestCase
):
103 ACCOUNT_MSG
= RwCloudYang
.YangData_RwProject_Project_CloudAccounts_CloudAccountList
.from_dict({
104 "account_type": "openstack",
107 "secret": "mypasswd",
108 "auth_url": 'http://10.66.4.18:5000/v3/',
110 "mgmt_network": "private"
115 self
._loop
= asyncio
.get_event_loop()
116 self
._log
= logging
.getLogger(__file__
)
117 self
._account
= cloud
.CloudAccount(
119 RwLog
.Ctx
.new(__file__
), TestUploadProgress
.ACCOUNT_MSG
122 def test_many_updates(self
):
123 vim_id
= "a7f30def-0942-4425-8454-1ffe02b7db1e"
126 executor
= concurrent
.futures
.ThreadPoolExecutor(10)
129 for _
in range(instances
):
130 plugin
= rw_peas
.PeasPlugin("rwmon_ceilometer", 'RwMon-1.0')
131 impl
= plugin
.get_interface("Monitoring")
132 task
= update(self
._loop
, self
._log
, executor
, self
._account
.cal_account_msg
, impl
, vim_id
)
134 task
= update(self
._loop
, self
._log
, executor
, self
._account
.cal_account_msg
, impl
, vim_id
)
136 task
= update(self
._loop
, self
._log
, executor
, self
._account
.cal_account_msg
, impl
, vim_id
)
138 self
._log
.debug("Running %s update tasks", instances
)
139 self
._loop
.run_until_complete(asyncio
.wait(tasks
, loop
=self
._loop
, timeout
=20))
142 def main(argv
=sys
.argv
[1:]):
143 logging
.basicConfig(format
='TEST %(message)s')
145 runner
= xmlrunner
.XMLTestRunner(output
=os
.environ
["RIFT_MODULE_TEST"])
146 parser
= argparse
.ArgumentParser()
147 parser
.add_argument('-v', '--verbose', action
='store_true')
148 parser
.add_argument('-n', '--no-runner', action
='store_true')
150 args
, unknown
= parser
.parse_known_args(argv
)
154 # Set the global logging level
155 logging
.getLogger().setLevel(logging
.DEBUG
if args
.verbose
else logging
.ERROR
)
157 # The unittest framework requires a program name, so use the name of this
158 # file instead (we do not want to have to pass a fake program name to main
159 # when this is called from the interpreter).
160 unittest
.main(argv
=[__file__
] + unknown
+ ["-v"], testRunner
=runner
)
162 if __name__
== '__main__':