Esempio n. 1
0
    def build(self, response_id='-1'):
        timestamp = int(time.time() * 1000)

        hostInfo = HostInfo(self.config)
        agentEnv = {}
        hostInfo.register(agentEnv, runExpensiveChecks=True)

        current_ping_port = self.config.get('agent', 'ping_port')

        register = {
            'id': int(response_id),
            'timestamp': timestamp,
            'hostname': hostname.hostname(self.config),
            'currentPingPort': int(current_ping_port),
            'publicHostname': hostname.public_hostname(self.config),
            'hardwareProfile': self.hardware.get(),
            'agentEnv': agentEnv,
            'agentVersion': Utils.read_agent_version(self.config),
            'prefix': self.config.get('agent', 'prefix')
        }
        return register
Esempio n. 2
0
    def test_public_hostname_override(self):
        fd = tempfile.mkstemp(text=True)
        tmpname = fd[1]
        os.close(fd[0])
        os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)

        tmpfile = file(tmpname, "w+")

        config = AmbariConfig.config
        try:
            tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
            tmpfile.close()

            config.set('agent', 'public_hostname_script', tmpname)

            self.assertEquals(hostname.public_hostname(), 'test.example.com',
                              "expected hostname 'test.example.com'")
        finally:
            os.remove(tmpname)
            config.remove_option('agent', 'public_hostname_script')

        pass
  def test_public_hostname_override(self):
    fd = tempfile.mkstemp(text=True)
    tmpname = fd[1]
    os.close(fd[0])
    os.chmod(tmpname, os.stat(tmpname).st_mode | stat.S_IXUSR)
   
    tmpfile = file(tmpname, "w+")

    config = AmbariConfig.config
    try:
      tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
      tmpfile.close()

      config.set('agent', 'public_hostname_script', tmpname)

      self.assertEquals(hostname.public_hostname(), 'test.example.com', 
                        "expected hostname 'test.example.com'")
    finally:
      os.remove(tmpname)
      config.remove_option('agent', 'public_hostname_script')

    pass