Merge "Fixes missing method in Hyper-V Utils (Metering)"

This commit is contained in:
Jenkins 2013-12-22 21:09:38 +00:00 committed by Gerrit Code Review
commit b347f851df
3 changed files with 58 additions and 13 deletions

View File

@ -74,6 +74,12 @@ class HyperVUtilsV2(utils.HyperVUtils):
ResourceSettings=[res_setting_data.path_()]) ResourceSettings=[res_setting_data.path_()])
self._check_job_status(ret_val, job) self._check_job_status(ret_val, job)
def _add_virt_feature(self, element, res_setting_data):
vs_man_svc = self._conn.Msvm_VirtualSystemManagementService()[0]
(job_path, out_set_data, ret_val) = vs_man_svc.AddFeatureSettings(
element.path_(), [res_setting_data.GetText_(1)])
self._check_job_status(ret_val, job_path)
def disconnect_switch_port( def disconnect_switch_port(
self, vswitch_name, switch_port_name, delete_port): self, vswitch_name, switch_port_name, delete_port):
"""Disconnects the switch port.""" """Disconnects the switch port."""

View File

@ -27,6 +27,10 @@ from neutron.plugins.hyperv.agent import hyperv_neutron_agent
from neutron.plugins.hyperv.agent import utilsfactory from neutron.plugins.hyperv.agent import utilsfactory
from neutron.tests import base from neutron.tests import base
cfg.CONF.import_opt('enable_metrics_collection',
'neutron.plugins.hyperv.agent.hyperv_neutron_agent',
'AGENT')
class TestHyperVNeutronAgent(base.BaseTestCase): class TestHyperVNeutronAgent(base.BaseTestCase):
@ -65,15 +69,29 @@ class TestHyperVNeutronAgent(base.BaseTestCase):
'start_flag': True} 'start_flag': True}
self.agent_state = fake_agent_state self.agent_state = fake_agent_state
def test_port_bound(self): def test_port_bound_enable_metrics(self):
port = mock.Mock() 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' net_uuid = 'my-net-uuid'
with mock.patch.object(
self.agent._utils, 'connect_vnic_to_vswitch'): with mock.patch.multiple(
with mock.patch.object( self.agent._utils,
self.agent._utils, 'set_vswitch_port_vlan_id'): 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.agent._port_bound(port, net_uuid, 'vlan', None, None)
self.assertEqual(enable_metrics, mock_enable_metrics.called)
def test_port_unbound(self): def test_port_unbound(self):
map = { map = {
'network_type': 'vlan', 'network_type': 'vlan',

View File

@ -97,6 +97,24 @@ class TestHyperVUtilsV2(base.BaseTestCase):
mock_svc.AddResourceSettings.assert_called_with(self._FAKE_VM_PATH, mock_svc.AddResourceSettings.assert_called_with(self._FAKE_VM_PATH,
[self._FAKE_RES_DATA]) [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): def test_modify_virt_resource(self):
mock_svc = self._utils._conn.Msvm_VirtualSystemManagementService()[0] mock_svc = self._utils._conn.Msvm_VirtualSystemManagementService()[0]
mock_svc.ModifyResourceSettings.return_value = (self._FAKE_JOB_PATH, mock_svc.ModifyResourceSettings.return_value = (self._FAKE_JOB_PATH,
@ -220,11 +238,14 @@ class TestHyperVUtilsV2(base.BaseTestCase):
mock_port, True)) mock_port, True))
mock_acl = mock.MagicMock() mock_acl = mock.MagicMock()
self._utils._get_default_setting_data = mock.MagicMock(
return_value=mock_acl) with mock.patch.multiple(
self._utils._add_virt_feature = mock.MagicMock() self._utils,
_get_default_setting_data=mock.MagicMock(return_value=mock_acl),
_add_virt_feature=mock.MagicMock()):
self._utils.enable_port_metrics_collection(self._FAKE_PORT_NAME) self._utils.enable_port_metrics_collection(self._FAKE_PORT_NAME)
self.assertEqual(4, len(self._utils._add_virt_feature.mock_calls)) 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._add_virt_feature.assert_called_with(
mock_port, mock_acl)