示例#1
0
    def setup_method(self, method):
        super(MySQLMetaCollectorTestCase, self).setup_method(method)
        context._setup_object_tank()

        mysql_manager = MySQLManager()
        mysql_manager._discover_objects()
        found_objects = context.objects.find_all(types=mysql_manager.types)

        self.mysql_object = found_objects[0]
    def test_discover_objects(self):
        mysql_manager = MySQLManager()
        assert_that(mysql_manager, not_none())

        # check to make sure there are no mysqlds
        mysql_objects = context.objects.find_all(types=mysql_manager.types)
        assert_that(mysql_objects, has_length(0))

        # find objects
        mysql_manager._discover_objects()

        # check to see that a mysqld is found
        mysql_objects = context.objects.find_all(types=mysql_manager.types)
        assert_that(mysql_objects, has_length(1))
示例#3
0
    def test_collect_remote(self):
        context.app_config['mysql']['remote'] = True
        context.app_config['mysql']['host'] = '127.0.0.1'
        context.app_config['mysql']['port'] = '3306'
        context.app_config['mysql'].pop('unix_socket', None)
        mysql_manager = MySQLManager()
        mysql_manager._discover_objects()
        found_objects = context.objects.find_all(types=mysql_manager.types)

        self.mysql_object = found_objects[0]
        mysql_meta_collector = MySQLMetaCollector(
            object=self.mysql_object,
            interval=self.mysql_object.intervals['meta'])

        # collect and assert that meta is not empty
        mysql_meta_collector.collect()

        # check value
        assert_that(
            mysql_meta_collector.meta,
            has_entries({
                'display_name': 'mysql @ hostname.nginx',
                'local_id':
                'd47bcca34c2b2836266086c5d5d428b754cc4831e2df6e251b2ffa27bca59b3b',
                'type': 'mysql',
                'cmd': 'unknown',
                'pid': 'unknown',
                'conf_path': 'unknown',
                'root_uuid': DEFAULT_UUID,
                'bin_path': 'unknown',
                'connection_location': '127.0.0.1:3306',
                'version': starts_with('5.5'),
            }))

        # check that it matches the object metad
        assert_that(mysql_meta_collector.meta,
                    equal_to(self.mysql_object.metad.current))
    def test_restart_objects(self):
        mysql_manager = MySQLManager()
        assert_that(mysql_manager, not_none())

        # check to make sure there are no mysqlds
        mysql_objects = context.objects.find_all(types=mysql_manager.types)
        assert_that(mysql_objects, has_length(0))

        # find objects
        mysql_manager._discover_objects()

        # check to see that a mysqld is found
        mysql_objects = context.objects.find_all(types=mysql_manager.types)
        assert_that(mysql_objects, has_length(1))

        # store the mysqld id
        old_master_id = mysql_objects[0].id

        # stop mysqld
        self.stop_mysqld()

        time.sleep(0.1)

        # restart mysqld
        self.start_mysqld()

        time.sleep(0.1)

        # re-discover
        mysql_manager._discover_objects()

        # check to see that a mysql is found
        mysql_objects = context.objects.find_all(types=mysql_manager.types)
        assert_that(mysql_objects, has_length(1))

        master_id = mysql_objects[0].id
        assert_that(master_id, not_(equal_to(old_master_id)))