Пример #1
0
    def test_bad_plus_status_discovery_with_config(self):
        amplify.agent.context.context.app_config['nginx']['plus_status'] = '/foo_plus'
        amplify.agent.context.context.app_config['nginx']['stub_status'] = '/foo_basic'

        self.stop_first_nginx()
        self.start_second_nginx(conf='nginx_bad_status.conf')
        container = NginxContainer()
        container.discover_objects()
        assert_that(container.objects, has_length(1))

        # self.http_request should look like this
        # [
        # first - internal plus statuses
        # 'http://127.0.0.1:82/plus_status', 'https://127.0.0.1:82/plus_status',
        # 'http://127.0.0.1/foo_plus', 'https://127.0.0.1/foo_plus',
        #
        # then external plus statuses
        # 'http://bad.status.naas.nginx.com:82/plus_status', 'https://bad.status.naas.nginx.com:82/plus_status',
        #
        # finally - stub statuses
        # 'http://127.0.0.1:82/basic_status', 'https://127.0.0.1:82/basic_status',
        # 'http://127.0.0.1/foo_basic', 'https://127.0.0.1/foo_basic'
        # ]

        assert_that(self.http_requests[2], equal_to('http://127.0.0.1/foo_plus'))
        assert_that(self.http_requests[-2], equal_to('http://127.0.0.1/foo_basic'))
Пример #2
0
    def test_collect(self):
        container = NginxContainer()
        container.discover_objects()

        nginx_obj = container.objects.values().pop(0)
        collectors = nginx_obj.collectors
        cfg_collector = collectors[2]

        # run collect
        cfg_collector.collect()
        assert_that(nginx_obj.configd.current, not_(equal_to({})))
Пример #3
0
    def test_bad_stub_status_discovery_with_config(self):
        amplify.agent.context.context.app_config['nginx']['stub_status'] = '/foo_basic'

        self.stop_first_nginx()
        self.start_second_nginx(conf='nginx_bad_status.conf')
        container = NginxContainer()
        container.discover_objects()
        assert_that(container.objects, has_length(1))

        assert_that(self.http_requests[-1], equal_to('https://127.0.0.1/foo_basic'))
        assert_that(self.http_requests[-2], equal_to('http://127.0.0.1/foo_basic'))
Пример #4
0
    def test_two_instances(self):
        container = NginxContainer()
        container.discover_objects()
        obj = container.objects.values().pop(0)

        self.start_second_nginx()

        container.discover_objects()
        assert_that(container.objects.values(), has_length(2))

        local_ids = map(lambda x: x.local_id, container.objects.values())
        assert_that(local_ids, has_item(obj.local_id))
Пример #5
0
    def test_bad_plus_status_discovery(self):
        self.stop_first_nginx()
        self.start_second_nginx(conf='nginx_bad_status.conf')
        container = NginxContainer()
        container.discover_objects()

        assert_that(container.objects, has_length(1))

        # get nginx object
        nginx_obj = container.objects.values().pop(0)

        # check all plus status urls
        assert_that(nginx_obj.plus_status_enabled, equal_to(True))
        assert_that(nginx_obj.plus_status_internal_url, equal_to(None))
        assert_that(nginx_obj.plus_status_external_url, equal_to('http://bad.status.naas.nginx.com:82/plus_status'))
Пример #6
0
    def test_ssl_config_doesnt_work_if_ssl_disabled(self):
        # set upload_ssl to True
        context.app_config['containers']['nginx']['upload_ssl'] = False

        container = NginxContainer()
        container.discover_objects()
        assert_that(container.objects, has_length(1))

        # get nginx object
        nginx_obj = container.objects.values().pop(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))
Пример #7
0
    def test_plus_status_discovery(self):
        """
        Checks that for plus nginx we collect two status urls:
        - one for web link (with server name)
        - one for agent purposes (local url)
        """
        container = NginxContainer()
        container.discover_objects()
        assert_that(container.objects, has_length(1))

        # get nginx object
        nginx_obj = container.objects.values().pop(0)

        # check all plus status urls
        assert_that(nginx_obj.plus_status_enabled, equal_to(True))
        assert_that(nginx_obj.plus_status_internal_url, equal_to('https://127.0.0.1:443/plus_status'))
        assert_that(nginx_obj.plus_status_external_url, equal_to('http://status.naas.nginx.com:443/plus_status_bad'))
Пример #8
0
    def test_reload(self):
        old_master, old_workers = self.get_master_workers()

        container = NginxContainer()
        container.discover_objects()
        assert_that(container.objects, has_length(1))
        obj = container.objects.values().pop(0)
        # The following assertion is unreliable for some reason.
        assert_that(obj.pid, equal_to(old_master))
        assert_that(obj.workers, equal_to(old_workers))

        self.reload_nginx()
        new_master, new_workers = self.get_master_workers()
        assert_that(new_master, equal_to(old_master))

        container.discover_objects()
        obj = container.objects.values().pop(0)
        assert_that(obj.pid, equal_to(old_master))
        assert_that(obj.workers, not_(equal_to(old_workers)))
        assert_that(obj.workers, equal_to(new_workers))
Пример #9
0
    def test_restart(self):
        old_master, old_workers = self.get_master_workers()

        container = NginxContainer()
        container.discover_objects()
        assert_that(container.objects, has_length(1))
        obj = container.objects.values().pop(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()

        container.discover_objects()
        assert_that(container.objects, has_length(1))
        obj = container.objects.values().pop(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))
Пример #10
0
    def test_test_run_time(self):
        container = NginxContainer()
        container.discover_objects()

        nginx_obj = container.objects.values().pop(0)
        collectors = nginx_obj.collectors
        cfg_collector = collectors[2]
        assert_that(nginx_obj.run_config_test, equal_to(True))

        # set maximum run time for test to 0.0
        context.app_config['containers']['nginx']['max_test_duration'] = 0.0

        # run collect
        cfg_collector.collect()
        assert_that(nginx_obj.run_config_test, equal_to(False))
        events = nginx_obj.eventd.current.values()
        messages = []
        for event in events:
            messages.append(event.message)

        assert_that(messages, has_item(starts_with('/usr/sbin/nginx -t -c /etc/nginx/nginx.conf took')))