summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-01-25 13:20:41 +0000
committerGerrit Code Review <review@openstack.org>2018-01-25 13:20:41 +0000
commit3334fb5e5b2c73b4cadfaca1c6983dbf359b8656 (patch)
tree9bb0962632c6b2fa829f52b3e5022619d0ccef30
parent98ef3ba8ba4dc06e2d1c4bb2536271ae19e17daf (diff)
parentd5b72f4250ce3a60fb85f751c99fbba88a71ced0 (diff)
Merge "tests: Use mock autospec in unit tests"
-rw-r--r--networking_hyperv/neutron/agent/hnv_neutron_agent.py1
-rw-r--r--networking_hyperv/neutron/agent/layer2.py4
-rw-r--r--networking_hyperv/tests/base.py15
-rw-r--r--networking_hyperv/tests/unit/neutron/agent/test_base.py10
-rw-r--r--networking_hyperv/tests/unit/neutron/agent/test_hnv_metadata_agent.py9
-rw-r--r--networking_hyperv/tests/unit/neutron/agent/test_hnv_neutron_agent.py9
-rw-r--r--networking_hyperv/tests/unit/neutron/agent/test_hyperv_neutron_agent.py30
-rw-r--r--networking_hyperv/tests/unit/neutron/agent/test_layer2.py23
-rw-r--r--networking_hyperv/tests/unit/neutron/qos/test_qos_driver.py3
-rw-r--r--networking_hyperv/tests/unit/neutron/test_neutron_client.py5
-rw-r--r--networking_hyperv/tests/unit/neutron/test_nvgre_ops.py16
-rw-r--r--networking_hyperv/tests/unit/neutron/test_security_groups_driver.py8
-rw-r--r--networking_hyperv/tests/unit/neutron/test_trunk_driver.py10
13 files changed, 88 insertions, 55 deletions
diff --git a/networking_hyperv/neutron/agent/hnv_neutron_agent.py b/networking_hyperv/neutron/agent/hnv_neutron_agent.py
index 17d66af..ca083dd 100644
--- a/networking_hyperv/neutron/agent/hnv_neutron_agent.py
+++ b/networking_hyperv/neutron/agent/hnv_neutron_agent.py
@@ -72,6 +72,7 @@ class HNVAgent(hyperv_base.Layer2Agent):
72 """Bind the port to the recived network.""" 72 """Bind the port to the recived network."""
73 super(HNVAgent, self)._port_bound(port_id, network_id, network_type, 73 super(HNVAgent, self)._port_bound(port_id, network_id, network_type,
74 physical_network, segmentation_id, 74 physical_network, segmentation_id,
75 port_security_enabled,
75 set_port_sriov) 76 set_port_sriov)
76 LOG.debug("Getting the profile id for the current port.") 77 LOG.debug("Getting the profile id for the current port.")
77 profile_id = self._neutron_client.get_port_profile_id(port_id) 78 profile_id = self._neutron_client.get_port_profile_id(port_id)
diff --git a/networking_hyperv/neutron/agent/layer2.py b/networking_hyperv/neutron/agent/layer2.py
index 76be6f0..27b232f 100644
--- a/networking_hyperv/neutron/agent/layer2.py
+++ b/networking_hyperv/neutron/agent/layer2.py
@@ -109,12 +109,12 @@ class Layer2Agent(base_agent.BaseAgent):
109 [topics.PORT, topics.DELETE] 109 [topics.PORT, topics.DELETE]
110 ]) 110 ])
111 111
112 self.connection = agent_rpc.create_consumers( 112 self._connection = agent_rpc.create_consumers(
113 self._endpoints, self._topic, self._consumers, 113 self._endpoints, self._topic, self._consumers,
114 start_listening=False 114 start_listening=False
115 ) 115 )
116 self._setup_qos_extension() 116 self._setup_qos_extension()
117 self.connection.consume_in_threads() 117 self._connection.consume_in_threads()
118 118
119 report_interval = CONF.AGENT.report_interval 119 report_interval = CONF.AGENT.report_interval
120 if report_interval: 120 if report_interval:
diff --git a/networking_hyperv/tests/base.py b/networking_hyperv/tests/base.py
index 14cb745..38465f3 100644
--- a/networking_hyperv/tests/base.py
+++ b/networking_hyperv/tests/base.py
@@ -27,6 +27,7 @@ import fixtures
27import mock 27import mock
28from os_win import utilsfactory 28from os_win import utilsfactory
29from oslo_utils import strutils 29from oslo_utils import strutils
30from oslotest import mock_fixture
30import testtools 31import testtools
31 32
32from networking_hyperv.neutron import config 33from networking_hyperv.neutron import config
@@ -35,6 +36,8 @@ CONF = config.CONF
35 36
36LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" 37LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
37 38
39mock_fixture.patch_mock_module()
40
38 41
39def bool_from_env(key, strict=False, default=False): 42def bool_from_env(key, strict=False, default=False):
40 value = os.environ.get(key) 43 value = os.environ.get(key)
@@ -43,8 +46,12 @@ def bool_from_env(key, strict=False, default=False):
43 46
44class BaseTestCase(testtools.TestCase): 47class BaseTestCase(testtools.TestCase):
45 48
49 _autospec_classes = []
50
46 def setUp(self): 51 def setUp(self):
47 super(BaseTestCase, self).setUp() 52 super(BaseTestCase, self).setUp()
53 self.useFixture(mock_fixture.MockAutospecFixture())
54 self._patch_autospec_classes()
48 55
49 self.addCleanup(CONF.reset) 56 self.addCleanup(CONF.reset)
50 self.addCleanup(mock.patch.stopall) 57 self.addCleanup(mock.patch.stopall)
@@ -78,6 +85,14 @@ class BaseTestCase(testtools.TestCase):
78 85
79 self.addOnException(self.check_for_systemexit) 86 self.addOnException(self.check_for_systemexit)
80 87
88 def _patch_autospec_classes(self):
89 for class_type in self._autospec_classes:
90 mocked_class = mock.Mock(autospec=class_type)
91 patcher = mock.patch(
92 '.'.join([class_type.__module__, class_type.__name__]),
93 mocked_class)
94 patcher.start()
95
81 def check_for_systemexit(self, exc_info): 96 def check_for_systemexit(self, exc_info):
82 if isinstance(exc_info[1], SystemExit): 97 if isinstance(exc_info[1], SystemExit):
83 self.fail("A SystemExit was raised during the test. %s" 98 self.fail("A SystemExit was raised during the test. %s"
diff --git a/networking_hyperv/tests/unit/neutron/agent/test_base.py b/networking_hyperv/tests/unit/neutron/agent/test_base.py
index 0a335d0..9f4908c 100644
--- a/networking_hyperv/tests/unit/neutron/agent/test_base.py
+++ b/networking_hyperv/tests/unit/neutron/agent/test_base.py
@@ -18,6 +18,7 @@ Unit tests for Neutron base agent.
18""" 18"""
19 19
20import mock 20import mock
21from neutron.agent import rpc as agent_rpc
21 22
22from networking_hyperv.neutron.agent import base as agent_base 23from networking_hyperv.neutron.agent import base as agent_base
23from networking_hyperv.tests import base as test_base 24from networking_hyperv.tests import base as test_base
@@ -44,13 +45,8 @@ class TestBaseAgent(test_base.HyperVBaseTestCase):
44 45
45 self._agent._agent_id = mock.sentinel.agent_id 46 self._agent._agent_id = mock.sentinel.agent_id
46 self._agent._context = mock.sentinel.admin_context 47 self._agent._context = mock.sentinel.admin_context
47 self._agent._utils = mock.MagicMock() 48 self._agent._state_rpc = mock.MagicMock(
48 49 autospec=agent_rpc.PluginReportStateAPI)
49 self._agent._client = mock.MagicMock()
50 self._agent._plugin_rpc = mock.Mock()
51 self._agent._connection = mock.MagicMock()
52
53 self._agent._state_rpc = mock.MagicMock()
54 50
55 def test_set_agent_state(self): 51 def test_set_agent_state(self):
56 self._agent._agent_state = {} 52 self._agent._agent_state = {}
diff --git a/networking_hyperv/tests/unit/neutron/agent/test_hnv_metadata_agent.py b/networking_hyperv/tests/unit/neutron/agent/test_hnv_metadata_agent.py
index 83535c2..7cbdf62 100644
--- a/networking_hyperv/tests/unit/neutron/agent/test_hnv_metadata_agent.py
+++ b/networking_hyperv/tests/unit/neutron/agent/test_hnv_metadata_agent.py
@@ -30,15 +30,14 @@ CONF = cfg.CONF
30 30
31class TestMetadataProxyHandler(test_base.BaseTestCase): 31class TestMetadataProxyHandler(test_base.BaseTestCase):
32 32
33 @mock.patch("networking_hyperv.neutron.neutron_client.NeutronAPIClient") 33 _autospec_classes = [
34 @mock.patch("neutron_lib.context.get_admin_context_without_session") 34 hnv_metadata_agent.neutron_client.NeutronAPIClient,
35 def _get_proxy(self, mock_get_context, mock_neutron_client): 35 ]
36 return hnv_metadata_agent._MetadataProxyHandler()
37 36
38 def setUp(self): 37 def setUp(self):
39 super(TestMetadataProxyHandler, self).setUp() 38 super(TestMetadataProxyHandler, self).setUp()
40 hnv_metadata_agent.register_config_opts() 39 hnv_metadata_agent.register_config_opts()
41 self._proxy = self._get_proxy() 40 self._proxy = hnv_metadata_agent._MetadataProxyHandler()
42 self._neutron_client = self._proxy._neutron_client 41 self._neutron_client = self._proxy._neutron_client
43 42
44 @mock.patch.object(hnv_metadata_agent._MetadataProxyHandler, 43 @mock.patch.object(hnv_metadata_agent._MetadataProxyHandler,
diff --git a/networking_hyperv/tests/unit/neutron/agent/test_hnv_neutron_agent.py b/networking_hyperv/tests/unit/neutron/agent/test_hnv_neutron_agent.py
index fa8b6ca..5cb188e 100644
--- a/networking_hyperv/tests/unit/neutron/agent/test_hnv_neutron_agent.py
+++ b/networking_hyperv/tests/unit/neutron/agent/test_hnv_neutron_agent.py
@@ -28,6 +28,10 @@ from networking_hyperv.tests import base as test_base
28 28
29class TestHNVAgent(test_base.HyperVBaseTestCase): 29class TestHNVAgent(test_base.HyperVBaseTestCase):
30 30
31 _autospec_classes = [
32 hnv_agent.neutron_client.NeutronAPIClient,
33 ]
34
31 @mock.patch.object(hnv_agent.HNVAgent, "_setup") 35 @mock.patch.object(hnv_agent.HNVAgent, "_setup")
32 @mock.patch.object(hnv_agent.HNVAgent, "_setup_rpc") 36 @mock.patch.object(hnv_agent.HNVAgent, "_setup_rpc")
33 @mock.patch.object(hnv_agent.HNVAgent, "_set_agent_state") 37 @mock.patch.object(hnv_agent.HNVAgent, "_set_agent_state")
@@ -38,7 +42,7 @@ class TestHNVAgent(test_base.HyperVBaseTestCase):
38 super(TestHNVAgent, self).setUp() 42 super(TestHNVAgent, self).setUp()
39 43
40 self.agent = self._get_agent() 44 self.agent = self._get_agent()
41 self.agent._neutron_client = mock.Mock() 45 self.agent._utils = mock.Mock(autospec=self.agent._utils)
42 46
43 def test_get_agent_configurations(self): 47 def test_get_agent_configurations(self):
44 self.config(logical_network=mock.sentinel.logical_network, 48 self.config(logical_network=mock.sentinel.logical_network,
@@ -88,7 +92,8 @@ class TestHNVAgent(test_base.HyperVBaseTestCase):
88 mock_super_port_bound.assert_called_once_with( 92 mock_super_port_bound.assert_called_once_with(
89 mock.sentinel.port_id, mock.sentinel.network_id, 93 mock.sentinel.port_id, mock.sentinel.network_id,
90 mock.sentinel.network_type, mock.sentinel.physical_network, 94 mock.sentinel.network_type, mock.sentinel.physical_network,
91 mock.sentinel.segmentation_id, mock.sentinel.set_port_sriov) 95 mock.sentinel.segmentation_id, mock.sentinel.port_security_enabled,
96 mock.sentinel.set_port_sriov)
92 mock_neutron_client = self.agent._neutron_client 97 mock_neutron_client = self.agent._neutron_client
93 mock_neutron_client.get_port_profile_id.assert_called_once_with( 98 mock_neutron_client.get_port_profile_id.assert_called_once_with(
94 mock.sentinel.port_id) 99 mock.sentinel.port_id)
diff --git a/networking_hyperv/tests/unit/neutron/agent/test_hyperv_neutron_agent.py b/networking_hyperv/tests/unit/neutron/agent/test_hyperv_neutron_agent.py
index f28e3c9..c00c00d 100644
--- a/networking_hyperv/tests/unit/neutron/agent/test_hyperv_neutron_agent.py
+++ b/networking_hyperv/tests/unit/neutron/agent/test_hyperv_neutron_agent.py
@@ -22,6 +22,8 @@ import sys
22 22
23import ddt 23import ddt
24import mock 24import mock
25from neutron.agent import rpc as agent_rpc
26from neutron.common import rpc as n_rpc
25from neutron.common import topics 27from neutron.common import topics
26from os_win import exceptions 28from os_win import exceptions
27 29
@@ -69,18 +71,22 @@ class TestHyperVNeutronAgent(base.HyperVBaseTestCase):
69 super(TestHyperVNeutronAgent, self).setUp() 71 super(TestHyperVNeutronAgent, self).setUp()
70 self.agent = self._get_agent() 72 self.agent = self._get_agent()
71 73
72 self.agent._qos_ext = mock.MagicMock() 74 self.agent._utils = mock.MagicMock(autospec=self.agent._utils)
73 self.agent._plugin_rpc = mock.Mock() 75 self.agent._metricsutils = mock.MagicMock(
74 self.agent._metricsutils = mock.MagicMock() 76 autospec=self.agent._metricsutils)
75 self.agent._utils = mock.MagicMock() 77 self.agent._nvgre_ops = mock.MagicMock(
76 self.agent._sec_groups_agent = mock.MagicMock() 78 autospec=hyperv_agent.nvgre_ops.HyperVNvgreOps)
77 self.agent._context = mock.Mock() 79
78 self.agent._client = mock.MagicMock() 80 self.agent._sec_groups_agent = mock.MagicMock(
79 self.agent._connection = mock.MagicMock() 81 autospec=hyperv_agent.HyperVSecurityAgent)
80 self.agent._agent_id = mock.Mock() 82 self.agent._vlan_driver = mock.MagicMock(
81 self.agent._utils = mock.MagicMock() 83 autospec=hyperv_agent.trunk_driver.HyperVTrunkDriver)
82 self.agent._nvgre_ops = mock.MagicMock() 84 self.agent._qos_ext = mock.MagicMock(
83 self.agent._vlan_driver = mock.MagicMock() 85 autospec=hyperv_agent.qos_extension.QosAgentExtension)
86
87 self.agent._plugin_rpc = mock.MagicMock(autospec=agent_rpc.PluginApi)
88 self.agent._client = mock.MagicMock(autospec=n_rpc.BackingOffClient)
89 self.agent._connection = mock.MagicMock(autospec=n_rpc.Connection)
84 self.agent._refresh_cache = False 90 self.agent._refresh_cache = False
85 self.agent._added_ports = set() 91 self.agent._added_ports = set()
86 92
diff --git a/networking_hyperv/tests/unit/neutron/agent/test_layer2.py b/networking_hyperv/tests/unit/neutron/agent/test_layer2.py
index 687d602..4c9f5e5 100644
--- a/networking_hyperv/tests/unit/neutron/agent/test_layer2.py
+++ b/networking_hyperv/tests/unit/neutron/agent/test_layer2.py
@@ -66,21 +66,16 @@ class TestLayer2Agent(test_base.HyperVBaseTestCase):
66 66
67 self._agent = self._get_agent() 67 self._agent = self._get_agent()
68 68
69 self._agent._qos_ext = mock.MagicMock() 69 self._agent._utils = mock.MagicMock(
70 self._agent._plugin_rpc = mock.Mock() 70 autospec=self._agent._utils)
71 self._agent._metricsutils = mock.MagicMock() 71 self._agent._plugin_rpc = mock.Mock(
72 self._agent._utils = mock.MagicMock() 72 autospec=agent_base.agent_rpc.PluginApi)
73 self._agent._context = mock.Mock()
74 self._agent._client = mock.MagicMock()
75 self._agent._connection = mock.MagicMock()
76 self._agent._agent_id = mock.Mock()
77 self._agent._utils = mock.MagicMock()
78 self._agent._nvgre_ops = mock.MagicMock()
79 self._agent._vlan_driver = mock.MagicMock()
80 self._agent._physical_network_mappings = collections.OrderedDict()
81 self._agent._config = mock.MagicMock()
82 self._agent._endpoints = mock.MagicMock() 73 self._agent._endpoints = mock.MagicMock()
83 self._agent._event_callback_pairs = mock.MagicMock() 74 self._agent._client = mock.MagicMock(
75 autospec=agent_base.n_rpc.BackingOffClient)
76 self._agent._connection = mock.MagicMock(
77 autospec=agent_base.n_rpc.Connection)
78 self._agent._physical_network_mappings = collections.OrderedDict()
84 self._agent._network_vswitch_map = {} 79 self._agent._network_vswitch_map = {}
85 80
86 def _get_fake_port_details(self): 81 def _get_fake_port_details(self):
diff --git a/networking_hyperv/tests/unit/neutron/qos/test_qos_driver.py b/networking_hyperv/tests/unit/neutron/qos/test_qos_driver.py
index b698f25..33c1027 100644
--- a/networking_hyperv/tests/unit/neutron/qos/test_qos_driver.py
+++ b/networking_hyperv/tests/unit/neutron/qos/test_qos_driver.py
@@ -30,7 +30,8 @@ class TestQosHyperVAgentDriver(base.BaseTestCase):
30 def setUp(self): 30 def setUp(self):
31 super(TestQosHyperVAgentDriver, self).setUp() 31 super(TestQosHyperVAgentDriver, self).setUp()
32 self.driver = qos_driver.QosHyperVAgentDriver() 32 self.driver = qos_driver.QosHyperVAgentDriver()
33 self.driver._utils = mock.Mock() 33 self.driver.initialize()
34 self.driver._utils = mock.Mock(autospec=self.driver._utils)
34 35
35 @mock.patch.object(qos_driver, 'networkutils') 36 @mock.patch.object(qos_driver, 'networkutils')
36 def test_initialize(self, mock_networkutils): 37 def test_initialize(self, mock_networkutils):
diff --git a/networking_hyperv/tests/unit/neutron/test_neutron_client.py b/networking_hyperv/tests/unit/neutron/test_neutron_client.py
index 57f98a4..4cdb5a1 100644
--- a/networking_hyperv/tests/unit/neutron/test_neutron_client.py
+++ b/networking_hyperv/tests/unit/neutron/test_neutron_client.py
@@ -29,6 +29,10 @@ CONF = config.CONF
29 29
30class TestNeutronClient(base.BaseTestCase): 30class TestNeutronClient(base.BaseTestCase):
31 31
32 _autospec_classes = [
33 neutron_client.clientv20.Client,
34 ]
35
32 _FAKE_CIDR = '10.0.0.0/24' 36 _FAKE_CIDR = '10.0.0.0/24'
33 _FAKE_GATEWAY = '10.0.0.1' 37 _FAKE_GATEWAY = '10.0.0.1'
34 _FAKE_HOST = 'fake_host' 38 _FAKE_HOST = 'fake_host'
@@ -36,7 +40,6 @@ class TestNeutronClient(base.BaseTestCase):
36 def setUp(self): 40 def setUp(self):
37 super(TestNeutronClient, self).setUp() 41 super(TestNeutronClient, self).setUp()
38 self._neutron = neutron_client.NeutronAPIClient() 42 self._neutron = neutron_client.NeutronAPIClient()
39 self._neutron._client = mock.MagicMock()
40 43
41 @mock.patch.object(neutron_client.clientv20, "Client") 44 @mock.patch.object(neutron_client.clientv20, "Client")
42 @mock.patch.object(neutron_client, "ks_loading") 45 @mock.patch.object(neutron_client, "ks_loading")
diff --git a/networking_hyperv/tests/unit/neutron/test_nvgre_ops.py b/networking_hyperv/tests/unit/neutron/test_nvgre_ops.py
index 2348f29..28dbc37 100644
--- a/networking_hyperv/tests/unit/neutron/test_nvgre_ops.py
+++ b/networking_hyperv/tests/unit/neutron/test_nvgre_ops.py
@@ -29,6 +29,10 @@ CONF = config.CONF
29 29
30class TestHyperVNvgreOps(base.HyperVBaseTestCase): 30class TestHyperVNvgreOps(base.HyperVBaseTestCase):
31 31
32 _autospec_classes = [
33 nvgre_ops.neutron_client.NeutronAPIClient,
34 ]
35
32 FAKE_MAC_ADDR = 'fa:ke:ma:ca:dd:re:ss' 36 FAKE_MAC_ADDR = 'fa:ke:ma:ca:dd:re:ss'
33 FAKE_CIDR = '10.0.0.0/24' 37 FAKE_CIDR = '10.0.0.0/24'
34 FAKE_VSWITCH_NAME = 'fake_vswitch' 38 FAKE_VSWITCH_NAME = 'fake_vswitch'
@@ -41,11 +45,11 @@ class TestHyperVNvgreOps(base.HyperVBaseTestCase):
41 self.ops._vswitch_ips[mock.sentinel.network_name] = ( 45 self.ops._vswitch_ips[mock.sentinel.network_name] = (
42 mock.sentinel.ip_addr) 46 mock.sentinel.ip_addr)
43 self.ops.context = self.context 47 self.ops.context = self.context
44 self.ops._notifier = mock.MagicMock() 48 self.ops._notifier = mock.MagicMock(
45 self.ops._hyperv_utils = mock.MagicMock() 49 autospec=nvgre_ops.hyperv_agent_notifier.AgentNotifierApi)
46 self.ops._nvgre_utils = mock.MagicMock() 50 self.ops._hyperv_utils = mock.MagicMock(
47 self.ops._n_client = mock.MagicMock() 51 autospec=self.ops._hyperv_utils)
48 self.ops._db = mock.MagicMock() 52 self.ops._nvgre_utils = mock.MagicMock(autospec=self.ops._nvgre_utils)
49 53
50 @mock.patch.object(nvgre_ops.hyperv_agent_notifier, 'AgentNotifierApi') 54 @mock.patch.object(nvgre_ops.hyperv_agent_notifier, 'AgentNotifierApi')
51 def test_init_notifier(self, mock_notifier): 55 def test_init_notifier(self, mock_notifier):
@@ -227,6 +231,7 @@ class TestHyperVNvgreOps(base.HyperVBaseTestCase):
227 231
228 @mock.patch.object(nvgre_ops.HyperVNvgreOps, '_register_lookup_record') 232 @mock.patch.object(nvgre_ops.HyperVNvgreOps, '_register_lookup_record')
229 def test_refresh_nvgre_records(self, mock_register_record): 233 def test_refresh_nvgre_records(self, mock_register_record):
234 self.ops._n_client.get_tunneling_agents.return_value = {}
230 self.ops._nvgre_ports.append(mock.sentinel.processed_port_id) 235 self.ops._nvgre_ports.append(mock.sentinel.processed_port_id)
231 self.ops._tunneling_agents[mock.sentinel.host_id] = ( 236 self.ops._tunneling_agents[mock.sentinel.host_id] = (
232 mock.sentinel.agent_ip) 237 mock.sentinel.agent_ip)
@@ -262,6 +267,7 @@ class TestHyperVNvgreOps(base.HyperVBaseTestCase):
262 267
263 @mock.patch.object(nvgre_ops.HyperVNvgreOps, '_register_lookup_record') 268 @mock.patch.object(nvgre_ops.HyperVNvgreOps, '_register_lookup_record')
264 def test_refresh_nvgre_records_exception(self, mock_register_record): 269 def test_refresh_nvgre_records_exception(self, mock_register_record):
270 self.ops._n_client.get_tunneling_agents.return_value = {}
265 self.ops._tunneling_agents[mock.sentinel.host_id] = ( 271 self.ops._tunneling_agents[mock.sentinel.host_id] = (
266 mock.sentinel.agent_ip) 272 mock.sentinel.agent_ip)
267 self.ops._network_vsids[mock.sentinel.net_id] = (mock.sentinel.vsid) 273 self.ops._network_vsids[mock.sentinel.net_id] = (mock.sentinel.vsid)
diff --git a/networking_hyperv/tests/unit/neutron/test_security_groups_driver.py b/networking_hyperv/tests/unit/neutron/test_security_groups_driver.py
index 954f04d..dee4527 100644
--- a/networking_hyperv/tests/unit/neutron/test_security_groups_driver.py
+++ b/networking_hyperv/tests/unit/neutron/test_security_groups_driver.py
@@ -60,6 +60,10 @@ class SecurityGroupRuleTestHelper(base.HyperVBaseTestCase):
60 60
61class TestHyperVSecurityGroupsDriver(SecurityGroupRuleTestHelper): 61class TestHyperVSecurityGroupsDriver(SecurityGroupRuleTestHelper):
62 62
63 _autospec_classes = [
64 sg_driver.SecurityGroupRuleGeneratorR2,
65 ]
66
63 _FAKE_DEVICE = 'fake_device' 67 _FAKE_DEVICE = 'fake_device'
64 _FAKE_ID = 'fake_id' 68 _FAKE_ID = 'fake_id'
65 _FAKE_PARAM_NAME = 'fake_param_name' 69 _FAKE_PARAM_NAME = 'fake_param_name'
@@ -69,8 +73,7 @@ class TestHyperVSecurityGroupsDriver(SecurityGroupRuleTestHelper):
69 super(TestHyperVSecurityGroupsDriver, self).setUp() 73 super(TestHyperVSecurityGroupsDriver, self).setUp()
70 74
71 self._driver = sg_driver.HyperVSecurityGroupsDriver() 75 self._driver = sg_driver.HyperVSecurityGroupsDriver()
72 self._driver._utils = mock.MagicMock() 76 self._driver._utils = mock.MagicMock(autospec=self._driver._utils)
73 self._driver._sg_gen = mock.MagicMock()
74 77
75 def test__select_sg_rules_for_port(self): 78 def test__select_sg_rules_for_port(self):
76 mock_port = self._get_port() 79 mock_port = self._get_port()
@@ -194,6 +197,7 @@ class TestHyperVSecurityGroupsDriver(SecurityGroupRuleTestHelper):
194 return_value=self._FAKE_SOURCE_IP_PREFIX) 197 return_value=self._FAKE_SOURCE_IP_PREFIX)
195 198
196 mock_gen_rules.return_value = {new_mock_port['id']: [fake_rule_new]} 199 mock_gen_rules.return_value = {new_mock_port['id']: [fake_rule_new]}
200 self._driver._sg_gen.expand_wildcard_rules.return_value = []
197 201
198 self._driver._security_ports[mock_port['device']] = mock_port 202 self._driver._security_ports[mock_port['device']] = mock_port
199 self._driver._sec_group_rules[new_mock_port['id']] = [] 203 self._driver._sec_group_rules[new_mock_port['id']] = []
diff --git a/networking_hyperv/tests/unit/neutron/test_trunk_driver.py b/networking_hyperv/tests/unit/neutron/test_trunk_driver.py
index 55e7ae7..6c19a82 100644
--- a/networking_hyperv/tests/unit/neutron/test_trunk_driver.py
+++ b/networking_hyperv/tests/unit/neutron/test_trunk_driver.py
@@ -31,8 +31,10 @@ from networking_hyperv.tests import base
31 31
32class TestHyperVTrunkDriver(base.HyperVBaseTestCase): 32class TestHyperVTrunkDriver(base.HyperVBaseTestCase):
33 33
34 @mock.patch.object(trunk_driver.trunk_rpc, 'TrunkStub', 34 _autospec_classes = [
35 lambda *args, **kwargs: None) 35 trunk_driver.trunk_rpc.TrunkStub,
36 ]
37
36 @mock.patch.object(trunk_driver.trunk_rpc.TrunkSkeleton, '__init__', 38 @mock.patch.object(trunk_driver.trunk_rpc.TrunkSkeleton, '__init__',
37 lambda *args, **kwargs: None) 39 lambda *args, **kwargs: None)
38 def setUp(self): 40 def setUp(self):
@@ -40,8 +42,8 @@ class TestHyperVTrunkDriver(base.HyperVBaseTestCase):
40 42
41 self.trunk_driver = trunk_driver.HyperVTrunkDriver( 43 self.trunk_driver = trunk_driver.HyperVTrunkDriver(
42 mock.sentinel.context) 44 mock.sentinel.context)
43 self.trunk_driver._utils = mock.MagicMock() 45 self.trunk_driver._utils = mock.MagicMock(
44 self.trunk_driver._trunk_rpc = mock.MagicMock() 46 autospec=self.trunk_driver._utils)
45 47
46 def test_handle_trunks_deleted(self): 48 def test_handle_trunks_deleted(self):
47 mock_trunk = mock.MagicMock() 49 mock_trunk = mock.MagicMock()