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]
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))
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))
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))
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))
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)))
def setup_method(self, method): super(PHPFPMPoolManagerTestCase, self).setup_method(method) context._setup_object_tank() self.phpfpm_manager = PHPFPMManager() self.phpfpm_manager._discover_objects()
class PHPFPMPoolManagerTestCase(PHPFPMTestCase): """ Test case for PHPFPMPoolManager. """ def setup_method(self, method): super(PHPFPMPoolManagerTestCase, self).setup_method(method) context._setup_object_tank() self.phpfpm_manager = PHPFPMManager() self.phpfpm_manager._discover_objects() def teardown_method(self, method): context._setup_object_tank() super(PHPFPMPoolManagerTestCase, self).teardown_method(method) def test_find_all(self): pool_manager = PHPFPMPoolManager() assert_that(pool_manager, not_none()) found_pools = pool_manager._find_all() assert_that(found_pools, not_none()) assert_that(found_pools, has_length(2)) # This checks the first pool in the found_pools and makes assumptions # as to which one it will be. This may not be true on other test # systems found_pool = found_pools[0] assert_that(found_pool['parent_id'], equal_to(1)) assert_that(found_pool['parent_local_id'], equal_to( 'af230c9e0343ec22e88333783e89857a0f5129b0fd8e4cfe21e12b1ae35fb3b4' )) assert_that(found_pool['local_id'], equal_to( 'e0b5a78cc437378205afc20c5f30d904936771605266aaee39917556e994bdfe' )) assert_that(found_pool['file'], equal_to('/etc/php5/fpm/pool.d/www.conf')) assert_that(found_pool['name'], equal_to('www')) assert_that(found_pool['listen'], equal_to('/run/php/php7.0-fpm.sock')) assert_that(found_pool['status_path'], equal_to('/status')) def test_discover_objects(self): pool_manager = PHPFPMPoolManager() assert_that(pool_manager, not_none()) # check to make sure there are no pools current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(0)) # find pools pool_manager._discover_objects() # check that a pool is found current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(2)) def test_remove(self): pool_manager = PHPFPMPoolManager() assert_that(pool_manager, not_none()) # check to make sure there are no pools current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(0)) # find pools pool_manager._discover_objects() # check that a pool is found current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(2)) # stop php-fpm self.stop_fpm() time.sleep(0.1) # release gil # re-run master manager to remove the master self.phpfpm_manager._discover_objects() # check to see pools are also removed current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(0))
class PHPFPMPoolManagerTestCase(PHPFPMTestCase): def setup_method(self, method): super(PHPFPMPoolManagerTestCase, self).setup_method(method) context._setup_object_tank() self.phpfpm_manager = PHPFPMManager() self.phpfpm_manager._discover_objects() def teardown_method(self, method): context._setup_object_tank() super(PHPFPMPoolManagerTestCase, self).teardown_method(method) def test_find_all(self): pool_manager = PHPFPMPoolManager() assert_that(pool_manager, not_none()) found_pools = pool_manager._find_all() assert_that(found_pools, not_none()) assert_that(found_pools, has_length(2)) # This checks the first pool in the found_pools and makes assumptions # as to which one it will be. This may not be true on other test # systems found_pool = found_pools[0] assert_that(found_pool['parent_id'], equal_to(1)) assert_that( found_pool['parent_local_id'], equal_to( 'e5942daaa5bf35af722bac3b9582b17c07515f0f77936fb5c7f771c7736cc157' )) assert_that( found_pool['local_id'], equal_to( '6eea242cd7825e81d309458c302b8bd18923812eb99ae70f2e8b5c5fb18d02b3' )) assert_that(found_pool['file'], equal_to('/etc/php5/fpm/pool.d/www.conf')) assert_that(found_pool['name'], equal_to('www')) assert_that(found_pool['listen'], equal_to('/run/php/php7.0-fpm.sock')) assert_that(found_pool['status_path'], equal_to('/status')) def test_discover_objects(self): pool_manager = PHPFPMPoolManager() assert_that(pool_manager, not_none()) # check to make sure there are no pools current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(0)) # find pools pool_manager._discover_objects() # check that a pool is found current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(2)) def test_remove(self): pool_manager = PHPFPMPoolManager() assert_that(pool_manager, not_none()) # check to make sure there are no pools current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(0)) # find pools pool_manager._discover_objects() # check that a pool is found current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(2)) # stop php-fpm self.stop_fpm() time.sleep(0.1) # release gil # re-run master manager to remove the master self.phpfpm_manager._discover_objects() # check to see pools are also removed current_pools = context.objects.find_all(types=pool_manager.types) assert_that(current_pools, has_length(0))