Пример #1
0
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [
                {
                    'url': 'http://localhost:5050'
                }
            ]
        }

        mocks = {
            '_get_master_roles': lambda x, y, z: json.loads(Fixtures.read_file('roles.json')),
            '_get_master_stats': lambda x, y, z: json.loads(Fixtures.read_file('stats.json')),
            '_get_master_state': lambda x, y, z: json.loads(Fixtures.read_file('state.json')),
        }

        klass = get_check_class('mesos_master')
        check = klass('mesos_master', {}, {})
        self.run_check_twice(config, mocks=mocks)
        metrics = {}
        for d in (check.CLUSTER_TASKS_METRICS, check.CLUSTER_SLAVES_METRICS,
                  check.CLUSTER_RESOURCES_METRICS, check.CLUSTER_REGISTRAR_METRICS,
                  check.CLUSTER_FRAMEWORK_METRICS, check.SYSTEM_METRICS, check.STATS_METRICS):
            metrics.update(d)
        [self.assertMetric(v[0]) for k, v in check.FRAMEWORK_METRICS.iteritems()]
        [self.assertMetric(v[0]) for k, v in metrics.iteritems()]
        [self.assertMetric(v[0]) for k, v in check.ROLE_RESOURCES_METRICS.iteritems()]
        self.assertMetric('mesos.cluster.total_frameworks')
        self.assertMetric('mesos.framework.total_tasks')
        self.assertMetric('mesos.role.frameworks.count')
        self.assertMetric('mesos.role.weight')
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [
                {
                    'url': 'http://localhost:5051',
                    'tasks': ['hello']
                }
            ]
        }

        mocks = {
            '_get_stats': lambda x, y, z: json.loads(
                Fixtures.read_file('stats.json', sdk_dir=self.FIXTURE_DIR)),
            '_get_state': lambda x, y, z: json.loads(
                Fixtures.read_file('state.json', sdk_dir=self.FIXTURE_DIR))
        }

        klass = get_check_class('mesos_slave')
        check = klass('mesos_slave', {}, {})
        self.run_check_twice(config, mocks=mocks)
        metrics = {}
        for d in (check.SLAVE_TASKS_METRICS, check.SYSTEM_METRICS, check.SLAVE_RESOURCE_METRICS,
                  check.SLAVE_EXECUTORS_METRICS, check.STATS_METRICS):
            metrics.update(d)
        [self.assertMetric(v[0]) for k, v in check.TASK_METRICS.iteritems()]
        [self.assertMetric(v[0]) for k, v in metrics.iteritems()]
        self.assertServiceCheck('hello.ok', count=1, status=AgentCheck.OK)
Пример #3
0
    def test_check(self):
        """Integration test for supervisord check. Using a mocked supervisord."""
        check_class = get_check_class('supervisord')
        agentConfig = {'version': '0.1', 'api_key': 'tota'}

        for tc in self.TEST_CASES:
            check, instances = check_class.from_yaml(yaml_text=tc['yaml'],
                                                     check_name='supervisord',
                                                     agentConfig=agentConfig)

            self.assertTrue(check is not None, msg=check)
            self.assertEquals(tc['expected_instances'], instances)
            for instance in instances:
                name = instance['name']

                try:
                    # Run the check
                    check.check(instance)
                except Exception as e:
                    if 'error_message' in tc:  # excepted error
                        self.assertEquals(str(e), tc['error_message'])
                    else:
                        self.assertTrue(False, msg=str(e))
                else:
                    # Assert that the check collected the right metrics
                    expected_metrics = tc['expected_metrics'][name]
                    self.assert_metrics(expected_metrics, check.get_metrics())

                    # Assert that the check generated the right service checks
                    expected_service_checks = tc['expected_service_checks'][
                        name]
                    self.assert_service_checks(expected_service_checks,
                                               check.get_service_checks())
Пример #4
0
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [
                {
                    'url': 'http://localhost:5051',
                    'tasks': ['hello']
                }
            ]
        }

        mocks = {
            '_get_stats': lambda x, y, z: json.loads(Fixtures.read_file('stats.json')),
            '_get_state': lambda x, y, z: json.loads(Fixtures.read_file('state.json'))
        }

        klass = get_check_class('mesos_slave')
        check = klass('mesos_slave', {}, {})
        self.run_check_twice(config, mocks=mocks)
        metrics = {}
        for d in (check.SLAVE_TASKS_METRICS, check.SYSTEM_METRICS, check.SLAVE_RESOURCE_METRICS,
                  check.SLAVE_EXECUTORS_METRICS, check.STATS_METRICS):
            metrics.update(d)
        [self.assertMetric(v[0]) for k, v in check.TASK_METRICS.iteritems()]
        [self.assertMetric(v[0]) for k, v in metrics.iteritems()]
        self.assertServiceCheck('hello.ok', count=1, status=AgentCheck.OK)
Пример #5
0
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [
                {
                    'url': 'http://localhost:5050'
                }
            ]
        }

        klass = get_check_class('mesos_master')
        with patch.object(klass, '_get_master_state', _mocked_get_master_state):
            with patch.object(klass, '_get_master_stats', _mocked_get_master_stats):
                with patch.object(klass, '_get_master_roles', _mocked_get_master_roles):
                    check = klass('mesos_master', {}, {})
                    self.run_check_twice(config)
                    metrics = {}
                    for d in (check.CLUSTER_TASKS_METRICS, check.CLUSTER_SLAVES_METRICS,
                              check.CLUSTER_RESOURCES_METRICS, check.CLUSTER_REGISTRAR_METRICS,
                              check.CLUSTER_FRAMEWORK_METRICS, check.SYSTEM_METRICS, check.STATS_METRICS):
                        metrics.update(d)
                    [self.assertMetric(v[0]) for k, v in check.FRAMEWORK_METRICS.iteritems()]
                    [self.assertMetric(v[0]) for k, v in metrics.iteritems()]
                    [self.assertMetric(v[0]) for k, v in check.ROLE_RESOURCES_METRICS.iteritems()]
                    self.assertMetric('mesos.cluster.total_frameworks')
                    self.assertMetric('mesos.framework.total_tasks')
                    self.assertMetric('mesos.role.frameworks.count')
                    self.assertMetric('mesos.role.weight')
Пример #6
0
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [{
                'url': 'http://localhost:5050',
                'tasks': ['hello']
            }]
        }

        klass = get_check_class('mesos_slave')
        with patch.object(klass, '_get_state', _mocked_get_state):
            with patch.object(klass, '_get_stats', _mocked_get_stats):
                check = klass('mesos_slave', {}, {})
                self.run_check_twice(config)
                metrics = {}
                for d in (check.SLAVE_TASKS_METRICS, check.SYSTEM_METRICS,
                          check.SLAVE_RESOURCE_METRICS,
                          check.SLAVE_EXECUTORS_METRICS, check.STATS_METRICS):
                    metrics.update(d)
                [
                    self.assertMetric(v[0])
                    for k, v in check.TASK_METRICS.iteritems()
                ]
                [self.assertMetric(v[0]) for k, v in metrics.iteritems()]
                self.assertServiceCheck('hello.ok',
                                        count=1,
                                        status=AgentCheck.OK)
Пример #7
0
    def test_tag_include_all(self):
        """exclude all, except ubuntu and debian."""
        instance = {
            'include': [],
            'exclude': [
                'docker_image:ubuntu',
                'docker_image:debian',
            ],
        }

        klass = get_check_class('docker')
        # NO-OP but loads the check
        with patch.object(klass, '_find_cgroup', _mocked_find_cgroup):
            check = klass('docker', {}, {})

        check._prepare_filters(instance)
        self.assertEquals(len(instance['exclude_patterns']), 2)
        self.assertEquals(len(instance['include_patterns']), 0)

        truth_table_exclusion = {
            'some_tag': False,
            'debian:ubuntu': False,
            'docker_image:centos': False,
            'docker_image:ubuntu': True,
            'docker_image:debian': True,
        }

        for tag, val in truth_table_exclusion.iteritems():
            self.assertEquals(
                check._is_container_excluded(instance, [tag]),
                val,
                "{0} expected {1} but is not".format(tag, val)
            )
Пример #8
0
    def test_tag_include_all(self):
        """ exclude all, except ubuntu and debian. """
        instance = {
            'include': [],
            'exclude': [
                'docker_image:ubuntu',
                'docker_image:debian',
            ],
        }

        klass = get_check_class('docker')
        # NO-OP but loads the check
        with patch.object(klass, '_find_cgroup', _mocked_find_cgroup):
            check = klass('docker', {}, {})

        check._prepare_filters(instance)
        self.assertEquals(len(instance['exclude_patterns']), 2)
        self.assertEquals(len(instance['include_patterns']), 0)

        truth_table_exclusion = {
            'some_tag': False,
            'debian:ubuntu': False,
            'docker_image:centos': False,
            'docker_image:ubuntu': True,
            'docker_image:debian': True,
        }

        for tag, val in truth_table_exclusion.iteritems():
            self.assertEquals(
                check._is_container_excluded(instance, [tag]),
                val,
                "{0} expected {1} but is not".format(tag, val)
            )
    def test_check(self):
        """Integration test for supervisord check. Using a mocked supervisord."""
        check_class = get_check_class('supervisord')
        agentConfig = {
            'version': '0.1',
            'api_key': 'tota'
        }

        for tc in self.TEST_CASES:
            check, instances = check_class.from_yaml(yaml_text=tc['yaml'],
                                                     check_name='supervisord',
                                                     agentConfig=agentConfig)

            self.assertTrue(check is not None, msg=check)
            self.assertEquals(tc['expected_instances'], instances)
            for instance in instances:
                name = instance['name']

                try:
                    # Run the check
                    check.check(instance)
                except Exception as e:
                    if 'error_message' in tc:  # excepted error
                        self.assertEquals(str(e), tc['error_message'])
                    else:
                        self.assertTrue(False, msg=str(e))
                else:
                    # Assert that the check collected the right metrics
                    expected_metrics = tc['expected_metrics'][name]
                    self.assert_metrics(expected_metrics, check.get_metrics())

                    # Assert that the check generated the right service checks
                    expected_service_checks = tc['expected_service_checks'][name]
                    self.assert_service_checks(expected_service_checks,
                                               check.get_service_checks())
Пример #10
0
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [{
                'url': 'http://localhost:5050',
                'tags': ['instance:mytag1']
            }]
        }

        mocks = {
            '_get_master_roles':
            lambda v, x, y, z: json.loads(
                Fixtures.read_file('roles.json', sdk_dir=self.FIXTURE_DIR)),
            '_get_master_stats':
            lambda v, x, y, z: json.loads(
                Fixtures.read_file('stats.json', sdk_dir=self.FIXTURE_DIR)),
            '_get_master_state':
            lambda v, x, y, z: json.loads(
                Fixtures.read_file('state.json', sdk_dir=self.FIXTURE_DIR)),
        }

        klass = get_check_class('mesos_master')
        check = klass('mesos_master', {}, {})
        self.run_check_twice(config, mocks=mocks)
        metrics = {}
        for d in (check.CLUSTER_TASKS_METRICS, check.CLUSTER_SLAVES_METRICS,
                  check.CLUSTER_RESOURCES_METRICS,
                  check.CLUSTER_REGISTRAR_METRICS,
                  check.CLUSTER_FRAMEWORK_METRICS, check.SYSTEM_METRICS,
                  check.STATS_METRICS):
            metrics.update(d)
        [
            self.assertMetric(v[0])
            for k, v in check.FRAMEWORK_METRICS.iteritems()
        ]
        [self.assertMetric(v[0]) for k, v in metrics.iteritems()]
        [
            self.assertMetric(v[0])
            for k, v in check.ROLE_RESOURCES_METRICS.iteritems()
        ]
        self.assertMetric('mesos.cluster.total_frameworks')
        self.assertMetric('mesos.framework.total_tasks')
        self.assertMetric('mesos.role.frameworks.count')
        self.assertMetric('mesos.role.weight')
    def test_build_message(self):
        """Unit test supervisord build service check message."""
        process = {
            'now': 1414815513,
            'group': 'mysql',
            'description': 'pid 787, uptime 0:02:05',
            'pid': 787,
            'stderr_logfile': '/var/log/supervisor/mysql-stderr---supervisor-3ATI82.log',
            'stop': 0,
            'statename': 'RUNNING',
            'start': 1414815388,
            'state': 20,
            'stdout_logfile': '/var/log/mysql/mysql.log',
            'logfile': '/var/log/mysql/mysql.log',
            'exitstatus': 0,
            'spawnerr': '',
            'name': 'mysql'
        }

        expected_message = """Current time: 2014-11-01 04:18:33
Process name: mysql
Process group: mysql
Description: pid 787, uptime 0:02:05
Error log file: /var/log/supervisor/mysql-stderr---supervisor-3ATI82.log
Stdout log file: /var/log/mysql/mysql.log
Log file: /var/log/mysql/mysql.log
State: RUNNING
Start time: 2014-11-01 04:16:28
Stop time: \nExit Status: 0"""

        check_class = get_check_class('supervisord')
        agentConfig = {
            'version': '0.1',
            'api_key': 'tota'
        }
        check, _ = check_class.from_yaml(yaml_text=self.TEST_CASES[0]['yaml'],
                                         check_name='supervisord',
                                         agentConfig=agentConfig)
        self.assertEquals(expected_message, check._build_message(process))
Пример #12
0
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [
                {
                    'url': 'http://localhost:5050',
                    'tasks': ['hello']
                }
            ]
        }

        klass = get_check_class('mesos_slave')
        with patch.object(klass, '_get_state', _mocked_get_state):
            with patch.object(klass, '_get_stats', _mocked_get_stats):
                check = klass('mesos_slave', {}, {})
                self.run_check_twice(config)
                metrics = {}
                for d in (check.SLAVE_TASKS_METRICS, check.SYSTEM_METRICS, check.SLAVE_RESOURCE_METRICS,
                          check.SLAVE_EXECUTORS_METRICS, check.STATS_METRICS):
                    metrics.update(d)
                [self.assertMetric(v[0]) for k, v in check.TASK_METRICS.iteritems()]
                [self.assertMetric(v[0]) for k, v in metrics.iteritems()]
                self.assertServiceCheck('hello.ok', count=1, status=AgentCheck.OK)
Пример #13
0
    def test_build_message(self):
        """Unit test supervisord build service check message."""
        process = {
            'now': 1414815513,
            'group': 'mysql',
            'description': 'pid 787, uptime 0:02:05',
            'pid': 787,
            'stderr_logfile':
            '/var/log/supervisor/mysql-stderr---supervisor-3ATI82.log',
            'stop': 0,
            'statename': 'RUNNING',
            'start': 1414815388,
            'state': 20,
            'stdout_logfile': '/var/log/mysql/mysql.log',
            'logfile': '/var/log/mysql/mysql.log',
            'exitstatus': 0,
            'spawnerr': '',
            'name': 'mysql'
        }

        expected_message = """Current time: 2014-11-01 04:18:33
Process name: mysql
Process group: mysql
Description: pid 787, uptime 0:02:05
Error log file: /var/log/supervisor/mysql-stderr---supervisor-3ATI82.log
Stdout log file: /var/log/mysql/mysql.log
Log file: /var/log/mysql/mysql.log
State: RUNNING
Start time: 2014-11-01 04:16:28
Stop time: \nExit Status: 0"""

        check_class = get_check_class('supervisord')
        agentConfig = {'version': '0.1', 'api_key': 'tota'}
        check, _ = check_class.from_yaml(yaml_text=self.TEST_CASES[0]['yaml'],
                                         check_name='supervisord',
                                         agentConfig=agentConfig)
        self.assertEquals(expected_message, check._build_message(process))
Пример #14
0
    def test_checks(self):
        config = {
            'init_config': {},
            'instances': [{
                'url': 'http://*****:*****@127.0.0.1:5051', 'task_name:hello'
        ]
        self.assertServiceCheck('hello.ok',
                                tags=service_check_tags,
                                count=1,
                                status=AgentCheck.OK)