Beispiel #1
0
  def test_main(self, ping_port_init_mock, ping_port_start_mock, data_clean_init_mock,data_clean_start_mock,
                parse_args_mock, join_mock, start_mock, Controller_init_mock, try_to_connect_mock,
                update_log_level_mock, daemonize_mock, perform_prestart_checks_mock,
                resolve_ambari_config_mock, stop_mock, bind_signal_handlers_mock, setup_logging_mock):
    data_clean_init_mock.return_value = None
    Controller_init_mock.return_value = None
    ping_port_init_mock.return_value = None
    options = MagicMock()
    parse_args_mock.return_value = (options, MagicMock)

    #testing call without command-line arguments
    main.main()

    self.assertTrue(setup_logging_mock.called)
    self.assertTrue(bind_signal_handlers_mock.called)
    self.assertTrue(stop_mock.called)
    self.assertTrue(resolve_ambari_config_mock.called)
    self.assertTrue(perform_prestart_checks_mock.called)
    self.assertTrue(daemonize_mock.called)
    self.assertTrue(update_log_level_mock.called)
    try_to_connect_mock.assert_called_once_with(ANY, -1, ANY)
    self.assertTrue(start_mock.called)
    self.assertTrue(data_clean_init_mock.called)
    self.assertTrue(data_clean_start_mock.called)
    self.assertTrue(ping_port_init_mock.called)
    self.assertTrue(ping_port_start_mock.called)

    perform_prestart_checks_mock.reset_mock()

    # Testing call with --expected-hostname parameter
    options.expected_hostname = "test.hst"
    main.main()
    perform_prestart_checks_mock.assert_called_once_with(options.expected_hostname)
Beispiel #2
0
  def test_main(self, ping_port_init_mock, ping_port_start_mock, data_clean_init_mock,data_clean_start_mock,
                parse_args_mock, join_mock, start_mock, Controller_init_mock, try_to_connect_mock,
                update_log_level_mock, daemonize_mock, perform_prestart_checks_mock,
                resolve_ambari_config_mock, stop_mock, bind_signal_handlers_mock,
                setup_logging_mock, socket_mock):
    data_clean_init_mock.return_value = None
    Controller_init_mock.return_value = None
    ping_port_init_mock.return_value = None
    options = MagicMock()
    parse_args_mock.return_value = (options, MagicMock)

    #testing call without command-line arguments
    main.main()

    self.assertTrue(setup_logging_mock.called)
    self.assertTrue(bind_signal_handlers_mock.called)
    self.assertTrue(stop_mock.called)
    self.assertTrue(resolve_ambari_config_mock.called)
    self.assertTrue(perform_prestart_checks_mock.called)
    self.assertTrue(daemonize_mock.called)
    self.assertTrue(update_log_level_mock.called)
    try_to_connect_mock.assert_called_once_with(ANY, -1, ANY)
    self.assertTrue(start_mock.called)
    self.assertTrue(data_clean_init_mock.called)
    self.assertTrue(data_clean_start_mock.called)
    self.assertTrue(ping_port_init_mock.called)
    self.assertTrue(ping_port_start_mock.called)

    perform_prestart_checks_mock.reset_mock()

    # Testing call with --expected-hostname parameter
    options.expected_hostname = "test.hst"
    main.main()
    perform_prestart_checks_mock.assert_called_once_with(options.expected_hostname)
  def SvcDoRun(self):
    parse_options()
    self.redirect_output_streams()

    # Soft dependency on the Windows Time service
    ensure_time_service_is_started()

    self.heartbeat_stop_handler = HeartbeatStopHandlers(AmbariAgentService._heventSvcStop)

    self.ReportServiceStatus(win32service.SERVICE_RUNNING)

    from ambari_agent import main

    main.main(self.heartbeat_stop_handler)
Beispiel #4
0
  def SvcDoRun(self):
    parse_options()
    self.redirect_output_streams()

    # Soft dependency on the Windows Time service
    ensure_time_service_is_started()

    self.heartbeat_stop_handler = HeartbeatStopHandlers(AmbariAgentService._heventSvcStop)

    self.ReportServiceStatus(win32service.SERVICE_RUNNING)

    from ambari_agent import main

    main.main(self.heartbeat_stop_handler)
Beispiel #5
0
    def test_main(self, cleanup_mock, ping_port_init_mock,
                  ping_port_start_mock, data_clean_init_mock,
                  data_clean_start_mock, parse_args_mock, join_mock,
                  start_mock, Controller_init_mock, try_to_connect_mock,
                  update_log_level_mock, daemonize_mock,
                  perform_prestart_checks_mock, ambari_config_mock, stop_mock,
                  bind_signal_handlers_mock, setup_logging_mock, socket_mock):
        data_clean_init_mock.return_value = None
        Controller_init_mock.return_value = None
        ping_port_init_mock.return_value = None
        options = MagicMock()
        parse_args_mock.return_value = (options, MagicMock)
        try_to_connect_mock.return_value = (0, True)
        # use default unix config
        ambari_config_mock.return_value = os.path.abspath(
            "../../../conf/unix/ambari-agent.ini")
        #testing call without command-line arguments

        main.main()

        self.assertTrue(setup_logging_mock.called)
        self.assertTrue(bind_signal_handlers_mock.called)
        if OSCheck.get_os_family() != OSConst.WINSRV_FAMILY:
            self.assertTrue(stop_mock.called)
        #self.assertTrue(resolve_ambari_config_mock.called)
        self.assertTrue(perform_prestart_checks_mock.called)
        if OSCheck.get_os_family() != OSConst.WINSRV_FAMILY:
            self.assertTrue(daemonize_mock.called)
        self.assertTrue(update_log_level_mock.called)
        try_to_connect_mock.assert_called_once_with(ANY, -1, ANY)
        self.assertTrue(start_mock.called)
        self.assertTrue(data_clean_init_mock.called)
        self.assertTrue(data_clean_start_mock.called)
        self.assertTrue(ping_port_init_mock.called)
        self.assertTrue(ping_port_start_mock.called)
        self.assertTrue(cleanup_mock.called)
        perform_prestart_checks_mock.reset_mock()

        # Testing call with --expected-hostname parameter
        options.expected_hostname = "test.hst"
        main.main()
        perform_prestart_checks_mock.assert_called_once_with(
            options.expected_hostname)
  def test_main(self, cleanup_mock, ping_port_init_mock, ping_port_start_mock, data_clean_init_mock,data_clean_start_mock,
                parse_args_mock, join_mock, start_mock, Controller_init_mock, try_to_connect_mock,
                update_log_level_mock, daemonize_mock, perform_prestart_checks_mock,
                ambari_config_mock,
                stop_mock, bind_signal_handlers_mock,
                setup_logging_mock, socket_mock):
    data_clean_init_mock.return_value = None
    Controller_init_mock.return_value = None
    ping_port_init_mock.return_value = None
    options = MagicMock()
    parse_args_mock.return_value = (options, MagicMock)
    try_to_connect_mock.return_value = (0, True)
    # use default unix config
    ambari_config_mock.return_value = os.path.abspath("../../../conf/unix/ambari-agent.ini")
    #testing call without command-line arguments

    main.main()

    self.assertTrue(setup_logging_mock.called)
    self.assertTrue(bind_signal_handlers_mock.called)
    if OSCheck.get_os_family() != OSConst.WINSRV_FAMILY:
      self.assertTrue(stop_mock.called)
    #self.assertTrue(resolve_ambari_config_mock.called)
    self.assertTrue(perform_prestart_checks_mock.called)
    if OSCheck.get_os_family() != OSConst.WINSRV_FAMILY:
      self.assertTrue(daemonize_mock.called)
    self.assertTrue(update_log_level_mock.called)
    try_to_connect_mock.assert_called_once_with(ANY, -1, ANY)
    self.assertTrue(start_mock.called)
    self.assertTrue(data_clean_init_mock.called)
    self.assertTrue(data_clean_start_mock.called)
    self.assertTrue(ping_port_init_mock.called)
    self.assertTrue(ping_port_start_mock.called)
    self.assertTrue(cleanup_mock.called)
    perform_prestart_checks_mock.reset_mock()

    # Testing call with --expected-hostname parameter
    options.expected_hostname = "test.hst"
    main.main()
    perform_prestart_checks_mock.assert_called_once_with(options.expected_hostname)
Beispiel #7
0
    def test_main(self, start_mock, Controller_init_mock, initSecurity_mock,
                  CertificateManager_init_mock, try_to_connect_mock,
                  update_log_level_mock, killstaleprocesses_mock,
                  daemonize_mock, perform_prestart_checks_mock,
                  resolve_ambari_config_mock, stop_mock,
                  bind_signal_handlers_mock, setup_logging_mock):
        CertificateManager_init_mock.return_value = None
        Controller_init_mock.return_value = None

        #testing call without command-line arguments
        main.main()

        self.assertTrue(setup_logging_mock.called)
        self.assertTrue(bind_signal_handlers_mock.called)
        self.assertFalse(stop_mock.called)
        self.assertTrue(resolve_ambari_config_mock.called)
        self.assertTrue(perform_prestart_checks_mock.called)
        self.assertTrue(daemonize_mock.called)
        self.assertTrue(killstaleprocesses_mock.called)
        self.assertTrue(update_log_level_mock.called)
        try_to_connect_mock.assert_called_once_with(ANY, -1, ANY)
        self.assertTrue(initSecurity_mock.called)
        self.assertTrue(start_mock.called)
Beispiel #8
0
    def test_main(self, get_status_commands_executor_mock,
                  exithelper_exit_mock, cleanup_mock, ping_port_init_mock,
                  ping_port_start_mock, data_clean_init_mock,
                  data_clean_start_mock, parse_args_mock, start_mock,
                  Controller_is_alive_mock, Controller_init_mock,
                  try_to_connect_mock, update_log_level_mock, daemonize_mock,
                  perform_prestart_checks_mock, ambari_config_mock, stop_mock,
                  bind_signal_handlers_mock, setup_logging_mock, socket_mock):
        data_clean_init_mock.return_value = None
        Controller_init_mock.return_value = None
        Controller_is_alive_mock.return_value = False
        ping_port_init_mock.return_value = None
        options = MagicMock()
        parse_args_mock.return_value = (options, MagicMock)
        try_to_connect_mock.return_value = (0, True, False
                                            )  # (retries, connected, stopped)
        # use default unix config
        ambari_config_mock.return_value = self.init_ambari_config_mock()
        #testing call without command-line arguments

        main.main()

        self.assertTrue(setup_logging_mock.called)
        self.assertTrue(perform_prestart_checks_mock.called)
        if OSCheck.get_os_family() != OSConst.WINSRV_FAMILY:
            self.assertTrue(daemonize_mock.called)
        self.assertTrue(update_log_level_mock.called)
        try_to_connect_mock.assert_called_once_with(ANY, main.MAX_RETRIES, ANY)
        self.assertTrue(start_mock.called)
        self.assertTrue(data_clean_init_mock.called)
        self.assertTrue(data_clean_start_mock.called)
        self.assertTrue(ping_port_init_mock.called)
        self.assertTrue(ping_port_start_mock.called)
        self.assertTrue(exithelper_exit_mock.called)
        perform_prestart_checks_mock.reset_mock()

        # Testing call with --expected-hostname parameter
        options.expected_hostname = "test.hst"
        main.main()
        perform_prestart_checks_mock.assert_called_once_with(
            options.expected_hostname)

        # Test with multiple server hostnames
        default_server_hostnames = hostname.cached_server_hostnames
        hostname.cached_server_hostnames = ['host1', 'host2', 'host3']

        def try_to_connect_impl(*args, **kwargs):
            for server_hostname in hostname.cached_server_hostnames:
                if (args[0].find(server_hostname) != -1):
                    if server_hostname == 'host1':
                        return 0, False, False
                    elif server_hostname == 'host2':
                        return 0, False, False
                    elif server_hostname == 'host3':
                        return 0, True, False
                    else:
                        return 0, True, False
            pass

        try_to_connect_mock.reset_mock()
        try_to_connect_mock.side_effect = try_to_connect_impl
        active_server = main.main()
        self.assertEquals(active_server, 'host3')
        hostname.cached_server_hostnames = default_server_hostnames
        pass