Adds Hyper-V utils methods
Adds Hyper-V utils methods which will be used in the next commit.
(cherry picked from commit c823016d31
)
Partial-Bug: #1263766
Change-Id: I7556001557cd013c10b7f883dbf371afa8d09626
This commit is contained in:
parent
8520e7b629
commit
d57ce79c95
|
@ -74,6 +74,12 @@ class HyperVUtilsV2(utils.HyperVUtils):
|
|||
ResourceSettings=[res_setting_data.path_()])
|
||||
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(
|
||||
self, vswitch_name, switch_port_name, delete_port):
|
||||
"""Disconnects the switch port."""
|
||||
|
@ -190,3 +196,18 @@ class HyperVUtilsV2(utils.HyperVUtils):
|
|||
acl.Action = self._ACL_ACTION_METER
|
||||
acl.Applicability = self._ACL_APPLICABILITY_LOCAL
|
||||
self._add_virt_feature(port, acl)
|
||||
|
||||
def _create_acl(self, direction, acl_type, action):
|
||||
acl = self._get_default_setting_data(self._PORT_ALLOC_ACL_SET_DATA)
|
||||
acl.set(Direction=direction,
|
||||
AclType=acl_type,
|
||||
Action=action,
|
||||
Applicability=self._ACL_APPLICABILITY_LOCAL)
|
||||
return acl
|
||||
|
||||
def _filter_acls(self, acls, action, direction, acl_type, remote_addr=""):
|
||||
return [v for v in acls
|
||||
if v.Action == action and
|
||||
v.Direction == direction and
|
||||
v.AclType == acl_type and
|
||||
v.RemoteAddress == remote_addr]
|
||||
|
|
|
@ -41,6 +41,11 @@ class TestHyperVUtilsV2(base.BaseTestCase):
|
|||
_FAKE_CLASS_NAME = "fake_class_name"
|
||||
_FAKE_ELEMENT_NAME = "fake_element_name"
|
||||
|
||||
_FAKE_ACL_ACT = 'fake_acl_action'
|
||||
_FAKE_ACL_DIR = 'fake_acl_dir'
|
||||
_FAKE_ACL_TYPE = 'fake_acl_type'
|
||||
_FAKE_REMOTE_ADDR = '0.0.0.0/0'
|
||||
|
||||
def setUp(self):
|
||||
super(TestHyperVUtilsV2, self).setUp()
|
||||
self._utils = utilsv2.HyperVUtilsV2()
|
||||
|
@ -228,3 +233,21 @@ class TestHyperVUtilsV2(base.BaseTestCase):
|
|||
|
||||
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()
|
||||
mock_acl.Action = self._FAKE_ACL_ACT
|
||||
mock_acl.Applicability = self._utils._ACL_APPLICABILITY_LOCAL
|
||||
mock_acl.Direction = self._FAKE_ACL_DIR
|
||||
mock_acl.AclType = self._FAKE_ACL_TYPE
|
||||
mock_acl.RemoteAddress = self._FAKE_REMOTE_ADDR
|
||||
|
||||
acls = [mock_acl, mock_acl]
|
||||
good_acls = self._utils._filter_acls(
|
||||
acls, self._FAKE_ACL_ACT, self._FAKE_ACL_DIR,
|
||||
self._FAKE_ACL_TYPE, self._FAKE_REMOTE_ADDR)
|
||||
bad_acls = self._utils._filter_acls(
|
||||
acls, self._FAKE_ACL_ACT, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE)
|
||||
|
||||
self.assertEqual(acls, good_acls)
|
||||
self.assertEqual([], bad_acls)
|
||||
|
|
Loading…
Reference in New Issue