#!/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 # 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()