Merge lp:~javier.collado/ubuntu-test-cases/bug1087630 into lp:ubuntu-test-cases/server

Proposed by Javier Collado
Status: Merged
Merge reported by: James Page
Merged at revision: not available
Proposed branch: lp:~javier.collado/ubuntu-test-cases/bug1087630
Merge into: lp:ubuntu-test-cases/server
Diff against target: 148 lines (+48/-25)
5 files modified
preseeds/minimal-virtual.preseed (+1/-1)
preseeds/templates/base (+2/-0)
preseeds/templates/minimal-virtual (+3/-0)
testsuites/minimal-virtual/test_install_size/tc_control (+1/-1)
testsuites/minimal-virtual/test_install_size/test.py (+41/-23)
To merge this branch: bzr merge lp:~javier.collado/ubuntu-test-cases/bug1087630
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Javier Collado (community) Needs Resubmitting
Para Siva (community) Approve
James Page Pending
Review via email: mp+142161@code.launchpad.net

Description of the change

The branch make some changes to the minimal-virtual scenario to make the
install_size test case work.

In particular:
- late command in the preseed is used to gather disk usage before testing
  packages (needed by utah) are installed.
- test case script reads the log file with that information instead of running
  `df`.

The test case is working now for me when running the test case locally in a VM
with the new preseed.

However, I believe that still the usage in the log file includes the packages
in `pkgsel/include` (`preseed/late_command` seems to be executed after
`pkgsel/include`), but not the ones that are installed later using `gdebi`, so
the figure isn't completely precise yet.

To post a comment you must log in.
Revision history for this message
Para Siva (psivaa) wrote :

Not sure if it's really important but do we not need to change the template preseed file, http://bazaar.launchpad.net/~javier.collado/ubuntu-test-cases/bug1087630/view/head:/preseeds/templates/minimal-virtual to include the late command just to be consistent?

review: Needs Information
Revision history for this message
Javier Collado (javier.collado) wrote :

Since this is something needed just in this test case (as far as I know) and it
has its own preseed already, I think it's fine to make the change only in the
preseed this test case preseed.

If we find that the same thing is needed in other test cases, then we can move
it to the base template later. Do you agree?

81. By Javier Collado

Added late_command block to customize late_command in templates

This is needed if the scenario needs a different late_command configuration
such as the minimal virtual one.

82. By Javier Collado

Updated minimal virtual template to customize late_command

Generated late_command now gathers the root partition usage.

Revision history for this message
Para Siva (psivaa) wrote :

Looks good now. Thanks

review: Approve
Revision history for this message
Javier Collado (javier.collado) wrote :

Sorry I'm not familiar with the templates in this branch and I didn't know that
there's a template for minimal-virtual that should be used to generate
minimal-virtual.preseed even if both are under version control. Thanks Siva for
the explanation through irc.

I've added a couple of revisions to deal with that:
- make late_command customizable in the templates
- use that in the minimal-virtual template to gather the root partition usage

review: Needs Resubmitting
Revision history for this message
Max Brustkern (nuclearbob) wrote :

The [ "$?" -eq "0" ] isn't really necessary. That's in the default preseed so that a latecommand will exist, and that particular command was chosen to avoid masking the exit status of the utah latecommand if no other latecommand is present. If another latecommand is present, that doesn't really serve a purpose. That said, it doesn't hurt anything either.

Also, /var/log/utah-install is used for other things which can come before or after this use. It doesn't look to me like the current code will detect the correct line and not just the first line of the file, but I could be wrong about that.

review: Needs Information
Revision history for this message
Max Brustkern (nuclearbob) wrote :

To clarify, [ "$?" -eq "0" ] isn't necessary on merge lines like 9 and 36. It should remain on lines like 22 where it's the only thing.

83. By Javier Collado

Removed unneeded command in preseed

84. By Javier Collado

Improved parsing

The previous code expected the first line in /var/log/utah-install to be the
one about the install size. This make parsing more solid just in case some
change in utah changes this assumption.

Revision history for this message
Javier Collado (javier.collado) wrote :

Max, I've updated the merge to address your concerns:

- the unneeded return code check in the late command has been removed

- the parsing now looks for the first line that starts with "Root partition
  usage:" to avoid problems due to unexpected ordering of lines in
  /var/log/utah-install

review: Needs Resubmitting
Revision history for this message
Max Brustkern (nuclearbob) wrote :

I like the changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'preseeds/minimal-virtual.preseed'
2--- preseeds/minimal-virtual.preseed 2012-11-23 11:22:06 +0000
3+++ preseeds/minimal-virtual.preseed 2013-01-10 16:53:25 +0000
4@@ -327,7 +327,7 @@
5 # directly, or use the apt-install and in-target commands to easily install
6 # packages and run commands in the target system.
7 #d-i preseed/late_command string echo "send host-name \"<hostname>\";" >> /target/etc/dhcp3/dhclient.conf;
8-d-i preseed/late_command string [ "$?" -eq "0" ]
9+d-i preseed/late_command string in-target sh -c 'echo "Root partition usage: $(df / | tail -n1 | awk '\''{print $3}'\'')">>/var/log/utah-install'
10
11
12
13
14=== modified file 'preseeds/templates/base'
15--- preseeds/templates/base 2012-11-23 11:22:06 +0000
16+++ preseeds/templates/base 2013-01-10 16:53:25 +0000
17@@ -307,7 +307,9 @@
18 # directly, or use the apt-install and in-target commands to easily install
19 # packages and run commands in the target system.
20 #d-i preseed/late_command string echo "send host-name \"<hostname>\";" >> /target/etc/dhcp3/dhclient.conf;
21+{% block late_command %}
22 d-i preseed/late_command string [ "$?" -eq "0" ]
23+{% endblock %}
24
25 {% block preseed_extra %}
26 {% endblock %}
27
28=== modified file 'preseeds/templates/minimal-virtual'
29--- preseeds/templates/minimal-virtual 2012-08-29 15:47:42 +0000
30+++ preseeds/templates/minimal-virtual 2013-01-10 16:53:25 +0000
31@@ -28,4 +28,7 @@
32 {% block d_i_answers %}
33 d-i base-installer/kernel/headers boolean false
34 {% endblock %}
35+{% block late_command %}
36+d-i preseed/late_command string in-target sh -c 'echo "Root partition usage: $(df / | tail -n1 | awk '\''{print $3}'\'')">>/var/log/utah-install'
37+{% endblock %}
38
39
40=== modified file 'testsuites/minimal-virtual/test_install_size/tc_control'
41--- testsuites/minimal-virtual/test_install_size/tc_control 2012-11-14 10:56:53 +0000
42+++ testsuites/minimal-virtual/test_install_size/tc_control 2013-01-10 16:53:25 +0000
43@@ -1,7 +1,7 @@
44 description: A test to check installed size of a vm
45 dependencies: n/a
46 action: |
47- 1. Check the used space is less than the maximum instal size
48+ 1. Check the used space is less than the maximum install size
49 expected_results: |
50 1. The used space is less than the max install size
51 type: userland
52
53=== modified file 'testsuites/minimal-virtual/test_install_size/test.py'
54--- testsuites/minimal-virtual/test_install_size/test.py 2012-11-30 09:03:46 +0000
55+++ testsuites/minimal-virtual/test_install_size/test.py 2013-01-10 16:53:25 +0000
56@@ -1,51 +1,69 @@
57 #!/usr/bin/python
58-#
59+#
60 # Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
61 #
62 # This file is part of ubuntu-server-iso-testing.
63-#
64-# ubuntu-server-iso-testing is free software: you can redistribute it
65-# and/or modify it under the terms of the GNU General Public License
66-# as published by the Free Software Foundation, either version 3 of
67+#
68+# ubuntu-server-iso-testing is free software: you can redistribute it
69+# and/or modify it under the terms of the GNU General Public License
70+# as published by the Free Software Foundation, either version 3 of
71 # the License, or (at your option) any later version.
72-#
73-# ubuntu-server-iso-testing is distributed in the hope that it will
74-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
75+#
76+# ubuntu-server-iso-testing is distributed in the hope that it will
77+# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
78 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79 # GNU General Public License for more details.
80-#
81+#
82 # You should have received a copy of the GNU General Public License
83-# along with ubuntu-server-iso-testing. If not, see
84+# along with ubuntu-server-iso-testing. If not, see
85 # <http://www.gnu.org/licenses/>.
86-#
87-
88+#
89+
90+"""Check disk usage matches the expected one.
91+
92+Get root partition usage as stored by the late command in the preseed and
93+compare it against the expected value.
94+
95+`df` isn't directly used in the test case to avoid getting the size of all the
96+packages installed because of utah, but not really present in a default
97+installation.
98+
99+"""
100
101 import logging
102-import os.path
103-import subprocess
104 import unittest
105 import platform
106
107-logging.basicConfig(level=logging.INFO)
108
109 class MinimalVirtualTest(unittest.TestCase):
110+ LOG_MESSAGE = "Root partition usage:"
111
112 def testInstallSize(self):
113- cmd = ["df", "/"]
114- logging.debug("Cmd: %s" % (cmd))
115- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
116- logging.debug("Cmd output: %s" % (output))
117- lines = output.split("\n")
118- self.assertEqual(len(lines), 3)
119+ logging.info('Getting root partition usage '
120+ 'as stored by late command...')
121+ with open('/var/log/utah-install') as f:
122+ line = next(line for line in f
123+ if line.startswith(self.LOG_MESSAGE))
124+ used = int(line.split()[-1])
125+ logging.info('{} {}'.format(self.LOG_MESSAGE, used))
126
127- used = int(lines[1].split()[2])
128 # 700 minimal max install size + 150 test overlay
129 max_install_size = 870400
130+
131 # Add overhead for multiarch package lists on amd64
132 # +32MB roughly
133 if platform.machine() == "x86_64":
134 max_install_size += 32256
135- self.assertTrue( used < max_install_size, "Used: %s" % (used))
136+
137+ self.assertLess(
138+ used, max_install_size,
139+ "Usage ({}) is *not* less than the maximum expected value: {}"
140+ .format(used, max_install_size))
141+
142+ logging.info("Usage ({}) is less than the maximum expected value: {}"
143+ .format(used, max_install_size))
144
145 if __name__ == '__main__':
146+ logging.basicConfig(level=logging.DEBUG,
147+ format='%(levelname)s: %(message)s')
148 unittest.main()

Subscribers

People subscribed via source and target branches