Merge lp:~corey.bryant/charm-helpers/fix-global-reqs into lp:charm-helpers

Proposed by Corey Bryant
Status: Merged
Merged at revision: 391
Proposed branch: lp:~corey.bryant/charm-helpers/fix-global-reqs
Merge into: lp:charm-helpers
Diff against target: 145 lines (+35/-15)
2 files modified
charmhelpers/contrib/openstack/utils.py (+13/-7)
tests/contrib/openstack/test_openstack_utils.py (+22/-8)
To merge this branch: bzr merge lp:~corey.bryant/charm-helpers/fix-global-reqs
Reviewer Review Type Date Requested Status
Jorge Niedbalski (community) Approve
Billy Olsen Approve
Review via email: mp+262469@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Corey Bryant (corey.bryant) wrote :

This fixes the following error: http://paste.ubuntu.com/11737211/

The problem is that on trusty a virtualenv is created with an old setuptools and therefore and old pkg_resource. When the update.py script from the master branch of global requirements is executed, it fails because of the old version of pkg_resources.

This fix provides two things:
1) upgrade setuptools to latest version after creating the virtualenv
2) when executing 'python update.py <package_dir>' use the python from the virtualenv

Revision history for this message
Billy Olsen (billy-olsen) wrote :

Looks good to me.

review: Approve
Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

LGTM

review: Approve
Revision history for this message
Corey Bryant (corey.bryant) wrote :

Thanks Jorge!

On Mon, Jun 22, 2015 at 6:49 PM, <email address hidden> wrote:

> The proposal to merge lp:~corey.bryant/charm-helpers/fix-global-reqs into
> lp:charm-helpers has been updated.
>
> Status: Needs review => Merged
>
> For more details, see:
>
> https://code.launchpad.net/~corey.bryant/charm-helpers/fix-global-reqs/+merge/262469
> --
> You are the owner of lp:~corey.bryant/charm-helpers/fix-global-reqs.
>

--
Regards,
Corey

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/openstack/utils.py'
--- charmhelpers/contrib/openstack/utils.py 2015-06-11 14:41:04 +0000
+++ charmhelpers/contrib/openstack/utils.py 2015-06-19 16:09:56 +0000
@@ -555,6 +555,11 @@
555555
556 pip_create_virtualenv(os.path.join(parent_dir, 'venv'))556 pip_create_virtualenv(os.path.join(parent_dir, 'venv'))
557557
558 # Upgrade setuptools from default virtualenv version. The default version
559 # in trusty breaks update.py in global requirements master branch.
560 pip_install('setuptools', upgrade=True, proxy=http_proxy,
561 venv=os.path.join(parent_dir, 'venv'))
562
558 for p in projects['repositories']:563 for p in projects['repositories']:
559 repo = p['repository']564 repo = p['repository']
560 branch = p['branch']565 branch = p['branch']
@@ -616,24 +621,24 @@
616 else:621 else:
617 repo_dir = dest_dir622 repo_dir = dest_dir
618623
624 venv = os.path.join(parent_dir, 'venv')
625
619 if update_requirements:626 if update_requirements:
620 if not requirements_dir:627 if not requirements_dir:
621 error_out('requirements repo must be cloned before '628 error_out('requirements repo must be cloned before '
622 'updating from global requirements.')629 'updating from global requirements.')
623 _git_update_requirements(repo_dir, requirements_dir)630 _git_update_requirements(venv, repo_dir, requirements_dir)
624631
625 juju_log('Installing git repo from dir: {}'.format(repo_dir))632 juju_log('Installing git repo from dir: {}'.format(repo_dir))
626 if http_proxy:633 if http_proxy:
627 pip_install(repo_dir, proxy=http_proxy,634 pip_install(repo_dir, proxy=http_proxy, venv=venv)
628 venv=os.path.join(parent_dir, 'venv'))
629 else:635 else:
630 pip_install(repo_dir,636 pip_install(repo_dir, venv=venv)
631 venv=os.path.join(parent_dir, 'venv'))
632637
633 return repo_dir638 return repo_dir
634639
635640
636def _git_update_requirements(package_dir, reqs_dir):641def _git_update_requirements(venv, package_dir, reqs_dir):
637 """642 """
638 Update from global requirements.643 Update from global requirements.
639644
@@ -642,7 +647,8 @@
642 """647 """
643 orig_dir = os.getcwd()648 orig_dir = os.getcwd()
644 os.chdir(reqs_dir)649 os.chdir(reqs_dir)
645 cmd = ['python', 'update.py', package_dir]650 python = os.path.join(venv, 'bin/python')
651 cmd = [python, 'update.py', package_dir]
646 try:652 try:
647 subprocess.check_call(cmd)653 subprocess.check_call(cmd)
648 except subprocess.CalledProcessError:654 except subprocess.CalledProcessError:
649655
=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
--- tests/contrib/openstack/test_openstack_utils.py 2015-05-11 18:53:44 +0000
+++ tests/contrib/openstack/test_openstack_utils.py 2015-06-19 16:09:56 +0000
@@ -642,11 +642,13 @@
642 error_out.assert_called_with(642 error_out.assert_called_with(
643 'openstack-origin-git key \'%s\' is missing' % key)643 'openstack-origin-git key \'%s\' is missing' % key)
644644
645 @patch('os.path.join')
645 @patch.object(openstack, 'error_out')646 @patch.object(openstack, 'error_out')
646 @patch.object(openstack, '_git_clone_and_install_single')647 @patch.object(openstack, '_git_clone_and_install_single')
648 @patch.object(openstack, 'pip_install')
647 @patch.object(openstack, 'pip_create_virtualenv')649 @patch.object(openstack, 'pip_create_virtualenv')
648 def test_git_clone_and_install_errors(self, pip_venv, git_install_single,650 def test_git_clone_and_install_errors(self, pip_venv, pip_install,
649 error_out):651 git_install_single, error_out, join):
650 git_missing_repos = """652 git_missing_repos = """
651 repostories:653 repostories:
652 - {name: requirements,654 - {name: requirements,
@@ -704,19 +706,26 @@
704 openstack.git_clone_and_install(git_wrong_order_2, 'keystone', depth=1)706 openstack.git_clone_and_install(git_wrong_order_2, 'keystone', depth=1)
705 error_out.assert_called_with('requirements git repo must be specified first')707 error_out.assert_called_with('requirements git repo must be specified first')
706708
709 @patch('os.path.join')
707 @patch.object(openstack, 'charm_dir')710 @patch.object(openstack, 'charm_dir')
708 @patch.object(openstack, 'error_out')711 @patch.object(openstack, 'error_out')
709 @patch.object(openstack, '_git_clone_and_install_single')712 @patch.object(openstack, '_git_clone_and_install_single')
713 @patch.object(openstack, 'pip_install')
710 @patch.object(openstack, 'pip_create_virtualenv')714 @patch.object(openstack, 'pip_create_virtualenv')
711 def test_git_clone_and_install_success(self, pip_venv, _git_install_single,715 def test_git_clone_and_install_success(self, pip_venv, pip_install,
712 error_out, charm_dir):716 _git_install_single, error_out,
717 charm_dir, join):
713 proj = 'keystone'718 proj = 'keystone'
714 charm_dir.return_value = '/var/lib/juju/units/testing-foo-0/charm'719 charm_dir.return_value = '/var/lib/juju/units/testing-foo-0/charm'
715 # the following sets the global requirements_dir720 # the following sets the global requirements_dir
716 _git_install_single.return_value = '/mnt/openstack-git/requirements'721 _git_install_single.return_value = '/mnt/openstack-git/requirements'
722 join.return_value = '/mnt/openstack-git/venv'
717723
718 openstack.git_clone_and_install(openstack_origin_git, proj, depth=1)724 openstack.git_clone_and_install(openstack_origin_git, proj, depth=1)
719 self.assertTrue(pip_venv.called)725 self.assertTrue(pip_venv.called)
726 pip_install.assert_called_with('setuptools', upgrade=True,
727 proxy=None,
728 venv='/mnt/openstack-git/venv')
720 self.assertTrue(_git_install_single.call_count == 2)729 self.assertTrue(_git_install_single.call_count == 2)
721 expected = [730 expected = [
722 call('git://git.openstack.org/openstack/requirements',731 call('git://git.openstack.org/openstack/requirements',
@@ -775,6 +784,7 @@
775 parent_dir = '/mnt/openstack-git/'784 parent_dir = '/mnt/openstack-git/'
776 http_proxy = 'http://squid-proxy-url'785 http_proxy = 'http://squid-proxy-url'
777 dest_dir = '/mnt/openstack-git'786 dest_dir = '/mnt/openstack-git'
787 venv_dir = '/mnt/openstack-git'
778 reqs_dir = '/mnt/openstack-git/requirements-dir'788 reqs_dir = '/mnt/openstack-git/requirements-dir'
779 join.return_value = dest_dir789 join.return_value = dest_dir
780 openstack.requirements_dir = reqs_dir790 openstack.requirements_dir = reqs_dir
@@ -786,23 +796,27 @@
786 mkdir.assert_called_with(parent_dir)796 mkdir.assert_called_with(parent_dir)
787 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,797 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,
788 branch=branch)798 branch=branch)
789 _git_update_reqs.assert_called_with(dest_dir, reqs_dir)799 _git_update_reqs.assert_called_with(venv_dir, dest_dir, reqs_dir)
790 pip_install.assert_called_with(dest_dir, venv='/mnt/openstack-git',800 pip_install.assert_called_with(dest_dir, venv='/mnt/openstack-git',
791 proxy='http://squid-proxy-url')801 proxy='http://squid-proxy-url')
792802
803 @patch('os.path.join')
793 @patch('os.getcwd')804 @patch('os.getcwd')
794 @patch('os.chdir')805 @patch('os.chdir')
795 @patch('subprocess.check_call')806 @patch('subprocess.check_call')
796 def test_git_update_requirements(self, check_call, chdir, getcwd):807 def test_git_update_requirements(self, check_call, chdir, getcwd, join):
797 pkg_dir = '/mnt/openstack-git/repo-dir'808 pkg_dir = '/mnt/openstack-git/repo-dir'
798 reqs_dir = '/mnt/openstack-git/reqs-dir'809 reqs_dir = '/mnt/openstack-git/reqs-dir'
799 orig_dir = '/var/lib/juju/units/testing-foo-0/charm'810 orig_dir = '/var/lib/juju/units/testing-foo-0/charm'
811 venv_dir = '/mnt/openstack-git/venv'
800 getcwd.return_value = orig_dir812 getcwd.return_value = orig_dir
813 join.return_value = '/mnt/openstack-git/venv/python'
801814
802 openstack._git_update_requirements(pkg_dir, reqs_dir)815 openstack._git_update_requirements(venv_dir, pkg_dir, reqs_dir)
803 expected = [call(reqs_dir), call(orig_dir)]816 expected = [call(reqs_dir), call(orig_dir)]
804 self.assertEquals(expected, chdir.call_args_list)817 self.assertEquals(expected, chdir.call_args_list)
805 check_call.assert_called_with(['python', 'update.py', pkg_dir])818 check_call.assert_called_with(['/mnt/openstack-git/venv/python',
819 'update.py', pkg_dir])
806820
807 @patch('os.path.join')821 @patch('os.path.join')
808 @patch('subprocess.check_call')822 @patch('subprocess.check_call')

Subscribers

People subscribed via source and target branches