diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 487: Make sure the new --extra-boot-args argument works when the extra_boot_args_options attribute of ...

Message ID 20120125115516.21494.45891.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Guilherme Salgado Jan. 25, 2012, 11:55 a.m. UTC
Merge authors:
  Guilherme Salgado (salgado)
Related merge proposals:
  https://code.launchpad.net/~salgado/linaro-image-tools/fix-913819/+merge/89975
  proposed by: Guilherme Salgado (salgado)
  review: Approve - Mattias Backman (mabac)
------------------------------------------------------------
revno: 487 [merge]
committer: Guilherme Salgado <guilherme.salgado@linaro.org>
branch nick: trunk
timestamp: Wed 2012-01-25 08:52:33 -0300
message:
  Make sure the new --extra-boot-args argument works when the extra_boot_args_options attribute of the board config is set to None
modified:
  linaro_image_tools/media_create/boards.py
  linaro_image_tools/media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py	2012-01-18 15:27:35 +0000
+++ linaro_image_tools/media_create/boards.py	2012-01-24 18:40:27 +0000
@@ -577,7 +577,10 @@ 
     @classmethod
     def add_boot_args(cls, extra_args):
         if extra_args is not None:
-            cls.extra_boot_args_options += ' %s' % extra_args
+            if cls.extra_boot_args_options is None:
+                cls.extra_boot_args_options = extra_args
+            else:
+                cls.extra_boot_args_options += ' %s' % extra_args
 
     @classmethod
     def add_boot_args_from_file(cls, path):

=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py	2012-01-17 14:50:47 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2012-01-24 18:40:27 +0000
@@ -1414,96 +1414,70 @@ 
 
 class TestExtraBootCmd(TestCaseWithFixtures):
 
-    def test_no_extra_args(self):
-        boot_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
-        class config(BoardConfig):
-            extra_boot_args_options = boot_args
-        boot_commands = config._get_boot_env(
-            is_live=False, is_lowmem=False, consoles=['ttyXXX'],
-            rootfs_uuid="deadbeef", d_img_data=None)
-        expected = ' '.join([' console=ttyXXX  root=UUID=deadbeef rootwait ro',
-                             boot_args])
-        self.assertEqual(expected, boot_commands['bootargs'])
-
-    def test_none_extra_args(self):
-        boot_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
-        extra_args = None
-        class config(BoardConfig):
-            extra_boot_args_options = boot_args
-        config.add_boot_args(extra_args)
-        boot_commands = config._get_boot_env(
-            is_live=False, is_lowmem=False, consoles=['ttyXXX'],
-            rootfs_uuid="deadbeef", d_img_data=None)
-        expected = ' '.join([' console=ttyXXX  root=UUID=deadbeef rootwait ro',
-                             boot_args])
-        self.assertEqual(expected, boot_commands['bootargs'])
-
-    def test_string_extra_args(self):
-        boot_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
-        extra_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
-        class config(BoardConfig):
-            extra_boot_args_options = boot_args
-        config.add_boot_args(extra_args)
-        boot_commands = config._get_boot_env(
-            is_live=False, is_lowmem=False, consoles=['ttyXXX'],
-            rootfs_uuid="deadbeef", d_img_data=None)
-        expected = ' '.join([' console=ttyXXX  root=UUID=deadbeef rootwait ro',
-                             boot_args, extra_args])
-        self.assertEqual(expected, boot_commands['bootargs'])
-
-    def test_file_extra_args(self):
-        boot_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
-        extra_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
+    def test_extra_boot_args_options_is_picked_by_get_boot_env(self):
+        boot_args = 'whatever'
+        class config(BoardConfig):
+            extra_boot_args_options = boot_args
+        boot_commands = config._get_boot_env(
+            is_live=False, is_lowmem=False, consoles=['ttyXXX'],
+            rootfs_uuid="deadbeef", d_img_data=None)
+        expected = (
+            ' console=ttyXXX  root=UUID=deadbeef rootwait ro %s' % boot_args)
+        self.assertEqual(expected, boot_commands['bootargs'])
+
+    def test_passing_None_to_add_boot_args(self):
+        boot_args = 'extra-args'
+        class config(BoardConfig):
+            extra_boot_args_options = boot_args
+        config.add_boot_args(None)
+        self.assertEqual(boot_args, config.extra_boot_args_options)
+
+    def test_passing_string_to_add_boot_args(self):
+        boot_args = 'extra-args'
+        extra_args = 'user-args'
+        class config(BoardConfig):
+            extra_boot_args_options = boot_args
+        config.add_boot_args(extra_args)
+        self.assertEqual(
+            "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
+
+    def test_passing_string_to_add_boot_args_with_no_default_extra_args(self):
+        extra_args = 'user-args'
+        class config(BoardConfig):
+            extra_boot_args_options = None
+        config.add_boot_args(extra_args)
+        self.assertEqual(extra_args, config.extra_boot_args_options)
+
+    def test_add_boot_args_from_file(self):
+        boot_args = 'extra-args'
+        extra_args = 'user-args'
         boot_arg_path = self.createTempFileAsFixture()
         with open(boot_arg_path, 'w') as boot_arg_file:
             boot_arg_file.write(extra_args)
         class config(BoardConfig):
             extra_boot_args_options = boot_args
         config.add_boot_args_from_file(boot_arg_path)
-        boot_commands = config._get_boot_env(
-            is_live=False, is_lowmem=False, consoles=['ttyXXX'],
-            rootfs_uuid="deadbeef", d_img_data=None)
-        expected = ' '.join([' console=ttyXXX  root=UUID=deadbeef rootwait ro',
-                             boot_args, extra_args])
-        self.assertEqual(expected, boot_commands['bootargs'])
+        self.assertEqual(
+            "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
 
-    def test_none_file_extra_args(self):
-        boot_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
-        boot_arg_path = None
+    def test_passing_None_to_add_boot_args_from_file(self):
+        boot_args = 'extra-args'
         class config(BoardConfig):
             extra_boot_args_options = boot_args
-        config.add_boot_args_from_file(boot_arg_path)
-        boot_commands = config._get_boot_env(
-            is_live=False, is_lowmem=False, consoles=['ttyXXX'],
-            rootfs_uuid="deadbeef", d_img_data=None)
-        expected = ' '.join([' console=ttyXXX  root=UUID=deadbeef rootwait ro',
-                             boot_args])
-        self.assertEqual(expected, boot_commands['bootargs'])
+        config.add_boot_args_from_file(None)
+        self.assertEqual(boot_args, config.extra_boot_args_options)
 
-    def test_whitespace_file_extra_args(self):
-        boot_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
-        extra_args = ''.join(
-            random.choice(string.ascii_lowercase) for x in range(15))
+    def test_add_boot_args_from_file_strips_whitespace_from_file(self):
+        boot_args = 'extra-args'
+        extra_args = 'user-args'
         boot_arg_path = self.createTempFileAsFixture()
         with open(boot_arg_path, 'w') as boot_arg_file:
             boot_arg_file.write('\n\n \t ' + extra_args + '  \n\n')
         class config(BoardConfig):
             extra_boot_args_options = boot_args
         config.add_boot_args_from_file(boot_arg_path)
-        boot_commands = config._get_boot_env(
-            is_live=False, is_lowmem=False, consoles=['ttyXXX'],
-            rootfs_uuid="deadbeef", d_img_data=None)
-        expected = ' '.join([' console=ttyXXX  root=UUID=deadbeef rootwait ro',
-                             boot_args, extra_args])
-        self.assertEqual(expected, boot_commands['bootargs'])
+        self.assertEqual(
+            "%s %s" % (boot_args, extra_args), config.extra_boot_args_options)
 
 
 class TestGetBootCmdAndroid(TestCase):