Revision caad16e2

b/daemons/ganeti-noded
412 412
                         live_port_needed=params[4], source=params[0])
413 413

  
414 414
  @staticmethod
415
  def perspective_node_has_ip_address(params):
416
    """Checks if a node has the given ip address.
417

  
418
    """
419
    return utils.OwnIpAddress(params[0])
420

  
421
  @staticmethod
415 422
  def perspective_node_info(params):
416 423
    """Query node information.
417 424

  
b/lib/backend.py
117 117
    return False
118 118

  
119 119
  if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT):
120
    if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT,
121
                     source=constants.LOCALHOST_IP_ADDRESS):
120
    if utils.OwnIpAddress(master_ip):
122 121
      # we already have the ip:
123 122
      logging.debug("Already started")
124 123
    else:
b/lib/bootstrap.py
128 128
                               " range (%s). Please fix DNS or %s." %
129 129
                               (hostname.ip, constants.ETC_HOSTS))
130 130

  
131
  if not utils.TcpPing(hostname.ip, constants.DEFAULT_NODED_PORT,
132
                       source=constants.LOCALHOST_IP_ADDRESS):
131
  if not utils.OwnIpAddress(hostname.ip):
133 132
    raise errors.OpPrereqError("Inconsistency: this host's name resolves"
134 133
                               " to %s,\nbut this ip address does not"
135 134
                               " belong to this host."
......
145 144
    if not utils.IsValidIP(secondary_ip):
146 145
      raise errors.OpPrereqError("Invalid secondary ip given")
147 146
    if (secondary_ip != hostname.ip and
148
        (not utils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT,
149
                           source=constants.LOCALHOST_IP_ADDRESS))):
147
        not utils.OwnIpAddress(secondary_ip)):
150 148
      raise errors.OpPrereqError("You gave %s as secondary IP,"
151 149
                                 " but it does not belong to this host." %
152 150
                                 secondary_ip)
b/lib/cmdlib.py
1774 1774
    utils.AddHostToEtcHosts(new_node.name)
1775 1775

  
1776 1776
    if new_node.secondary_ip != new_node.primary_ip:
1777
      if not self.rpc.call_node_tcp_ping(new_node.name,
1778
                                         constants.LOCALHOST_IP_ADDRESS,
1779
                                         new_node.secondary_ip,
1780
                                         constants.DEFAULT_NODED_PORT,
1781
                                         10, False):
1777
      if not self.rpc.call_node_has_ip_address(new_node.name,
1778
                                               new_node.secondary_ip):
1782 1779
        raise errors.OpExecError("Node claims it doesn't have the secondary ip"
1783 1780
                                 " you gave (%s). Please fix and re-run this"
1784 1781
                                 " command." % new_node.secondary_ip)
b/lib/rpc.py
339 339
    """Do a TcpPing on the remote node
340 340

  
341 341
    This is a single-node call.
342

  
342 343
    """
343 344
    c = Client("node_tcp_ping", [source, target, port, timeout,
344 345
                                 live_port_needed])
......
346 347
    c.run()
347 348
    return c.getresult().get(node, False)
348 349

  
350
  def call_node_has_ip_address(self, node, address):
351
    """Checks if a node has the given IP address.
352

  
353
    This is a single-node call.
354

  
355
    """
356
    c = Client("node_has_ip_address", [address])
357
    c.connect(node)
358
    c.run()
359
    return c.getresult().get(node, False)
349 360

  
350 361
  def call_node_info(self, node_list, vg_name, hypervisor_type):
351 362
    """Return node information.
b/lib/utils.py
823 823
  return success
824 824

  
825 825

  
826
def OwnIpAddress(address):
827
  """Check if the current host has the the given IP address.
828

  
829
  Currently this is done by tcp-pinging the address from the loopback
830
  address.
831

  
832
  @type address: string
833
  @param address: the addres to check
834
  @rtype: bool
835

  
836
  """
837
  return TcpPing(address, constants.DEFAULT_NODED_PORT,
838
                 source=constants.LOCALHOST_IP_ADDRESS)
839

  
840

  
826 841
def ListVisibleFiles(path):
827 842
  """Returns a list of all visible files in a directory.
828 843

  
b/test/ganeti.utils_unittest.py
41 41
     RemoveFile, CheckDict, MatchNameComponent, FormatUnit, \
42 42
     ParseUnit, AddAuthorizedKey, RemoveAuthorizedKey, \
43 43
     ShellQuote, ShellQuoteArgs, TcpPing, ListVisibleFiles, \
44
     SetEtcHostsEntry, RemoveEtcHostsEntry, FirstFree
44
     SetEtcHostsEntry, RemoveEtcHostsEntry, FirstFree, OwnIpAddress
45 45
from ganeti.errors import LockError, UnitParseError, GenericError, \
46 46
     ProgrammerError
47 47

  
......
635 635
                 "failed to ping alive host on deaf port (no source addr)")
636 636

  
637 637

  
638
class TestOwnIpAddress(unittest.TestCase):
639
  """Testcase for OwnIpAddress"""
640

  
641
  def testOwnLoopback(self):
642
    """check having the loopback ip"""
643
    self.failUnless(OwnIpAddress(constants.LOCALHOST_IP_ADDRESS),
644
                    "Should own the loopback address")
645

  
646
  def testNowOwnAddress(self):
647
    """check that I don't own an address"""
648

  
649
    # network 192.0.2.0/24 is reserved for test/documentation as per
650
    # rfc 3330, so we *should* not have an address of this range... if
651
    # this fails, we should extend the test to multiple addresses
652
    DST_IP = "192.0.2.1"
653
    self.failIf(OwnIpAddress(DST_IP), "Should not own IP address %s" % DST_IP)
654

  
655

  
638 656
class TestListVisibleFiles(unittest.TestCase):
639 657
  """Test case for ListVisibleFiles"""
640 658

  

Also available in: Unified diff