Test Failed
Pull Request — master (#3556)
by Lakshmi
04:46
created

SetupVirtualEnvironmentAction.__init__()   A

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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 st2common.runners.base_action import Action
17
from st2common.util.virtualenvs import setup_pack_virtualenv
18
19
__all__ = [
20
    'SetupVirtualEnvironmentAction'
21
]
22
23
24
class SetupVirtualEnvironmentAction(Action):
25
    """
26
    Action which sets up virtual environment for the provided packs.
27
28
    Setup consists of the following step:
29
30
    1. Create virtual environment for the pack
31
    2. Install base requirements which are common to all the packs
32
    3. Install pack-specific requirements (if any)
33
34
    If the 'update' parameter is set to True, the setup skips the deletion and
35
    creation of the virtual environment and performs an update of the
36
    current dependencies as well as an installation of new dependencies
37
    """
38
    def __init__(self, config=None, action_service=None):
39
        super(SetupVirtualEnvironmentAction, self).__init__(
40
            config=config,
41
            action_service=action_service)
42
43
        self.https_proxy = self.config.get('https_proxy', None)
44
        self.http_proxy = self.config.get('http_proxy', None)
45
        self.ca_bundle_path = self.config.get('ca_bundle_path', None)
46
        self.proxy_config = {
47
            'https_proxy': self.https_proxy,
48
            'http_proxy': self.http_proxy,
49
            'ca_bundle_path': self.ca_bundle_path
50
        }
51
52
    def run(self, packs, update=False):
53
        """
54
        :param packs: A list of packs to create the environment for.
55
        :type: packs: ``list``
56
57
        :param update: True to update dependencies inside the virtual environment.
58
        :type update: ``bool``
59
        """
60
61
        for pack_name in packs:
62
            setup_pack_virtualenv(pack_name=pack_name, update=update, logger=self.logger,
63
                                  proxy_config=self.proxy_config)
64
65
        message = ('Successfuly set up virtualenv for the following packs: %s' %
66
                   (', '.join(packs)))
67
        return message
68