Merge lp:~pwlars/lava-test/softwareprofile into lp:lava-test/0.0

Proposed by Paul Larson
Status: Merged
Merged at revision: 20
Proposed branch: lp:~pwlars/lava-test/softwareprofile
Merge into: lp:lava-test/0.0
Diff against target: 124 lines (+103/-1)
3 files modified
abrek/swprofile.py (+51/-0)
tests/__init__.py (+2/-1)
tests/test_swprofile.py (+50/-0)
To merge this branch: bzr merge lp:~pwlars/lava-test/softwareprofile
Reviewer Review Type Date Requested Status
Linaro Infrastructure Pending
Review via email: mp+31771@code.launchpad.net

Description of the change

This simply gets the sw_context information that the dashboard wants and includes unit tests. Not utilized yet, but I'll get to that after adding support for gathering hardware information too.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

On Wed, 04 Aug 2010 17:34:04 -0000, Paul Larson <email address hidden> wrote:
> Paul Larson has proposed merging lp:~pwlars/abrek/softwareprofile into lp:abrek.
>
> Requested reviews:
> Linaro Infrastructure (arm-infrastructure)
>
>
> This simply gets the sw_context information that the dashboard wants
> and includes unit tests. Not utilized yet, but I'll get to that after
> adding support for gathering hardware information too.

Hi Paul,

This looks fine to me.

Any reason you didn't take the code that zyga had written for this?

Thanks,

James

Revision history for this message
Paul Larson (pwlars) wrote :

I started with the assumption that I was going to use the reference implementation that he provides in the client code, however while the format has been agreed on, the codebase has still been churning some. Also, after looking at it, it seemed that this is really something that needs to be provided by abrek regardless of the server that it might be communicating with. The framework for running tests does not rely on the dashboard even existing, and is ideally possible to use with other servers that you might want to upload to. TBH, after looking at the options, it seemed simpler to just take the pieces I needed, make a few changes to make it fit better in abrek, and do it here rather than waiting for it to land and rely on it as a dependency.

Revision history for this message
James Westby (james-w) wrote :

On Wed, 04 Aug 2010 18:16:42 -0000, Paul Larson <email address hidden> wrote:
> I started with the assumption that I was going to use the reference
> implementation that he provides in the client code, however while the
> format has been agreed on, the codebase has still been churning some.
> Also, after looking at it, it seemed that this is really something
> that needs to be provided by abrek regardless of the server that it
> might be communicating with. The framework for running tests does not
> rely on the dashboard even existing, and is ideally possible to use
> with other servers that you might want to upload to. TBH, after
> looking at the options, it seemed simpler to just take the pieces I
> needed, make a few changes to make it fit better in abrek, and do it
> here rather than waiting for it to land and rely on it as a
> dependency.

I agree, but I was thinking you would just copy and paste the code and
tests from there.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'abrek/swprofile.py'
2--- abrek/swprofile.py 1970-01-01 00:00:00 +0000
3+++ abrek/swprofile.py 2010-08-04 17:33:54 +0000
4@@ -0,0 +1,51 @@
5+import apt
6+import lsb_release
7+
8+def get_packages(apt_cache=None):
9+ """ Get information about the packages installed
10+
11+ apt_cache - if not provided, this will be read from the system
12+ """
13+ if apt_cache == None:
14+ apt_cache = apt.Cache()
15+ packages = []
16+ for apt_pkg in apt_cache:
17+ if hasattr(apt_pkg, 'is_installed'):
18+ is_installed = apt_pkg.is_installed
19+ else:
20+ is_installed = apt_pkg.isInstalled # old style API
21+ if is_installed:
22+ pkg = {"name":apt_pkg.name, "version":apt_pkg.installed.version}
23+ packages.append(pkg)
24+ return packages
25+
26+def get_sw_context(test_id, time_check=False, apt_cache=None,
27+ lsb_information=None):
28+ """ Return dict used for storing sw_context information
29+
30+ test_id - Unique identifier for this test
31+ time_check - whether or not a check was performed to see if
32+ the time on the system was synced with a time server
33+ apt_cache - if not provided, this will be read from the system
34+ lsb_information - if not provided, this will be read from the system
35+ """
36+ sw_context = {}
37+ sw_context['sw_image'] = get_sw_image(lsb_information)
38+ sw_context['packages'] = get_packages(apt_cache)
39+ sw_context['time_check_performed'] = time_check
40+ sw_context['test_id'] = test_id
41+ return sw_context
42+
43+def get_sw_image(lsb_information=None):
44+ """ Get information about the image we are running
45+
46+ For now, this just uses the description from lsb-release. This will
47+ be extended to provide more detailed information about the image if
48+ it becomes available
49+
50+ lsb_information - if not provided, this will be read from the system
51+ """
52+ if lsb_information == None:
53+ lsb_information = lsb_release.get_lsb_information()
54+ desc = lsb_information['DESCRIPTION']
55+ return {"desc":desc}
56
57=== modified file 'tests/__init__.py'
58--- tests/__init__.py 2010-07-22 14:49:49 +0000
59+++ tests/__init__.py 2010-08-04 17:33:54 +0000
60@@ -5,7 +5,8 @@
61 'tests.test_abrekcmd',
62 'tests.test_abrektestinstaller',
63 'tests.test_abrektestrunner',
64- 'tests.test_abrektestparser']
65+ 'tests.test_abrektestparser',
66+ 'tests.test_swprofile']
67 loader = unittest.TestLoader()
68 suite = loader.loadTestsFromNames(module_names)
69 return suite
70
71=== added file 'tests/test_swprofile.py'
72--- tests/test_swprofile.py 1970-01-01 00:00:00 +0000
73+++ tests/test_swprofile.py 2010-08-04 17:33:54 +0000
74@@ -0,0 +1,50 @@
75+import unittest
76+
77+import abrek.swprofile
78+
79+class Version:
80+ def __init__(self, version):
81+ self.version = version
82+
83+class Package:
84+ def __init__(self, name, version, is_installed=True):
85+ self.is_installed = is_installed
86+ self.name = name
87+ self.installed = Version(version)
88+
89+class AptCache:
90+ def __init__(self, packages=[]):
91+ self.packages = packages
92+
93+ def __iter__(self):
94+ return iter(self.packages)
95+
96+class SwprofileTests(unittest.TestCase):
97+ def setUp(self):
98+ self.lsb_desc = 'test description'
99+ self.lsb_information = {'DESCRIPTION':self.lsb_desc}
100+ self.testpackage = Package('testpkg', '7.77')
101+ self.cache = AptCache([self.testpackage])
102+
103+ def make_profile(self, test_id='unit', cache=None, info=None):
104+ if cache == None:
105+ cache = self.cache
106+ if info == None:
107+ info = self.lsb_information
108+ return abrek.swprofile.get_sw_context(test_id, apt_cache=cache,
109+ lsb_information=info)
110+
111+ def test_pkg_name(self):
112+ a = self.make_profile()
113+ for pkg in a['packages']:
114+ self.assertEqual(self.testpackage.name, pkg['name'])
115+
116+ def test_pkg_version(self):
117+ a = self.make_profile()
118+ for pkg in a['packages']:
119+ self.assertEqual(self.testpackage.installed.version, pkg['version'])
120+
121+ def test_image_desc(self):
122+ a = self.make_profile()
123+ self.assertEqual(self.lsb_desc, a['sw_image']['desc'])
124+

Subscribers

People subscribed via source and target branches