Skip to content

Commit

Permalink
Merge pull request #2372 from lakshmi-kannan/virtualenv_fix
Browse files Browse the repository at this point in the history
RFR: Add --always-copy option to create_virtualenv method for pack virtual…
  • Loading branch information
lakshmi-kannan committed Jan 13, 2016
2 parents 9aff265 + 8f421df commit 48ae45e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ in development
* Fix runaway action triggers caused by state miscalculation for mistral workflow. (bug fix)
* Throw a more friendly error message if casting parameter value fails because the value contains
an invalid type or similar. (improvement)
* Use ``--always-copy`` option when creating virtualenv for packs from packs.setup_virtualenv
action. This is required when st2actionrunner is kicked off from python within a virtualenv.

1.2.0 - December 07, 2015
-------------------------
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ requirements: virtualenv .sdist-requirements

# Make sure we use latest version of pip
$(VIRTUALENV_DIR)/bin/pip install --upgrade pip
$(VIRTUALENV_DIR)/bin/pip install virtualenv # Required for packs.install in dev envs.

# Generate all requirements to support current CI pipeline.
$(VIRTUALENV_DIR)/bin/python scripts/fixate-requirements.py --skip=virtualenv -s st2*/in-requirements.txt -f fixed-requirements.txt -o requirements.txt
Expand Down
6 changes: 3 additions & 3 deletions conf/st2.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ logging = conf/logging.conf

[api]
# List of origins allowed
allow_origin = ['http://localhost:3000']
allow_origin = http://localhost:3000 # comma separated list allowed here.
# location of the logging.conf file
logging = conf/logging.conf
# True to mask secrets in API responses
Expand Down Expand Up @@ -114,15 +114,15 @@ collection_interval = 600
# Controls if stderr should be redirected to the logs.
redirect_stderr = False
# Exclusion list of loggers to omit.
excludes =
excludes =
# True to mask secrets in the log files.
mask_secrets = True

[messaging]
# URL of the messaging server.
url = amqp://guest:guest@127.0.0.1:5672//
# URL of all the nodes in a messaging service cluster.
cluster_urls = []
cluster_urls = # comma separated list or URLs allowed here.

[mistral]
# URL Mistral uses to talk back to the API.If not provided it defaults to public API URL. Note: This needs to be a base URL without API version (e.g. http://127.0.0.1:9101)
Expand Down
1 change: 1 addition & 0 deletions conf/st2.package.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ logging = /etc/st2/logging.rulesengine.conf

[actionrunner]
logging = /etc/st2/logging.actionrunner.conf
virtualenv_opts = --always-copy

[resultstracker]
logging = /etc/st2/logging.resultstracker.conf
Expand Down
17 changes: 15 additions & 2 deletions contrib/packs/actions/pack_mgmt/setup_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,28 @@ def _setup_pack_virtualenv(self, pack_name, update=False):

def _create_virtualenv(self, virtualenv_path):
python_binary = cfg.CONF.actionrunner.python_binary
virtualenv_binary = cfg.CONF.actionrunner.virtualenv_binary
virtualenv_opts = cfg.CONF.actionrunner.virtualenv_opts

if not os.path.isfile(python_binary):
raise Exception('Python binary "%s" doesn\'t exist' % (python_binary))

if not os.path.isfile(virtualenv_binary):
raise Exception('Virtualenv binary "%s" doesn\'t exist.' % (virtualenv_binary))

self.logger.debug('Creating virtualenv in "%s" using Python binary "%s"' %
(virtualenv_path, python_binary))

cmd = ['virtualenv', '-p', python_binary, '--system-site-packages', virtualenv_path]
exit_code, _, stderr = run_command(cmd=cmd)
cmd = [virtualenv_binary, '-p', python_binary]
cmd.extend(virtualenv_opts)
cmd.extend([virtualenv_path])
self.logger.debug('Running command "%s" to create virtualenv.', ' '.join(cmd))

try:
exit_code, _, stderr = run_command(cmd=cmd)
except OSError as e:
raise Exception('Error executing command %s. %s.' % (' '.join(cmd),
e.message))

if exit_code != 0:
raise Exception('Failed to create virtualenv in "%s": %s' %
Expand Down
13 changes: 11 additions & 2 deletions st2actions/st2actions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Configuration options registration and useful routines.
"""

import os
import sys

from oslo_config import cfg
Expand All @@ -41,11 +42,19 @@ def _register_common_opts():


def _register_action_runner_opts():
default_python_bin_path = sys.executable
base_dir = os.path.dirname(os.path.realpath(default_python_bin_path))
default_virtualenv_bin_path = os.path.join(base_dir, 'virtualenv')
logging_opts = [
cfg.StrOpt('logging', default='conf/logging.conf',
help='location of the logging.conf file'),
cfg.StrOpt('python_binary', default=sys.executable,
help='Python binary which will be used by Python actions.')
cfg.StrOpt('python_binary', default=default_python_bin_path,
help='Python binary which will be used by Python actions.'),
cfg.StrOpt('virtualenv_binary', default=default_virtualenv_bin_path,
help='Virtualenv binary which should be used to create pack virtualenvs.'),
cfg.ListOpt('virtualenv_opts', default=['--always-copy', '--system-site-packages'],
help='List of virtualenv options to be passsed to "virtualenv" command that ' +
'creates pack virtualenv.')
]
CONF.register_opts(logging_opts, group='actionrunner')

Expand Down

0 comments on commit 48ae45e

Please sign in to comment.