Merge "Fixes Hyper-V agent security groups enable issue"
This commit is contained in:
@@ -419,11 +419,12 @@ class HyperVUtilsV2R2(HyperVUtilsV2):
|
|||||||
return [v for v in acls
|
return [v for v in acls
|
||||||
if v.Action == action and
|
if v.Action == action and
|
||||||
v.Direction == direction and
|
v.Direction == direction and
|
||||||
v.LocalPort in [str(local_port), self._ACL_DEFAULT] and
|
v.LocalPort == str(local_port) and
|
||||||
v.Protocol in [protocol] and
|
v.Protocol == protocol and
|
||||||
v.RemoteIPAddress == remote_addr]
|
v.RemoteIPAddress == remote_addr]
|
||||||
|
|
||||||
def _get_new_weight(self, acls):
|
def _get_new_weight(self, acls):
|
||||||
|
acls = [a for a in acls if a.Action is not self._ACL_ACTION_DENY]
|
||||||
if not acls:
|
if not acls:
|
||||||
return self._MAX_WEIGHT - 1
|
return self._MAX_WEIGHT - 1
|
||||||
|
|
||||||
|
|||||||
@@ -449,14 +449,19 @@ class TestHyperVUtilsV2R2(base.BaseTestCase):
|
|||||||
default, default, self._FAKE_REMOTE_ADDR)
|
default, default, self._FAKE_REMOTE_ADDR)
|
||||||
|
|
||||||
def _test_filter_security_acls(self, local_port, protocol, remote_addr):
|
def _test_filter_security_acls(self, local_port, protocol, remote_addr):
|
||||||
mock_acl = mock.MagicMock()
|
acls = []
|
||||||
mock_acl.Action = self._utils._ACL_ACTION_ALLOW
|
default = self._utils._ACL_DEFAULT
|
||||||
mock_acl.Direction = self._FAKE_ACL_DIR
|
for port, proto in [(default, default), (local_port, protocol)]:
|
||||||
mock_acl.LocalPort = local_port
|
mock_acl = mock.MagicMock()
|
||||||
mock_acl.Protocol = protocol
|
mock_acl.Action = self._utils._ACL_ACTION_ALLOW
|
||||||
mock_acl.RemoteIPAddress = remote_addr
|
mock_acl.Direction = self._FAKE_ACL_DIR
|
||||||
|
mock_acl.LocalPort = port
|
||||||
|
mock_acl.Protocol = proto
|
||||||
|
mock_acl.RemoteIPAddress = remote_addr
|
||||||
|
acls.append(mock_acl)
|
||||||
|
|
||||||
|
right_acls = [a for a in acls if a.LocalPort == local_port]
|
||||||
|
|
||||||
acls = [mock_acl, mock_acl]
|
|
||||||
good_acls = self._utils._filter_security_acls(
|
good_acls = self._utils._filter_security_acls(
|
||||||
acls, mock_acl.Action, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE,
|
acls, mock_acl.Action, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE,
|
||||||
local_port, protocol, remote_addr)
|
local_port, protocol, remote_addr)
|
||||||
@@ -464,7 +469,7 @@ class TestHyperVUtilsV2R2(base.BaseTestCase):
|
|||||||
acls, self._FAKE_ACL_ACT, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE,
|
acls, self._FAKE_ACL_ACT, self._FAKE_ACL_DIR, self._FAKE_ACL_TYPE,
|
||||||
local_port, protocol, remote_addr)
|
local_port, protocol, remote_addr)
|
||||||
|
|
||||||
self.assertEqual(acls, good_acls)
|
self.assertEqual(right_acls, good_acls)
|
||||||
self.assertEqual([], bad_acls)
|
self.assertEqual([], bad_acls)
|
||||||
|
|
||||||
def test_get_new_weight(self):
|
def test_get_new_weight(self):
|
||||||
@@ -478,3 +483,13 @@ class TestHyperVUtilsV2R2(base.BaseTestCase):
|
|||||||
def test_get_new_weight_no_acls(self):
|
def test_get_new_weight_no_acls(self):
|
||||||
self.assertEqual(self._utils._MAX_WEIGHT - 1,
|
self.assertEqual(self._utils._MAX_WEIGHT - 1,
|
||||||
self._utils._get_new_weight([]))
|
self._utils._get_new_weight([]))
|
||||||
|
|
||||||
|
def test_get_new_weight_default_acls(self):
|
||||||
|
mockacl1 = mock.MagicMock()
|
||||||
|
mockacl1.Weight = self._utils._MAX_WEIGHT - 1
|
||||||
|
mockacl2 = mock.MagicMock()
|
||||||
|
mockacl2.Weight = self._utils._MAX_WEIGHT - 2
|
||||||
|
mockacl2.Action = self._utils._ACL_ACTION_DENY
|
||||||
|
|
||||||
|
self.assertEqual(self._utils._MAX_WEIGHT - 2,
|
||||||
|
self._utils._get_new_weight([mockacl1, mockacl2]))
|
||||||
|
|||||||
Reference in New Issue
Block a user