Passed
Push — develop ( b7e2c3...d0345b )
by Plexxi
08:11 queued 04:18
created

_override_keyvalue_opts()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from oslo_config import cfg, types
17
18
from st2common import log as logging
19
import st2common.config as common_config
20
from st2common.constants.sensors import DEFAULT_PARTITION_LOADER
21
from st2tests.fixturesloader import get_fixtures_base_path
22
23
CONF = cfg.CONF
24
LOG = logging.getLogger(__name__)
25
26
27
def parse_args():
28
    _setup_config_opts()
29
    CONF(args=[])
30
31
32
def _setup_config_opts():
33
    cfg.CONF.reset()
34
35
    try:
36
        _register_config_opts()
37
    except Exception as e:
38
        print(e)
39
        # Some scripts register the options themselves which means registering them again will
40
        # cause a non-fatal exception
41
        return
42
    _override_config_opts()
43
44
45
def _override_config_opts():
46
    _override_db_opts()
47
    _override_common_opts()
48
    _override_api_opts()
49
    _override_keyvalue_opts()
50
51
52
def _register_config_opts():
53
    _register_common_opts()
54
    _register_api_opts()
55
    _register_stream_opts()
56
    _register_auth_opts()
57
    _register_action_sensor_opts()
58
    _register_ssh_runner_opts()
59
    _register_cloudslang_opts()
60
    _register_scheduler_opts()
61
    _register_exporter_opts()
62
    _register_sensor_container_opts()
63
64
65
def _override_db_opts():
66
    CONF.set_override(name='db_name', override='st2-test', group='database')
67
68
69
def _override_common_opts():
70
    packs_base_path = get_fixtures_base_path()
71
    CONF.set_override(name='base_path', override=packs_base_path, group='system')
72
    CONF.set_override(name='system_packs_base_path', override=packs_base_path, group='content')
73
    CONF.set_override(name='packs_base_paths', override=packs_base_path, group='content')
74
    CONF.set_override(name='api_url', override='http://127.0.0.1', group='auth')
75
    CONF.set_override(name='mask_secrets', override=True, group='log')
76
    CONF.set_override(name='url', override='zake://', group='coordination')
77
    CONF.set_override(name='lock_timeout', override=1, group='coordination')
78
79
80
def _override_api_opts():
81
    CONF.set_override(name='allow_origin', override=['http://127.0.0.1:3000', 'http://dev'],
82
                      group='api')
83
84
85
def _override_keyvalue_opts():
86
    CONF.set_override(name='encryption_key_path',
87
                      override='st2tests/conf/st2_kvstore_tests.crypto.key.json',
88
                      group='keyvalue')
89
90
91
def _register_common_opts():
92
    try:
93
        common_config.register_opts(ignore_errors=True)
94
    except:
95
        LOG.exception('Common config registration failed.')
96
97
98
def _register_api_opts():
99
    # XXX: note : template_path value only works if started from the top-level of the codebase.
100
    # Brittle!
101
    pecan_opts = [
102
        cfg.StrOpt('root',
103
                   default='st2api.controllers.root.RootController',
104
                   help='Pecan root controller'),
105
        cfg.StrOpt('template_path',
106
                   default='%(confdir)s/st2api/st2api/templates'),
107
        cfg.ListOpt('modules', default=['st2api']),
108
        cfg.BoolOpt('debug', default=True),
109
        cfg.BoolOpt('auth_enable', default=True),
110
        cfg.DictOpt('errors', default={404: '/error/404', '__force_dict__': True})
111
    ]
112
    _register_opts(pecan_opts, group='api_pecan')
113
114
    messaging_opts = [
115
        cfg.StrOpt('url', default='amqp://guest:[email protected]:5672//',
116
                   help='URL of the messaging server.'),
117
        cfg.ListOpt('cluster_urls', default=[],
118
                    help='URL of all the nodes in a messaging service cluster.')
119
    ]
120
    _register_opts(messaging_opts, group='messaging')
121
122
    ssh_runner_opts = [
123
        cfg.StrOpt('remote_dir',
124
                   default='/tmp',
125
                   help='Location of the script on the remote filesystem.'),
126
        cfg.BoolOpt('allow_partial_failure',
127
                    default=False,
128
                    help='How partial success of actions run on multiple nodes should be treated.'),
129
        cfg.BoolOpt('use_ssh_config',
130
                    default=False,
131
                    help='Use the .ssh/config file. Useful to override ports etc.')
132
    ]
133
    _register_opts(ssh_runner_opts, group='ssh_runner')
134
135
136
def _register_stream_opts():
137
    stream_opts = [
138
        cfg.IntOpt('heartbeat', default=25,
139
                   help='Send empty message every N seconds to keep connection open'),
140
        cfg.BoolOpt('debug', default=False,
141
                    help='Specify to enable debug mode.'),
142
    ]
143
    _register_opts(stream_opts, group='stream')
144
145
146
def _register_auth_opts():
147
    auth_opts = [
148
        cfg.StrOpt('host', default='0.0.0.0'),
149
        cfg.IntOpt('port', default=9100),
150
        cfg.BoolOpt('use_ssl', default=False),
151
        cfg.StrOpt('mode', default='proxy'),
152
        cfg.StrOpt('logging', default='conf/logging.conf'),
153
        cfg.IntOpt('token_ttl', default=86400, help='Access token ttl in seconds.'),
154
        cfg.BoolOpt('debug', default=True)
155
    ]
156
    _register_opts(auth_opts, group='auth')
157
158
159
def _register_action_sensor_opts():
160
    action_sensor_opts = [
161
        cfg.BoolOpt('enable', default=True,
162
                    help='Whether to enable or disable the ability ' +
163
                         'to post a trigger on action.'),
164
        cfg.StrOpt('triggers_base_url', default='http://127.0.0.1:9101/v1/triggertypes/',
165
                   help='URL for action sensor to post TriggerType.'),
166
        cfg.IntOpt('request_timeout', default=1,
167
                   help='Timeout value of all httprequests made by action sensor.'),
168
        cfg.IntOpt('max_attempts', default=10,
169
                   help='No. of times to retry registration.'),
170
        cfg.IntOpt('retry_wait', default=1,
171
                   help='Amount of time to wait prior to retrying a request.')
172
    ]
173
    _register_opts(action_sensor_opts, group='action_sensor')
174
175
176
def _register_ssh_runner_opts():
177
    ssh_runner_opts = [
178
        cfg.BoolOpt('use_ssh_config', default=False,
179
                    help='Use the .ssh/config file. Useful to override ports etc.'),
180
        cfg.StrOpt('remote_dir',
181
                   default='/tmp',
182
                   help='Location of the script on the remote filesystem.'),
183
        cfg.BoolOpt('allow_partial_failure',
184
                    default=False,
185
                    help='How partial success of actions run on multiple nodes ' +
186
                         'should be treated.'),
187
        cfg.BoolOpt('use_paramiko_ssh_runner',
188
                    default=False,
189
                    help='Use Paramiko based SSH runner as the default remote runner. ' +
190
                         'EXPERIMENTAL!!! USE AT YOUR OWN RISK.'),
191
        cfg.IntOpt('max_parallel_actions', default=50,
192
                   help='Max number of parallel remote SSH actions that should be run.  ' +
193
                        'Works only with Paramiko SSH runner.'),
194
    ]
195
    _register_opts(ssh_runner_opts, group='ssh_runner')
196
197
198
def _register_cloudslang_opts():
199
    cloudslang_opts = [
200
        cfg.StrOpt('home_dir', default='/opt/cslang',
201
                   help='CloudSlang home directory.')
202
    ]
203
    _register_opts(cloudslang_opts, group='cloudslang')
204
205
206
def _register_scheduler_opts():
207
    scheduler_opts = [
208
        cfg.IntOpt('delayed_execution_recovery', default=600,
209
                   help='The time in seconds to wait before recovering delayed action executions.'),
210
        cfg.IntOpt('rescheduling_interval', default=300,
211
                   help='The frequency for rescheduling action executions.')
212
    ]
213
    _register_opts(scheduler_opts, group='scheduler')
214
215
216
def _register_exporter_opts():
217
    exporter_opts = [
218
        cfg.StrOpt('dump_dir', default='/opt/stackstorm/exports/',
219
                   help='Directory to dump data to.')
220
    ]
221
    _register_opts(exporter_opts, group='exporter')
222
223
224
def _register_sensor_container_opts():
225
    partition_opts = [
226
        cfg.StrOpt('sensor_node_name', default='sensornode1',
227
                   help='name of the sensor node.'),
228
        cfg.Opt('partition_provider', type=types.Dict(value_type=types.String()),
229
                default={'name': DEFAULT_PARTITION_LOADER},
230
                help='Provider of sensor node partition config.')
231
    ]
232
    _register_opts(partition_opts, group='sensorcontainer')
233
234
    sensor_test_opt = cfg.StrOpt('sensor-ref', help='Only run sensor with the provided reference. \
235
        Value is of the form pack.sensor-name.')
236
    _register_cli_opts([sensor_test_opt])
237
238
239
def _register_opts(opts, group=None):
240
    CONF.register_opts(opts, group)
241
242
243
def _register_cli_opts(opts):
244
    cfg.CONF.register_cli_opts(opts)
245