NFVBENCH-215 Fix wrong throughput ratio in latency tests
[nfvbench.git] / test / test_nfvbench.py
index c772d7b..e48fbda 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 #
+import openstack
+from keystoneauth1.exceptions import HTTPClientError
 from mock import patch
 import pytest
 
@@ -32,8 +34,8 @@ from nfvbench.traffic_client import GeneratorConfig
 from nfvbench.traffic_client import IpBlock
 from nfvbench.traffic_client import TrafficClient
 from nfvbench.traffic_client import TrafficClientException
-import nfvbench.traffic_gen.traffic_utils as traffic_utils
-import nfvbench.utils as utils
+from nfvbench.traffic_gen import traffic_utils
+from nfvbench import utils
 
 # just to get rid of the unused function warning
 no_op()
@@ -139,13 +141,41 @@ def test_load_from_rate():
 # =========================================================================
 
 def test_no_credentials():
-    cred = Credentials('/completely/wrong/path/openrc', None, False)
-    if cred.rc_auth_url:
-        # shouldn't get valid data unless user set environment variables
+    with patch.object(openstack, 'connect') as mock:
+        cred = Credentials('/completely/wrong/path/openrc', None, None, False)
+        if cred.rc_auth_url:
+            # shouldn't get valid data unless user set environment variables
+            assert False
+        else:
+            assert True
+    mock.assert_not_called()
+
+
+def test_clouds_file_credentials():
+    with patch.object(openstack, 'connect') as mock:
+        Credentials(None, 'openstack', None, False)
+    mock.assert_called_once()
+
+
+@patch('nfvbench.nfvbench.credentials')
+def test_is_not_admin(mock_session):
+    mock_session.Session.return_value.get.return_value.raiseError.side_effect = HTTPClientError
+    cred = Credentials(None, 'openstack', None, False)
+    if cred.is_admin:
         assert False
     else:
         assert True
 
+
+def test_is_admin():
+    with patch.object(openstack, 'connect'):
+        cred = Credentials(None, 'openstack', None, False)
+        if cred.is_admin:
+            assert True
+        else:
+            assert False
+
+
 def test_ip_block():
     ipb = IpBlock('10.0.0.0', '0.0.0.1', 256)
     assert ipb.get_ip() == '10.0.0.0'
@@ -1070,8 +1100,9 @@ def _get_dummy_tg_config(chain_type, rate, scc=1, fc=10, step_ip='0.0.0.1',
         'no_flow_stats': False,
         'no_latency_stats': False,
         'no_latency_streams': False,
-        'intf_speed': '10Gbps'
-
+        'intf_speed': '10Gbps',
+        'periodic_gratuitous_arp': False,
+        'gratuitous_arp_pps': 1
     })
 
 def _get_traffic_client(user_info=None):