Merge lp:~sergiusens/phablet-tools/server_options into lp:phablet-tools

Proposed by Sergio Schvezov
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 215
Merged at revision: 208
Proposed branch: lp:~sergiusens/phablet-tools/server_options
Merge into: lp:phablet-tools
Diff against target: 158 lines (+38/-24)
5 files modified
phabletutils/arguments.py (+4/-0)
phabletutils/downloads.py (+11/-8)
phabletutils/environment.py (+11/-5)
phabletutils/ubuntuimage.py (+8/-9)
tests/test_ubuntuimage.py (+4/-2)
To merge this branch: bzr merge lp:~sergiusens/phablet-tools/server_options
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Andy Doan (community) Approve
Stéphane Graber Approve
Matt Fischer (community) Approve
Review via email: mp+191269@code.launchpad.net

Commit message

phablet-flash: Add an option for an alternate server for system images

To post a comment you must log in.
Revision history for this message
Matt Fischer (mfisch) wrote :

Not working for me:

mfisch@caprica:/tmp/server_options$ ./phablet-flash ubuntu-system --channel devel-proposed --alternate-server http://23.21.157.252/~ubuntu/touch-mirror/system-image.ubuntu.com --no-backup
INFO:phablet-flash:Device detected as mako
INFO:urllib3.connectionpool:Starting new HTTPS connection (1): system-image.ubuntu.com
INFO:phablet-flash:Download directory set to /home/mfisch/Downloads/phablet-flash/imageupdates
INFO:phablet-flash:Downloading https://system-image.ubuntu.com/pool/ubuntu-4a26dee7e03f278bb3e2c2ce48b065e3e68f2c0ec88649959ecaff7cddb43b4c.tar.xz to /home/mfisch/Downloads/phablet-flash/imageupdates/pool/ubuntu-4a26dee7e03f278bb3e2c2ce48b065e3e68f2c0ec88649959ecaff7cddb43b4c.tar.xz
--2013-10-15 12:46:03-- https://system-image.ubuntu.com/pool/ubuntu-4a26dee7e03f278bb3e2c2ce48b065e3e68f2c0ec88649959ecaff7cddb43b4c.tar.xz
Resolving system-image.ubuntu.com (system-image.ubuntu.com)..

209. By Sergio Schvezov

Using uri that comes from arguments.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
210. By Sergio Schvezov

Using the right args

Revision history for this message
Matt Fischer (mfisch) wrote :

Still broken. I see 2 issues, first it has curl issues and second it still claims to be reading system-image.

mfisch@caprica:/tmp/server_options$ ./phablet-flash ubuntu-system --channel devel-proposed --alternate-server http://23.21.157.252/~ubuntu/touch-mirror/system-image.ubuntu.com --no-backup
INFO:phablet-flash:Device detected as mako
INFO:urllib3.connectionpool:Starting new HTTPS connection (1): system-image.ubuntu.com
INFO:phablet-flash:Download directory set to /home/mfisch/Downloads/phablet-flash/imageupdates
INFO:phablet-flash:Downloading http://23.21.157.252/~ubuntu/touch-mirror/system-image.ubuntu.com/pool/ubuntu-1c82da4133142a3ace9105bceb63488a55752a77b3044575e643ac73286e7b44.tar.xz to /home/mfisch/Downloads/phablet-flash/imageupdates/pool/ubuntu-1c82da4133142a3ace9105bceb63488a55752a77b3044575e643ac73286e7b44.tar.xz
** Resuming transfer from byte position 405
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
  0 405 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
ERROR:phablet-flash:Command '['curl', '-L', '-C', '-', u'http://23.21.157.252/~ubuntu/touch-mirror/system-image.ubuntu.com/pool/ubuntu-1c82da4133142a3ace9105bceb63488a55752a77b3044575e643ac73286e7b44.tar.xz', '-o', u'/home/mfisch/Downloads/phablet-flash/imageupdates/pool/ubuntu-1c82da4133142a3ace9105bceb63488a55752a77b3044575e643ac73286e7b44.tar.xz']' returned non-zero exit status 33
Removing directory /tmp/tmpp0ykfe

Revision history for this message
Matt Fischer (mfisch) wrote :

That URL curl is trying to use is bad, i Think because line 28 in ubuntuimage.py still uses the wrong URL.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
211. By Sergio Schvezov

sending uri to get json index and using uri to generate hash for download dir

212. By Sergio Schvezov

Adding get_sha256_hash funtion and preferring wget over everything else.

213. By Sergio Schvezov

Adding uri parameter for getting indexes

Revision history for this message
Matt Fischer (mfisch) wrote :

Working great. Thanks

review: Approve
Revision history for this message
Andy Doan (doanac) wrote :

8 + parser.add_argument('--alternate-server',
9 + default=settings.system_image_uri,
10 + help='Use an alternate system server, the default '
11 + 'server is %s' % settings.system_image_uri)

nitpick, but i think:
  help='Use an alternate system server, the default '
       'server is %(default)s')

is more common.

I'm not a big fan of the download function logic:
 + if uri.startswith('http://10.97.0.26'):

but adding some "--curl" option and then passing it around everyone is a bit cumbersome also.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Andy Doan (doanac) wrote :

> I'm not a big fan of the download function logic:
> + if uri.startswith('http://10.97.0.26'):
>
> but adding some "--curl" option and then passing it around everyone is a bit
> cumbersome also.

I'm starting to think we should make this optional. For example, we have an upcoming lab move and we probably don't want to tie phablet-tools to our current lab configuration. I think there are two alternatives you could try:

1) add a new "--curl" option that says to use curl.

2) add a new "--download-cmd" option that allows you to specify what command to download with. The default command would then be: "wget -c {uri} -O {path}".

Revision history for this message
Stéphane Graber (stgraber) wrote :

Looks good here, just ran against https://phablet.stgraber.org (channel test-customized) and it downloaded everything as expected.

review: Approve
214. By Sergio Schvezov

Fixing help

Revision history for this message
Andy Doan (doanac) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
215. By Sergio Schvezov

Updating tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Tested, worked fine with stgraber's server.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'phabletutils/arguments.py'
2--- phabletutils/arguments.py 2013-09-17 12:51:01 +0000
3+++ phabletutils/arguments.py 2013-10-16 01:55:23 +0000
4@@ -135,6 +135,10 @@
5 type=int,
6 help='''Download a relative revision from current
7 (-1, -2, ...) or a specific version.''')
8+ parser.add_argument('--alternate-server',
9+ default=settings.system_image_uri,
10+ help='''Use an alternate system server, the default
11+ server is %(default)s''')
12 group = parser.add_mutually_exclusive_group()
13 group.add_argument('--no-backup',
14 action='store_false',
15
16=== modified file 'phabletutils/downloads.py'
17--- phabletutils/downloads.py 2013-09-06 13:29:01 +0000
18+++ phabletutils/downloads.py 2013-10-16 01:55:23 +0000
19@@ -76,6 +76,10 @@
20 return directory
21
22
23+def get_sha256_hash(string):
24+ return hashlib.sha256(string).hexdigest()
25+
26+
27 def checksum_verify(file_path, file_hash, sum_method=hashlib.sha256):
28 '''Returns the checksum for a file with a specified algorightm.'''
29 file_sum = sum_method()
30@@ -96,14 +100,7 @@
31
32
33 def _download(uri, path):
34- if uri.startswith('http://cdimage.ubuntu.com') or \
35- uri.startswith('https://system-image.ubuntu.com'):
36- subprocess.check_call(['wget',
37- '-c',
38- uri,
39- '-O',
40- path])
41- else:
42+ if uri.startswith('http://10.97.0.26'):
43 subprocess.check_call(['curl',
44 '-L',
45 '-C',
46@@ -111,6 +108,12 @@
47 uri,
48 '-o',
49 path])
50+ else:
51+ subprocess.check_call(['wget',
52+ '-c',
53+ uri,
54+ '-O',
55+ path])
56
57
58 def download_sig(artifact):
59
60=== modified file 'phabletutils/environment.py'
61--- phabletutils/environment.py 2013-09-17 23:17:37 +0000
62+++ phabletutils/environment.py 2013-10-16 01:55:23 +0000
63@@ -146,17 +146,23 @@
64
65 def setup_ubuntu_system(args):
66 device = detect_device(args.serial, args.device)
67+ uri = args.alternate_server
68 if args.revision <= 0:
69 json = ubuntuimage.get_json_from_index(device,
70 args.channel,
71- args.revision)
72+ args.revision,
73+ uri)
74 else:
75 json = ubuntuimage.get_json_from_version(device,
76 args.channel,
77- args.revision)
78- download_dir = downloads.get_full_path(os.path.join(
79- settings.download_dir, args.project))
80- uri = settings.system_image_uri
81+ args.revision,
82+ uri)
83+ download_dir_part = os.path.join(settings.download_dir, args.project)
84+ if uri != settings.system_image_uri:
85+ base_uri = downloads.get_sha256_hash(uri)
86+ download_dir_part = os.path.join(download_dir_part, base_uri)
87+ download_dir = downloads.get_full_path(download_dir_part)
88+
89 files, command_part = ubuntuimage.get_files(download_dir, uri, json)
90 return projects.UbuntuTouchSystem(
91 file_list=files,
92
93=== modified file 'phabletutils/ubuntuimage.py'
94--- phabletutils/ubuntuimage.py 2013-09-17 23:17:37 +0000
95+++ phabletutils/ubuntuimage.py 2013-10-16 01:55:23 +0000
96@@ -20,30 +20,29 @@
97 from phabletutils import downloads
98 from phabletutils import fileutils
99 from phabletutils import resources
100-from phabletutils import settings
101-
102-
103-def _get_json(device, channel):
104+
105+
106+def _get_json(device, channel, uri):
107 json_index_uri = '%s/%s/%s/index.json' % \
108- (settings.system_image_uri, channel, device)
109+ (uri, channel, device)
110 json_content = downloads.get_content(json_index_uri)
111 if not json_content:
112 raise RuntimeError('%s cannot be retrieved' % json_index_uri)
113 return json.loads(json_content)
114
115
116-def get_json_from_index(device, channel, index):
117+def get_json_from_index(device, channel, index, uri):
118 """Returns json index for device"""
119 index -= 1
120- json_index = _get_json(device, channel)
121+ json_index = _get_json(device, channel, uri)
122 json_dict = sorted([entry for entry in json_index['images']
123 if entry['type'] == "full"],
124 key=lambda entry: entry['version'])[index]
125 return json_dict
126
127
128-def get_json_from_version(device, channel, version):
129- for entry in _get_json(device, channel)['images']:
130+def get_json_from_version(device, channel, version, uri):
131+ for entry in _get_json(device, channel, uri)['images']:
132 if entry['type'] == 'full' and entry['version'] == version:
133 return entry
134 raise RuntimeError('Version %s cannot be retrieved' % version)
135
136=== modified file 'tests/test_ubuntuimage.py'
137--- tests/test_ubuntuimage.py 2013-08-28 14:44:14 +0000
138+++ tests/test_ubuntuimage.py 2013-10-16 01:55:23 +0000
139@@ -38,7 +38,8 @@
140 # when
141 json_dict = ubuntuimage.get_json_from_index(self.device,
142 self.channel,
143- 0)
144+ 0,
145+ 'http://server.com')
146 # then
147 self.assertThat(json_dict['version'], Equals(20130808))
148 self.assertThat(json_dict['description'], Equals('20130807'))
149@@ -51,7 +52,8 @@
150 # when
151 json_dict = ubuntuimage.get_json_from_index(self.device,
152 self.channel,
153- -1)
154+ -1,
155+ 'http://server.com')
156 # then
157 self.assertThat(json_dict['version'], Equals(20130807))
158 self.assertThat(json_dict['description'], Equals('20130806.1'))

Subscribers

People subscribed via source and target branches