Fixes missing method in Hyper-V Utils (Metering)

This cherry-picked commit is different from the original one because
the missing method was already added and merged into stable/havana
through another bug fix. (https://review.openstack.org/#/c/83222/)

This patch is meant to contain unit tests only.

Closes-Bug: #1252712
(cherry picked from commit 7af673ef1a)

Change-Id: I2beecfd13617fb243008016b810f49db5593fc65
This commit is contained in:
Claudiu Belu 2013-11-19 06:42:19 -08:00
parent f569afd50d
commit f1c271a56c
2 changed files with 52 additions and 13 deletions

View File

@ -27,6 +27,10 @@ from neutron.plugins.hyperv.agent import hyperv_neutron_agent
from neutron.plugins.hyperv.agent import utilsfactory
from neutron.tests import base
cfg.CONF.import_opt('enable_metrics_collection',
'neutron.plugins.hyperv.agent.hyperv_neutron_agent',
'AGENT')
class TestHyperVNeutronAgent(base.BaseTestCase):
@ -67,14 +71,28 @@ class TestHyperVNeutronAgent(base.BaseTestCase):
'start_flag': True}
self.agent_state = fake_agent_state
def test_port_bound(self):
port = mock.Mock()
def test_port_bound_enable_metrics(self):
cfg.CONF.set_override('enable_metrics_collection', True, 'AGENT')
self._test_port_bound(True)
def test_port_bound_no_metrics(self):
cfg.CONF.set_override('enable_metrics_collection', False, 'AGENT')
self._test_port_bound(False)
def _test_port_bound(self, enable_metrics):
port = mock.MagicMock()
mock_enable_metrics = mock.MagicMock()
net_uuid = 'my-net-uuid'
with mock.patch.object(
self.agent._utils, 'connect_vnic_to_vswitch'):
with mock.patch.object(
self.agent._utils, 'set_vswitch_port_vlan_id'):
self.agent._port_bound(port, net_uuid, 'vlan', None, None)
with mock.patch.multiple(
self.agent._utils,
connect_vnic_to_vswitch=mock.MagicMock(),
set_vswitch_port_vlan_id=mock.MagicMock(),
enable_port_metrics_collection=mock_enable_metrics):
self.agent._port_bound(port, net_uuid, 'vlan', None, None)
self.assertEqual(enable_metrics, mock_enable_metrics.called)
def test_port_unbound(self):
map = {

View File

@ -103,6 +103,24 @@ class TestHyperVUtilsV2(base.BaseTestCase):
mock_svc.AddResourceSettings.assert_called_with(self._FAKE_VM_PATH,
[self._FAKE_RES_DATA])
def test_add_virt_feature(self):
mock_svc = self._utils._conn.Msvm_VirtualSystemManagementService()[0]
mock_svc.AddFeatureSettings.return_value = (self._FAKE_JOB_PATH,
mock.MagicMock(),
self._FAKE_RET_VAL)
mock_res_setting_data = mock.MagicMock()
mock_res_setting_data.GetText_.return_value = self._FAKE_RES_DATA
mock_vm = mock.MagicMock()
mock_vm.path_.return_value = self._FAKE_VM_PATH
self._utils._check_job_status = mock.MagicMock()
self._utils._add_virt_feature(mock_vm, mock_res_setting_data)
mock_svc.AddFeatureSettings.assert_called_once_with(
self._FAKE_VM_PATH, [self._FAKE_RES_DATA])
def test_modify_virt_resource(self):
mock_svc = self._utils._conn.Msvm_VirtualSystemManagementService()[0]
mock_svc.ModifyResourceSettings.return_value = (self._FAKE_JOB_PATH,
@ -226,14 +244,17 @@ class TestHyperVUtilsV2(base.BaseTestCase):
mock_port, True))
mock_acl = mock.MagicMock()
self._utils._get_default_setting_data = mock.MagicMock(
return_value=mock_acl)
self._utils._add_virt_feature = mock.MagicMock()
self._utils.enable_port_metrics_collection(self._FAKE_PORT_NAME)
with mock.patch.multiple(
self._utils,
_get_default_setting_data=mock.MagicMock(return_value=mock_acl),
_add_virt_feature=mock.MagicMock()):
self.assertEqual(4, len(self._utils._add_virt_feature.mock_calls))
self._utils._add_virt_feature.assert_called_with(mock_port, mock_acl)
self._utils.enable_port_metrics_collection(self._FAKE_PORT_NAME)
self.assertEqual(4, len(self._utils._add_virt_feature.mock_calls))
self._utils._add_virt_feature.assert_called_with(
mock_port, mock_acl)
def test_filter_acls(self):
mock_acl = mock.MagicMock()