Completed
Pull Request — master (#2304)
by Arma
07:07
created

st2tests.WiringTest.test_concurrent_load()   A

Complexity

Conditions 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4286
cc 3
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
49
50
def _register_config_opts():
51
    _register_common_opts()
52
    _register_api_opts()
53
    _register_auth_opts()
54
    _register_action_sensor_opts()
55
    _register_ssh_runner_opts()
56
    _register_cloudslang_opts()
57
    _register_scheduler_opts()
58
    _register_exporter_opts()
59
    _register_sensor_container_opts()
60
61
62
def _override_db_opts():
63
    CONF.set_override(name='db_name', override='st2-test', group='database')
64
65
66
def _override_common_opts():
67
    packs_base_path = get_fixtures_base_path()
68
    CONF.set_override(name='base_path', override=packs_base_path, group='system')
69
    CONF.set_override(name='system_packs_base_path', override=packs_base_path, group='content')
70
    CONF.set_override(name='packs_base_paths', override=packs_base_path, group='content')
71
    CONF.set_override(name='api_url', override='http://localhost', group='auth')
72
    CONF.set_override(name='admin_users', override=['admin_user'], group='system')
73
    CONF.set_override(name='mask_secrets', override=True, group='log')
74
    CONF.set_override(name='url', override='zake://', group='coordination')
75
    CONF.set_override(name='lock_timeout', override=1, group='coordination')
76
77
78
def _register_common_opts():
79
    try:
80
        common_config.register_opts(ignore_errors=True)
81
    except:
82
        LOG.exception('Common config registration failed.')
83
84
85
def _register_api_opts():
86
    api_opts = [
87
        cfg.ListOpt('allow_origin', default=['http://localhost:3000', 'http://dev'],
88
                    help='List of origins allowed'),
89
        cfg.IntOpt('heartbeat', default=25,
90
                   help='Send empty message every N seconds to keep connection open'),
91
        cfg.BoolOpt('mask_secrets', default=True,
92
                    help='True to mask secrets in API responses')
93
    ]
94
    _register_opts(api_opts, group='api')
95
96
    # XXX: note : template_path value only works if started from the top-level of the codebase.
97
    # Brittle!
98
    pecan_opts = [
99
        cfg.StrOpt('root',
100
                   default='st2api.controllers.root.RootController',
101
                   help='Pecan root controller'),
102
        cfg.StrOpt('template_path',
103
                   default='%(confdir)s/st2api/st2api/templates'),
104
        cfg.ListOpt('modules', default=['st2api']),
105
        cfg.BoolOpt('debug', default=True),
106
        cfg.BoolOpt('auth_enable', default=True),
107
        cfg.DictOpt('errors', default={404: '/error/404', '__force_dict__': True})
108
    ]
109
    _register_opts(pecan_opts, group='api_pecan')
110
111
    messaging_opts = [
112
        cfg.StrOpt('url', default='amqp://guest:[email protected]:5672//',
113
                   help='URL of the messaging server.'),
114
        cfg.ListOpt('cluster_urls', default=[],
115
                    help='URL of all the nodes in a messaging service cluster.')
116
    ]
117
    _register_opts(messaging_opts, group='messaging')
118
119
    ssh_runner_opts = [
120
        cfg.StrOpt('remote_dir',
121
                   default='/tmp',
122
                   help='Location of the script on the remote filesystem.'),
123
        cfg.BoolOpt('allow_partial_failure',
124
                    default=False,
125
                    help='How partial success of actions run on multiple nodes should be treated.'),
126
        cfg.BoolOpt('use_ssh_config',
127
                    default=False,
128
                    help='Use the .ssh/config file. Useful to override ports etc.')
129
    ]
130
    _register_opts(ssh_runner_opts, group='ssh_runner')
131
132
133
def _register_auth_opts():
134
    auth_opts = [
135
        cfg.StrOpt('host', default='0.0.0.0'),
136
        cfg.IntOpt('port', default=9100),
137
        cfg.BoolOpt('use_ssl', default=False),
138
        cfg.StrOpt('mode', default='proxy'),
139
        cfg.StrOpt('logging', default='conf/logging.conf'),
140
        cfg.IntOpt('token_ttl', default=86400, help='Access token ttl in seconds.'),
141
        cfg.BoolOpt('debug', default=True)
142
    ]
143
    _register_opts(auth_opts, group='auth')
144
145
146
def _register_action_sensor_opts():
147
    action_sensor_opts = [
148
        cfg.BoolOpt('enable', default=True,
149
                    help='Whether to enable or disable the ability ' +
150
                         'to post a trigger on action.'),
151
        cfg.StrOpt('triggers_base_url', default='http://localhost:9101/v1/triggertypes/',
152
                   help='URL for action sensor to post TriggerType.'),
153
        cfg.IntOpt('request_timeout', default=1,
154
                   help='Timeout value of all httprequests made by action sensor.'),
155
        cfg.IntOpt('max_attempts', default=10,
156
                   help='No. of times to retry registration.'),
157
        cfg.IntOpt('retry_wait', default=1,
158
                   help='Amount of time to wait prior to retrying a request.')
159
    ]
160
    _register_opts(action_sensor_opts, group='action_sensor')
161
162
163
def _register_ssh_runner_opts():
164
    ssh_runner_opts = [
165
        cfg.BoolOpt('use_ssh_config', default=False,
166
                    help='Use the .ssh/config file. Useful to override ports etc.'),
167
        cfg.StrOpt('remote_dir',
168
                   default='/tmp',
169
                   help='Location of the script on the remote filesystem.'),
170
        cfg.BoolOpt('allow_partial_failure',
171
                    default=False,
172
                    help='How partial success of actions run on multiple nodes ' +
173
                         'should be treated.'),
174
        cfg.BoolOpt('use_paramiko_ssh_runner',
175
                    default=False,
176
                    help='Use Paramiko based SSH runner as the default remote runner. ' +
177
                         'EXPERIMENTAL!!! USE AT YOUR OWN RISK.'),
178
        cfg.IntOpt('max_parallel_actions', default=50,
179
                   help='Max number of parallel remote SSH actions that should be run.  ' +
180
                        'Works only with Paramiko SSH runner.'),
181
    ]
182
    _register_opts(ssh_runner_opts, group='ssh_runner')
183
184
185
def _register_cloudslang_opts():
186
    cloudslang_opts = [
187
        cfg.StrOpt('home_dir', default='/opt/cslang',
188
                   help='CloudSlang home directory.')
189
    ]
190
    _register_opts(cloudslang_opts, group='cloudslang')
191
192
193
def _register_scheduler_opts():
194
    scheduler_opts = [
195
        cfg.IntOpt('delayed_execution_recovery', default=600,
196
                   help='The time in seconds to wait before recovering delayed action executions.'),
197
        cfg.IntOpt('rescheduling_interval', default=300,
198
                   help='The frequency for rescheduling action executions.')
199
    ]
200
    _register_opts(scheduler_opts, group='scheduler')
201
202
203
def _register_exporter_opts():
204
    exporter_opts = [
205
        cfg.StrOpt('dump_dir', default='/opt/stackstorm/exports/',
206
                   help='Directory to dump data to.')
207
    ]
208
    _register_opts(exporter_opts, group='exporter')
209
210
211
def _register_sensor_container_opts():
212
    partition_opts = [
213
        cfg.StrOpt('sensor_node_name', default='sensornode1',
214
                   help='name of the sensor node.'),
215
        cfg.Opt('partition_provider', type=types.Dict(value_type=types.String()),
216
                default={'name': DEFAULT_PARTITION_LOADER},
217
                help='Provider of sensor node partition config.')
218
    ]
219
    _register_opts(partition_opts, group='sensorcontainer')
220
221
    sensor_test_opt = cfg.StrOpt('sensor-ref', help='Only run sensor with the provided reference. \
222
        Value is of the form pack.sensor-name.')
223
    _register_cli_opts([sensor_test_opt])
224
225
226
def _register_opts(opts, group=None):
227
    CONF.register_opts(opts, group)
228
229
230
def _register_cli_opts(opts):
231
    cfg.CONF.register_cli_opts(opts)
232