How to use the amplify.agent.managers.nginx.NginxManager function in amplify

To help you get started, we’ve selected a few amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nginxinc / nginx-amplify-agent / test / unit / agent / managers / nginx.py View on Github external
def test_two_instances(self):
        manager = NginxManager()
        manager._discover_objects()
        obj = manager.objects.find_all(types=manager.types)[0]

        self.start_second_nginx()

        manager._discover_objects()
        assert_that(manager.objects.find_all(types=manager.types), has_length(2))

        local_ids = map(lambda x: x.local_id, manager.objects.find_all(types=manager.types))
        assert_that(local_ids, has_item(obj.local_id))
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / collectors / config.py View on Github external
def test_ssl_config_doesnt_work_if_ssl_disabled(self):
        # set upload_ssl to True
        context.app_config['containers']['nginx']['upload_ssl'] = False

        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
        collectors = nginx_obj.collectors
        cfg_collector = collectors[2]
        cfg_collector.collect()

        config = nginx_obj.configd.current
        assert_that(config['data']['ssl_certificates'], has_length(0))
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / nginx / meta.py View on Github external
def test_collect_meta(self):
        manager = NginxManager()
        manager._discover_objects()
        nginx_obj = manager.objects.find_all(types=manager.types)[0]

        collector = NginxMetaCollector(object=nginx_obj, interval=nginx_obj.intervals['meta'])
        assert_that(not_(collector.in_container))
        collector.collect()

        assert_that(nginx_obj.metad.current, contains_inanyorder(
            'type', 'local_id', 'root_uuid', 'running', 'stub_status_enabled', 'status_module_enabled', 'ssl',
            'stub_status_url', 'plus_status_url', 'version', 'plus', 'configure', 'packages', 'path',
            'built_from_source', 'parent_hostname', 'start_time', 'pid', 'display_name'
        ))
github nginxinc / nginx-amplify-agent / test / unit / agent / managers / plus.py View on Github external
plus_manager._discover_objects()
        assert_that(plus_manager.objects.find_all(types=plus_manager.types), has_length(10))

        self.stop_first_nginx()

        nginx_manager = NginxManager()
        nginx_manager._discover_objects()
        assert_that(nginx_manager.objects.objects_by_type[nginx_manager.type], has_length(0))

        plus_manager = PlusManager()
        plus_manager._discover_objects()
        assert_that(plus_manager.objects.find_all(types=plus_manager.types), has_length(0))

        self.start_first_nginx()

        nginx_manager = NginxManager()
        nginx_manager._discover_objects()
        assert_that(nginx_manager.objects.objects_by_type[nginx_manager.type], has_length(1))

        # get nginx object
        nginx_obj = nginx_manager.objects.objects[nginx_manager.objects.objects_by_type[nginx_manager.type][0]]

        # get metrics collector - the third in the list
        metrics_collector = nginx_obj.collectors[2]

        # run plus status - twice, because counters will appear only on the second run
        metrics_collector.plus_status()
        time.sleep(1)
        metrics_collector.plus_status()

        plus_manager = PlusManager()
        plus_manager._discover_objects()
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / collectors / metrics.py View on Github external
def test_plus_status(self):
        time.sleep(1)  # Give N+ some time to start
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # get metrics collector - the second from the list
        collectors = nginx_obj.collectors
        metrics_collector = collectors[1]

        # run plus status - twice, because counters will appear only on the second run
        metrics_collector.plus_status()
        time.sleep(1)
        metrics_collector.plus_status()

        # check counters
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / object.py View on Github external
def test_preserve_parse_errors_after_object_restart(self):
        self.start_first_nginx()
        manager = NginxManager()
        manager._discover_objects()

        # check that the config after parsing has no errors
        nginx_obj = manager.objects.find_all(types=manager.types)[0]
        nginx_obj.config.full_parse()
        assert_that(nginx_obj.config.parser_errors, has_length(0))

        nginx_obj.config.parser_errors.append('failed to parse /etc/nginx/nginx.conf')
        nginx_obj.need_restart = True
        # restart nginx and discover objects again
        self.restart_nginx()
        time.sleep(1)
        manager._discover_objects()

        # check that nginx object has parse errors after reload
        nginx_obj = manager.objects.find_all(types=manager.types)[0]
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / object.py View on Github external
def test_skip_upload_ssl(self):
        context.app_config['containers']['nginx']['upload_ssl'] = False
        manager = NginxManager()
        manager._discover_objects()

        # check that the config has only been parsed once (at startup)
        nginx_obj = manager.objects.find_all(types=manager.types)[0]

        assert_that(nginx_obj.upload_ssl, equal_to(False))
        assert_that(nginx_obj.config.ssl_certificates, has_length(0))
github nginxinc / nginx-amplify-agent / test / unit / agent / managers / nginx.py View on Github external
def test_restart(self):
        old_master, old_workers = self.get_master_workers()

        manager = NginxManager()
        manager._discover_objects()
        assert_that(manager.objects.find_all(types=manager.types), has_length(1))
        obj = manager.objects.find_all(types=manager.types)[0]
        assert_that(obj.pid, equal_to(old_master))
        assert_that(obj.workers, equal_to(old_workers))

        self.restart_nginx()
        new_master, new_workers = self.get_master_workers()

        manager._discover_objects()
        assert_that(manager.objects.find_all(types=manager.types), has_length(1))
        obj = manager.objects.find_all(types=manager.types)[0]
        assert_that(obj.pid, not_(equal_to(old_master)))
        assert_that(obj.pid, equal_to(new_master))
        assert_that(obj.workers, not_(equal_to(old_workers)))
        assert_that(obj.workers, equal_to(new_workers))
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / collectors / metrics.py View on Github external
def test_plus_status_priority(self):
        """
        Checks that if we can reach plus status then we don't use stub_status
        """
        time.sleep(1)  # Give N+ some time to start
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # check that it has n+ status and stub_status enabled
        assert_that(nginx_obj.plus_status_enabled, equal_to(True))
        assert_that(nginx_obj.stub_status_enabled, equal_to(True))

        # get metrics collector - the second from the list
        collectors = nginx_obj.collectors
        metrics_collector = collectors[1]

        # run status twice
        metrics_collector.status()
github nginxinc / nginx-amplify-agent / test / unit / agent / tanks / nginx_config.py View on Github external
def test_discover(self):
        assert_that(context.nginx_configs, has_length(0))

        # init manager and make sure that object count is 0
        manager = NginxManager()
        assert_that(context.objects.find_all(types=manager.types), has_length(0))

        # discover objects and make sure that there is now 1 managed nginx object
        manager._discover_objects()
        assert_that(context.objects.find_all(types=manager.types), has_length(1))

        # check to see that there is now one nginx config
        assert_that(context.nginx_configs, has_length(1))