예제 #1
0
    def setup_method(self, method):
        super(PHPFPMMetaCollectorTestCase, self).setup_method(method)
        context._setup_object_tank()

        phpfpm_manager = PHPFPMManager()
        phpfpm_manager._discover_objects()
        found_masters = context.objects.find_all(types=phpfpm_manager.types)

        self.phpfpm_obj = found_masters[0]
예제 #2
0
    def test_discover_objects(self):
        phpfpm_manager = PHPFPMManager()
        assert_that(phpfpm_manager, not_none())

        # check to make sure there are no masters
        current_masters = context.objects.find_all(types=phpfpm_manager.types)
        assert_that(current_masters, has_length(0))

        # find masters
        phpfpm_manager._discover_objects()

        # check to see that a master is found
        current_masters = context.objects.find_all(types=phpfpm_manager.types)
        assert_that(current_masters, has_length(1))
예제 #3
0
    def test_find_all(self):
        phpfpm_manager = PHPFPMManager()
        assert_that(phpfpm_manager, not_none())

        found_masters = phpfpm_manager._find_all()
        assert_that(found_masters, not_none())
        assert_that(found_masters, has_length(1))

        found_master = found_masters[0]
        assert_that(
            found_master['cmd'],
            equal_to('php-fpm: master process (/etc/php5/fpm/php-fpm.conf)'))
        assert_that(found_master['conf_path'],
                    equal_to('/etc/php5/fpm/php-fpm.conf'))
        assert_that(found_master['pid'], not_none())
        assert_that(
            found_master['local_id'],
            equal_to(
                'af230c9e0343ec22e88333783e89857a0f5129b0fd8e4cfe21e12b1ae35fb3b4'
            ))
        assert_that(found_master['workers'], has_length(4))
예제 #4
0
    def test_find_all(self):
        phpfpm_manager = PHPFPMManager()
        assert_that(phpfpm_manager, not_none())

        found_masters = phpfpm_manager._find_all()
        assert_that(found_masters, not_none())
        assert_that(found_masters, has_length(1))

        found_master = found_masters[0]
        assert_that(
            found_master['cmd'],
            equal_to('php-fpm: master process (/etc/php5/fpm/php-fpm.conf)'))
        assert_that(found_master['conf_path'],
                    equal_to('/etc/php5/fpm/php-fpm.conf'))
        assert_that(found_master['pid'], not_none())
        assert_that(
            found_master['local_id'],
            equal_to(
                'e5942daaa5bf35af722bac3b9582b17c07515f0f77936fb5c7f771c7736cc157'
            ))
        assert_that(found_master['workers'], has_length(4))
예제 #5
0
    def test_bad_ps(self):
        phpfpm_manager = PHPFPMManager()
        assert_that(phpfpm_manager, not_none())

        bad_ps_stdout = [
            '15923     1 php-fpm: master process (/etc/php-fpm.conf)',
            '20704 15923 php-fpm: pool www',
            '20925 15923 php-fpm: pool www',
            '21350 15923 php-fpm: pool www',
            '21385 15923 php-fpm: pool www',
            '21386 15923 php-fpm: pool www',
            '21575 15923 php-fpm: pool www',
            '21699 15923 php-fpm: pool www',
            '21734 15923 php-fpm: pool www',
            '21735 15923 php-fpm: pool www',
            '21781 15923 php-fpm: pool www',
            '21782 15923 php-fpm: pool www',
            '22287 15923 php-fpm: pool www',
            '22330 15923 php-fpm: pool www',
            '22331 15923 php-fpm: pool www',
            '22495 15923 php-fpm: pool www',
            '22654 21386 php-fpm: pool www',  # <---- Wut?
            ''
        ]  # 16 workers

        found_masters = phpfpm_manager._find_all(ps=bad_ps_stdout)
        assert_that(found_masters, not_none())
        assert_that(found_masters, has_length(1))  # ignore the second worker

        found_master = found_masters[0]
        assert_that(found_master['cmd'],
                    equal_to('php-fpm: master process (/etc/php-fpm.conf)'))
        assert_that(found_master['conf_path'], equal_to('/etc/php-fpm.conf'))
        assert_that(found_master['pid'], not_none())
        assert_that(
            found_master['local_id'],
            equal_to(
                '435ef2cd03cd3487d4c2f7c7047706c48bd61b4b34c99e96e1d5608e264893ed'
            ))
        assert_that(found_master['workers'], has_length(15))
예제 #6
0
    def test_restart_objects(self):
        phpfpm_manager = PHPFPMManager()
        assert_that(phpfpm_manager, not_none())

        # check to make sure there are no masters
        current_masters = context.objects.find_all(types=phpfpm_manager.types)
        assert_that(current_masters, has_length(0))

        # find masters
        phpfpm_manager._discover_objects()

        # check to see that a master is found
        current_masters = context.objects.find_all(types=phpfpm_manager.types)
        assert_that(current_masters, has_length(1))

        # store the master id
        old_master_id = current_masters[0].id

        # stop php-fpm
        self.stop_fpm()

        time.sleep(0.1)  # release gil

        # restart php-fpm
        self.start_fpm()

        time.sleep(0.1)  # release gil

        # re-discover
        phpfpm_manager._discover_objects()

        # check to make sure there are no masters
        current_masters = context.objects.find_all(types=phpfpm_manager.types)
        assert_that(current_masters, has_length(1))

        master_id = current_masters[0].id
        assert_that(master_id, not_(equal_to(old_master_id)))
예제 #7
0
 def setup_method(self, method):
     super(PHPFPMPoolManagerTestCase, self).setup_method(method)
     context._setup_object_tank()
     self.phpfpm_manager = PHPFPMManager()
     self.phpfpm_manager._discover_objects()