1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/usr/bin/env python
#
# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors: Michal Minar <miminar@redhat.com>
#
from common import *
class TestSoftwarePackage(SoftwareBaseTestCase):
CLASS_NAME = "LMI_SoftwarePackage"
KEYS = ( "Name", "SoftwareElementID", "SoftwareElementState"
, "TargetOperatingSystem", "Version")
def make_op(self, name, epoch, ver, rel, arch, ses=2):
op = self.op.copy()
op["Name"] = name
op["SoftwareElementID"] = make_nevra(
name, epoch, ver, rel, arch, "ALWAYS")
op["SoftwareElementState"] = pywbem.Uint16(ses)
op["TargetOperatingSystem"] = pywbem.Uint16(36)
op["Version"] = ver
return op
def test_get_instance(self):
for pkg in packages:
if is_installed(pkg.name):
remove_pkg(pkg.name)
op = self.make_op(pkg.name, pkg.epoch, pkg.ver,
pkg.rel, pkg.arch, 1)
inst = self.conn.GetInstance(InstanceName=op, LocalOnly=False)
self.assertEqual(inst.path, op)
for key in self.KEYS:
self.assertTrue(inst.properties.has_key(key))
self.assertEqual(inst.path[key], inst[key])
self.assertEqual(inst['Release'], pkg.rel)
install_pkg(*pkg[:5])
op['SoftwareElementState'] = pywbem.Uint16(2)
inst = self.conn.GetInstance(InstanceName=op, LocalOnly=False)
self.assertEqual(inst.path, op)
# try to leave out epoch part
if pkg.epoch == "0":
op_no_epoch = op.copy()
op_no_epoch["SoftwareElementID"] = make_nevra(pkg.name, pkg.epoch,
pkg.ver, pkg.rel, pkg.arch, "NEVER")
self.assertNotIn(":", op_no_epoch["SoftwareElementID"])
inst = self.conn.GetInstance(
InstanceName=op_no_epoch, LocalOnly=False)
self.assertIn(inst.path, (op, op_no_epoch))
def test_method_install(self):
for pkg in packages:
if is_installed(pkg.name):
remove_pkg(pkg.name)
op = self.make_op(pkg.name, pkg.epoch, pkg.ver,
pkg.rel, pkg.arch, 1)
(rval, oparms) = self.conn.InvokeMethod(
MethodName="Install",
ObjectName=op)
self.assertEqual(rval, pywbem.Uint32(1))
self.assertEqual(len(oparms), 1)
self.assertTrue(oparms.has_key('Installed'))
op['SoftwareElementState'] = pywbem.Uint16(2)
self.assertEqual(oparms['Installed'], op)
self.assertTrue(is_installed(pkg.name))
(rval, oparms) = self.conn.InvokeMethod(
MethodName="Install",
ObjectName=op)
self.assertEqual(rval, pywbem.Uint32(0))
self.assertEqual(len(oparms), 1)
self.assertEqual(oparms['Installed'], op)
def test_method_remove(self):
for pkg in packages:
if not is_installed(pkg.name):
install_pkg(*pkg[:5])
op = self.make_op(*pkg[:5])
(rval, oparms) = self.conn.InvokeMethod(
MethodName="Remove",
ObjectName=op)
self.assertEqual(rval, pywbem.Uint16(1))
self.assertEqual(len(oparms), 0)
self.assertFalse(is_installed(pkg.name))
op["SoftwareElementState"] = pywbem.Uint16(1)
(rval, oparms) = self.conn.InvokeMethod(
MethodName="Remove",
ObjectName=op)
self.assertEqual(rval, pywbem.Uint32(0))
self.assertEqual(len(oparms), 0)
if __name__ == '__main__':
unittest.main()
|