def _test_ovs_api(self, rpcapi, topic, method, rpc_method, **kwargs): ctxt = context.RequestContext('fake_user', 'fake_project') expected_retval = 'foo' if method == 'call' else None expected_msg = rpcapi.make_msg(method, **kwargs) expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION if rpc_method == 'cast' and method == 'run_instance': kwargs['call'] = False self.fake_args = None self.fake_kwargs = None def _fake_rpc_method(*args, **kwargs): self.fake_args = args self.fake_kwargs = kwargs if expected_retval: return expected_retval self.stubs = stubout.StubOutForTesting() self.stubs.Set(rpc, rpc_method, _fake_rpc_method) retval = getattr(rpcapi, method)(ctxt, **kwargs) self.assertEqual(retval, expected_retval) expected_args = [ctxt, topic, expected_msg] for arg, expected_arg in zip(self.fake_args, expected_args): self.assertEqual(arg, expected_arg)
def setup_rpc(self, physical_interfaces): if physical_interfaces: mac = utils.get_interface_mac(physical_interfaces[0]) else: devices = ip_lib.IPWrapper(self.root_helper).get_devices(True) if devices: mac = utils.get_interface_mac(devices[0].name) else: LOG.error("Unable to obtain MAC address for unique ID. " "Agent terminated!") exit(1) self.agent_id = '%s%s' % ('lb', (mac.replace(":", ""))) LOG.info("RPC agent_id: %s" % self.agent_id) self.topic = topics.AGENT self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN) # RPC network init self.context = context.RequestContext('quantum', 'quantum', is_admin=False) # Handle updates from service self.callbacks = LinuxBridgeRpcCallbacks(self.context, self.linux_br) self.dispatcher = self.callbacks.create_rpc_dispatcher() # Define the listening consumers for the agent consumers = [[topics.PORT, topics.UPDATE], [topics.NETWORK, topics.DELETE]] self.connection = agent_rpc.create_consumers(self.dispatcher, self.topic, consumers) self.udev = pyudev.Context() monitor = pyudev.Monitor.from_netlink(self.udev) monitor.filter_by('net')
def __init__(self, conf): self.conf = conf self.cache = NetworkCache() self.dhcp_driver_cls = importutils.import_class(conf.dhcp_driver) ctx = context.RequestContext('quantum', 'quantum', is_admin=True) self.plugin_rpc = DhcpPluginApi(topics.PLUGIN, ctx) self.device_manager = DeviceManager(self.conf, self.plugin_rpc) self.notifications = agent_rpc.NotificationDispatcher() self.lease_relay = DhcpLeaseRelay(self.update_lease)
def setup_rpc(self): # RPC support for dhcp self.topic = topics.PLUGIN self.rpc_context = context.RequestContext('quantum', 'quantum', is_admin=False) self.conn = rpc.create_connection(new=True) self.callbacks = NVPRpcCallbacks(self.rpc_context) self.dispatcher = self.callbacks.create_rpc_dispatcher() self.conn.create_consumer(self.topic, self.dispatcher, fanout=False) # Consume from all consumers in a thread self.conn.consume_in_thread()
def _test_rpc_call(self, method): agent = rpc.PluginApi('fake_topic') ctxt = context.RequestContext('fake_user', 'fake_project') expect_val = 'foo' with mock.patch('quantum.openstack.common.rpc.call') as rpc_call: rpc_call.return_value = expect_val func_obj = getattr(agent, method) if method == 'tunnel_sync': actual_val = func_obj(ctxt, 'fake_tunnel_ip') else: actual_val = func_obj(ctxt, 'fake_device', 'fake_agent_id') self.assertEqual(actual_val, expect_val)
def setup_rpc(self): # RPC support self.topic = topics.PLUGIN self.rpc_context = context.RequestContext('quantum', 'quantum', is_admin=False) self.conn = rpc.create_connection(new=True) self.notifier = AgentNotifierApi(topics.AGENT) self.callbacks = OVSRpcCallbacks(self.rpc_context, self.notifier) self.dispatcher = self.callbacks.create_rpc_dispatcher() self.conn.create_consumer(self.topic, self.dispatcher, fanout=False) # Consume from all consumers in a thread self.conn.consume_in_thread()
def test_plugin_report_state(self): topic = 'test' reportStateAPI = rpc.PluginReportStateAPI(topic) expected_agent_state = {'agent': 'test'} with mock.patch.object(reportStateAPI, 'call') as call: ctxt = context.RequestContext('fake_user', 'fake_project') reportStateAPI.report_state(ctxt, expected_agent_state) self.assertEqual(call.call_args[0][0], ctxt) self.assertEqual(call.call_args[0][1]['method'], 'report_state') self.assertEqual(call.call_args[0][1]['args']['agent_state'], {'agent_state': expected_agent_state}) self.assertIsInstance(call.call_args[0][1]['args']['time'], str) self.assertEqual(call.call_args[1]['topic'], topic)
def _setup_rpc(self): # RPC support self.topic = topics.PLUGIN self.rpc_context = context.RequestContext('quantum', 'quantum', is_admin=False) self.conn = rpc.create_connection(new=True) self.callbacks = BridgeRpcCallbacks() self.dispatcher = self.callbacks.create_rpc_dispatcher() self.conn.create_consumer(self.topic, self.dispatcher, fanout=False) # Consume from all consumers in a thread self.conn.consume_in_thread() self.notifier = AgentNotifierApi(topics.AGENT) self.dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI() self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify
def __init__(self): LOG.info('QuantumRestProxy: Starting plugin. Version=%s' % version_string_with_vcs()) # init DB, proxy's persistent store defaults to in-memory sql-lite DB options = { "sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection, "sql_max_retries": cfg.CONF.DATABASE.sql_max_retries, "reconnect_interval": cfg.CONF.DATABASE.reconnect_interval, "base": models_v2.model_base.BASEV2 } db.configure_db(options) # 'servers' is the list of network controller REST end-points # (used in order specified till one suceeds, and it is sticky # till next failure). Use 'serverauth' to encode api-key servers = cfg.CONF.RESTPROXY.servers serverauth = cfg.CONF.RESTPROXY.serverauth serverssl = cfg.CONF.RESTPROXY.serverssl syncdata = cfg.CONF.RESTPROXY.syncdata timeout = cfg.CONF.RESTPROXY.servertimeout # validate config assert servers is not None, 'Servers not defined. Aborting plugin' servers = tuple(s.rsplit(':', 1) for s in servers.split(',')) servers = tuple((server, int(port)) for server, port in servers) assert all(len(s) == 2 for s in servers), SYNTAX_ERROR_MESSAGE # init network ctrl connections self.servers = ServerPool(servers, serverssl, serverauth, timeout) # init dhcp support self.topic = topics.PLUGIN self.rpc_context = glbcontext.RequestContext('quantum', 'quantum', is_admin=False) self.conn = rpc.create_connection(new=True) self.callbacks = RpcProxy(self.rpc_context) self.dispatcher = self.callbacks.create_rpc_dispatcher() self.conn.create_consumer(self.topic, self.dispatcher, fanout=False) # Consume from all consumers in a thread self.conn.consume_in_thread() if syncdata: self._send_all_data() LOG.debug("QuantumRestProxyV2: initialization done")
def setup_rpc(self, integ_br): mac = utils.get_interface_mac(integ_br) self.agent_id = '%s%s' % ('ovs', (mac.replace(":", ""))) self.topic = topics.AGENT self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN) # RPC network init self.context = context.RequestContext('quantum', 'quantum', is_admin=False) # Handle updates from service self.dispatcher = self.create_rpc_dispatcher() # Define the listening consumers for the agent consumers = [[topics.PORT, topics.UPDATE], [topics.NETWORK, topics.DELETE], [constants.TUNNEL, topics.UPDATE]] self.connection = agent_rpc.create_consumers(self.dispatcher, self.topic, consumers)
def __init__(self, integ_br, root_helper, polling_interval): '''Constructor. :param integ_br: name of the integration bridge. :param root_helper: utility to use when running shell cmds. :param polling_interval: interval (secs) to check the bridge. ''' self.int_br = ovs_lib.OVSBridge(integ_br, root_helper) self.polling_interval = polling_interval self.host = socket.gethostname() self.agent_id = 'nec-q-agent.%s' % self.host self.datapath_id = "0x%s" % self.int_br.get_datapath_id() # RPC network init self.context = context.RequestContext('quantum', 'quantum', is_admin=False) self.conn = rpc.create_connection(new=True)
def _test_rpc_api(self, rpcapi, topic, method, rpc_method, **kwargs): ctxt = context.RequestContext('fake_user', 'fake_project') expected_retval = 'foo' if method == 'call' else None expected_msg = rpcapi.make_msg(method, **kwargs) expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION if rpc_method == 'cast' and method == 'run_instance': kwargs['call'] = False rpc_method_mock = mock.Mock() rpc_method_mock.return_value = expected_retval setattr(rpc, rpc_method, rpc_method_mock) retval = getattr(rpcapi, method)(ctxt, **kwargs) self.assertEqual(retval, expected_retval) expected_args = [ctxt, topic, expected_msg] for arg, expected_arg in zip(rpc_method_mock.call_args[0], expected_args): self.assertEqual(arg, expected_arg)
def setup_rpc(self, physical_interfaces): # REVISIT try until one succeeds? mac = utils.get_interface_mac(physical_interfaces[0]) self.agent_id = '%s%s' % ('lb', (mac.replace(":", ""))) self.topic = topics.AGENT self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN) # RPC network init self.context = context.RequestContext('quantum', 'quantum', is_admin=False) # Handle updates from service self.callbacks = LinuxBridgeRpcCallbacks(self.context, self.linux_br) self.dispatcher = self.callbacks.create_rpc_dispatcher() # Define the listening consumers for the agent consumers = [[topics.PORT, topics.UPDATE], [topics.NETWORK, topics.DELETE]] self.connection = agent_rpc.create_consumers(self.dispatcher, self.topic, consumers) self.udev = pyudev.Context() monitor = pyudev.Monitor.from_netlink(self.udev) monitor.filter_by('net')