t_plat.py revision 290
290N/A
290N/A#!/usr/bin/python
290N/A#
290N/A# CDDL HEADER START
290N/A#
290N/A# The contents of this file are subject to the terms of the
290N/A# Common Development and Distribution License (the "License").
290N/A# You may not use this file except in compliance with the License.
290N/A#
290N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
290N/A# or http://www.opensolaris.org/os/licensing.
290N/A# See the License for the specific language governing permissions
290N/A# and limitations under the License.
290N/A#
290N/A# When distributing Covered Code, include this CDDL HEADER in each
290N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
290N/A# If applicable, add the following below this CDDL HEADER, with the
290N/A# fields enclosed by brackets "[]" replaced with your own identifying
290N/A# information: Portions Copyright [yyyy] [name of copyright owner]
290N/A#
290N/A# CDDL HEADER END
290N/A#
290N/A
290N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
290N/A# Use is subject to license terms.
290N/A
290N/Aimport os
290N/Aimport unittest
290N/Aimport tempfile
290N/Aimport pkg.fmri as fmri
290N/Aimport pkg.portable.util as util
290N/Aimport pkg.portable as portable
290N/A
290N/Aclass TestPlat(unittest.TestCase):
290N/A def setUp(self):
290N/A pass
290N/A
290N/A def testbasic(self):
290N/A portable.get_isainfo()
290N/A portable.get_release()
290N/A portable.get_platform()
290N/A
290N/A def testGroup(self):
290N/A if os.path.exists("/etc/group"):
290N/A self.assertRaises(KeyError, portable.get_group_by_name,
290N/A "ThisShouldNotExist", "/", True)
290N/A
290N/A self.assertRaises(KeyError, portable.get_name_by_gid, 87285, "/", True)
290N/A
290N/A def testUser(self):
290N/A if os.path.exists("/etc/passwd"):
290N/A self.assertRaises(KeyError, portable.get_user_by_name,
290N/A "ThisShouldNotExist", "/", True)
290N/A
290N/A self.assertRaises(KeyError, portable.get_name_by_uid, 87285, "/", True)
290N/A
290N/A
290N/A def testAdmin(self):
290N/A if os.name == 'posix' and os.getuid() == 0:
290N/A self.assert_(portable.is_admin())
290N/A if os.name == 'posix' and os.getuid() != 0:
290N/A self.assert_(not portable.is_admin())
290N/A
290N/A def testUtils(self):
290N/A self.assertNotEqual("unknown", util.get_canonical_os_type())
290N/A self.assertNotEqual("unknown", util.get_canonical_os_name())
290N/A
290N/A def testRelease(self):
290N/A rel = util.get_os_release()
290N/A # make sure it can be used in an fmri
290N/A test_fmri = fmri.PkgFmri("testpkg", build_release = rel)
290N/A
290N/A def testForcibleRename(self):
290N/A # rename a file on top of another file which already exists
290N/A (fd1, path1) = tempfile.mkstemp()
290N/A os.write(fd1, "foo")
290N/A (fd2, path2) = tempfile.mkstemp()
290N/A os.write(fd2, "bar")
290N/A os.close(fd1)
290N/A os.close(fd2)
290N/A portable.rename(path1, path2)
290N/A self.failIf(os.path.exists(path1))
290N/A self.failUnless(os.path.exists(path2))
290N/A fd2 = os.open(path2, os.O_RDONLY)
290N/A self.assertEquals(os.read(fd2, 3), "foo")
290N/A os.close(fd2)
290N/A os.unlink(path2)
290N/A
290N/Aif __name__ == "__main__":
290N/A unittest.main()