Add "TrafficGeneratorProducer" for "GenericTrafficGen" instances
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_base.py
index ebedcb4..ca3831c 100644 (file)
 
 import multiprocessing
 import os
+import uuid
 
 import mock
+from oslo_config import cfg
+import oslo_messaging
 import unittest
 
+from yardstick.common import messaging
 from yardstick.network_services.vnf_generic.vnf import base
 from yardstick.ssh import SSH
 
@@ -221,7 +225,7 @@ class TestGenericVNF(unittest.TestCase):
         self.assertEqual(msg, str(exc.exception))
 
 
-class TestGenericTrafficGen(unittest.TestCase):
+class GenericTrafficGenTestCase(unittest.TestCase):
 
     def test_definition(self):
         """Make sure that the abstract class cannot be instantiated"""
@@ -234,3 +238,24 @@ class TestGenericTrafficGen(unittest.TestCase):
                "abstract methods collect_kpi, instantiate, run_traffic, "
                "scale, terminate")
         self.assertEqual(msg, str(exc.exception))
+
+
+class TrafficGeneratorProducerTestCase(unittest.TestCase):
+
+    @mock.patch.object(oslo_messaging, 'Target', return_value='rpc_target')
+    @mock.patch.object(oslo_messaging, 'RPCClient')
+    @mock.patch.object(oslo_messaging, 'get_rpc_transport',
+                       return_value='rpc_transport')
+    @mock.patch.object(cfg, 'CONF')
+    def test__init(self, mock_config, mock_transport, mock_rpcclient,
+                   mock_target):
+        pid = uuid.uuid1().int
+        tg_producer = base.TrafficGeneratorProducer(pid)
+        mock_transport.assert_called_once_with(
+            mock_config, url='rabbit://yardstick:yardstick@localhost:5672/')
+        mock_target.assert_called_once_with(topic=messaging.TOPIC_TG,
+                                            fanout=True,
+                                            server=messaging.SERVER)
+        mock_rpcclient.assert_called_once_with('rpc_transport', 'rpc_target')
+        self.assertEqual(pid, tg_producer._pid)
+        self.assertEqual(messaging.TOPIC_TG, tg_producer._topic)