Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_method(self, method):
super(MySQLMetricsCollectorTestCase, self).setup_method(method)
context._setup_object_tank()
self.mysql_obj = MySQLObject(
local_id=123,
pid=2,
cmd='/usr/sbin/mysqld --basedir=/usr',
conf_path='/etc/mysql/my.cnf',
)
context.objects.register(self.mysql_obj)
def setup_method(self, method):
super(PHPFPMPoolMetricsCollectorTestCase, self).setup_method(method)
context._setup_object_tank()
self.phpfpm_obj = PHPFPMObject(
local_id=123,
pid=2,
cmd='php-fpm: master process (/etc/php5/fpm/php-fpm.conf)',
conf_path='/etc/php5/fpm/php-fpm.conf',
workers=[3, 4]
)
context.objects.register(self.phpfpm_obj)
pool_data = {
'status_path': '/status',
'name': 'www',
'file': '/etc/php5/fpm/pool.d/www.conf',
'listen': '/run/php/php7.0-fpm.sock'
}
self.phpfpm_pool_obj = PHPFPMPoolObject(
local_id=124,
parent_local_id=123,
**pool_data
)
context.objects.register(self.phpfpm_pool_obj, parent_obj=self.phpfpm_obj)
def test_clean(self):
manager = NginxManager()
manager._discover_objects()
# check to see that there is now one nginx config
assert_that(context.nginx_configs, has_length(1))
self.stop_first_nginx()
manager._discover_objects()
# check to see that nginx object removed
assert_that(context.objects.find_all(types=manager.types), has_length(0))
# check that the nginx config is also removed
assert_that(context.nginx_configs, has_length(0))
# restart nginx to avoid teardown error
self.start_first_nginx()
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))
context.objects.register(self.phpfpm_obj)
pool_data = {
'status_path': '/status',
'name': 'www',
'file': '/etc/php5/fpm/pool.d/www.conf',
'listen': '/run/php/php7.0-fpm.sock'
}
self.phpfpm_pool_obj = PHPFPMPoolObject(
local_id=124,
parent_local_id=123,
**pool_data
)
context.objects.register(self.phpfpm_pool_obj, parent_obj=self.phpfpm_obj)
def root_uuid(self, meta):
meta['root_uuid'] = self.object.root_uuid or context.objects.root_object.uuid
def api_internal_url(self):
"""
Property that tracks back the plus_api_internal_url from the parent
nginx object and caching it. This cache works because child objects
are stopped and unregistered when nginx objects are modified
(restarted, etc.).
"""
if not self.api_internal_url_cache:
parent_obj = context.objects.find_parent(obj_id=self.id)
if parent_obj:
self.api_internal_url_cache = parent_obj.api_internal_url
return self.api_internal_url_cache
for object_manager_name in self.object_manager_order:
object_manager = self.object_managers[object_manager_name]
object_manager.run()
# run external object managers
external_object_managers = filter(lambda x: x not in self.object_manager_order, self.object_managers.keys())
for object_manager_name in external_object_managers:
object_manager = self.object_managers[object_manager_name]
object_manager.run()
# manage external regular managers
self.manage_external_managers()
# talk to cloud
try:
if context.objects.root_object:
if context.objects.root_object.definition and context.objects.root_object.definition_healthy:
context.inc_action_id()
self.talk_to_cloud(root_object=context.objects.root_object.definition)
else:
context.log.error('Problem with root object definition, agent stopping')
self.stop()
else:
pass
# context.default_log.debug('No root object defined during supervisor main run')
except AmplifyCriticalException:
pass
self.check_bridge()
except OSError as e:
if e.errno == 12: # OSError errno 12 is a memory error (unable to allocate, out of memory, etc.)
context.log.error('OSError: [Errno %s] %s' % (e.errno, e.message), exc_info=True)