Merge lp:~sinzui/juju-release-tools/win-agents into lp:juju-release-tools

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 84
Proposed branch: lp:~sinzui/juju-release-tools/win-agents
Merge into: lp:juju-release-tools
Diff against target: 249 lines (+147/-28)
4 files modified
tests/test_make_release_notes.py (+1/-12)
tests/test_winbuildtest.py (+91/-0)
tests/utils.py (+12/-0)
winbuildtest.py (+43/-16)
To merge this branch: bzr merge lp:~sinzui/juju-release-tools/win-agents
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+238942@code.launchpad.net

Description of the change

This branch adds support to create a win amd64 jujud agent each time a win 386 juju client is created.

The changes look more invasive than actual.
1. renamed build => build_client
   and the dir and command constants are passed to the function to make testing easier.
2. renamed package => create_installer
   and the dir and command constants are passed to the function to make testing easier.
3. added build_agent based on build_client
4. added create_cloud_agent
5. added cleanup of old agent files per the way old installers are cleaned up
6. extracted temp_dir() to utils.py to reuse it in new win tests
7. I added tests for the functions I changed and the two new functions I added.

A future branch in juju-ci-tools will change the tests to capture the agent tgz when the installer is captured.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test_make_release_notes.py'
2--- tests/test_make_release_notes.py 2014-09-18 20:16:00 +0000
3+++ tests/test_make_release_notes.py 2014-10-20 19:01:48 +0000
4@@ -1,9 +1,6 @@
5-from contextlib import contextmanager
6 from mock import patch
7 import os
8-import shutil
9 from StringIO import StringIO
10-from tempfile import mkdtemp
11 from unittest import TestCase
12
13
14@@ -18,15 +15,7 @@
15 save_notes,
16 STABLE,
17 )
18-
19-
20-@contextmanager
21-def temp_dir():
22- dirname = mkdtemp()
23- try:
24- yield dirname
25- finally:
26- shutil.rmtree(dirname)
27+from utils import temp_dir
28
29
30 class FakeBug(object):
31
32=== added file 'tests/test_winbuildtest.py'
33--- tests/test_winbuildtest.py 1970-01-01 00:00:00 +0000
34+++ tests/test_winbuildtest.py 2014-10-20 19:01:48 +0000
35@@ -0,0 +1,91 @@
36+from mock import patch
37+import os
38+import tarfile
39+from unittest import TestCase
40+
41+from winbuildtest import (
42+ build_agent,
43+ build_client,
44+ create_cloud_agent,
45+ create_installer,
46+ GO_CMD,
47+ GOPATH,
48+ ISS_CMD,
49+)
50+from utils import temp_dir
51+
52+
53+class WinBuildTestTestCase(TestCase):
54+
55+ def test_build_client(self):
56+ # build_client() builds the juju client with go and moved the
57+ # exe to the iss dir.
58+ with temp_dir() as cmd_dir:
59+ with temp_dir() as iss_dir:
60+
61+ def make_juju(*args, **kwargs):
62+ with open('%s/juju.exe' % cmd_dir, 'w') as fake_juju:
63+ fake_juju.write('juju')
64+
65+ with patch('winbuildtest.run',
66+ return_value='', side_effect=make_juju) as run_mock:
67+ devnull = open(os.devnull, 'w')
68+ with patch('sys.stdout', devnull):
69+ build_client(cmd_dir, GO_CMD, GOPATH, iss_dir)
70+ args, kwargs = run_mock.call_args
71+ self.assertEqual((GO_CMD, 'build'), args)
72+ self.assertEqual('386', kwargs['env'].get('GOARCH'))
73+ self.assertEqual(GOPATH, kwargs['env'].get('GOPATH'))
74+ client_path = os.path.join(iss_dir, 'juju.exe')
75+ self.assertTrue(os.path.isfile(client_path))
76+
77+ def test_create_installer(self):
78+ # create_installer() creates an iss-style installer and copies it
79+ # to the ci dir.
80+ with temp_dir() as iss_dir:
81+ with temp_dir() as ci_dir:
82+ installer_name = 'juju-setup-1.20.1.exe'
83+
84+ def make_installer(*args, **kwargs):
85+ output_dir = os.path.join(iss_dir, 'output')
86+ os.makedirs(output_dir)
87+ installer_path = os.path.join(
88+ output_dir, installer_name)
89+ with open(installer_path, 'w') as fake_installer:
90+ fake_installer.write('juju installer')
91+
92+ with patch('winbuildtest.run',
93+ return_value='',
94+ side_effect=make_installer) as run_mock:
95+ devnull = open(os.devnull, 'w')
96+ with patch('sys.stdout', devnull):
97+ create_installer('1.20.1', iss_dir, ISS_CMD, ci_dir)
98+ args, kwargs = run_mock.call_args
99+ self.assertEqual((ISS_CMD, 'setup.iss'), args)
100+ installer_path = os.path.join(ci_dir, installer_name)
101+ self.assertTrue(os.path.isfile(installer_path))
102+
103+ def test_build_agent(self):
104+ # build_agent creates a win amd64 jujud.
105+ with temp_dir() as jujud_cmd_dir:
106+ with patch('winbuildtest.run', return_value='') as run_mock:
107+ devnull = open(os.devnull, 'w')
108+ with patch('sys.stdout', devnull):
109+ build_agent(jujud_cmd_dir, GO_CMD, GOPATH)
110+ args, kwargs = run_mock.call_args
111+ self.assertEqual((GO_CMD, 'build'), args)
112+ self.assertEqual('amd64', kwargs['env'].get('GOARCH'))
113+ self.assertEqual(GOPATH, kwargs['env'].get('GOPATH'))
114+
115+ def test_create_cloud_agent(self):
116+ # create_cloud_agent() creates an agent tgz from the jujud and
117+ # copies it to the ci dir.
118+ with temp_dir() as cmd_dir:
119+ with temp_dir() as ci_dir:
120+ with open('%s/jujud.exe' % cmd_dir, 'w') as fake_jujud:
121+ fake_jujud.write('jujud')
122+ create_cloud_agent('1.20.1', cmd_dir, ci_dir)
123+ agent = os.path.join(ci_dir, 'juju-1.20.1-win2012-amd64.tgz')
124+ self.assertTrue(os.path.isfile(agent))
125+ with tarfile.open(name=agent, mode='r:gz') as tar:
126+ self.assertEqual(['jujud.exe'], tar.getnames())
127
128=== added file 'tests/utils.py'
129--- tests/utils.py 1970-01-01 00:00:00 +0000
130+++ tests/utils.py 2014-10-20 19:01:48 +0000
131@@ -0,0 +1,12 @@
132+from contextlib import contextmanager
133+import shutil
134+from tempfile import mkdtemp
135+
136+
137+@contextmanager
138+def temp_dir():
139+ dirname = mkdtemp()
140+ try:
141+ yield dirname
142+ finally:
143+ shutil.rmtree(dirname)
144
145=== modified file 'winbuildtest.py'
146--- winbuildtest.py 2014-07-07 18:55:30 +0000
147+++ winbuildtest.py 2014-10-20 19:01:48 +0000
148@@ -22,6 +22,8 @@
149 GOPATH = os.path.join(CI_DIR, 'gogo')
150 JUJU_CMD_DIR = os.path.join(
151 GOPATH, 'src', 'github.com', 'juju', 'juju', 'cmd', 'juju')
152+JUJUD_CMD_DIR = os.path.join(
153+ GOPATH, 'src', 'github.com', 'juju', 'juju', 'cmd', 'juju')
154 ISS_DIR = os.path.join(
155 GOPATH, 'src', 'github.com', 'juju', 'juju', 'scripts', 'win-installer')
156
157@@ -60,6 +62,11 @@
158 path = os.path.join(CI_DIR, name)
159 os.remove(path)
160 print('Removed {0}'.format(path))
161+ agent_tars = [n for n in os.listdir(CI_DIR) if 'tgz' in n]
162+ for name in agent_tars:
163+ path = os.path.join(CI_DIR, name)
164+ os.remove(path)
165+ print('Removed {0}'.format(path))
166 juju_execs = [
167 n for n in os.listdir(CI_DIR) if 'juju-setup' in n and '.exe' in n]
168 for name in juju_execs:
169@@ -95,26 +102,26 @@
170 print('Moved {0} to {1}'.format(dir_path, GOPATH))
171
172
173-def build():
174+def build_client(juju_cmd_dir, go_cmd, gopath, iss_dir):
175 env = dict(os.environ)
176- env['GOPATH'] = GOPATH
177+ env['GOPATH'] = gopath
178 env['GOARCH'] = '386'
179- with WorkingDirectory(JUJU_CMD_DIR):
180- output = run(GO_CMD, 'build', env=env)
181+ with WorkingDirectory(juju_cmd_dir):
182+ output = run(go_cmd, 'build', env=env)
183 print(output)
184 print('Built Juju.exe')
185- shutil.move('juju.exe', ISS_DIR)
186- print('Moved {0} to {1}'.format('juju.exe', ISS_DIR))
187-
188-
189-def package(version):
190- with WorkingDirectory(ISS_DIR):
191- output = run(ISS_CMD, 'setup.iss')
192+ shutil.move('juju.exe', iss_dir)
193+ print('Moved {0} to {1}'.format('juju.exe', iss_dir))
194+
195+
196+def create_installer(version, iss_dir, iss_cmd, ci_dir):
197+ with WorkingDirectory(iss_dir):
198+ output = run(iss_cmd, 'setup.iss')
199 print(output)
200 installer_name = 'juju-setup-{0}.exe'.format(version)
201- installer_path = os.path.join(ISS_DIR, 'output', installer_name)
202- shutil.move(installer_path, CI_DIR)
203- print('Moved {0} to {1}'.format(installer_path, CI_DIR))
204+ installer_path = os.path.join(iss_dir, 'output', installer_name)
205+ shutil.move(installer_path, ci_dir)
206+ print('Moved {0} to {1}'.format(installer_path, ci_dir))
207 return installer_name
208
209
210@@ -132,6 +139,24 @@
211 raise Exception("Juju did not install")
212
213
214+def build_agent(jujud_cmd_dir, go_cmd, gopath):
215+ env = dict(os.environ)
216+ env['GOPATH'] = gopath
217+ env['GOARCH'] = 'amd64'
218+ with WorkingDirectory(jujud_cmd_dir):
219+ output = run(go_cmd, 'build', env=env)
220+ print(output)
221+ print('Built jujud.exe')
222+
223+
224+def create_cloud_agent(version, jujud_cmd_dir, ci_dir):
225+ tarball_name = 'juju-{}-win2012-amd64.tgz'.format(version)
226+ tarball_path = os.path.join(ci_dir, tarball_name)
227+ agent_path = os.path.join(jujud_cmd_dir, 'jujud.exe')
228+ with tarfile.open(name=tarball_path, mode='w:gz') as tar:
229+ tar.add(agent_path, arcname='jujud.exe')
230+
231+
232 def main():
233 if len(sys.argv) != 2:
234 print('USAGE: {0} juju-core_X.X.X.tar.gz')
235@@ -147,10 +172,12 @@
236 setup(tarball_name)
237 untar(tarball_path)
238 move_source_to_gopath(tarball_name)
239- build()
240- installer_name = package(version)
241+ build_client(JUJU_CMD_DIR, GO_CMD, GOPATH, ISS_DIR)
242+ installer_name = create_installer(version, ISS_DIR, ISS_CMD, CI_DIR)
243 install(installer_name)
244 test(version)
245+ build_agent(JUJUD_CMD_DIR, GO_CMD, GOPATH)
246+ create_cloud_agent(version, JUJUD_CMD_DIR, CI_DIR)
247 return 0
248 except Exception as e:
249 print(str(e))

Subscribers

People subscribed via source and target branches