Esempio n. 1
0
    def test_server_hostnames_multiple_override(self):
        hostname.cached_server_hostnames = []
        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()
        try:
            tmpfile.write(
                "#!/bin/sh\n\necho 'host1.example.com, host2.example.com, host3.example.com'"
            )
            tmpfile.close()

            config.set('server', 'hostname_script', tmpname)

            expected_hostnames = [
                'host1.example.com', 'host2.example.com', 'host3.example.com'
            ]
            server_hostnames = hostname.server_hostnames(config)
            self.assertEquals(
                server_hostnames, expected_hostnames,
                "expected hostnames {0}; got {1}".format(
                    expected_hostnames, server_hostnames))
        finally:
            os.remove(tmpname)
            config.remove_option('server', 'hostname_script')
        pass
  def test_server_hostname_override(self):
    hostname.cached_server_hostname = None
    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()
    try:
      tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
      tmpfile.close()

      config.set('server', 'hostname_script', tmpname)

      self.assertEquals(hostname.server_hostname(config), 'test.example.com', "expected hostname 'test.example.com'")
    finally:
      os.remove(tmpname)
      config.remove_option('server', 'hostname_script')
    pass
Esempio n. 3
0
  def test_hostname_override(self):
    hostname.cached_hostname = None
    hostname.cached_public_hostname = None
    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()
    try:
      tmpfile.write("#!/bin/sh\n\necho 'test.example.com'")
      tmpfile.close()

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

      self.assertEquals(hostname.hostname(config), 'test.example.com', "expected hostname 'test.example.com'")
    finally:
      os.remove(tmpname)
      config.remove_option('agent', 'hostname_script')
    pass
Esempio n. 4
0
  def test_server_hostnames_multiple_override(self):
    hostname.cached_server_hostnames = []
    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()
    try:
      tmpfile.write("#!/bin/sh\n\necho 'host1.example.com, host2.example.com, host3.example.com'")
      tmpfile.close()

      config.set('server', 'hostname_script', tmpname)

      expected_hostnames = ['host1.example.com', 'host2.example.com', 'host3.example.com']
      server_hostnames = hostname.server_hostnames(config)
      self.assertEquals(server_hostnames, expected_hostnames, "expected hostnames {0}; got {1}".format(expected_hostnames, server_hostnames))
    finally:
      os.remove(tmpname)
      config.remove_option('server', 'hostname_script')
    pass
Esempio n. 5
0
    def test_ambari_config_get_command_file_retention_policy(self):
        config = AmbariConfig()

        # unset value yields, "keep"
        if config.has_option(
                "agent", AmbariConfig.COMMAND_FILE_RETENTION_POLICY_PROPERTY):
            config.remove_option(
                "agent", AmbariConfig.COMMAND_FILE_RETENTION_POLICY_PROPERTY)
        self.assertEqual(config.command_file_retention_policy,
                         AmbariConfig.COMMAND_FILE_RETENTION_POLICY_KEEP)

        config.set("agent",
                   AmbariConfig.COMMAND_FILE_RETENTION_POLICY_PROPERTY,
                   AmbariConfig.COMMAND_FILE_RETENTION_POLICY_KEEP)
        self.assertEqual(config.command_file_retention_policy,
                         AmbariConfig.COMMAND_FILE_RETENTION_POLICY_KEEP)

        config.set("agent",
                   AmbariConfig.COMMAND_FILE_RETENTION_POLICY_PROPERTY,
                   AmbariConfig.COMMAND_FILE_RETENTION_POLICY_REMOVE)
        self.assertEqual(config.command_file_retention_policy,
                         AmbariConfig.COMMAND_FILE_RETENTION_POLICY_REMOVE)

        config.set(
            "agent", AmbariConfig.COMMAND_FILE_RETENTION_POLICY_PROPERTY,
            AmbariConfig.COMMAND_FILE_RETENTION_POLICY_REMOVE_ON_SUCCESS)
        self.assertEqual(
            config.command_file_retention_policy,
            AmbariConfig.COMMAND_FILE_RETENTION_POLICY_REMOVE_ON_SUCCESS)

        # Invalid value yields, "keep"
        config.set("agent",
                   AmbariConfig.COMMAND_FILE_RETENTION_POLICY_PROPERTY,
                   "invalid_value")
        self.assertEqual(config.command_file_retention_policy,
                         AmbariConfig.COMMAND_FILE_RETENTION_POLICY_KEEP)