vnf_generic: convert sshmanager to class
[yardstick.git] / tests / unit / benchmark / scenarios / networking / test_pktgen.py
index a20382c..f50fa10 100644 (file)
 
 # Unittest for yardstick.benchmark.scenarios.networking.pktgen.Pktgen
 
-import mock
+from __future__ import absolute_import
+
 import unittest
-import json
+
+import mock
+from oslo_serialization import jsonutils
 
 from yardstick.benchmark.scenarios.networking import pktgen
 
@@ -23,19 +26,25 @@ class PktgenTestCase(unittest.TestCase):
 
     def setUp(self):
         self.ctx = {
-            'host': '172.16.0.137',
-            'target': '172.16.0.138',
-            'user': 'cirros',
-            'key_filename': "mykey.key"
+            'host': {
+                'ip': '172.16.0.137',
+                'user': 'root',
+                'key_filename': 'mykey.key'
+            },
+            'target': {
+                'ip': '172.16.0.138',
+                'user': 'root',
+                'key_filename': 'mykey.key',
+                'ipaddr': '172.16.0.138'
+            }
         }
 
     def test_pktgen_successful_setup(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60},
-            'ipaddr': '172.16.0.139'
         }
+        p = pktgen.Pktgen(args, self.ctx)
         p.setup()
 
         mock_ssh.SSH().execute.return_value = (0, '', '')
@@ -45,11 +54,10 @@ class PktgenTestCase(unittest.TestCase):
 
     def test_pktgen_successful_iptables_setup(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139'
         }
+        p = pktgen.Pktgen(args, self.ctx)
         p.server = mock_ssh.SSH()
         p.number_of_ports = args['options']['number_of_ports']
 
@@ -64,11 +72,11 @@ class PktgenTestCase(unittest.TestCase):
 
     def test_pktgen_unsuccessful_iptables_setup(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139'
         }
+
+        p = pktgen.Pktgen(args, self.ctx)
         p.server = mock_ssh.SSH()
         p.number_of_ports = args['options']['number_of_ports']
 
@@ -77,11 +85,11 @@ class PktgenTestCase(unittest.TestCase):
 
     def test_pktgen_successful_iptables_get_result(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139'
         }
+
+        p = pktgen.Pktgen(args, self.ctx)
         p.server = mock_ssh.SSH()
         p.number_of_ports = args['options']['number_of_ports']
 
@@ -95,11 +103,12 @@ class PktgenTestCase(unittest.TestCase):
 
     def test_pktgen_unsuccessful_iptables_get_result(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139'
         }
+
+        p = pktgen.Pktgen(args, self.ctx)
+
         p.server = mock_ssh.SSH()
         p.number_of_ports = args['options']['number_of_ports']
 
@@ -108,11 +117,13 @@ class PktgenTestCase(unittest.TestCase):
 
     def test_pktgen_successful_no_sla(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139'
         }
+        result = {}
+
+        p = pktgen.Pktgen(args, self.ctx)
+
         p.server = mock_ssh.SSH()
         p.client = mock_ssh.SSH()
 
@@ -124,19 +135,21 @@ class PktgenTestCase(unittest.TestCase):
             "packets_sent": 149776, "flows": 110}'
         mock_ssh.SSH().execute.return_value = (0, sample_output, '')
 
-        result = p.run(args)
-        expected_result = json.loads(sample_output)
+        p.run(result)
+        expected_result = jsonutils.loads(sample_output)
         expected_result["packets_received"] = 149300
         self.assertEqual(result, expected_result)
 
     def test_pktgen_successful_sla(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139',
             'sla': {'max_ppm': 10000}
         }
+        result = {}
+
+        p = pktgen.Pktgen(args, self.ctx)
+
         p.server = mock_ssh.SSH()
         p.client = mock_ssh.SSH()
 
@@ -148,19 +161,21 @@ class PktgenTestCase(unittest.TestCase):
             "packets_sent": 149776, "flows": 110}'
         mock_ssh.SSH().execute.return_value = (0, sample_output, '')
 
-        result = p.run(args)
-        expected_result = json.loads(sample_output)
+        p.run(result)
+        expected_result = jsonutils.loads(sample_output)
         expected_result["packets_received"] = 149300
         self.assertEqual(result, expected_result)
 
     def test_pktgen_unsuccessful_sla(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139',
             'sla': {'max_ppm': 1000}
         }
+        result = {}
+
+        p = pktgen.Pktgen(args, self.ctx)
+
         p.server = mock_ssh.SSH()
         p.client = mock_ssh.SSH()
 
@@ -171,21 +186,23 @@ class PktgenTestCase(unittest.TestCase):
         sample_output = '{"packets_per_second": 9753, "errors": 0, \
             "packets_sent": 149776, "flows": 110}'
         mock_ssh.SSH().execute.return_value = (0, sample_output, '')
-        self.assertRaises(AssertionError, p.run, args)
+        self.assertRaises(AssertionError, p.run, result)
 
     def test_pktgen_unsuccessful_script_error(self, mock_ssh):
 
-        p = pktgen.Pktgen(self.ctx)
         args = {
             'options': {'packetsize': 60, 'number_of_ports': 10},
-            'ipaddr': '172.16.0.139',
             'sla': {'max_ppm': 1000}
         }
+        result = {}
+
+        p = pktgen.Pktgen(args, self.ctx)
+
         p.server = mock_ssh.SSH()
         p.client = mock_ssh.SSH()
 
         mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
-        self.assertRaises(RuntimeError, p.run, args)
+        self.assertRaises(RuntimeError, p.run, result)
 
 
 def main():