def main(): register_options(cfg.CONF) calico_config.register_options(cfg.CONF) common_config.init(sys.argv[1:]) setup_logging() agent = CalicoDhcpAgent() agent.run()
def main(): register_options(cfg.CONF) calico_config.register_options(cfg.CONF) common_config.init(sys.argv[1:]) setup_logging() agent = CalicoDhcpAgent() agent.run()
def test_must_update(self): # Start a real local etcd server. self.start_etcd_server() # Set up minimal config, so EtcdWatcher will use that etcd. calico_config.register_options(cfg.CONF) # Ensure etcd server is ready. self.wait_etcd_ready() # Try a put with MUST_UPDATE; should fail as does not yet exist. succeeded = etcdv3.put("/testkey", "testvalue", mod_revision=etcdv3.MUST_UPDATE) self.assertFalse(succeeded) # Try a put with mod_revision 0, i.e. must create. succeeded = etcdv3.put("/testkey", "testvalue", mod_revision=0) self.assertTrue(succeeded) # Try again with MUST_UPDATE; should now succeed. succeeded = etcdv3.put("/testkey", "testvalue2", mod_revision=etcdv3.MUST_UPDATE) self.assertTrue(succeeded) # Try again with mod_revision 0; should now fail. succeeded = etcdv3.put("/testkey", "testvalue2", mod_revision=0) self.assertFalse(succeeded) # Kill the etcd server. self.stop_etcd_server()
def setUp(self): super(TestDhcpAgent, self).setUp() register_options(cfg.CONF) calico_config.register_options(cfg.CONF) self.mock_makedirs_p = mock.patch("os.makedirs") self.mock_makedirs = self.mock_makedirs_p.start() self.hostname = socket.gethostname() cfg.CONF.host = self.hostname
def main(): register_options(cfg.CONF) calico_config.register_options(cfg.CONF) common_config.init(sys.argv[1:]) setup_logging() try: # Neutron agent code has been migrating from rootwrap to privsep. # Initialize the privsep system if it is available. config.setup_privsep() except Exception as e: # But don't worry if it isn't; that means we are running with older # Neutron code. LOG.info("Couldn't setup_privsep(): %r", e) agent = CalicoDhcpAgent() agent.run()
def setUp(self): super(TestDhcpAgent, self).setUp() register_options(cfg.CONF) calico_config.register_options(cfg.CONF)
def setUp(self): super(TestDhcpAgent, self).setUp() register_options(cfg.CONF) calico_config.register_options(cfg.CONF) self.mock_makedirs_p = mock.patch("os.makedirs") self.mock_makedirs = self.mock_makedirs_p.start()
LOG = log.getLogger(__name__) # The node hostname is used as the default identity for leader election _hostname = socket.gethostname() # Elector configuration; elector_opt = cfg.StrOpt( 'elector_name', default=_hostname, help="A unique name to identify this node in leader election" ) # Register Calico related configuration options calico_config.register_options(cfg.CONF, additional_options=[elector_opt]) ETCD_DELETE_ACTIONS = set(["delete", "expire", "compareAndDelete"]) class RestartElection(Exception): """Exception indicating that we should start our leader election over.""" pass class Elector(object): def __init__(self, server_id, election_key, old_key=None, interval=30, ttl=60): """Class that manages elections.
def test_additional_options_registered(self): add_opt = cfg.StrOpt('test_option', default='test') config.register_options(cfg.CONF, additional_options=[add_opt]) self.assertEqual(cfg.CONF['calico']['test_option'], 'test')
def test_additional_options_registered(self): add_opt = cfg.StrOpt('test_option', default='test') config.register_options(cfg.CONF, additional_options=[add_opt]) self.assertEqual(cfg.CONF['calico']['test_option'], 'test')
from networking_calico import etcdutils from networking_calico.plugins.ml2.drivers.calico.election import Elector # The node hostname is used as the default identity for leader election _hostname = socket.gethostname() # Elector configuration; elector_opt = cfg.StrOpt( 'elector_name', default=_hostname, help="A unique name to identify this node in leader election" ) # Register Calico related configuration options calico_config.register_options(cfg.CONF, additional_options=[elector_opt]) # The amount of time in seconds to wait for etcd responses. ETCD_TIMEOUT = 5 OPENSTACK_ENDPOINT_RE = re.compile( r'^' + datamodel_v1.HOST_DIR + r'/(?P<hostname>[^/]+)/.*openstack.*/endpoint/(?P<endpoint_id>[^/]+)') LOG = log.getLogger(__name__) # Set a low refresh interval on the master key. This reduces the chance of # the etcd event buffer wrapping while non-masters are waiting for the key to # be refreshed. MASTER_REFRESH_INTERVAL = 10
def _test_restart_resilience(self, restart_interval_secs): # Start a real local etcd server. self.start_etcd_server() # Set up minimal config, so EtcdWatcher will use that etcd. calico_config.register_options(cfg.CONF) # Ensure etcd server is ready. self.wait_etcd_ready() # Create and start an EtcdWatcher. ew = etcdutils.EtcdWatcher('/calico/felix/v2/abc/host', '/round-trip-check') debug_msgs = [] ew.debug_reporter = lambda msg: debug_msgs.append(msg) eventlet.spawn(ew.start) # Let it run for 5 seconds normally. The EtcdWatcher writes a # round-trip-check key every 3.3s (WATCH_TIMEOUT_SECS / 3), so # 5s is enough for at least one of those writes. eventlet.sleep(5) # Stop the etcd server. debug_msgs.append("Stopping etcd server") self.stop_etcd_server() # Wait for the specified restart interval. eventlet.sleep(restart_interval_secs) # Restart the etcd server. debug_msgs.append("Restarting etcd server") self.start_etcd_server() # Ensure etcd server is ready. self.wait_etcd_ready() # Let it run for 5 seconds more. As above, this should be # enough for at least one round-trip-check key write. eventlet.sleep(5) # Stop the EtcdWatcher. debug_msgs.append("Stopping EtcdWatcher") ew.stop() # Find the message for "Restarting etcd server" and count # "Wrote round-trip key" messages before and after that. Both # counts should be non-zero if the EtcdWatcher is working # correctly before and after the etcd server restart. num_key_writes_before_restart = 0 num_key_writes_after_restart = 0 seen_restart_msg = False for msg in debug_msgs: if msg == "Restarting etcd server": seen_restart_msg = True if msg == "Wrote round-trip key": if seen_restart_msg: num_key_writes_after_restart += 1 else: num_key_writes_before_restart += 1 self.assertGreater( num_key_writes_before_restart, 0, msg="No round-trip key writes before restart: %r" % debug_msgs, ) self.assertGreater( num_key_writes_after_restart, 0, msg="No round-trip key writes after restart: %r" % debug_msgs, ) # Kill the etcd server. self.stop_etcd_server()