Ejemplo n.º 1
0
    def test_load_definitions(self):
        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, None)

        definitions = scheduler._AlertSchedulerHandler__load_definitions()

        self.assertEquals(len(definitions), 1)
Ejemplo n.º 2
0
  def test_load_definitions(self):
    definitions = {
     'alertDefinitions':
      [
       {
         'source': 
         {
           'type': 'PORT'
         }
       }
       ]
     }
    initializer_module = InitializerModule()
    initializer_module.init()
    initializer_module.alert_definitions_cache.rewrite_cluster_cache('0', definitions)
    
    scheduler = AlertSchedulerHandler(initializer_module)#(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, None, self.config, None)
    scheduler._AlertSchedulerHandler__config_maps = {
      'cluster': {}
    }

    definitions = scheduler._AlertSchedulerHandler__load_definitions()

    alert_def = definitions[0]
    self.assertTrue(isinstance(alert_def, PortAlert))
Ejemplo n.º 3
0
    def test_load_definitions(self):
        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, None, None)
        scheduler._AlertSchedulerHandler__config_maps = {'cluster': {}}

        definitions = scheduler._AlertSchedulerHandler__load_definitions()

        alert_def = definitions[0]
        self.assertTrue(isinstance(alert_def, PortAlert))
Ejemplo n.º 4
0
    def test_load_definitions_noFile(self):
        scheduler = AlertSchedulerHandler('wrong_path', 'wrong_path',
                                          'wrong_path', 'wrong_path', None,
                                          None)
        scheduler._AlertSchedulerHandler__config_maps = {'cluster': {}}

        definitions = scheduler._AlertSchedulerHandler__load_definitions()

        self.assertEquals(definitions, [])
  def test_load_definitions_noFile(self):
    scheduler = AlertSchedulerHandler('wrong_path', 'wrong_path', 'wrong_path', 'wrong_path', 5, None, None, None)
    scheduler._AlertSchedulerHandler__config_maps = {
      'cluster': {}
    }

    definitions = scheduler._AlertSchedulerHandler__load_definitions()

    self.assertEquals(definitions, [])
Ejemplo n.º 6
0
    def test_start(self, aps_add_interval_job_mock, aps_start_mock):
        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')

        ash = AlertSchedulerHandler(test_file_path, test_stack_path)
        ash.start()

        self.assertTrue(aps_add_interval_job_mock.called)
        self.assertTrue(aps_start_mock.called)
Ejemplo n.º 7
0
    def test_json_to_callable_none(self):
        json_definition = {'source': {'type': 'SOMETHING'}}

        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, None, None)
        callable_result = scheduler._AlertSchedulerHandler__json_to_callable(
            'cluster', 'host', copy.deepcopy(json_definition))

        self.assertTrue(callable_result is None)
  def test_execute_alert_emptyCommands(self):
    execution_commands = []

    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, 5, None, None, None)
    alert_mock = Mock()
    scheduler._AlertSchedulerHandler__json_to_callable = Mock(return_value=alert_mock)

    scheduler.execute_alert(execution_commands)

    self.assertFalse(alert_mock.collect.called)
  def test_load_definitions(self):
    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, 5, None, None, None)
    scheduler._AlertSchedulerHandler__config_maps = {
      'cluster': {}
    }

    definitions = scheduler._AlertSchedulerHandler__load_definitions()

    alert_def = definitions[0]
    self.assertTrue(isinstance(alert_def, PortAlert))
  def test_json_to_callable_none(self):
    json_definition = {
      'source': {
        'type': 'SOMETHING'
      }
    }

    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, 5, None, None, None)
    callable_result = scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', copy.deepcopy(json_definition))

    self.assertTrue(callable_result is None)
Ejemplo n.º 11
0
    def test_execute_alert_emptyCommands(self):
        execution_commands = []

        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, None, None)
        alert_mock = Mock()
        scheduler._AlertSchedulerHandler__json_to_callable = Mock(
            return_value=alert_mock)

        scheduler.execute_alert(execution_commands)

        self.assertFalse(alert_mock.collect.called)
Ejemplo n.º 12
0
    def test_json_to_callable_port(self):
        json_definition = {'source': {'type': 'PORT'}}

        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, None, None)
        callable_result = scheduler._AlertSchedulerHandler__json_to_callable(
            'cluster', 'host', copy.deepcopy(json_definition))

        self.assertTrue(callable_result is not None)
        self.assertTrue(isinstance(callable_result, PortAlert))
        self.assertEquals(callable_result.alert_meta, json_definition)
        self.assertEquals(callable_result.alert_source_meta,
                          json_definition['source'])
    def test_json_to_callable_ams(self):
        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, None, self.config, None)
        json_definition = {'source': {'type': 'AMS'}}

        callable_result = scheduler._AlertSchedulerHandler__json_to_callable(
            'cluster', 'host', copy.deepcopy(json_definition))

        self.assertTrue(callable_result is not None)
        self.assertTrue(isinstance(callable_result, AmsAlert))
        self.assertEquals(callable_result.alert_meta, json_definition)
        self.assertEquals(callable_result.alert_source_meta,
                          json_definition['source'])
Ejemplo n.º 14
0
  def test_load_definitions_noFile(self):
    initializer_module = InitializerModule()
    initializer_module.init()
    
    scheduler = AlertSchedulerHandler(initializer_module)
    #('wrong_path', 'wrong_path', 'wrong_path', 'wrong_path', 'wrong_path', None, self.config, None)
    scheduler._AlertSchedulerHandler__config_maps = {
      'cluster': {}
    }

    definitions = scheduler._AlertSchedulerHandler__load_definitions()

    self.assertEquals(definitions, [])
  def test_json_to_callable_port(self):
    json_definition = {
      'source': {
        'type': 'PORT'
      }
    }

    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, 5, None, None, None)
    callable_result = scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', copy.deepcopy(json_definition))

    self.assertTrue(callable_result is not None)
    self.assertTrue(isinstance(callable_result, PortAlert))
    self.assertEquals(callable_result.alert_meta, json_definition)
    self.assertEquals(callable_result.alert_source_meta, json_definition['source'])
Ejemplo n.º 16
0
  def test_execute_alert_emptyCommands(self):
    execution_commands = []

    initializer_module = InitializerModule()
    initializer_module.init()
    
    scheduler = AlertSchedulerHandler(initializer_module)
    #TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, None, self.config, None)
    alert_mock = Mock()
    scheduler._AlertSchedulerHandler__json_to_callable = Mock(return_value=alert_mock)

    scheduler.execute_alert(execution_commands)

    self.assertFalse(alert_mock.collect.called)
Ejemplo n.º 17
0
    def test_start(self):
        execution_commands = [{
            'clusterName': 'cluster',
            'hostName': 'host',
            'alertDefinition': {
                'name': 'alert1'
            }
        }]

        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, None, None)
        alert_mock = MagicMock()
        alert_mock.interval = Mock(return_value=5)
        alert_mock.collect = Mock()
        alert_mock.set_helpers = Mock()
        scheduler.schedule_definition = MagicMock()
        scheduler._AlertSchedulerHandler__scheduler = MagicMock()
        scheduler._AlertSchedulerHandler__scheduler.running = False
        scheduler._AlertSchedulerHandler__scheduler.start = Mock()
        scheduler._AlertSchedulerHandler__json_to_callable = Mock(
            return_value=alert_mock)
        scheduler._AlertSchedulerHandler__config_maps = {'cluster': {}}

        scheduler.start()

        self.assertTrue(
            scheduler._AlertSchedulerHandler__scheduler.start.called)
        scheduler.schedule_definition.assert_called_with(alert_mock)
  def test_json_to_callable_ams(self):
    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, None, self.config, None)
    json_definition = {
      'source': {
        'type': 'AMS'
      }
    }

    callable_result = scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', copy.deepcopy(json_definition))

    self.assertTrue(callable_result is not None)
    self.assertTrue(isinstance(callable_result, AmsAlert))
    self.assertEquals(callable_result.alert_meta, json_definition)
    self.assertEquals(callable_result.alert_source_meta, json_definition['source'])
Ejemplo n.º 19
0
  def test_json_to_callable_none(self):
    json_definition = {
      'source': {
        'type': 'SOMETHING'
      }
    }

    initializer_module = InitializerModule()
    initializer_module.init()
    
    scheduler = AlertSchedulerHandler(initializer_module)
    #(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, None, self.config, None)
    callable_result = scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', 'host', copy.deepcopy(json_definition))

    self.assertTrue(callable_result is None)
Ejemplo n.º 20
0
  def test_start(self, aps_add_interval_job_mock, aps_start_mock):
    test_file_path = os.path.join('ambari_agent', 'dummy_files')
    test_stack_path = os.path.join('ambari_agent', 'dummy_files')
    test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
    test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

    cluster_configuration = self.__get_cluster_configuration()

    ash = AlertSchedulerHandler(test_file_path, test_stack_path,
      test_common_services_path, test_host_scripts_path, cluster_configuration,
      None)

    ash.start()

    self.assertTrue(aps_add_interval_job_mock.called)
    self.assertTrue(aps_start_mock.called)
Ejemplo n.º 21
0
    def init(self):
        """
    Initialize properties
    """
        self.config = AmbariConfig.get_resolved_config()

        self.is_registered = False

        self.metadata_cache = ClusterMetadataCache(
            self.config.cluster_cache_dir)
        self.topology_cache = ClusterTopologyCache(
            self.config.cluster_cache_dir, self.config)
        self.host_level_params_cache = ClusterHostLevelParamsCache(
            self.config.cluster_cache_dir)
        self.configurations_cache = ClusterConfigurationCache(
            self.config.cluster_cache_dir)
        self.alert_definitions_cache = ClusterAlertDefinitionsCache(
            self.config.cluster_cache_dir)
        self.configuration_builder = ConfigurationBuilder(self)
        self.stale_alerts_monitor = StaleAlertsMonitor(self)

        self.file_cache = FileCache(self.config)

        self.customServiceOrchestrator = CustomServiceOrchestrator(self)

        self.recovery_manager = RecoveryManager(self.config.recovery_cache_dir)
        self.commandStatuses = CommandStatusDict(self)
        self.action_queue = ActionQueue(self)
        self.alert_scheduler_handler = AlertSchedulerHandler(self)
Ejemplo n.º 22
0
    def test_reschedule(self):
        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')

        ash = AlertSchedulerHandler(test_file_path, test_stack_path)
        ash.start()

        self.assertEquals(1, ash.get_job_count())
        ash.reschedule()
        self.assertEquals(1, ash.get_job_count())
Ejemplo n.º 23
0
    def test_immediate_alert(self):
        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')
        test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
        test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

        cluster_configuration = self.__get_cluster_configuration()
        ash = AlertSchedulerHandler(test_file_path, test_stack_path,
                                    test_common_services_path,
                                    test_host_scripts_path,
                                    cluster_configuration, None)

        ash.start()

        self.assertEquals(1, ash.get_job_count())
        self.assertEquals(0, len(ash._collector.alerts()))

        execution_commands = [{
            "clusterName":
            "c1",
            "hostName":
            "c6401.ambari.apache.org",
            "alertDefinition":
            self._get_port_alert_definition()
        }]

        # execute the alert immediately and verify that the collector has the result
        ash.execute_alert(execution_commands)
        self.assertEquals(1, len(ash._collector.alerts()))
  def test_start(self):
    execution_commands = [
      {
        'clusterName': 'cluster',
        'hostName': 'host',
        'alertDefinition': {
          'name': 'alert1'
        }
      }
    ]

    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, 5, None, None, None)
    alert_mock = MagicMock()
    alert_mock.interval = Mock(return_value=5)
    alert_mock.collect = Mock()
    alert_mock.set_helpers = Mock()
    scheduler.schedule_definition = MagicMock()
    scheduler._AlertSchedulerHandler__scheduler = MagicMock()
    scheduler._AlertSchedulerHandler__scheduler.running = False
    scheduler._AlertSchedulerHandler__scheduler.start = Mock()
    scheduler._AlertSchedulerHandler__json_to_callable = Mock(return_value=alert_mock)
    scheduler._AlertSchedulerHandler__config_maps = {
      'cluster': {}
    }

    scheduler.start()

    self.assertTrue(scheduler._AlertSchedulerHandler__scheduler.start.called)
    scheduler.schedule_definition.assert_called_with(alert_mock)
Ejemplo n.º 25
0
  def test_json_to_callable_metric(self):
    initializer_module = InitializerModule()
    initializer_module.init()
    
    scheduler = AlertSchedulerHandler(initializer_module)
    #(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, None, self.config, None)
    json_definition = {
      'source': {
        'type': 'METRIC'
      }
    }

    callable_result = scheduler._AlertSchedulerHandler__json_to_callable('cluster', 'host', 'host', copy.deepcopy(json_definition))

    self.assertTrue(callable_result is not None)
    self.assertTrue(isinstance(callable_result, MetricAlert))
    self.assertEquals(callable_result.alert_meta, json_definition)
    self.assertEquals(callable_result.alert_source_meta, json_definition['source'])
Ejemplo n.º 26
0
 def init_threads(self):
     """
 Initialize thread objects
 """
     self.component_status_executor = ComponentStatusExecutor(self)
     self.action_queue = ActionQueue(self)
     self.alert_scheduler_handler = AlertSchedulerHandler(self)
     self.command_status_reporter = CommandStatusReporter(self)
     self.host_status_reporter = HostStatusReporter(self)
     self.alert_status_reporter = AlertStatusReporter(self)
     self.heartbeat_thread = HeartbeatThread.HeartbeatThread(self)
Ejemplo n.º 27
0
  def test_immediate_alert(self):
    test_file_path = os.path.join('ambari_agent', 'dummy_files')
    test_stack_path = os.path.join('ambari_agent', 'dummy_files')
    test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
    test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

    cluster_configuration = self.__get_cluster_configuration()
    ash = AlertSchedulerHandler(test_file_path, test_stack_path,
      test_common_services_path, test_host_scripts_path, cluster_configuration,
      None)

    ash.start()

    self.assertEquals(1, ash.get_job_count())
    self.assertEquals(0, len(ash._collector.alerts()))

    execution_commands = [ {
      "clusterName": "c1",
      "hostName": "c6401.ambari.apache.org",
      "alertDefinition": self._get_port_alert_definition()
    } ]

    # execute the alert immediately and verify that the collector has the result
    ash.execute_alert(execution_commands)
    self.assertEquals(1, len(ash._collector.alerts()))
Ejemplo n.º 28
0
    def test_execute_alert_from_extension(self):
        execution_commands = [{
            'clusterName': 'cluster',
            'hostName': 'host',
            'publicHostName': 'host',
            'alertDefinition': {
                'name': 'alert1'
            }
        }]

        scheduler = AlertSchedulerHandler('wrong_path', 'wrong_path',
                                          'wrong_path', TEST_PATH,
                                          'wrong_path', None, self.config,
                                          None)
        alert_mock = MagicMock()
        alert_mock.collect = Mock()
        alert_mock.set_helpers = Mock()
        scheduler._AlertSchedulerHandler__json_to_callable = Mock(
            return_value=alert_mock)
        scheduler._AlertSchedulerHandler__config_maps = {'cluster': {}}

        scheduler.execute_alert(execution_commands)

        scheduler._AlertSchedulerHandler__json_to_callable.assert_called_with(
            'cluster', 'host', 'host', {'name': 'alert1'})
        self.assertTrue(alert_mock.collect.called)
Ejemplo n.º 29
0
  def test_reschedule(self):
    test_file_path = os.path.join('ambari_agent', 'dummy_files')
    test_stack_path = os.path.join('ambari_agent', 'dummy_files')
    test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
    test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

    cluster_configuration = self.__get_cluster_configuration()

    ash = AlertSchedulerHandler(test_file_path, test_stack_path,
      test_common_services_path, test_host_scripts_path, cluster_configuration,
      None)

    ash.start()

    self.assertEquals(1, ash.get_job_count())
    ash.reschedule()
    self.assertEquals(1, ash.get_job_count())
Ejemplo n.º 30
0
    def test_job_context_injector(self, reconfigure_urllib2_opener_mock):
        self.config.use_system_proxy_setting = lambda: False
        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, TEST_PATH, None,
                                          self.config, None)
        scheduler._job_context_injector(self.config)

        self.assertTrue(reconfigure_urllib2_opener_mock.called)

        reconfigure_urllib2_opener_mock.reset_mock()

        self.config.use_system_proxy_setting = lambda: True
        scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH,
                                          TEST_PATH, TEST_PATH, None,
                                          self.config, None)
        scheduler._job_context_injector(self.config)
        self.assertFalse(reconfigure_urllib2_opener_mock.called)
  def test_execute_alert(self):
    execution_commands = [
      {
        'clusterName': 'cluster',
        'hostName': 'host',
        'alertDefinition': {
          'name': 'alert1'
        }
      }
    ]

    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, 5, None, None, None)
    alert_mock = MagicMock()
    alert_mock.collect = Mock()
    alert_mock.set_helpers = Mock()
    scheduler._AlertSchedulerHandler__json_to_callable = Mock(return_value=alert_mock)
    scheduler._AlertSchedulerHandler__config_maps = {
      'cluster': {}
    }

    scheduler.execute_alert(execution_commands)

    scheduler._AlertSchedulerHandler__json_to_callable.assert_called_with('cluster', 'host', {'name': 'alert1'})
    self.assertTrue(alert_mock.collect.called)
Ejemplo n.º 32
0
    def test_immediate_alert(self):
        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')
        test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
        test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

        ash = AlertSchedulerHandler(test_file_path, test_stack_path,
                                    test_common_services_path,
                                    test_host_scripts_path, None)
        ash.start()

        self.assertEquals(1, ash.get_job_count())
        self.assertEquals(0, len(ash._collector.alerts()))

        execution_commands = [{
            "clusterName": "c1",
            "hostName": "c6401.ambari.apache.org",
            "alertDefinition": {
                "name": "namenode_process",
                "service": "HDFS",
                "component": "NAMENODE",
                "label": "NameNode process",
                "interval": 6,
                "scope": "host",
                "enabled": True,
                "uuid": "c1f73191-4481-4435-8dae-fd380e4c0be1",
                "source": {
                    "type": "PORT",
                    "uri": "{{hdfs-site/my-key}}",
                    "default_port": 50070,
                    "reporting": {
                        "ok": {
                            "text":
                            "(Unit Tests) TCP OK - {0:.4f} response time on port {1}"
                        },
                        "critical": {
                            "text":
                            "(Unit Tests) Could not load process info: {0}"
                        }
                    }
                }
            }
        }]

        # execute the alert immediately and verify that the collector has the result
        ash.execute_alert(execution_commands)
        self.assertEquals(1, len(ash._collector.alerts()))
Ejemplo n.º 33
0
    def test_update_configurations(self, json_mock):
        def open_side_effect(file, mode):
            if mode == 'w':
                file_mock = MagicMock()
                return file_mock
            else:
                return self.original_open(file, mode)

        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')
        test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
        test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

        commands = [{
            "clusterName": "c1",
            "configurations": {
                "hdfs-site": {
                    "dfs.namenode.http-address":
                    "c6401.ambari.apache.org:50071"
                }
            }
        }]
        with open(os.path.join(test_stack_path, "definitions.json"),
                  "r") as fp:
            all_commands = json.load(fp)
        all_commands[0]['configurations']['hdfs-site'].update(
            {"dfs.namenode.http-address": "c6401.ambari.apache.org:50071"})

        ash = AlertSchedulerHandler(test_file_path, test_stack_path,
                                    test_common_services_path,
                                    test_host_scripts_path, None)
        ash.start()

        with patch("__builtin__.open") as open_mock:
            open_mock.side_effect = open_side_effect
            ash.update_configurations(commands)

        self.assertTrue(json_mock.called)
        self.assertTrue(json_mock.called_with(all_commands))
Ejemplo n.º 34
0
    def test_update_configurations_without_reschedule(self, json_mock,
                                                      reschedule_mock):
        def open_side_effect(file, mode):
            if mode == 'w':
                file_mock = MagicMock()
                return file_mock
            else:
                return self.original_open(file, mode)

        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')
        test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
        test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

        with open(os.path.join(test_stack_path, "definitions.json"),
                  "r") as fp:
            all_commands = json.load(fp)

        # create a copy of the configurations from definitions.json, then add
        # a brand new property - this should not cause a restart since there are
        # no alerts that use this new property
        commands = [{"clusterName": "c1"}]
        commands[0]['configurations'] = all_commands[0]['configurations']
        commands[0]['configurations'].update({"foo": "bar"})

        ash = AlertSchedulerHandler(test_file_path, test_stack_path,
                                    test_common_services_path,
                                    test_host_scripts_path, None)

        ash.start()

        with patch("__builtin__.open") as open_mock:
            open_mock.side_effect = open_side_effect
            ash.update_configurations(commands)

        self.assertTrue(json_mock.called)
        self.assertTrue(json_mock.called_with(all_commands))
        self.assertFalse(reschedule_mock.called)
Ejemplo n.º 35
0
  def test_disabled_definitions(self):
    test_file_path = os.path.join('ambari_agent', 'dummy_files')
    test_stack_path = os.path.join('ambari_agent', 'dummy_files')
    test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
    test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

    cluster_configuration = self.__get_cluster_configuration()

    ash = AlertSchedulerHandler(test_file_path, test_stack_path,
      test_common_services_path, test_host_scripts_path, cluster_configuration,
      None)

    ash.start()

    self.assertEquals(1, ash.get_job_count())

    definition_json = self._get_port_alert_definition()

    alert = PortAlert(definition_json, definition_json['source'])
    ash.schedule_definition(alert)

    self.assertEquals(2, ash.get_job_count())

    definition_json['enabled'] = False
    alert = PortAlert(definition_json, definition_json['source'])
    ash.schedule_definition(alert)

    # verify disabled alert not scheduled
    self.assertEquals(2, ash.get_job_count())

    definition_json['enabled'] = True
    pa = PortAlert(definition_json, definition_json['source'])
    ash.schedule_definition(pa)

    # verify enabled alert was scheduled
    self.assertEquals(3, ash.get_job_count())
Ejemplo n.º 36
0
    def test_disabled_definitions(self):
        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')

        ash = AlertSchedulerHandler(test_file_path, test_stack_path)
        ash.start()

        self.assertEquals(1, ash.get_job_count())

        json = {
            "name": "namenode_process",
            "service": "HDFS",
            "component": "NAMENODE",
            "label": "NameNode process",
            "interval": 6,
            "scope": "host",
            "enabled": True,
            "uuid": "c1f73191-4481-4435-8dae-fd380e4c0be1",
            "source": {
                "type": "PORT",
                "uri": "{{hdfs-site/my-key}}",
                "default_port": 50070,
                "reporting": {
                    "ok": {
                        "text": "TCP OK - {0:.4f} response time on port {1}"
                    },
                    "critical": {
                        "text": "Could not load process info: {0}"
                    }
                }
            }
        }

        pa = PortAlert(json, json['source'])
        ash.schedule_definition(pa)

        self.assertEquals(2, ash.get_job_count())

        json['enabled'] = False
        pa = PortAlert(json, json['source'])
        ash.schedule_definition(pa)

        # verify disabled alert not scheduled
        self.assertEquals(2, ash.get_job_count())

        json['enabled'] = True
        pa = PortAlert(json, json['source'])
        ash.schedule_definition(pa)

        # verify enabled alert was scheduled
        self.assertEquals(3, ash.get_job_count())
Ejemplo n.º 37
0
    def test_disabled_definitions(self):
        test_file_path = os.path.join('ambari_agent', 'dummy_files')
        test_stack_path = os.path.join('ambari_agent', 'dummy_files')
        test_common_services_path = os.path.join('ambari_agent', 'dummy_files')
        test_host_scripts_path = os.path.join('ambari_agent', 'dummy_files')

        cluster_configuration = self.__get_cluster_configuration()

        ash = AlertSchedulerHandler(test_file_path, test_stack_path,
                                    test_common_services_path,
                                    test_host_scripts_path,
                                    cluster_configuration, None)

        ash.start()

        self.assertEquals(1, ash.get_job_count())

        definition_json = self._get_port_alert_definition()

        alert = PortAlert(definition_json, definition_json['source'])
        ash.schedule_definition(alert)

        self.assertEquals(2, ash.get_job_count())

        definition_json['enabled'] = False
        alert = PortAlert(definition_json, definition_json['source'])
        ash.schedule_definition(alert)

        # verify disabled alert not scheduled
        self.assertEquals(2, ash.get_job_count())

        definition_json['enabled'] = True
        pa = PortAlert(definition_json, definition_json['source'])
        ash.schedule_definition(pa)

        # verify enabled alert was scheduled
        self.assertEquals(3, ash.get_job_count())
  def test_load_definitions(self):
    scheduler = AlertSchedulerHandler(TEST_PATH, TEST_PATH, TEST_PATH, TEST_PATH, None)

    definitions = scheduler._AlertSchedulerHandler__load_definitions()

    self.assertEquals(len(definitions), 1)