summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorahothan <ahothan@cisco.com>2018-10-14 15:15:36 -0700
committerahothan <ahothan@cisco.com>2018-10-14 16:00:37 -0700
commitc0ef57f8ec086c07053d529510992c869c30c9d2 (patch)
tree1a63c2501028eb0a4844feff2f8a31277a0e7078 /test
parentb68b487864cc080b86ad358a5b1fb9bad912efd4 (diff)
NFVBENCH-103 Add --hypervisor cli options and fix vm placement for multi-chain2.0.0
Change-Id: I80ab8b7c39221132ff43b95cd453dbfd4edd580c Signed-off-by: ahothan <ahothan@cisco.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_chains.py52
1 files changed, 44 insertions, 8 deletions
diff --git a/test/test_chains.py b/test/test_chains.py
index 519748b..e952eb8 100644
--- a/test/test_chains.py
+++ b/test/test_chains.py
@@ -19,9 +19,11 @@ from mock_trex import no_op
from mock import MagicMock
from mock import patch
+import pytest
from nfvbench.chain_runner import ChainRunner
from nfvbench.chaining import ChainVnfPort
+from nfvbench.chaining import InstancePlacer
from nfvbench.compute import Compute
import nfvbench.credentials
from nfvbench.factory import BasicFactory
@@ -37,6 +39,7 @@ from nfvbench.traffic_client import TrafficClient
from nfvbench.traffic_gen.traffic_base import Latency
from nfvbench.traffic_gen.trex import TRex
+
# just to get rid of the unused function warning
no_op()
@@ -78,13 +81,9 @@ def test_chain_runner_ext_no_openstack():
runner = ChainRunner(config, None, specs, BasicFactory())
runner.close()
-def _mock_get_enabled_az_host_list(self, required_count=1):
- return ['nova:c1', 'nova:c2']
-
def _mock_find_image(self, image_name):
return True
-@patch.object(Compute, 'get_enabled_az_host_list', _mock_get_enabled_az_host_list)
@patch.object(Compute, 'find_image', _mock_find_image)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@@ -112,7 +111,6 @@ def test_pvp_chain_runner():
config = _get_chain_config(sc, scc, shared_net)
_test_pvp_chain(config, cred)
-@patch.object(Compute, 'get_enabled_az_host_list', _mock_get_enabled_az_host_list)
@patch.object(Compute, 'find_image', _mock_find_image)
@patch('nfvbench.chaining.Client')
@patch('nfvbench.chaining.neutronclient')
@@ -168,7 +166,6 @@ def _mock_get_mac(dummy):
mac_seq += 1
return '01:00:00:00:00:%02x' % mac_seq
-@patch.object(Compute, 'get_enabled_az_host_list', _mock_get_enabled_az_host_list)
@patch.object(Compute, 'find_image', _mock_find_image)
@patch.object(TrafficClient, 'skip_sleep', lambda x: True)
@patch.object(ChainVnfPort, 'get_mac', _mock_get_mac)
@@ -186,7 +183,6 @@ def test_nfvbench_run(mock_cred, mock_glance, mock_neutron, mock_client):
mock_neutron.Client.return_value.list_networks.return_value = {'networks': None}
_check_nfvbench_openstack()
-@patch.object(Compute, 'get_enabled_az_host_list', _mock_get_enabled_az_host_list)
@patch.object(Compute, 'find_image', _mock_find_image)
@patch.object(TrafficClient, 'skip_sleep', lambda x: True)
@patch('nfvbench.chaining.Client')
@@ -202,7 +198,6 @@ def test_nfvbench_ext_arp(mock_cred, mock_glance, mock_neutron, mock_client):
mock_neutron.Client.return_value.list_networks.return_value = {'networks': [netw]}
_check_nfvbench_openstack(sc=ChainType.EXT)
-@patch.object(Compute, 'get_enabled_az_host_list', _mock_get_enabled_az_host_list)
@patch.object(Compute, 'find_image', _mock_find_image)
@patch.object(TrafficClient, 'skip_sleep', lambda x: True)
@patch('nfvbench.chaining.Client')
@@ -282,6 +277,47 @@ def test_trex_streams_stats():
assert if_stats[1].tx == CH1_P1_TX + LCH1_P1_TX
assert if_stats[1].rx == CH1_P1_RX + LCH1_P1_RX
+def check_placer(az, hyp, req_az, resolved=False):
+ """Combine multiple combinatoons of placer tests."""
+ placer = InstancePlacer(az, hyp)
+ assert placer.is_resolved() == resolved
+ assert placer.get_required_az() == req_az
+ assert placer.register_full_name('nova:comp1')
+ assert placer.is_resolved()
+ assert placer.get_required_az() == 'nova:comp1'
+
+def test_placer_no_user_pref():
+ """Test placement when user does not provide any preference."""
+ check_placer(None, None, '')
+
+def test_placer_user_az():
+ """Test placement when user only provides an az."""
+ check_placer('nova', None, 'nova:')
+ check_placer(None, 'nova:', 'nova:')
+ check_placer('nebula', 'nova:', 'nova:')
+
+def test_placer_user_hyp():
+ """Test placement when user provides a hypervisor."""
+ check_placer(None, 'comp1', 'comp1')
+ check_placer('nova', 'comp1', 'nova:comp1', resolved=True)
+ check_placer(None, 'nova:comp1', 'nova:comp1', resolved=True)
+ # hyp overrides az
+ check_placer('nebula', 'nova:comp1', 'nova:comp1', resolved=True)
+ # also check for cases of extra parts (more than 1 ':')
+ check_placer('nova:nebula', 'comp1', 'nova:comp1', resolved=True)
+
+
+def test_placer_negative():
+ """Run negative tests on placer."""
+ # AZ mismatch
+ with pytest.raises(Exception):
+ placer = InstancePlacer('nova', None)
+ placer.register('nebula:comp1')
+ # comp mismatch
+ with pytest.raises(Exception):
+ placer = InstancePlacer(None, 'comp1')
+ placer.register('nebula:comp2')
+
# without total, with total and only 2 col
CHAIN_STATS = [{0: {'packets': [2000054, 1999996, 1999996]}},