2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#!/usr/bin/python
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# -*- coding: utf-8 -*-
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# CDDL HEADER START
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# The contents of this file are subject to the terms of the
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# Common Development and Distribution License (the "License").
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# You may not use this file except in compliance with the License.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# or http://www.opensolaris.org/os/licensing.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# See the License for the specific language governing permissions
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# and limitations under the License.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila# CDDL HEADER END
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila#
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen# Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen#
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenfrom . import testutils
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenif __name__ == "__main__":
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen testutils.setup_environment("../../../proto")
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenimport pkg5unittest
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenimport errno
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenimport os
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenimport platform
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenimport unittest
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenclass TestPkgInitInstall(pkg5unittest.SingleDepotTestCase):
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen persistent_setup = True
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen core = """\
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen open core-os@1.0
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add set name=pkg.fmri value=pkg://solaris/system/core-os@1.0
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add set name=pkg.summary value="Core Solaris"
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add set name=pkg.description value="Operating system core utilities, daemons, and configuration files."
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add dir path=etc group=sys owner=root mode=0555
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add dir path=etc/ftpd group=sys owner=root mode=0555
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add file path=etc/ftpd/ftpusers group=sys preserve=true owner=root mode=0444
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add link path=etc/ftpusers target=./ftpd/ftpusers
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add file path=etc/group group=sys preserve=true owner=root mode=0444
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add file path=etc/passwd group=sys preserve=true owner=root mode=0444
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add file path=etc/shadow group=sys mode=0400 preserve=true owner=root
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=adm gid=4
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=bin gid=2
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=daemon gid=12
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=dialout gid=13
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=games gid=20
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=lp gid=8
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=mail gid=6
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=noaccess gid=60002
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=nobody gid=60001
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=nogroup gid=65534
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=other gid=1
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=root gid=0
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=staff gid=10
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=sys gid=3
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=sysadmin gid=14
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=tty gid=7
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add group groupname=webservd gid=80
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add user username=adm ftpuser=false gcos-field=Admin group=adm home-dir=/var/adm lastchg=6445 login-shell=/bin/sh password=NP uid=4 group-list=lp group-list=sys group-list=tty
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add user username=bin ftpuser=false gcos-field="" group=bin group-list=sys home-dir=/ lastchg=6445 login-shell=/bin/sh password=NP uid=2
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen add user username=daemon ftpuser=false gcos-field="" group=other home-dir=/ lastchg=6445 login-shell=/bin/sh password=NP uid=1 group-list=adm group-list=bin
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi add user username=noaccess ftpuser=false gcos-field="No Access User" group=nogroup home-dir=/ lastchg=6445 login-shell=/bin/sh password=*LK* uid=60002
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi add user username=nobody ftpuser=false gcos-field="NFS Anonymous Access User" group=nobody home-dir=/ login-shell=/bin/sh uid=60001
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi add user username=nobody4 ftpuser=false gcos-field="SunOS 4.x NFS Anonymous Access User" group=nogroup home-dir=/ lastchg=6445 login-shell=/bin/sh password=*LK* uid=65534
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi add user username=root ftpuser=false gcos-field=Super-User group=root home-dir=/root lastchg=6445 login-shell=/usr/bin/bash password="" uid=0 group-list=adm group-list=bin group-list=daemon group-list=lp group-list=mail group-list=other group-list=sys group-list=tty
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi add user username=sys ftpuser=false gcos-field="" group=sys home-dir=/ lastchg=6445 login-shell=/bin/sh password=NP uid=3
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi add user username=webservd ftpuser=false gcos-field="WebServer Reserved UID" group=webservd home-dir=/ login-shell=/bin/sh password=*LK* uid=80
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi close
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi"""
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi misc_files = { "etc/passwd":"", "etc/group":"", "etc/shadow":"", "etc/ftpd/ftpusers":"" }
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi def setUp(self):
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi pkg5unittest.SingleDepotTestCase.setUp(self)
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi self.make_misc_files(self.misc_files)
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi def file_in_image(self, path):
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi return open(os.path.join(self.get_img_path(), path))
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila def file_is_sorted(self, path, column):
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila # make sure the ':' separated file is sorted in ascending order
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila # on the integer in the specified column
d31a407872fb93f907fc2587daaa780ffa9a6f56Martti Rannanjärvi previous = None
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila for line in self.file_in_image(path):
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila if previous is None:
efd203f312659a7ce82644fb2a39d791ac198b77Teemu Huovila previous = int(line.split(":")[column])
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen else:
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen now = int(line.split(":")[column])
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen self.assertTrue(now >= previous,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen "{0} is not sorted by column {1}".format(
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen path, column))
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen def test_init_install(self):
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen """test initial install of stripped down core OS"""
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen plist = self.pkgsend_bulk(self.rurl, self.core)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen self.image_create(self.rurl)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen self.pkg("install core-os")
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen self.pkg("verify")
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen # verify that /etc/passwd and /etc/group are in
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen # ascending [UG]ID order
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen self.file_is_sorted("etc/passwd", 2)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen self.file_is_sorted("etc/group", 2)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen