Skip to content

Commit

Permalink
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
Browse files Browse the repository at this point in the history
…trics
  • Loading branch information
bigmstone committed May 7, 2018
2 parents 18cdea5 + 5f89c1f commit 9c6b0ca
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 14 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ Fixed
Changed
~~~~~~~

* Update all the service and script entry points to use ``/etc/st2/st2.conf`` as a default value
for the config file location.

This way users don't need to explicitly provide ``--config-file`` CLI argument when running
various scripts (e.g. ``st2-track-result``, ``st2-apply-rbac-definitions``, etc.) and when they
just want to use a default config file. (improvement) #4111

2.7.1 - April 20, 2018
----------------------

Changed
~~~~~~~

* When creating a pack environment during the pack installation, we now pass ``--no-download`` flag
to the ``virtualenv`` binary. This way version of pip, wheel and distutils which is enforced by
virtualenv is used instead of downloading the latest stable versions from PyPi.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ generate-api-spec: requirements .generate-api-spec
echo "# Edit st2common/st2common/openapi.yaml.j2 and then run" >> st2common/st2common/openapi.yaml
echo "# make .generate-api-spec" >> st2common/st2common/openapi.yaml
echo "# to generate the final spec file" >> st2common/st2common/openapi.yaml
. virtualenv/bin/activate; st2common/bin/st2-generate-api-spec >> st2common/st2common/openapi.yaml
. virtualenv/bin/activate; st2common/bin/st2-generate-api-spec --config-file conf/st2.dev.conf >> st2common/st2common/openapi.yaml

.PHONY: circle-lint-api-spec
circle-lint-api-spec:
@echo
@echo "================== Lint API spec ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; st2common/bin/st2-validate-api-spec || echo "Open API spec lint failed."
. $(VIRTUALENV_DIR)/bin/activate; st2common/bin/st2-validate-api-spec --config-file conf/st2.dev.conf || echo "Open API spec lint failed."

.PHONY: flake8
flake8: requirements .flake8
Expand Down
4 changes: 3 additions & 1 deletion st2actions/st2actions/notifier/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import st2common.config as common_config
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH
common_config.register_opts()

CONF = cfg.CONF


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts():
Expand Down
4 changes: 3 additions & 1 deletion st2actions/st2actions/resultstracker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

from st2common import config as common_config
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH
common_config.register_opts()

CONF = cfg.CONF


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts():
Expand Down
4 changes: 3 additions & 1 deletion st2api/st2api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

import st2common.config as common_config
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH

CONF = cfg.CONF
BASE_DIR = os.path.dirname(os.path.abspath(__file__))


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts():
Expand Down
4 changes: 3 additions & 1 deletion st2auth/st2auth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

from st2common import config as st2cfg
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH
from st2common.constants.auth import DEFAULT_MODE
from st2common.constants.auth import DEFAULT_BACKEND
from st2common.constants.auth import VALID_MODES
from st2auth.backends import get_available_backends


def parse_args(args=None):
cfg.CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts():
Expand Down
4 changes: 3 additions & 1 deletion st2common/st2common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from distutils.spawn import find_executable

from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH
from st2common.constants.runners import PYTHON_RUNNER_DEFAULT_LOG_LEVEL


Expand Down Expand Up @@ -404,4 +405,5 @@ def register_opts(ignore_errors=False):

def parse_args(args=None):
register_opts()
cfg.CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])
5 changes: 5 additions & 0 deletions st2common/st2common/constants/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@
# limitations under the License.

from __future__ import absolute_import

import os

from st2common import __version__

__all__ = [
'VERSION_STRING',
'DEFAULT_CONFIG_FILE_PATH',

'API_URL_ENV_VARIABLE_NAME',
'AUTH_TOKEN_ENV_VARIABLE_NAME',
]

VERSION_STRING = 'StackStorm v%s' % (__version__)
DEFAULT_CONFIG_FILE_PATH = os.environ.get('ST2_CONFIG_PATH', '/etc/st2/st2.conf')

API_URL_ENV_VARIABLE_NAME = 'ST2_API_URL'
AUTH_TOKEN_ENV_VARIABLE_NAME = 'ST2_AUTH_TOKEN'
44 changes: 42 additions & 2 deletions st2common/tests/unit/test_service_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
import six
import mock

from oslo_config import cfg
from oslo_config.cfg import ConfigFilesNotFoundError

from st2common import service_setup
from st2common.transport.bootstrap_utils import register_exchanges
from st2common.transport.bootstrap_utils import QUEUES
from st2common import config as st2common_config

from st2tests.base import CleanFilesTestCase
from st2tests import config
Expand Down Expand Up @@ -57,11 +61,15 @@
datefmt=
""".strip()

MOCK_DEFAULT_CONFIG_FILE_PATH = '/etc/st2/st2.conf-test-patched'


def mock_get_logging_config_path():
return ''


class ServiceSetupTestCase(CleanFilesTestCase):
def test_no_logging_config_found(self):
def mock_get_logging_config_path():
return ''

config.get_logging_config_path = mock_get_logging_config_path

Expand Down Expand Up @@ -112,3 +120,35 @@ def test_register_exchanges_predeclare_queues(self, mock_declare):

register_exchanges()
self.assertEqual(mock_declare.call_count, len(QUEUES))

@mock.patch('st2common.constants.system.DEFAULT_CONFIG_FILE_PATH',
MOCK_DEFAULT_CONFIG_FILE_PATH)
@mock.patch('st2common.config.DEFAULT_CONFIG_FILE_PATH', MOCK_DEFAULT_CONFIG_FILE_PATH)
def test_service_setup_default_st2_conf_config_is_used(self):
st2common_config.get_logging_config_path = mock_get_logging_config_path
cfg.CONF.reset()

# 1. DEFAULT_CONFIG_FILE_PATH config path should be used by default (/etc/st2/st2.conf)
expected_msg = 'Failed to find some config files: %s' % (MOCK_DEFAULT_CONFIG_FILE_PATH)
self.assertRaisesRegexp(ConfigFilesNotFoundError, expected_msg, service_setup.setup,
service='api',
config=st2common_config,
config_args=['--debug'],
setup_db=False, register_mq_exchanges=False,
register_signal_handlers=False,
register_internal_trigger_types=False,
run_migrations=False)

cfg.CONF.reset()

# 2. --config-file should still override default config file path option
config_file_path = '/etc/st2/config.override.test'
expected_msg = 'Failed to find some config files: %s' % (config_file_path)
self.assertRaisesRegexp(ConfigFilesNotFoundError, expected_msg, service_setup.setup,
service='api',
config=st2common_config,
config_args=['--config-file', config_file_path],
setup_db=False, register_mq_exchanges=False,
register_signal_handlers=False,
register_internal_trigger_types=False,
run_migrations=False)
4 changes: 3 additions & 1 deletion st2exporter/st2exporter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@

import st2common.config as common_config
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH
common_config.register_opts()

CONF = cfg.CONF


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def get_logging_config_path():
Expand Down
4 changes: 3 additions & 1 deletion st2reactor/st2reactor/garbage_collector/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import st2common.config as common_config
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH
from st2common.constants.garbage_collection import DEFAULT_COLLECTION_INTERVAL
from st2common.constants.garbage_collection import DEFAULT_SLEEP_DELAY
common_config.register_opts()
Expand All @@ -26,7 +27,8 @@


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts():
Expand Down
4 changes: 3 additions & 1 deletion st2reactor/st2reactor/rules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import st2common.config as common_config
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH
common_config.register_opts()

CONF = cfg.CONF


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts():
Expand Down
4 changes: 3 additions & 1 deletion st2reactor/st2reactor/sensor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
from st2common import config as st2cfg
from st2common.constants.sensors import DEFAULT_PARTITION_LOADER
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH

CONF = cfg.CONF


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts(ignore_errors=False):
Expand Down
4 changes: 3 additions & 1 deletion st2stream/st2stream/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

import st2common.config as common_config
from st2common.constants.system import VERSION_STRING
from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH

CONF = cfg.CONF
BASE_DIR = os.path.dirname(os.path.abspath(__file__))


def parse_args(args=None):
CONF(args=args, version=VERSION_STRING)
cfg.CONF(args=args, version=VERSION_STRING,
default_config_files=[DEFAULT_CONFIG_FILE_PATH])


def register_opts():
Expand Down

0 comments on commit 9c6b0ca

Please sign in to comment.