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
=== modified file 'preseeds/minimal-virtual.preseed'
--- preseeds/minimal-virtual.preseed 2012-11-23 11:22:06 +0000
+++ preseeds/minimal-virtual.preseed 2013-01-10 16:53:25 +0000
@@ -327,7 +327,7 @@
327# directly, or use the apt-install and in-target commands to easily install327# directly, or use the apt-install and in-target commands to easily install
328# packages and run commands in the target system.328# packages and run commands in the target system.
329#d-i preseed/late_command string echo "send host-name \"<hostname>\";" >> /target/etc/dhcp3/dhclient.conf;329#d-i preseed/late_command string echo "send host-name \"<hostname>\";" >> /target/etc/dhcp3/dhclient.conf;
330d-i preseed/late_command string [ "$?" -eq "0" ]330d-i preseed/late_command string in-target sh -c 'echo "Root partition usage: $(df / | tail -n1 | awk '\''{print $3}'\'')">>/var/log/utah-install'
331331
332332
333333
334334
=== modified file 'preseeds/templates/base'
--- preseeds/templates/base 2012-11-23 11:22:06 +0000
+++ preseeds/templates/base 2013-01-10 16:53:25 +0000
@@ -307,7 +307,9 @@
307# directly, or use the apt-install and in-target commands to easily install307# directly, or use the apt-install and in-target commands to easily install
308# packages and run commands in the target system.308# packages and run commands in the target system.
309#d-i preseed/late_command string echo "send host-name \"<hostname>\";" >> /target/etc/dhcp3/dhclient.conf;309#d-i preseed/late_command string echo "send host-name \"<hostname>\";" >> /target/etc/dhcp3/dhclient.conf;
310{% block late_command %}
310d-i preseed/late_command string [ "$?" -eq "0" ]311d-i preseed/late_command string [ "$?" -eq "0" ]
312{% endblock %}
311313
312{% block preseed_extra %}314{% block preseed_extra %}
313{% endblock %}315{% endblock %}
314316
=== modified file 'preseeds/templates/minimal-virtual'
--- preseeds/templates/minimal-virtual 2012-08-29 15:47:42 +0000
+++ preseeds/templates/minimal-virtual 2013-01-10 16:53:25 +0000
@@ -28,4 +28,7 @@
28{% block d_i_answers %}28{% block d_i_answers %}
29d-i base-installer/kernel/headers boolean false29d-i base-installer/kernel/headers boolean false
30{% endblock %}30{% endblock %}
31{% block late_command %}
32d-i preseed/late_command string in-target sh -c 'echo "Root partition usage: $(df / | tail -n1 | awk '\''{print $3}'\'')">>/var/log/utah-install'
33{% endblock %}
3134
3235
=== modified file 'testsuites/minimal-virtual/test_install_size/tc_control'
--- testsuites/minimal-virtual/test_install_size/tc_control 2012-11-14 10:56:53 +0000
+++ testsuites/minimal-virtual/test_install_size/tc_control 2013-01-10 16:53:25 +0000
@@ -1,7 +1,7 @@
1description: A test to check installed size of a vm1description: A test to check installed size of a vm
2dependencies: n/a2dependencies: n/a
3action: |3action: |
4 1. Check the used space is less than the maximum instal size4 1. Check the used space is less than the maximum install size
5expected_results: |5expected_results: |
6 1. The used space is less than the max install size6 1. The used space is less than the max install size
7type: userland7type: userland
88
=== modified file 'testsuites/minimal-virtual/test_install_size/test.py'
--- testsuites/minimal-virtual/test_install_size/test.py 2012-11-30 09:03:46 +0000
+++ testsuites/minimal-virtual/test_install_size/test.py 2013-01-10 16:53:25 +0000
@@ -1,51 +1,69 @@
1#!/usr/bin/python1#!/usr/bin/python
2# 2#
3# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)3# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
4#4#
5# This file is part of ubuntu-server-iso-testing.5# This file is part of ubuntu-server-iso-testing.
6# 6#
7# ubuntu-server-iso-testing is free software: you can redistribute it 7# ubuntu-server-iso-testing is free software: you can redistribute it
8# and/or modify it under the terms of the GNU General Public License 8# and/or modify it under the terms of the GNU General Public License
9# as published by the Free Software Foundation, either version 3 of 9# as published by the Free Software Foundation, either version 3 of
10# the License, or (at your option) any later version.10# the License, or (at your option) any later version.
11# 11#
12# ubuntu-server-iso-testing is distributed in the hope that it will 12# ubuntu-server-iso-testing is distributed in the hope that it will
13# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.15# GNU General Public License for more details.
16# 16#
17# You should have received a copy of the GNU General Public License17# You should have received a copy of the GNU General Public License
18# along with ubuntu-server-iso-testing. If not, see 18# along with ubuntu-server-iso-testing. If not, see
19# <http://www.gnu.org/licenses/>.19# <http://www.gnu.org/licenses/>.
20# 20#
2121
22"""Check disk usage matches the expected one.
23
24Get root partition usage as stored by the late command in the preseed and
25compare it against the expected value.
26
27`df` isn't directly used in the test case to avoid getting the size of all the
28packages installed because of utah, but not really present in a default
29installation.
30
31"""
2232
23import logging33import logging
24import os.path
25import subprocess
26import unittest34import unittest
27import platform35import platform
2836
29logging.basicConfig(level=logging.INFO)
3037
31class MinimalVirtualTest(unittest.TestCase):38class MinimalVirtualTest(unittest.TestCase):
39 LOG_MESSAGE = "Root partition usage:"
3240
33 def testInstallSize(self):41 def testInstallSize(self):
34 cmd = ["df", "/"]42 logging.info('Getting root partition usage '
35 logging.debug("Cmd: %s" % (cmd))43 'as stored by late command...')
36 output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]44 with open('/var/log/utah-install') as f:
37 logging.debug("Cmd output: %s" % (output))45 line = next(line for line in f
38 lines = output.split("\n")46 if line.startswith(self.LOG_MESSAGE))
39 self.assertEqual(len(lines), 3)47 used = int(line.split()[-1])
48 logging.info('{} {}'.format(self.LOG_MESSAGE, used))
4049
41 used = int(lines[1].split()[2])
42 # 700 minimal max install size + 150 test overlay50 # 700 minimal max install size + 150 test overlay
43 max_install_size = 87040051 max_install_size = 870400
52
44 # Add overhead for multiarch package lists on amd6453 # Add overhead for multiarch package lists on amd64
45 # +32MB roughly54 # +32MB roughly
46 if platform.machine() == "x86_64":55 if platform.machine() == "x86_64":
47 max_install_size += 3225656 max_install_size += 32256
48 self.assertTrue( used < max_install_size, "Used: %s" % (used))57
58 self.assertLess(
59 used, max_install_size,
60 "Usage ({}) is *not* less than the maximum expected value: {}"
61 .format(used, max_install_size))
62
63 logging.info("Usage ({}) is less than the maximum expected value: {}"
64 .format(used, max_install_size))
4965
50if __name__ == '__main__':66if __name__ == '__main__':
67 logging.basicConfig(level=logging.DEBUG,
68 format='%(levelname)s: %(message)s')
51 unittest.main()69 unittest.main()

Subscribers

People subscribed via source and target branches