Merge lp:~corey.bryant/charm-helpers/systemd-fixup-and-upper-constraints into lp:charm-helpers

Proposed by Corey Bryant
Status: Merged
Merged at revision: 595
Proposed branch: lp:~corey.bryant/charm-helpers/systemd-fixup-and-upper-constraints
Merge into: lp:charm-helpers
Diff against target: 227 lines (+74/-15)
3 files modified
charmhelpers/contrib/openstack/utils.py (+58/-8)
charmhelpers/contrib/python/packages.py (+5/-1)
tests/contrib/openstack/test_openstack_utils.py (+11/-6)
To merge this branch: bzr merge lp:~corey.bryant/charm-helpers/systemd-fixup-and-upper-constraints
Reviewer Review Type Date Requested Status
James Page Pending
charmers Pending
Review via email: mp+298768@code.launchpad.net

Description of the change

This mp has a number of updates for openstack deploy from source that are explained in the commit messages.

To post a comment you must log in.
599. By Corey Bryant

Merge lp:charm-helpers

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-06-15 20:59:51 +0000
3+++ charmhelpers/contrib/openstack/utils.py 2016-06-30 12:59:15 +0000
4@@ -222,7 +222,6 @@
5 }
6
7 GIT_DEFAULT_BRANCHES = {
8- 'icehouse': 'icehouse-eol',
9 'kilo': 'stable/kilo',
10 'liberty': 'stable/liberty',
11 'mitaka': 'stable/mitaka',
12@@ -743,12 +742,18 @@
13 }
14 repos = [repo]
15
16+ # NOTE(coreycb): This is a temp work-around until the requirements
17+ # repo moves from stable/kilo branch to kilo-eol tag. The core
18+ # repos have already done this.
19+ if default == 'kilo':
20+ branch = 'kilo-eol'
21+
22 # neutron-* and nova-* charms require some additional repos
23 if service in ['neutron-api', 'neutron-gateway',
24 'neutron-openvswitch']:
25 core_project = 'neutron'
26 for project in ['neutron-fwaas', 'neutron-lbaas',
27- 'neutron-vpnaas']:
28+ 'neutron-vpnaas', 'nova']:
29 repo = {
30 'name': project,
31 'repository': GIT_DEFAULT_REPOS[project],
32@@ -837,6 +842,7 @@
33 pip_install(p, upgrade=True, proxy=http_proxy,
34 venv=os.path.join(parent_dir, 'venv'))
35
36+ constraints = None
37 for p in projects['repositories']:
38 repo = p['repository']
39 branch = p['branch']
40@@ -848,10 +854,15 @@
41 parent_dir, http_proxy,
42 update_requirements=False)
43 requirements_dir = repo_dir
44+ constraints = os.path.join(repo_dir, "upper-constraints.txt")
45+ # upper-constraints didn't exist until after icehouse
46+ if not os.path.isfile(constraints):
47+ constraints = None
48 else:
49 repo_dir = _git_clone_and_install_single(repo, branch, depth,
50 parent_dir, http_proxy,
51- update_requirements=True)
52+ update_requirements=True,
53+ constraints=constraints)
54
55 os.environ = old_environ
56
57@@ -883,7 +894,7 @@
58
59
60 def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy,
61- update_requirements):
62+ update_requirements, constraints=None):
63 """
64 Clone and install a single git repository.
65 """
66@@ -906,9 +917,10 @@
67
68 juju_log('Installing git repo from dir: {}'.format(repo_dir))
69 if http_proxy:
70- pip_install(repo_dir, proxy=http_proxy, venv=venv)
71+ pip_install(repo_dir, proxy=http_proxy, venv=venv,
72+ constraints=constraints)
73 else:
74- pip_install(repo_dir, venv=venv)
75+ pip_install(repo_dir, venv=venv, constraints=constraints)
76
77 return repo_dir
78
79@@ -988,6 +1000,7 @@
80 script generation, which is used by the OpenStack packages.
81 """
82 for f in os.listdir(templates_dir):
83+ # Create the init script and systemd unit file from the template
84 if f.endswith(".init.in"):
85 init_in_file = f
86 init_file = f[:-8]
87@@ -1013,10 +1026,47 @@
88 os.remove(init_dest)
89 if os.path.exists(service_dest):
90 os.remove(service_dest)
91- shutil.move(init_source, init_dest)
92- shutil.move(service_source, service_dest)
93+ shutil.copyfile(init_source, init_dest)
94+ shutil.copyfile(service_source, service_dest)
95 os.chmod(init_dest, 0o755)
96
97+ for f in os.listdir(templates_dir):
98+ # If there's a service.in file, use it instead of the generated one
99+ if f.endswith(".service.in"):
100+ service_in_file = f
101+ service_file = f[:-3]
102+
103+ service_in_source = os.path.join(templates_dir, service_in_file)
104+ service_source = os.path.join(templates_dir, service_file)
105+ service_dest = os.path.join('/lib/systemd/system', service_file)
106+
107+ shutil.copyfile(service_in_source, service_source)
108+
109+ if os.path.exists(service_dest):
110+ os.remove(service_dest)
111+ shutil.copyfile(service_source, service_dest)
112+
113+ for f in os.listdir(templates_dir):
114+ # Generate the systemd unit if there's no existing .service.in
115+ if f.endswith(".init.in"):
116+ init_in_file = f
117+ init_file = f[:-8]
118+ service_in_file = "{}.service.in".format(init_file)
119+ service_file = "{}.service".format(init_file)
120+
121+ init_in_source = os.path.join(templates_dir, init_in_file)
122+ service_in_source = os.path.join(templates_dir, service_in_file)
123+ service_source = os.path.join(templates_dir, service_file)
124+ service_dest = os.path.join('/lib/systemd/system', service_file)
125+
126+ if not os.path.exists(service_in_source):
127+ cmd = ['pkgos-gen-systemd-unit', init_in_source]
128+ subprocess.check_call(cmd)
129+
130+ if os.path.exists(service_dest):
131+ os.remove(service_dest)
132+ shutil.copyfile(service_source, service_dest)
133+
134
135 def os_workload_status(configs, required_interfaces, charm_func=None):
136 """
137
138=== modified file 'charmhelpers/contrib/python/packages.py'
139--- charmhelpers/contrib/python/packages.py 2016-02-02 10:46:04 +0000
140+++ charmhelpers/contrib/python/packages.py 2016-06-30 12:59:15 +0000
141@@ -80,7 +80,8 @@
142 pip_execute(command)
143
144
145-def pip_install(package, fatal=False, upgrade=False, venv=None, **options):
146+def pip_install(package, fatal=False, upgrade=False, venv=None,
147+ constraints=None, **options):
148 """Install a python package"""
149 if venv:
150 venv_python = os.path.join(venv, 'bin/pip')
151@@ -95,6 +96,9 @@
152 if upgrade:
153 command.append('--upgrade')
154
155+ if constraints:
156+ command.extend(['-c', constraints])
157+
158 if isinstance(package, list):
159 command.extend(package)
160 else:
161
162=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
163--- tests/contrib/openstack/test_openstack_utils.py 2016-05-27 09:05:48 +0000
164+++ tests/contrib/openstack/test_openstack_utils.py 2016-06-30 12:59:15 +0000
165@@ -730,13 +730,16 @@
166 error_out.assert_called_with(
167 'openstack-origin-git key \'%s\' is missing' % key)
168
169+ @patch('os.path.isfile')
170 @patch('os.path.join')
171 @patch.object(openstack, 'error_out')
172 @patch.object(openstack, '_git_clone_and_install_single')
173 @patch.object(openstack, 'pip_install')
174 @patch.object(openstack, 'pip_create_virtualenv')
175 def test_git_clone_and_install_errors(self, pip_venv, pip_install,
176- git_install_single, error_out, join):
177+ git_install_single, error_out, join,
178+ isfile):
179+ isfile.return_value = True
180 git_missing_repos = """
181 repostories:
182 - {name: requirements,
183@@ -809,13 +812,13 @@
184 charm_dir.return_value = '/var/lib/juju/units/testing-foo-0/charm'
185 # the following sets the global requirements_dir
186 _git_install_single.return_value = '/mnt/openstack-git/requirements'
187- join.return_value = '/mnt/openstack-git/venv'
188+ join.return_value = 'joined-path'
189
190 openstack.git_clone_and_install(openstack_origin_git, proj)
191 self.assertTrue(pip_venv.called)
192 pip_install.assert_called_with('setuptools', upgrade=True,
193 proxy=None,
194- venv='/mnt/openstack-git/venv')
195+ venv='joined-path')
196 self.assertTrue(_git_install_single.call_count == 2)
197 expected = [
198 call('git://git.openstack.org/openstack/requirements',
199@@ -823,7 +826,7 @@
200 update_requirements=False),
201 call('git://git.openstack.org/openstack/keystone',
202 'stable/juno', '1', '/mnt/openstack-git', None,
203- update_requirements=True)
204+ update_requirements=True, constraints=None)
205 ]
206 self.assertEquals(expected, _git_install_single.call_args_list)
207 assert not error_out.called
208@@ -855,7 +858,8 @@
209 branch=branch)
210 assert not _git_update_reqs.called
211 pip_install.assert_called_with(dest_dir, venv='/mnt/openstack-git',
212- proxy='http://squid-proxy-url')
213+ proxy='http://squid-proxy-url',
214+ constraints=None)
215
216 @patch('os.path.join')
217 @patch('os.mkdir')
218@@ -887,7 +891,8 @@
219 branch=branch)
220 _git_update_reqs.assert_called_with(venv_dir, dest_dir, reqs_dir)
221 pip_install.assert_called_with(dest_dir, venv='/mnt/openstack-git',
222- proxy='http://squid-proxy-url')
223+ proxy='http://squid-proxy-url',
224+ constraints=None)
225
226 @patch('os.path.join')
227 @patch('os.getcwd')

Subscribers

People subscribed via source and target branches