From 9f529afd477be981af26ab29f4bf961b34236b44 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Thu, 29 Sep 2011 15:06:54 +0100 Subject: install_venv: add support for distro specific code ... and use it to install virtualenv with yum if it's not available. Change-Id: Ibfeeb9c23324724bc26895504e6229076d793c6d --- tools/install_venv.py | 71 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/tools/install_venv.py b/tools/install_venv.py index 912d0a251..013ddc9a2 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -44,7 +44,7 @@ def check_python_version(): die("Need Python Version >= 2.6") -def run_command(cmd, redirect_output=True, check_exit_code=True): +def run_command_with_code(cmd, redirect_output=True, check_exit_code=True): """ Runs a command in an out-of-process shell, returning the output of that command. Working directory is ROOT. @@ -58,30 +58,63 @@ def run_command(cmd, redirect_output=True, check_exit_code=True): output = proc.communicate()[0] if check_exit_code and proc.returncode != 0: die('Command "%s" failed.\n%s', ' '.join(cmd), output) - return output + return (output, proc.returncode) -HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'], - check_exit_code=False).strip()) -HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'], - check_exit_code=False).strip()) +def run_command(cmd, redirect_output=True, check_exit_code=True): + return run_command_with_code(cmd, redirect_output, check_exit_code)[0] -def check_dependencies(): - """Make sure virtualenv is in the path.""" +class Distro(object): + + def check_cmd(self, cmd): + return bool(run_command(['which', cmd], check_exit_code=False).strip()) + + def install_virtualenv(self): + if self.check_cmd('virtualenv'): + return - if not HAS_VIRTUALENV: - print 'not found.' - # Try installing it via easy_install... - if HAS_EASY_INSTALL: + if self.check_cmd('easy_install'): print 'Installing virtualenv via easy_install...', - if not (run_command(['which', 'easy_install']) and - run_command(['easy_install', 'virtualenv'])): - die('ERROR: virtualenv not found.\n\nNova development' - ' requires virtualenv, please install it using your' - ' favorite package management tool') - print 'done.' - print 'done.' + if run_command(['easy_install', 'virtualenv']): + print 'Succeeded' + return + else: + print 'Failed' + + die('ERROR: virtualenv not found.\n\nNova development' + ' requires virtualenv, please install it using your' + ' favorite package management tool') + + +class Fedora(Distro): + + def check_pkg(self, pkg): + return run_command_with_code(['rpm', '-q', pkg], + check_exit_code=False)[1] == 0 + + def yum_install(self, pkg, **kwargs): + run_command(['sudo', 'yum', 'install', '-y', pkg], **kwargs) + + def install_virtualenv(self): + if self.check_cmd('virtualenv'): + return + + if not self.check_pkg('python-virtualenv'): + self.yum_install('python-virtualenv', check_exit_code=False) + + super(Fedora, self).install_virtualenv() + + +def get_distro(): + if os.path.exists('/etc/fedora-release'): + return Fedora() + else: + return Distro() + + +def check_dependencies(): + get_distro().install_virtualenv() def create_virtualenv(venv=VENV): -- cgit From 6c9743665629d7cf74de83202b4ba2909c43275e Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Thu, 29 Sep 2011 15:06:55 +0100 Subject: install_venv: pip install M2Crypto doesn't work on Fedora ... so use the system m2crypto library instead. M2Crypto won't build on Fedora because of some bizarre differences with Fedora's OpenSSL headers. I can get it to build by doing e.g. $> python ./tools/install_venv.py $> cd .nova-venv/build/M2Crypto $> for i in SWIG/_ec.i SWIG/_evp.i; do sed -i -e "s/opensslconf/opensslconf-x86_64/" $i ; done $> cd - $> SWIG_FEATURES=-cpperraswarn ./tools/with_venv.sh pip install M2Crypto but that's clearly no fun. It should be fine to just use the system version. Change-Id: I94c7464bf60ae586e16a2f38b7440cea8dc110e5 --- tools/install_venv.py | 13 +++++++++++++ tools/pip-requires | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/install_venv.py b/tools/install_venv.py index 013ddc9a2..78447c860 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -86,6 +86,9 @@ class Distro(object): ' requires virtualenv, please install it using your' ' favorite package management tool') + def install_m2crypto(self): + pip_install('M2Crypto') + class Fedora(Distro): @@ -105,6 +108,14 @@ class Fedora(Distro): super(Fedora, self).install_virtualenv() + # + # pip install M2Crypto fails on Fedora because of + # weird differences with OpenSSL headers + # + def install_m2crypto(self): + if not self.check_pkg('m2crypto'): + self.yum_install('m2crypto') + def get_distro(): if os.path.exists('/etc/fedora-release'): @@ -145,6 +156,8 @@ def install_dependencies(venv=VENV): pip_install('-r', PIP_REQUIRES) + get_distro().install_m2crypto() + # Tell the virtual env how to "import nova" pthfile = os.path.join(venv, "lib", PY_VERSION, "site-packages", "nova.pth") diff --git a/tools/pip-requires b/tools/pip-requires index 7f8401fb2..021a2a2ca 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -2,7 +2,6 @@ SQLAlchemy==0.6.3 pep8==0.6.1 pylint==0.19 Cheetah==2.4.4 -M2Crypto amqplib==0.6.1 anyjson==0.2.4 boto==1.9b -- cgit