def _sync(self, ironic): """Sync the inspector, ironic and dnsmasq state. Locked. :raises: IOError, OSError. :returns: None. """ LOG.debug('Syncing the driver') timestamp_start = timeutils.utcnow() active_macs = node_cache.active_macs() ironic_macs = set(port.address for port in ir_utils.call_with_retries( ironic.port.list, limit=0, fields=['address'])) blacklist_macs = _get_blacklist() # NOTE(milan) whitelist MACs of ports not kept in ironic anymore # also whitelist active MACs that are still blacklisted in the # dnsmasq configuration but have just been asked to be introspected for mac in ((blacklist_macs - ironic_macs) | (blacklist_macs & active_macs)): _whitelist_mac(mac) # blacklist new ports that aren't being inspected for mac in ironic_macs - (blacklist_macs | active_macs): _blacklist_mac(mac) _configure_unknown_hosts() timestamp_end = timeutils.utcnow() LOG.debug('The dnsmasq PXE filter was synchronized (took %s)', timestamp_end - timestamp_start)
def get_ironic_macs(ironic): ports = [ port for port in ir_utils.call_with_retries( ironic.ports, limit=None, fields=['address', 'extra']) ] _ib_mac_to_rmac_mapping(ports) return {port.address for port in ports}
def _get_blacklist(ironic): ports = [port for port in ir_utils.call_with_retries(ironic.port.list, limit=0, fields=['address', 'extra']) if port.address not in node_cache.active_macs()] _ib_mac_to_rmac_mapping(ports) return [port.address for port in ports]
def _get_blacklist(ironic): ports = [port.address for port in ir_utils.call_with_retries(ironic.port.list, limit=0, fields=['address', 'extra']) if port.address not in node_cache.active_macs()] _ib_mac_to_rmac_mapping(ports) return ports
def test_retries_on_ironicclient_error(self): self.call.side_effect = [ ironic_exc.ClientException('boom') ] * 3 + [mock.sentinel.result] result = ir_utils.call_with_retries(self.call, 'meow', answer=42) self.assertEqual(result, mock.sentinel.result) self.call.assert_called_with('meow', answer=42) self.assertEqual(4, self.call.call_count)
def test_retries_on_ironicclient_error(self): self.call.side_effect = [os_exc.SDKException('boom')] * 3 + [ mock.sentinel.result ] result = ir_utils.call_with_retries(self.call, 'meow', answer=42) self.assertEqual(result, mock.sentinel.result) self.call.assert_called_with('meow', answer=42) self.assertEqual(4, self.call.call_count)
def _sync(self, ironic): """Sync the inspector, ironic and dnsmasq state. Locked. :raises: IOError, OSError. :returns: None. """ LOG.debug('Syncing the driver') timestamp_start = timeutils.utcnow() # active_macs are the MACs for which introspection is active active_macs = node_cache.active_macs() # ironic_macs are all the MACs know to ironic (all ironic ports) ironic_macs = set(port.address for port in ir_utils.call_with_retries(ironic.port.list, limit=0, fields=['address'])) blacklist, whitelist = _get_black_white_lists() # removedlist are the MACs that are in either blacklist or whitelist, # but not kept in ironic (ironic_macs) any more removedlist = blacklist.union(whitelist).difference(ironic_macs) # Whitelist active MACs that are not already whitelisted for mac in active_macs.difference(whitelist): _whitelist_mac(mac) # Blacklist any ironic MACs that is not active for introspection unless # it is already blacklisted for mac in ironic_macs.difference(blacklist.union(active_macs)): _blacklist_mac(mac) # Whitelist or Blacklist unknown hosts and MACs not kept in ironic # NOTE(hjensas): Treat unknown hosts and MACs not kept in ironic the # same. Neither should boot the inspection image unless introspection # is active. Deleted MACs must be whitelisted when introspection is # active in case the host is re-enrolled. _configure_unknown_hosts() _configure_removedlist(removedlist) timestamp_end = timeutils.utcnow() LOG.debug('The dnsmasq PXE filter was synchronized (took %s)', timestamp_end - timestamp_start)
def _sync(self, ironic): """Sync the inspector, ironic and dnsmasq state. Locked. :raises: IOError, OSError. :returns: None. """ LOG.debug('Syncing the driver') timestamp_start = timeutils.utcnow() # active_macs are the MACs for which introspection is active active_macs = node_cache.active_macs() # ironic_macs are all the MACs know to ironic (all ironic ports) ironic_macs = set(port.address for port in ir_utils.call_with_retries( ironic.port.list, limit=0, fields=['address'])) blacklist, whitelist = _get_black_white_lists() # removedlist are the MACs that are in either blacklist or whitelist, # but not kept in ironic (ironic_macs) any more removedlist = blacklist.union(whitelist).difference(ironic_macs) # Whitelist active MACs that are not already whitelisted for mac in active_macs.difference(whitelist): _whitelist_mac(mac) # Blacklist any ironic MACs that is not active for introspection unless # it is already blacklisted for mac in ironic_macs.difference(blacklist.union(active_macs)): _blacklist_mac(mac) # Whitelist or Blacklist unknown hosts and MACs not kept in ironic # NOTE(hjensas): Treat unknown hosts and MACs not kept in ironic the # same. Neither should boot the inspection image unless introspection # is active. Deleted MACs must be whitelisted when introspection is # active in case the host is re-enrolled. _configure_unknown_hosts() _configure_removedlist(removedlist) timestamp_end = timeutils.utcnow() LOG.debug('The dnsmasq PXE filter was synchronized (took %s)', timestamp_end - timestamp_start)
def test_no_retries_on_success(self): result = ir_utils.call_with_retries(self.call, 'meow', answer=42) self.assertEqual(result, self.call.return_value) self.call.assert_called_once_with('meow', answer=42)