예제 #1
0
    def test_use_new_vcl(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_use.return_value = [[200]]

        loader = VclLoader(varnish_api_mock)

        assert_true(VclStatus.OK, loader.use_vcl(Vcl('vcl content')))
예제 #2
0
    def test_do_not_load_new_vcl_if_it_can_not_be_compiled(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_inline.return_value = [[400]]

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.ERROR, loader.load_new_vcl(Vcl('vcl content')))
예제 #3
0
    def test_do_not_load_new_vcl_if_it_can_not_be_compiled(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_inline.return_value = [[400]]

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.ERROR, loader.load_new_vcl(Vcl('vcl content')))
예제 #4
0
    def test_load_new_vcl(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_inline.return_value = [[200]]

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.OK, loader.load_new_vcl(Vcl('vcl content')))
예제 #5
0
    def test_load_new_vcl(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_inline.return_value = [[200]]

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.OK, loader.load_new_vcl(Vcl('vcl content')))
예제 #6
0
    def test_use_new_vcl(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_use.return_value = [[200]]

        loader = VclLoader(varnish_api_mock)

        assert_true(VclStatus.OK, loader.use_vcl(Vcl('vcl content')))
예제 #7
0
    def test_return_error_if_cannot_discard_unused_vcl(self, varnish_api_mock):
        varnish_api_mock.vcls.return_value = {'available': ['unused-1', 'usused-2']}
        varnish_api_mock.vcl_discard.return_value = [[400]]

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.ERROR, loader.discard_unused_vcls())
        assert_equals([call('unused-1'), call('usused-2')], varnish_api_mock.vcl_discard.call_args_list)
예제 #8
0
    def test_do_not_load_new_vcl_if_no_changes(self, varnish_api_mock):
        varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol_cfff4'
        vcl = Mock()
        vcl.name = 'vcl-new-vol_cfff4'

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.NO_CHANGES, loader.load_new_vcl(vcl))
예제 #9
0
    def test_do_not_load_new_vcl_if_no_changes(self, varnish_api_mock):
        varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol.cfff4'
        vcl = Mock()
        vcl.name = 'vcl-new-vol.cfff4'

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.NO_CHANGES, loader.load_new_vcl(vcl))
예제 #10
0
    def test_should_suppress_varnish_command_execution_exception_if_proper_parameter_is_passed(
            self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_inline.side_effect = AssertionError()
        loader = VclLoader(varnish_api_mock, True)

        assert_equals(VclStatus.NO_CHANGES,
                      loader.load_new_vcl(Vcl('vcl content')))
예제 #11
0
    def test_return_error_if_cannot_discard_unused_vcl(self, varnish_api_mock):
        varnish_api_mock.vcls.return_value = {'available': ['unused-1', 'usused-2']}
        varnish_api_mock.vcl_discard.return_value = [[400]]

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.ERROR, loader.discard_unused_vcls())
        assert_equals([call('unused-1'), call('usused-2')], varnish_api_mock.vcl_discard.call_args_list)
예제 #12
0
    def test_vcl_is_not_changed(self, varnish_api_mock):
        varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol_cfff2'

        vcl = Vcl('vcl content')
        vcl.name = 'vcl-new-vol.cfff2'

        loader = VclLoader(varnish_api_mock)

        assert_false(loader.vcl_has_changed(vcl))
예제 #13
0
    def test_vcl_is_not_changed(self, varnish_api_mock):
        varnish_api_mock.vcl_active_name.return_value = 'vcl-current-vol.cfff2'

        vcl = Vcl('vcl content')
        vcl.name = 'vcl-new-vol.cfff2'

        loader = VclLoader(varnish_api_mock)

        assert_false(loader.vcl_has_changed(vcl))
예제 #14
0
    def load_vcl_list(self, vcl_list):
        to_use = []
        start = time.time()
        aggregated_result = True
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
            future_results = []
            for server, vcl in vcl_list:
                loader = VclLoader(self.api_provider.get_api(server))
                future_results.append(
                    tuple([
                        vcl, loader, server,
                        executor.submit(loader.load_new_vcl, vcl)
                    ]))

            for vcl, loader, server, future_result in future_results:
                result = future_result.result()
                if result == VclStatus.ERROR:
                    aggregated_result = False
                if result == VclStatus.OK:
                    to_use.append(tuple([vcl, loader, server]))

        if aggregated_result is False:
            raise VclLoadException

        self.logger.debug("vcl's loaded: %f" % (time.time() - start))

        return to_use
예제 #15
0
 def _append_vcl(self, vcl, server, future_results, executor):
     loader = VclLoader(self.api_provider.get_api(server))
     future_results.append(
         tuple([
             vcl, loader, server,
             executor.submit(loader.load_new_vcl, vcl)
         ]))
예제 #16
0
파일: cluster.py 프로젝트: sshyran/vaas
 def _append_vcl(self, vcl, server, future_results, executor):
     """Suppress exceptions if cannot load vcl for server in maintenance state"""
     loader = VclLoader(self.api_provider.get_api(server),
                        server.status == 'maintenance')
     future_results.append(
         tuple([
             vcl, loader, server,
             executor.submit(loader.load_new_vcl, vcl)
         ]))
예제 #17
0
 def _append_vcl(self, vcl, server, future_results, executor):
     """Suppress exceptions if cannot load vcl for server in maintenance state"""
     try:
         loader = VclLoader(self.api_provider.get_api(server),
                            server.status == 'maintenance')
         future_results.append(
             tuple([
                 vcl, loader, server,
                 executor.submit(loader.load_new_vcl, vcl)
             ]))
     except VclLoadException as e:
         if server.cluster.partial_reload:
             return
         raise e
예제 #18
0
    def test_do_not_discard_unused_vcl_if_not_exists(self, varnish_api_mock):
        varnish_api_mock.vcls.return_value = {'available': []}

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.NO_CHANGES, loader.discard_unused_vcls())
예제 #19
0
    def test_vcl_is_changed(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'

        loader = VclLoader(varnish_api_mock)

        assert_true(loader.vcl_has_changed(Vcl('vcl content')))
예제 #20
0
    def test_do_not_discard_unused_vcl_if_not_exists(self, varnish_api_mock):
        varnish_api_mock.vcls.return_value = {'available': []}

        loader = VclLoader(varnish_api_mock)

        assert_equals(VclStatus.NO_CHANGES, loader.discard_unused_vcls())
예제 #21
0
    def test_vcl_is_changed(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'

        loader = VclLoader(varnish_api_mock)

        assert_true(loader.vcl_has_changed(Vcl('vcl content')))
예제 #22
0
파일: test_loader.py 프로젝트: allegro/vaas
    def test_should_suppress_varnish_command_execution_exception_if_proper_parameter_is_passed(self, varnish_api_mock):
        varnish_api_mock.vcl_content_active.return_value = 'vcl old content'
        varnish_api_mock.vcl_inline.side_effect = AssertionError()
        loader = VclLoader(varnish_api_mock, True)

        assert_equals(VclStatus.NO_CHANGES, loader.load_new_vcl(Vcl('vcl content')))