Merge lp:~jamesodhunt/ubuntu/wily/ubuntu-core-upgrader/call-upgrader-directly into lp:ubuntu/wily/ubuntu-core-upgrader

Proposed by James Hunt
Status: Work in progress
Proposed branch: lp:~jamesodhunt/ubuntu/wily/ubuntu-core-upgrader/call-upgrader-directly
Merge into: lp:ubuntu/wily/ubuntu-core-upgrader
Diff against target: 241 lines (+99/-15)
3 files modified
debian/changelog (+13/-0)
functional/test_upgrader.py (+85/-15)
ubuntucoreupgrader/upgrader.py (+1/-0)
To merge this branch: bzr merge lp:~jamesodhunt/ubuntu/wily/ubuntu-core-upgrader/call-upgrader-directly
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+259481@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

I put some python code comments inline, I am not sure about the approach to test the python object and the executable in two different code paths. I think it would be preferable to convert the call_upgrader_object to use the in-tree binary to avoid having two code paths. Once the code calls a external executable (the bin/ubuntu-core-upgrader from this source tree) it will be trivial to convert to call a different one once the need arises (i.e. once there is a external one that needs testing).

So instead of call_upgrader_{object,command} maybe something like:
"""
def call_upgrader(command_file, root_dir):
    pyroot = os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))
    env = copy.copy(os.environ)
    env["PYTHONPATH"] = pyroot
    subprocess.check_call(
        [os.path.join(pyroot, "bin", "ubuntu-core-upgrade"),
         '--root-dir', root_dir,
         '--debug', '1',
         # don't delete the archive and command files.
         # The tests clean up after themselves so they will get removed then,
         # but useful to have them around to diagnose test failures.
         '--leave-files',
         command_file],
    env=env)
"""

Revision history for this message
James Hunt (jamesodhunt) wrote :

I'm slightly confused by this - if we replace call_upgrader_object() and call_upgrader_command() with a single call_upgrader(), most of the in-line comments are no longer relevant right?

Revision history for this message
Sebastien Bacher (seb128) wrote :

seems like work is needed/ongoing discussion is going with mvo, changing to "work in progress" to get out of the sponsoring queue

Unmerged revisions

33. By James Hunt

* functional/test_upgrader.py:
  - prepare(): Set cache dir to the root dir if '--root-dir' specified.
* ubuntucoreupgrader/upgrader.py:
  - If the real upgrader exists, use it rather than creating an Upgrader
    object. This will eventually allow the upgrader to be replaced (but
    these tests to be retained, atleast for the medium term).
  - Renamed call_upgrader() to call_upgrader_object().
  - Removed unused update argument for call_upgrader_object().

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2015-04-23 09:01:01 +0000
+++ debian/changelog 2015-05-19 10:30:58 +0000
@@ -1,3 +1,16 @@
1ubuntu-core-upgrader (0.7.12) UNRELEASED; urgency=medium
2
3 * functional/test_upgrader.py:
4 - prepare(): Set cache dir to the root dir if '--root-dir' specified.
5 * ubuntucoreupgrader/upgrader.py:
6 - If the real upgrader exists, use it rather than creating an Upgrader
7 object. This will eventually allow the upgrader to be replaced (but
8 these tests to be retained, atleast for the medium term).
9 - Renamed call_upgrader() to call_upgrader_object().
10 - Removed unused update argument for call_upgrader_object().
11
12 -- James Hunt <james.hunt@ubuntu.com> Tue, 19 May 2015 11:28:09 +0100
13
1ubuntu-core-upgrader (0.7.11) vivid; urgency=medium14ubuntu-core-upgrader (0.7.11) vivid; urgency=medium
215
3 * ubuntucoreupgrader/upgrader.py: Call os.sync() at end of sync_partitions()16 * ubuntucoreupgrader/upgrader.py: Call os.sync() at end of sync_partitions()
417
=== modified file 'functional/test_upgrader.py'
--- functional/test_upgrader.py 2015-04-08 14:54:05 +0000
+++ functional/test_upgrader.py 2015-05-19 10:30:58 +0000
@@ -24,6 +24,7 @@
24import sys24import sys
25import os25import os
26import logging26import logging
27import subprocess
27import unittest28import unittest
2829
29from ubuntucoreupgrader.upgrader import (30from ubuntucoreupgrader.upgrader import (
@@ -42,16 +43,85 @@
42 UbuntuCoreUpgraderTestCase,43 UbuntuCoreUpgraderTestCase,
43 )44 )
4445
46log = logging.getLogger()
47
45CMD_FILE = 'ubuntu_command'48CMD_FILE = 'ubuntu_command'
4649
4750UPGRADER = '/usr/bin/ubuntu-core-upgrade'
48def call_upgrader(command_file, root_dir, update):51
52
53def call_upgrader(command_file, root_dir, upgrader=UPGRADER):
54
55 found = False
56
57 if os.path.exists(upgrader):
58 found = True
59
60 log.warning("Real upgrader ({}) {}found"
61 .format(upgrader, "" if found else "not"))
62
63 if not found:
64 log.warning("Creating an Upgrader object instead")
65
66 call_upgrader_object(command_file, root_dir)
67 return
68
69 # Running on a system with the upgrader installed, so exercise it!
70 log.warning("Calling upgrader directly")
71
72 options = [
73 # always run with full debug
74 '--debug', '2',
75 # don't delete the archive and command files.
76 # The tests clean up after themselves so they will get removed then,
77 # but useful to have them around to diagnose test failures.
78 '--leave-files',
79 ]
80
81 if root_dir:
82 options += ['--root-dir', root_dir]
83
84 call_upgrader_command(upgrader, options, command_file)
85
86
87def call_upgrader_command(upgrader=UPGRADER, options=[],
88 command_file=CMD_FILE):
89 '''
90 Invoke the upgrader binary directly.
91
92 :param upgrader: path to the upgrader to use.
93 :param options: array of options to pass to the upgrader
94 :param command_file: commands file to drive the upgrader.
95 '''
96 args = [upgrader]
97 args.extend(options)
98
99 args += [command_file]
100
101 proc = subprocess.Popen(args,
102 stdout=subprocess.PIPE,
103 stderr=subprocess.PIPE,
104 universal_newlines=True)
105
106 ret = proc.wait()
107
108 if ret == 0:
109 return
110
111 stdout, stderr = proc.communicate()
112 log.error("{} returned {}: stdout='{}', stderr='{}'"
113 .format(args,
114 ret,
115 stdout,
116 stderr))
117
118
119def call_upgrader_object(command_file, root_dir):
49 '''120 '''
50 Invoke the upgrader.121 Invoke the upgrader.
51122
52 :param command_file: commands file to drive the upgrader.123 :param command_file: commands file to drive the upgrader.
53 :param root_dir: Test directory to apply the upgrade to.124 :param root_dir: Test directory to apply the upgrade to.
54 :param update: UpdateTree object.
55 '''125 '''
56126
57 args = []127 args = []
@@ -207,7 +277,7 @@
207 # remove 'system' suffix that upgrader will add back on277 # remove 'system' suffix that upgrader will add back on
208 vdir = os.path.split(self.victim_dir)[0]278 vdir = os.path.split(self.victim_dir)[0]
209279
210 call_upgrader(cmd_file, vdir, self.update)280 call_upgrader(cmd_file, vdir)
211281
212 self.assertFalse(os.path.exists(file_path))282 self.assertFalse(os.path.exists(file_path))
213283
@@ -232,7 +302,7 @@
232 self.assertTrue(os.path.isdir(dir_path))302 self.assertTrue(os.path.isdir(dir_path))
233303
234 vdir = os.path.split(self.victim_dir)[0]304 vdir = os.path.split(self.victim_dir)[0]
235 call_upgrader(cmd_file, vdir, self.update)305 call_upgrader(cmd_file, vdir)
236306
237 self.assertFalse(os.path.exists(dir_path))307 self.assertFalse(os.path.exists(dir_path))
238308
@@ -265,7 +335,7 @@
265 self.assertTrue(os.path.islink(link_file_path))335 self.assertTrue(os.path.islink(link_file_path))
266336
267 vdir = os.path.split(self.victim_dir)[0]337 vdir = os.path.split(self.victim_dir)[0]
268 call_upgrader(cmd_file, vdir, self.update)338 call_upgrader(cmd_file, vdir)
269339
270 # original file should still be there340 # original file should still be there
271 self.assertTrue(os.path.exists(src_file_path))341 self.assertTrue(os.path.exists(src_file_path))
@@ -304,7 +374,7 @@
304 self.assertTrue(os.path.islink(link_file_path))374 self.assertTrue(os.path.islink(link_file_path))
305375
306 vdir = os.path.split(self.victim_dir)[0]376 vdir = os.path.split(self.victim_dir)[0]
307 call_upgrader(cmd_file, vdir, self.update)377 call_upgrader(cmd_file, vdir)
308378
309 # original directory should still be there379 # original directory should still be there
310 self.assertTrue(os.path.exists(src_dir_path))380 self.assertTrue(os.path.exists(src_dir_path))
@@ -347,7 +417,7 @@
347 self.assertTrue(src_inode == link_inode)417 self.assertTrue(src_inode == link_inode)
348418
349 vdir = os.path.split(self.victim_dir)[0]419 vdir = os.path.split(self.victim_dir)[0]
350 call_upgrader(cmd_file, vdir, self.update)420 call_upgrader(cmd_file, vdir)
351421
352 # original file should still be there422 # original file should still be there
353 self.assertTrue(os.path.exists(src_file_path))423 self.assertTrue(os.path.exists(src_file_path))
@@ -388,7 +458,7 @@
388 self.assertTrue(os.path.isfile(file_path))458 self.assertTrue(os.path.isfile(file_path))
389459
390 vdir = os.path.split(self.victim_dir)[0]460 vdir = os.path.split(self.victim_dir)[0]
391 call_upgrader(cmd_file, vdir, self.update)461 call_upgrader(cmd_file, vdir)
392462
393 # upgrader doesn't currently remove device files463 # upgrader doesn't currently remove device files
394 self.assertTrue(os.path.exists(file_path))464 self.assertTrue(os.path.exists(file_path))
@@ -418,7 +488,7 @@
418 file_path = os.path.join(self.victim_dir, file)488 file_path = os.path.join(self.victim_dir, file)
419 self.assertFalse(os.path.exists(file_path))489 self.assertFalse(os.path.exists(file_path))
420490
421 call_upgrader(cmd_file, self.victim_dir, self.update)491 call_upgrader(cmd_file, self.victim_dir)
422492
423 self.assertTrue(os.path.exists(file_path))493 self.assertTrue(os.path.exists(file_path))
424 self.assertTrue(os.path.isfile(file_path))494 self.assertTrue(os.path.isfile(file_path))
@@ -442,7 +512,7 @@
442 dir_path = os.path.join(self.victim_dir, dir)512 dir_path = os.path.join(self.victim_dir, dir)
443 self.assertFalse(os.path.exists(dir_path))513 self.assertFalse(os.path.exists(dir_path))
444514
445 call_upgrader(cmd_file, self.victim_dir, self.update)515 call_upgrader(cmd_file, self.victim_dir)
446516
447 self.assertTrue(os.path.exists(dir_path))517 self.assertTrue(os.path.exists(dir_path))
448 self.assertTrue(os.path.isdir(dir_path))518 self.assertTrue(os.path.isdir(dir_path))
@@ -487,7 +557,7 @@
487557
488 self.assertFalse(os.path.exists(victim_link_file_path))558 self.assertFalse(os.path.exists(victim_link_file_path))
489559
490 call_upgrader(cmd_file, self.victim_dir, self.update)560 call_upgrader(cmd_file, self.victim_dir)
491561
492 self.assertTrue(os.path.exists(victim_src_file_path))562 self.assertTrue(os.path.exists(victim_src_file_path))
493 self.assertTrue(os.path.isfile(victim_src_file_path))563 self.assertTrue(os.path.isfile(victim_src_file_path))
@@ -538,7 +608,7 @@
538608
539 self.assertFalse(os.path.exists(victim_link_file_path))609 self.assertFalse(os.path.exists(victim_link_file_path))
540610
541 call_upgrader(cmd_file, self.victim_dir, self.update)611 call_upgrader(cmd_file, self.victim_dir)
542612
543 self.assertTrue(os.path.exists(victim_src_file_path))613 self.assertTrue(os.path.exists(victim_src_file_path))
544 self.assertTrue(os.path.isfile(victim_src_file_path))614 self.assertTrue(os.path.isfile(victim_src_file_path))
@@ -581,7 +651,7 @@
581 self.assertFalse(os.path.exists(victim_src_file_path))651 self.assertFalse(os.path.exists(victim_src_file_path))
582 self.assertFalse(os.path.exists(victim_link_file_path))652 self.assertFalse(os.path.exists(victim_link_file_path))
583653
584 call_upgrader(cmd_file, self.victim_dir, self.update)654 call_upgrader(cmd_file, self.victim_dir)
585655
586 # source still shouldn't exist656 # source still shouldn't exist
587 self.assertFalse(os.path.exists(victim_src_file_path))657 self.assertFalse(os.path.exists(victim_src_file_path))
@@ -622,7 +692,7 @@
622 # XXX: There is an implicit test here since if the upgrader692 # XXX: There is an implicit test here since if the upgrader
623 # fails (as documented on LP: #1437225), this test will also693 # fails (as documented on LP: #1437225), this test will also
624 # fail.694 # fail.
625 call_upgrader(cmd_file, vdir, self.update)695 call_upgrader(cmd_file, vdir)
626696
627 self.assertTrue(os.path.exists(vdir))697 self.assertTrue(os.path.exists(vdir))
628 self.assertTrue(os.path.exists(self.victim_dir))698 self.assertTrue(os.path.exists(self.victim_dir))
629699
=== modified file 'ubuntucoreupgrader/upgrader.py'
--- ubuntucoreupgrader/upgrader.py 2015-04-22 09:37:35 +0000
+++ ubuntucoreupgrader/upgrader.py 2015-05-19 10:30:58 +0000
@@ -553,6 +553,7 @@
553553
554 if self.options.root_dir != '/':554 if self.options.root_dir != '/':
555 # Don't modify root when running in test mode555 # Don't modify root when running in test mode
556 self.cache_dir = self.options.root_dir
556 return557 return
557558
558 def run(self):559 def run(self):

Subscribers

People subscribed via source and target branches

to all changes: