Exemple #1
0
    def test_instances_tab_exception(self):
        try:
            config = self.database_configurations.first()

            # setup the configuration parameter manager
            config_param_mgr = config_param_manager.ConfigParamManager(
                config.id)
            config_param_mgr.configuration = config
            config_param_mgr.original_configuration_values = \
                dict.copy(config.values)

            self.mock_get.return_value = config_param_mgr

            self.mock_configuration_instances.side_effect = (
                self.exceptions.trove)

            details_url = self._get_url_with_arg(DETAIL_URL, config.id)
            url = details_url + '?tab=configuration_details__instance'

            res = self.client.get(url)
            self.assert_mock_multiple_calls_with_same_arguments(
                self.mock_get, 2, mock.call(test.IsHttpRequest(), config.id))
            self.mock_configuration_instances.assert_called_once_with(
                test.IsHttpRequest(), config.id)
            table_data = res.context['instances_table'].data
            self.assertNotEqual(len(self.configuration_instances.list()),
                                len(table_data))
            self.assertTemplateUsed(
                res, 'project/database_configurations/details.html')
        finally:
            config_param_manager.delete(config.id)
Exemple #2
0
    def test_add_new_parameter(self):
        config = self.database_configurations.first()
        self.mock_get_configuration.return_value = config
        try:
            self.mock_configuration_get.return_value = config

            ds = self._get_test_datastore('mysql')
            dsv = self._get_test_datastore_version(ds.id, '5.5')
            self.mock_configuration_parameters_list.return_value = (
                self.configuration_parameters.list())

            name = self.configuration_parameters.first().name
            value = 1

            self.mock_add_param.return_value = value

            post = {'method': 'AddParameterForm', 'name': name, 'value': value}

            res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
                                   post)
            self.mock_get_configuration.assert_called_once()
            self.mock_configuration_get.assert_called_once_with(
                test.IsHttpRequest())
            self.mock_configuration_parameters_list.assert_called_once_with(
                test.IsHttpRequest(), ds.name, dsv.name)
            self.mock_add_param.assert_called_once_with(name, value)
            self.assertNoFormErrors(res)
            self.assertMessageCount(success=1)
        finally:
            config_param_manager.delete(config.id)
Exemple #3
0
    def test_add_parameter_invalid_value(self):
        try:
            config = self.database_configurations.first()

            # setup the configuration parameter manager
            config_param_mgr = config_param_manager.ConfigParamManager(
                config.id)
            config_param_mgr.configuration = config
            config_param_mgr.original_configuration_values = \
                dict.copy(config.values)

            self.mock_get.return_value = config_param_mgr
            self.mock_configuration_parameters_list.return_value = (
                self.configuration_parameters.list())

            name = self.configuration_parameters.first().name
            value = "non-numeric"

            post = {'method': 'AddParameterForm', 'name': name, 'value': value}

            res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
                                   post)
            self.assert_mock_multiple_calls_with_same_arguments(
                self.mock_get, 2, mock.call(test.IsHttpRequest(),
                                            test.IsA(str)))
            self.assert_mock_multiple_calls_with_same_arguments(
                self.mock_configuration_parameters_list, 2,
                mock.call(test.IsHttpRequest(), test.IsA(str), test.IsA(str)))
            self.assertFormError(res, "form", 'value',
                                 ['Value must be a number.'])
        finally:
            config_param_manager.delete(config.id)
    def test_instances_tab_exception(self):
        try:
            config = self.database_configurations.first()

            # setup the configuration parameter manager
            config_param_mgr = config_param_manager.ConfigParamManager(
                config.id)
            config_param_mgr.configuration = config
            config_param_mgr.original_configuration_values = \
                dict.copy(config.values)

            config_param_manager.get(IsA(http.HttpRequest), config.id) \
                .MultipleTimes().AndReturn(config_param_mgr)

            api.trove.configuration_instances(IsA(http.HttpRequest),
                                              config.id) \
                .AndRaise(self.exceptions.trove)
            self.mox.ReplayAll()

            details_url = self._get_url_with_arg(DETAIL_URL, config.id)
            url = details_url + '?tab=configuration_details__instance'

            res = self.client.get(url)
            table_data = res.context['instances_table'].data
            self.assertNotEqual(len(self.configuration_instances.list()),
                                len(table_data))
            self.assertTemplateUsed(
                res, 'project/database_configurations/details.html')
        finally:
            config_param_manager.delete(config.id)
    def test_add_new_parameter(self):
        config = (config_param_manager.ConfigParamManager
                  .get_configuration()
                  .AndReturn(self.database_configurations.first()))
        try:
            config_param_manager.ConfigParamManager \
                .configuration_get(IsA(http.HttpRequest)) \
                .AndReturn(config)

            ds = self._get_test_datastore('mysql')
            dsv = self._get_test_datastore_version(ds.id, '5.5')
            api.trove.configuration_parameters_list(
                IsA(http.HttpRequest),
                ds.name,
                dsv.name) \
                .AndReturn(self.configuration_parameters.list())

            name = self.configuration_parameters.first().name
            value = 1

            config_param_manager.ConfigParamManager.add_param(name, value) \
                .AndReturn(value)

            self.mox.ReplayAll()
            post = {
                'method': 'AddParameterForm',
                'name': name,
                'value': value}

            res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
                                   post)
            self.assertNoFormErrors(res)
            self.assertMessageCount(success=1)
        finally:
            config_param_manager.delete(config.id)
Exemple #6
0
    def test_instances_tab_exception(self):
        try:
            config = self.database_configurations.first()

            # setup the configuration parameter manager
            config_param_mgr = config_param_manager.ConfigParamManager(
                config.id)
            config_param_mgr.configuration = config
            config_param_mgr.original_configuration_values = \
                dict.copy(config.values)

            config_param_manager.get(IsA(http.HttpRequest), config.id) \
                .MultipleTimes().AndReturn(config_param_mgr)

            api.trove.configuration_instances(IsA(http.HttpRequest),
                                              config.id) \
                .AndRaise(self.exceptions.trove)
            self.mox.ReplayAll()

            details_url = self._get_url_with_arg(DETAIL_URL, config.id)
            url = details_url + '?tab=configuration_details__instance'

            res = self.client.get(url)
            table_data = res.context['instances_table'].data
            self.assertNotEqual(len(self.configuration_instances.list()),
                                len(table_data))
            self.assertTemplateUsed(
                res, 'project/database_configurations/details.html')
        finally:
            config_param_manager.delete(config.id)
Exemple #7
0
    def test_add_new_parameter(self):
        config = (config_param_manager.ConfigParamManager.get_configuration().
                  AndReturn(self.database_configurations.first()))
        try:
            config_param_manager.ConfigParamManager \
                .configuration_get(IsA(http.HttpRequest)) \
                .AndReturn(config)

            ds = self._get_test_datastore('mysql')
            dsv = self._get_test_datastore_version(ds.id, '5.5')
            api.trove.configuration_parameters_list(
                IsA(http.HttpRequest),
                ds.name,
                dsv.name) \
                .AndReturn(self.configuration_parameters.list())

            name = self.configuration_parameters.first().name
            value = 1

            config_param_manager.ConfigParamManager.add_param(name, value) \
                .AndReturn(value)

            self.mox.ReplayAll()
            post = {'method': 'AddParameterForm', 'name': name, 'value': value}

            res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
                                   post)
            self.assertNoFormErrors(res)
            self.assertMessageCount(success=1)
        finally:
            config_param_manager.delete(config.id)
Exemple #8
0
    def test_add_parameter_invalid_value(self):
        try:
            config = self.database_configurations.first()

            # setup the configuration parameter manager
            config_param_mgr = config_param_manager.ConfigParamManager(
                config.id)
            config_param_mgr.configuration = config
            config_param_mgr.original_configuration_values = \
                dict.copy(config.values)

            (config_param_manager.get(
                IsA(http.HttpRequest),
                IsA(six.string_types)).MultipleTimes().AndReturn(
                    config_param_mgr))
            (api.trove.configuration_parameters_list(
                IsA(http.HttpRequest), IsA(six.string_types),
                IsA(six.string_types)).MultipleTimes().AndReturn(
                    self.configuration_parameters.list()))

            name = self.configuration_parameters.first().name
            value = "non-numeric"

            self.mox.ReplayAll()
            post = {'method': 'AddParameterForm', 'name': name, 'value': value}

            res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
                                   post)
            self.assertFormError(res, "form", 'value',
                                 ['Value must be a number.'])
        finally:
            config_param_manager.delete(config.id)
Exemple #9
0
    def handle(self, table, request, obj_ids):
        configuration_id = table.kwargs['configuration_id']
        if config_param_manager.get(request, configuration_id).has_changes():
            try:
                config_param_manager.delete(configuration_id)
                messages.success(request, _('Reset Parameters'))
            except Exception as ex:
                messages.error(request,
                               _('Error resetting parameters: %s') % ex)

        return shortcuts.redirect(request.build_absolute_uri())
    def handle(self, table, request, obj_ids):
        configuration_id = table.kwargs['configuration_id']
        if config_param_manager.get(request, configuration_id).has_changes():
            try:
                config_param_manager.delete(configuration_id)
                messages.success(request, _('Reset Parameters'))
            except Exception as ex:
                messages.error(
                    request,
                    _('Error resetting parameters: %s') % ex.message)

        return shortcuts.redirect(request.build_absolute_uri())
    def handle(self, table, request, obj_ids):
        configuration_id = table.kwargs['configuration_id']
        if config_param_manager.get(request, configuration_id).has_changes():
            try:
                api.trove.configuration_update(
                    request, configuration_id,
                    config_param_manager.get(request,
                                             configuration_id).to_json())
                messages.success(request, _('Applied changes to server'))
            except Exception:
                messages.error(request, _('Error applying changes'))
            finally:
                config_param_manager.delete(configuration_id)

        return shortcuts.redirect(request.build_absolute_uri())
    def handle(self, table, request, obj_ids):
        configuration_id = table.kwargs['configuration_id']
        if config_param_manager.get(request, configuration_id).has_changes():
            try:
                api.trove.configuration_update(
                    request, configuration_id,
                    config_param_manager.get(
                        request, configuration_id).to_json())
                messages.success(request, _('Applied changes to server'))
            except Exception:
                messages.error(request, _('Error applying changes'))
            finally:
                config_param_manager.delete(configuration_id)

        return shortcuts.redirect(request.build_absolute_uri())
Exemple #13
0
    def test_add_parameter_exception_on_parameters(self):
        try:
            config = (config_param_manager.ConfigParamManager.
                      get_configuration().AndReturn(
                          self.database_configurations.first()))

            config_param_manager.ConfigParamManager \
                .configuration_get(IsA(http.HttpRequest)) \
                .AndReturn(config)

            ds = self._get_test_datastore('mysql')
            dsv = self._get_test_datastore_version(ds.id, '5.5')
            api.trove.configuration_parameters_list(
                IsA(http.HttpRequest),
                ds.name,
                dsv.name) \
                .AndRaise(self.exceptions.trove)
            self.mox.ReplayAll()
            toSuppress = [
                "trove_dashboard.content."
                "database_configurations.forms",
            ]

            # Suppress expected log messages in the test output
            loggers = []
            for cls in toSuppress:
                logger = logging.getLogger(cls)
                loggers.append((logger, logger.getEffectiveLevel()))
                logger.setLevel(logging.CRITICAL)

            try:
                res = self.client.get(
                    self._get_url_with_arg(ADD_URL, config.id))
                self.assertEqual(res.status_code, 302)

            finally:
                # Restore the previous log levels
                for (log, level) in loggers:
                    log.setLevel(level)
        finally:
            config_param_manager.delete(config.id)
Exemple #14
0
    def test_add_parameter_exception_on_parameters(self):
        try:
            config = self.database_configurations.first()
            self.mock_get_configuration.return_value = config

            self.mock_configuration_get.return_value = config

            ds = self._get_test_datastore('mysql')
            dsv = self._get_test_datastore_version(ds.id, '5.5')
            self.mock_configuration_parameters_list.side_effect = (
                self.exceptions.trove)
            toSuppress = ["trove_dashboard.content."
                          "database_configurations.forms", ]

            # Suppress expected log messages in the test output
            loggers = []
            for cls in toSuppress:
                logger = logging.getLogger(cls)
                loggers.append((logger, logger.getEffectiveLevel()))
                logger.setLevel(logging.CRITICAL)

            try:
                res = self.client.get(
                    self._get_url_with_arg(ADD_URL, config.id))
                self.mock_get_configuration.assert_called_once()
                self.mock_configuration_get.assert_called_once_with(
                    test.IsHttpRequest())
                self.mock_configuration_parameters_list. \
                    assert_called_once_with(
                        test.IsHttpRequest(),
                        ds.name,
                        dsv.name
                    )
                self.assertEqual(res.status_code, 302)

            finally:
                # Restore the previous log levels
                for (log, level) in loggers:
                    log.setLevel(level)
        finally:
            config_param_manager.delete(config.id)
    def test_add_parameter_exception_on_parameters(self):
        try:
            config = (config_param_manager.ConfigParamManager
                      .get_configuration()
                      .AndReturn(self.database_configurations.first()))

            config_param_manager.ConfigParamManager \
                .configuration_get(IsA(http.HttpRequest)) \
                .AndReturn(config)

            ds = self._get_test_datastore('mysql')
            dsv = self._get_test_datastore_version(ds.id, '5.5')
            api.trove.configuration_parameters_list(
                IsA(http.HttpRequest),
                ds.name,
                dsv.name) \
                .AndRaise(self.exceptions.trove)
            self.mox.ReplayAll()
            toSuppress = ["trove_dashboard.content."
                          "database_configurations.forms", ]

            # Suppress expected log messages in the test output
            loggers = []
            for cls in toSuppress:
                logger = logging.getLogger(cls)
                loggers.append((logger, logger.getEffectiveLevel()))
                logger.setLevel(logging.CRITICAL)

            try:
                res = self.client.get(
                    self._get_url_with_arg(ADD_URL, config.id))
                self.assertEqual(res.status_code, 302)

            finally:
                # Restore the previous log levels
                for (log, level) in loggers:
                    log.setLevel(level)
        finally:
            config_param_manager.delete(config.id)
    def test_add_parameter_invalid_value(self):
        try:
            config = self.database_configurations.first()

            # setup the configuration parameter manager
            config_param_mgr = config_param_manager.ConfigParamManager(
                config.id)
            config_param_mgr.configuration = config
            config_param_mgr.original_configuration_values = \
                dict.copy(config.values)

            config_param_manager.get(IsA(http.HttpRequest), config.id) \
                .MultipleTimes().AndReturn(config_param_mgr)

            ds = self._get_test_datastore('mysql')
            dsv = self._get_test_datastore_version(ds.id, '5.5')
            api.trove.configuration_parameters_list(
                IsA(http.HttpRequest),
                ds.name,
                dsv.name) \
                .AndReturn(self.configuration_parameters.list())

            name = self.configuration_parameters.first().name
            value = "non-numeric"

            self.mox.ReplayAll()
            post = {
                'method': 'AddParameterForm',
                'name': name,
                'value': value}

            res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
                                   post)
            self.assertFormError(res, "form", 'value',
                                 ['Value must be a number.'])
        finally:
            config_param_manager.delete(config.id)