def test_create_synchronized_decorator(self, mock_sync_with_prefix): fake_method_side_effect = mock.Mock() lock_prefix = 'test-' port_synchronized = _common_utils.get_port_synchronized_decorator( lock_prefix) @port_synchronized def fake_method(fake_arg, port_id): fake_method_side_effect(fake_arg, port_id) mock_synchronized = mock_sync_with_prefix.return_value mock_synchronized.return_value = lambda x: x expected_lock_name = 'test-port-lock-%s' % mock.sentinel.port_id fake_method(fake_arg=mock.sentinel.arg, port_id=mock.sentinel.port_id) mock_sync_with_prefix.assert_called_once_with(lock_prefix) mock_synchronized.assert_called_once_with(expected_lock_name) fake_method_side_effect.assert_called_once_with( mock.sentinel.arg, mock.sentinel.port_id)
from oslo_log import log as logging import oslo_messaging from networking_hyperv.common.i18n import _, _LI, _LW, _LE # noqa from networking_hyperv.neutron import _common_utils as c_util from networking_hyperv.neutron.agent import layer2 as hyperv_base from networking_hyperv.neutron import config from networking_hyperv.neutron import constants as h_constant from networking_hyperv.neutron import exception from networking_hyperv.neutron import nvgre_ops from networking_hyperv.neutron import trunk_driver CONF = config.CONF LOG = logging.getLogger(__name__) _port_synchronized = c_util.get_port_synchronized_decorator('n-hv-agent-') class HyperVSecurityAgent(sg_agent_rpc.SecurityGroupAgentRpc): def __init__(self, context, plugin_rpc): super(HyperVSecurityAgent, self).__init__(context, plugin_rpc) if sg_agent_rpc.is_firewall_enabled(): self._setup_rpc() @property def use_enhanced_rpc(self): return True def _setup_rpc(self): self.topic = topics.AGENT
'icmp': networkutils.NetworkUtils._ICMP_PROTOCOL, 'ipv6-icmp': networkutils.NetworkUtils._ICMPV6_PROTOCOL, 'icmpv6': networkutils.NetworkUtils._ICMPV6_PROTOCOL }, 'action': { 'allow': networkutils.NetworkUtils._ACL_ACTION_ALLOW, 'deny': networkutils.NetworkUtils._ACL_ACTION_DENY }, 'default': "ANY", 'address_default': { 'IPv4': '0.0.0.0/0', 'IPv6': '::/0' } } _ports_synchronized = c_utils.get_port_synchronized_decorator('n-hv-driver-') class HyperVSecurityGroupsDriverMixin(object): """Security Groups Driver. Security Groups implementation for Hyper-V VMs. """ def __init__(self): self._utils = utilsfactory.get_networkutils() self._sg_gen = SecurityGroupRuleGeneratorR2() self._sec_group_rules = {} self._security_ports = {} self._sg_members = {} self._sg_rule_templates = {} self.cache_lock = threading.Lock()