Merge lp:~corey.bryant/charm-helpers/git-1531612 into lp:charm-helpers

Proposed by Corey Bryant
Status: Merged
Merged at revision: 515
Proposed branch: lp:~corey.bryant/charm-helpers/git-1531612
Merge into: lp:charm-helpers
Diff against target: 135 lines (+13/-22)
4 files modified
charmhelpers/contrib/openstack/utils.py (+6/-9)
charmhelpers/fetch/giturl.py (+0/-3)
tests/contrib/openstack/test_openstack_utils.py (+5/-5)
tests/fetch/test_giturl.py (+2/-5)
To merge this branch: bzr merge lp:~corey.bryant/charm-helpers/git-1531612
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+281994@code.launchpad.net
To post a comment you must log in.
515. By Corey Bryant

Add git clone depth option to OpenStack deploy from source

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

The deploy from source support in the OpenStack charms performs shallow git clones (e.g. git clone --depth 1) by default. This increases the speed of a git clone significantly. However, there is a side-effect of shallow clones when they are pip installed, in that it causes pip to list the package version as 0.0.0, when in actuality the package version may have been 11.0.0. The next time a pip installed package needs a minimum version of that package (e.g. let's say it needs >= 10.0.0), it'll see that 0.0.0 is installed and it'll install the latest package from pypi.

Non-shallow git clones enable pip to see the actual version and prevent this issue. The openstack-origin-git yaml should support an option to override the default depth of git clones on a per-repo basis.

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

Sample of yaml that overrides the default shallow clone to a normal git clone (see pbr depth):

repositories:
  - {name: requirements,
     repository: 'git://github.com/openstack/requirements',
     branch: stable/kilo}
  - {name: pbr,
     repository: 'git://github.com/coreycb/pbr',
     branch: stable/kilo,
     depth: 0}
  - {name: neutron-fwaas,
     repository: 'git://github.com/openstack/neutron-fwaas',
     branch: stable/kilo}
  - {name: neutron-lbaas,
     repository: 'git://github.com/openstack/neutron-lbaas',
     branch: stable/kilo}
  - {name: neutron-vpnaas,
     repository: 'git://github.com/openstack/neutron-vpnaas',
     branch: stable/kilo}
  - {name: neutron,
     repository: 'git://github.com/openstack/neutron',
     branch: stable/kilo}

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

Added a few inline comments.

Revision history for this message
Liam Young (gnuoy) wrote :

Approved

review: Approve

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 2016-01-05 09:10:53 +0000
+++ charmhelpers/contrib/openstack/utils.py 2016-01-08 13:28:07 +0000
@@ -593,7 +593,7 @@
593 return yaml.load(projects_yaml)593 return yaml.load(projects_yaml)
594594
595595
596def git_clone_and_install(projects_yaml, core_project, depth=1):596def git_clone_and_install(projects_yaml, core_project):
597 """597 """
598 Clone/install all specified OpenStack repositories.598 Clone/install all specified OpenStack repositories.
599599
@@ -643,6 +643,9 @@
643 for p in projects['repositories']:643 for p in projects['repositories']:
644 repo = p['repository']644 repo = p['repository']
645 branch = p['branch']645 branch = p['branch']
646 depth = '1'
647 if 'depth' in p.keys():
648 depth = p['depth']
646 if p['name'] == 'requirements':649 if p['name'] == 'requirements':
647 repo_dir = _git_clone_and_install_single(repo, branch, depth,650 repo_dir = _git_clone_and_install_single(repo, branch, depth,
648 parent_dir, http_proxy,651 parent_dir, http_proxy,
@@ -687,19 +690,13 @@
687 """690 """
688 Clone and install a single git repository.691 Clone and install a single git repository.
689 """692 """
690 dest_dir = os.path.join(parent_dir, os.path.basename(repo))
691
692 if not os.path.exists(parent_dir):693 if not os.path.exists(parent_dir):
693 juju_log('Directory already exists at {}. '694 juju_log('Directory already exists at {}. '
694 'No need to create directory.'.format(parent_dir))695 'No need to create directory.'.format(parent_dir))
695 os.mkdir(parent_dir)696 os.mkdir(parent_dir)
696697
697 if not os.path.exists(dest_dir):698 juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
698 juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))699 repo_dir = install_remote(repo, dest=parent_dir, branch=branch, depth=depth)
699 repo_dir = install_remote(repo, dest=parent_dir, branch=branch,
700 depth=depth)
701 else:
702 repo_dir = dest_dir
703700
704 venv = os.path.join(parent_dir, 'venv')701 venv = os.path.join(parent_dir, 'venv')
705702
706703
=== modified file 'charmhelpers/fetch/giturl.py'
--- charmhelpers/fetch/giturl.py 2015-12-11 17:02:13 +0000
+++ charmhelpers/fetch/giturl.py 2016-01-08 13:28:07 +0000
@@ -22,7 +22,6 @@
22 filter_installed_packages,22 filter_installed_packages,
23 apt_install,23 apt_install,
24)24)
25from charmhelpers.core.host import mkdir
2625
27if filter_installed_packages(['git']) != []:26if filter_installed_packages(['git']) != []:
28 apt_install(['git'])27 apt_install(['git'])
@@ -62,8 +61,6 @@
62 else:61 else:
63 dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",62 dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
64 branch_name)63 branch_name)
65 if not os.path.exists(dest_dir):
66 mkdir(dest_dir, perms=0o755)
67 try:64 try:
68 self.clone(source, dest_dir, branch, depth)65 self.clone(source, dest_dir, branch, depth)
69 except OSError as e:66 except OSError as e:
7067
=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
--- tests/contrib/openstack/test_openstack_utils.py 2016-01-05 09:10:53 +0000
+++ tests/contrib/openstack/test_openstack_utils.py 2016-01-08 13:28:07 +0000
@@ -714,7 +714,7 @@
714 - {name: requirements,714 - {name: requirements,
715 repository: 'git://git.openstack.org/openstack/requirements',715 repository: 'git://git.openstack.org/openstack/requirements',
716 branch: stable/juno}"""716 branch: stable/juno}"""
717 openstack.git_clone_and_install(git_wrong_order_1, 'keystone', depth=1)717 openstack.git_clone_and_install(git_wrong_order_1, 'keystone')
718 error_out.assert_called_with('keystone git repo must be specified last')718 error_out.assert_called_with('keystone git repo must be specified last')
719719
720 git_wrong_order_2 = """720 git_wrong_order_2 = """
@@ -722,7 +722,7 @@
722 - {name: keystone,722 - {name: keystone,
723 repository: 'git://git.openstack.org/openstack/keystone',723 repository: 'git://git.openstack.org/openstack/keystone',
724 branch: stable/juno}"""724 branch: stable/juno}"""
725 openstack.git_clone_and_install(git_wrong_order_2, 'keystone', depth=1)725 openstack.git_clone_and_install(git_wrong_order_2, 'keystone')
726 error_out.assert_called_with('requirements git repo must be specified first')726 error_out.assert_called_with('requirements git repo must be specified first')
727727
728 @patch('os.path.join')728 @patch('os.path.join')
@@ -740,7 +740,7 @@
740 _git_install_single.return_value = '/mnt/openstack-git/requirements'740 _git_install_single.return_value = '/mnt/openstack-git/requirements'
741 join.return_value = '/mnt/openstack-git/venv'741 join.return_value = '/mnt/openstack-git/venv'
742742
743 openstack.git_clone_and_install(openstack_origin_git, proj, depth=1)743 openstack.git_clone_and_install(openstack_origin_git, proj)
744 self.assertTrue(pip_venv.called)744 self.assertTrue(pip_venv.called)
745 pip_install.assert_called_with('setuptools', upgrade=True,745 pip_install.assert_called_with('setuptools', upgrade=True,
746 proxy=None,746 proxy=None,
@@ -748,10 +748,10 @@
748 self.assertTrue(_git_install_single.call_count == 2)748 self.assertTrue(_git_install_single.call_count == 2)
749 expected = [749 expected = [
750 call('git://git.openstack.org/openstack/requirements',750 call('git://git.openstack.org/openstack/requirements',
751 'stable/juno', 1, '/mnt/openstack-git', None,751 'stable/juno', '1', '/mnt/openstack-git', None,
752 update_requirements=False),752 update_requirements=False),
753 call('git://git.openstack.org/openstack/keystone',753 call('git://git.openstack.org/openstack/keystone',
754 'stable/juno', 1, '/mnt/openstack-git', None,754 'stable/juno', '1', '/mnt/openstack-git', None,
755 update_requirements=True)755 update_requirements=True)
756 ]756 ]
757 self.assertEquals(expected, _git_install_single.call_args_list)757 self.assertEquals(expected, _git_install_single.call_args_list)
758758
=== modified file 'tests/fetch/test_giturl.py'
--- tests/fetch/test_giturl.py 2015-12-11 17:02:13 +0000
+++ tests/fetch/test_giturl.py 2016-01-08 13:28:07 +0000
@@ -89,8 +89,7 @@
89 if dst:89 if dst:
90 shutil.rmtree(dst, ignore_errors=True)90 shutil.rmtree(dst, ignore_errors=True)
9191
92 @patch('charmhelpers.fetch.giturl.mkdir')92 def test_installs(self):
93 def test_installs(self, _mkdir):
94 self.fh.clone = MagicMock()93 self.fh.clone = MagicMock()
9594
96 for url in self.valid_urls:95 for url in self.valid_urls:
@@ -100,10 +99,8 @@
100 with patch.dict('os.environ', {'CHARM_DIR': 'foo'}):99 with patch.dict('os.environ', {'CHARM_DIR': 'foo'}):
101 where = self.fh.install(url)100 where = self.fh.install(url)
102 self.assertEqual(where, dest)101 self.assertEqual(where, dest)
103 _mkdir.assert_called_with(where, perms=0o755)
104102
105 @patch('charmhelpers.fetch.giturl.mkdir')103 def test_installs_specified_dest(self):
106 def test_installs_specified_dest(self, _mkdir):
107 self.fh.clone = MagicMock()104 self.fh.clone = MagicMock()
108105
109 for url in self.valid_urls:106 for url in self.valid_urls:

Subscribers

People subscribed via source and target branches