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
1=== modified file 'charmhelpers/contrib/openstack/utils.py'
2--- charmhelpers/contrib/openstack/utils.py 2016-01-05 09:10:53 +0000
3+++ charmhelpers/contrib/openstack/utils.py 2016-01-08 13:28:07 +0000
4@@ -593,7 +593,7 @@
5 return yaml.load(projects_yaml)
6
7
8-def git_clone_and_install(projects_yaml, core_project, depth=1):
9+def git_clone_and_install(projects_yaml, core_project):
10 """
11 Clone/install all specified OpenStack repositories.
12
13@@ -643,6 +643,9 @@
14 for p in projects['repositories']:
15 repo = p['repository']
16 branch = p['branch']
17+ depth = '1'
18+ if 'depth' in p.keys():
19+ depth = p['depth']
20 if p['name'] == 'requirements':
21 repo_dir = _git_clone_and_install_single(repo, branch, depth,
22 parent_dir, http_proxy,
23@@ -687,19 +690,13 @@
24 """
25 Clone and install a single git repository.
26 """
27- dest_dir = os.path.join(parent_dir, os.path.basename(repo))
28-
29 if not os.path.exists(parent_dir):
30 juju_log('Directory already exists at {}. '
31 'No need to create directory.'.format(parent_dir))
32 os.mkdir(parent_dir)
33
34- if not os.path.exists(dest_dir):
35- juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
36- repo_dir = install_remote(repo, dest=parent_dir, branch=branch,
37- depth=depth)
38- else:
39- repo_dir = dest_dir
40+ juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
41+ repo_dir = install_remote(repo, dest=parent_dir, branch=branch, depth=depth)
42
43 venv = os.path.join(parent_dir, 'venv')
44
45
46=== modified file 'charmhelpers/fetch/giturl.py'
47--- charmhelpers/fetch/giturl.py 2015-12-11 17:02:13 +0000
48+++ charmhelpers/fetch/giturl.py 2016-01-08 13:28:07 +0000
49@@ -22,7 +22,6 @@
50 filter_installed_packages,
51 apt_install,
52 )
53-from charmhelpers.core.host import mkdir
54
55 if filter_installed_packages(['git']) != []:
56 apt_install(['git'])
57@@ -62,8 +61,6 @@
58 else:
59 dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
60 branch_name)
61- if not os.path.exists(dest_dir):
62- mkdir(dest_dir, perms=0o755)
63 try:
64 self.clone(source, dest_dir, branch, depth)
65 except OSError as e:
66
67=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
68--- tests/contrib/openstack/test_openstack_utils.py 2016-01-05 09:10:53 +0000
69+++ tests/contrib/openstack/test_openstack_utils.py 2016-01-08 13:28:07 +0000
70@@ -714,7 +714,7 @@
71 - {name: requirements,
72 repository: 'git://git.openstack.org/openstack/requirements',
73 branch: stable/juno}"""
74- openstack.git_clone_and_install(git_wrong_order_1, 'keystone', depth=1)
75+ openstack.git_clone_and_install(git_wrong_order_1, 'keystone')
76 error_out.assert_called_with('keystone git repo must be specified last')
77
78 git_wrong_order_2 = """
79@@ -722,7 +722,7 @@
80 - {name: keystone,
81 repository: 'git://git.openstack.org/openstack/keystone',
82 branch: stable/juno}"""
83- openstack.git_clone_and_install(git_wrong_order_2, 'keystone', depth=1)
84+ openstack.git_clone_and_install(git_wrong_order_2, 'keystone')
85 error_out.assert_called_with('requirements git repo must be specified first')
86
87 @patch('os.path.join')
88@@ -740,7 +740,7 @@
89 _git_install_single.return_value = '/mnt/openstack-git/requirements'
90 join.return_value = '/mnt/openstack-git/venv'
91
92- openstack.git_clone_and_install(openstack_origin_git, proj, depth=1)
93+ openstack.git_clone_and_install(openstack_origin_git, proj)
94 self.assertTrue(pip_venv.called)
95 pip_install.assert_called_with('setuptools', upgrade=True,
96 proxy=None,
97@@ -748,10 +748,10 @@
98 self.assertTrue(_git_install_single.call_count == 2)
99 expected = [
100 call('git://git.openstack.org/openstack/requirements',
101- 'stable/juno', 1, '/mnt/openstack-git', None,
102+ 'stable/juno', '1', '/mnt/openstack-git', None,
103 update_requirements=False),
104 call('git://git.openstack.org/openstack/keystone',
105- 'stable/juno', 1, '/mnt/openstack-git', None,
106+ 'stable/juno', '1', '/mnt/openstack-git', None,
107 update_requirements=True)
108 ]
109 self.assertEquals(expected, _git_install_single.call_args_list)
110
111=== modified file 'tests/fetch/test_giturl.py'
112--- tests/fetch/test_giturl.py 2015-12-11 17:02:13 +0000
113+++ tests/fetch/test_giturl.py 2016-01-08 13:28:07 +0000
114@@ -89,8 +89,7 @@
115 if dst:
116 shutil.rmtree(dst, ignore_errors=True)
117
118- @patch('charmhelpers.fetch.giturl.mkdir')
119- def test_installs(self, _mkdir):
120+ def test_installs(self):
121 self.fh.clone = MagicMock()
122
123 for url in self.valid_urls:
124@@ -100,10 +99,8 @@
125 with patch.dict('os.environ', {'CHARM_DIR': 'foo'}):
126 where = self.fh.install(url)
127 self.assertEqual(where, dest)
128- _mkdir.assert_called_with(where, perms=0o755)
129
130- @patch('charmhelpers.fetch.giturl.mkdir')
131- def test_installs_specified_dest(self, _mkdir):
132+ def test_installs_specified_dest(self):
133 self.fh.clone = MagicMock()
134
135 for url in self.valid_urls:

Subscribers

People subscribed via source and target branches