コード例 #1
0
    def _setUp(self):
        '''Common test setup'''
        self.htpasswd = "/etc/nagios3/htpasswd.users"
        self.nagios_cfg = "/etc/nagios3/nagios.cfg"
        self.nagios_cmd = "/var/lib/nagios3/rw/nagios.cmd"

        # Make sure we're not running first
        self.apachedaemon = testlib.TestDaemon("/etc/init.d/apache2")
        self.nagiosdaemon = testlib.TestDaemon("/etc/init.d/nagios3")
        rc, result = self.nagiosdaemon.status()
        if (rc):
            self.nagiosdaemon.stop()
            time.sleep(2)
        rc, result = self.apachedaemon.status()
        if (rc):
            self.apachedaemon.stop()
            time.sleep(2)

        testlib.config_replace(self.htpasswd, "", True)
        rc, report = testlib.cmd(
            ['htpasswd', '-c', '-b', self.htpasswd, 'nagiosadmin', 'ubuntu'])

        # Turn on external commands
        testlib.config_replace(self.nagios_cfg, "", True)
        subprocess.call([
            'sed', '-i',
            's/^check_external_commands=0/check_external_commands=1/g',
            self.nagios_cfg
        ])

        # Fix permissions on command pipe dir (as per /usr/share/doc/nagios3/README.Debian)
        subprocess.call(['chmod', 'g+xs', '/var/lib/nagios3/rw'])
        subprocess.call(['chmod', 'o+x', '/var/lib/nagios3'])

        self._start()
コード例 #2
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.mailman_daemon = testlib.TestDaemon("/etc/init.d/mailman")
        self.mailman_cfg = '/etc/mailman/mm_cfg.py'
        self.mailman_aliases = '/var/lib/mailman/data/aliases'
        self.mailman_pid = '/var/run/mailman/mailman.pid'
        self.postfix_daemon = testlib.TestDaemon("/etc/init.d/postfix")
        self.postfix_mastercf = '/etc/postfix/master.cf'
        self.postfix_maincf = '/etc/postfix/main.cf'
        self.postfix_transport = '/etc/postfix/transportqrt'
        self.postfix_aliases = '/etc/aliases'
        self.ports_file = "/etc/apache2/ports.conf"
        self.mailman_site = "/etc/apache2/sites-enabled/mailman"
        self.tempdir = tempfile.mkdtemp()

        if self.lsb_release['Release'] >= 12.10:
            self.default_site = "/etc/apache2/sites-available/000-default.conf"
        else:
            self.default_site = "/etc/apache2/sites-available/default"

        if self.lsb_release['Release'] >= 13.10:
            self.apache_pid = "/var/run/apache2/apache2.pid"
        else:
            self.apache_pid = "/var/run/apache2.pid"

        self.cj = cookielib.LWPCookieJar()
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))

        # Make sure daemons are stopped before we begin
        self.postfix_daemon.stop()
        self.mailman_daemon.stop()

        testlib.config_replace(self.mailman_aliases, "", append=True)
        testlib.config_set(self.mailman_cfg,'MTA',"'Postfix'")
        subprocess.call(['/usr/lib/mailman/bin/genaliases'], stdout=subprocess.PIPE)
        subprocess.call(['chown', 'root:list', self.mailman_aliases])
        # Is this a packaging mistake?
        subprocess.call(['chown', 'list:list', '/var/lib/mailman/archives/private'])

        self._zap_lists()
        subprocess.call(['/usr/sbin/newlist', '-q', '*****@*****.**', '*****@*****.**' ,'ubuntu'], stdout=subprocess.PIPE)

        self._setUp_postfix()
        self._setUp_apache()

        self.mailman_daemon.restart()

        self.user = testlib.TestUser(lower=True)
        self.s = None
        # Silently allow for this connection to fail, to handle the
        # initial setup of the postfix server.
        try:
            self.s = smtplib.SMTP('localhost', port=25)
        except:
            pass
コード例 #3
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.haproxy_default = "/etc/default/haproxy"
        self.haproxy_config = "/etc/haproxy/haproxy.cfg"
        self.haproxy_daemon = testlib.TestDaemon("/etc/init.d/haproxy")
        self.my_ip = self._get_my_ip()

        testlib.config_set(self.haproxy_default, "ENABLED", "1", False)
        default_config = '''
global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:8000
    default_backend servers

backend servers
    server server1 127.0.0.1:80 maxconn 32
    server server2 %s:80 maxconn 32
''' % self.my_ip

        testlib.config_replace(self.haproxy_config, default_config)
        testlib_httpd.HttpdCommon._setUp(self, clearlogs=True)
        self.haproxy_daemon.restart()
コード例 #4
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.daemon = testlib.TestDaemon("/etc/init.d/cron")
        self.daemon.restart()

        self.tmpdir = tempfile.mkdtemp(prefix='testlib', dir='/tmp')

        self.seconds = 130

        self.spooldir = "/var/spool/cron/crontabs"
        self.script = os.path.join(self.tmpdir, "test.sh")
        self.cronfile = os.path.join(self.tmpdir, "test.cron")
        self.works = os.path.join(self.tmpdir, "it_works")

        contents = '''#!/bin/sh
set -e
touch %s
''' % (self.works)
        testlib.create_fill(self.script, contents, mode=0755)

        contents = "*/1 * * * *	%s\n" % (self.script)
        testlib.create_fill(self.cronfile, contents)

        self.user = testlib.TestUser()  #group='users',uidmin=2000,lower=True)
        os.chown(os.path.dirname(self.works), self.user.uid, self.user.gid)
コード例 #5
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.tomcat_daemon = testlib.TestDaemon("/etc/init.d/" + exe)
        self.users_file = "/etc/" + exe + "/tomcat-users.xml"
        self.html_page = "/var/lib/" + exe + "/webapps/ROOT/test.html"
        self.webapp_dir = "/var/lib/" + exe + "/webapps"
        self.war = ""

        self.admin_user = "******"
        #self.admin_pass = "******"
        self.admin_pass = testlib.random_string(10)
        testlib.config_replace(self.users_file, "", True)
        self.manager_group = "manager"
        if exe in ["tomcat7", "tomcat8"]:
            self.manager_group = "manager-gui"
        user_config = 's/^<tomcat-users>/<tomcat-users>\\n<role rolename=\"%s\"\/>\\n<user username=\"%s\" password=\"%s\" roles=\"%s\"\/>\\n/' % (
            self.manager_group, self.admin_user, self.admin_pass,
            self.manager_group)
        if exe in ["tomcat8"]:
            user_config = 's/^<\/tomcat-users>/<role rolename=\"%s\"\/>\\n<user username=\"%s\" password=\"%s\" roles=\"%s\"\/>\\n<\/tomcat-users>\\n/' % (
                self.manager_group, self.admin_user, self.admin_pass,
                self.manager_group)

        subprocess.call(['sed', '-i', user_config, self.users_file])
        subprocess.call(['chgrp', exe, self.users_file])

        self.tomcat_daemon.restart()
コード例 #6
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.fs_dir = os.path.abspath('.')
        testlib_archive.ArchiveCommon._setUp(self)
        self.dest_dir = "test-dest"
        self.dest_root = os.path.join(self.tempdir, self.dest_dir)
        os.mkdir(self.dest_root)

        self.rsyncd_default = "/etc/default/rsync"
        self.rsyncd_conf = "/etc/rsyncd.conf"
        self.rsyncd_secrets = "/etc/rsyncd.secrets"

        testlib.config_set(self.rsyncd_default,
                           'RSYNC_ENABLE',
                           'true',
                           spaces=False)
        testlib.config_replace(
            self.rsyncd_conf, '''[test-module]
  path = %s
  auth users = *
  secrets file = %s
''' % (self.archive_root, self.rsyncd_secrets))

        testlib.config_replace(self.rsyncd_secrets, '''gooduser:goodpass
''')
        os.chmod(self.rsyncd_secrets, 0700)

        self.daemon = testlib.TestDaemon("/etc/init.d/rsync")
        self.daemon.force_restart()
        time.sleep(1)
コード例 #7
0
 def setUp(self):
     '''Set up prior to each test_* function'''
     self.pidfile = "/var/run/iscsid.pid"
     self.exe = "/sbin/iscsid"
     self.daemon = testlib.TestDaemon("/etc/init.d/open-iscsi")
     self.initiatorname_iscsi = '/etc/iscsi/initiatorname.iscsi'
     self.iscsid_conf = '/etc/iscsi/iscsid.conf'
コード例 #8
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.server_initscript = "/etc/init.d/slpd"
        self.server_pidfile = "/var/run/slpd.pid"
        self.server_binary = "/usr/sbin/slpd"

        self.daemon = testlib.TestDaemon(self.server_initscript)
        self.daemon.restart()
コード例 #9
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.ts_disabled_tests = []
        self.ts_loc = "/usr/share/postgresql-common"
        self.testuser = "******"
        self.testdb = "testdb"
        self.user = None

        self.daemon = None
        for i in ['8.4']:
            p = '/etc/init.d/postgresql-%s' % (i)
            if os.path.exists(p):
                self.daemon = testlib.TestDaemon(p)
        if self.daemon == None:
            self.daemon = testlib.TestDaemon('/etc/init.d/postgresql')

        rc, result = self.daemon.start()
コード例 #10
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.pidfile = "/var/run/xfs/xfs.pid"
        self.exe = "/usr/bin/xfs"
        self.font_server = "unix/:7100"

        self.daemon = testlib.TestDaemon("/etc/init.d/xfs")
        self._restart_daemon()
コード例 #11
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.daemon = testlib.TestDaemon("/etc/init.d/memcached")
        self.daemon.restart()

        # Add some data
        self.test_data = { 'colour': 'blue',
                           'size'  : 'xl',
                           'day'   : 'friday',
                           'month' : 'january' }

        for k in self.test_data:
            self._set_key(k, self.test_data[k])
コード例 #12
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.user = testlib.TestUser()
        self.user_testfile = os.path.join(self.user.home, "testfile")
        self.user_teststring = "Ubuntu rocks!"
        testlib.create_fill(self.user_testfile, self.user_teststring)

        self.vsftpd_conf = "/etc/vsftpd.conf"
        testlib.config_set(self.vsftpd_conf,'write_enable','YES', spaces=False)
        testlib.config_set(self.vsftpd_conf,'local_enable','YES', spaces=False)

        self.tempdir = tempfile.mkdtemp(dir='/tmp',prefix="vsftpd-")

        self.daemon = testlib.TestDaemon("/etc/init.d/vsftpd")
        self.daemon.restart()

        self.current_dir = os.getcwd()
コード例 #13
0
    def setUp(self):
        '''Set up prior to each test_* function'''

        if self.lsb_release['Release'] < 15.04:
            self.document_root = "/usr/share/nginx/html"
        else:
            self.document_root = "/var/www/html"

        self.html_page = os.path.join(self.document_root, "test.html")

        self.default_vhost = "/etc/nginx/sites-available/default"
        self.ssl_crt = "/etc/nginx/cert.pem"
        self.ssl_key = "/etc/nginx/cert.key"

        self.pidfile = "/var/run/nginx.pid"

        self.daemon = testlib.TestDaemon("/etc/init.d/nginx")
        self.daemon.restart()
コード例 #14
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.daemon = testlib.TestDaemon("/etc/init.d/apport")
        self.defaults = "/etc/default/apport"
        self.core_pattern = "/proc/sys/kernel/core_pattern"
        self.tmpdir = tempfile.mkdtemp(dir='/tmp')
        self.crashdir = "/var/crash"
        self.user = testlib.TestUser()  #group='users',uidmin=2000,lower=True)
        testlib.cmd(['adduser', self.user.login, 'adm'])
        testlib.cmd(['adduser', self.user.login,
                     'admin'])  # needed by some tests
        self.test_dir = os.path.join(self.crashdir, "testlib-dir")
        self.test_empty = os.path.join(self.crashdir, "testlib.empty")
        self.test_old = os.path.join(self.crashdir, "testlib.old")

        # we need a program that is in a package here, for apport to generate
        # a report
        self.test_exec = "/usr/bin/free"
        self.test_exec_bak = "/usr/bin/free.testlib"
        self.test_exec_report = os.path.join(self.crashdir, "_usr_bin_free")

        # name this, but don't create it
        self.test_file = os.path.join(self.crashdir, "testlib-file")

        testlib.create_fill(self.test_empty, '')
        os.chown(self.test_empty, self.user.uid, self.user.gid)
        testlib.create_fill(self.test_old, 'stuff')
        subprocess.call(['touch', '-t', '200601010000', self.test_old])
        os.chown(self.test_old, self.user.uid, self.user.gid)

        os.mkdir(self.test_dir)
        os.chown(self.test_dir, self.user.uid, self.user.gid)

        # The location of the test-runner changed in karmic(?)
        if os.path.exists("/usr/share/apport/testsuite/run-tests"):
            self.testsuite = "/usr/share/apport/testsuite/run-tests"
        else:
            self.testsuite = "/usr/share/apport/testsuite/run"

        # Vivid no longer ships the test suite
        if self.lsb_release['Release'] >= 15.04:
            self.testsuite = None

        self.apt_sources = "/etc/apt/sources.list"
コード例 #15
0
    def setUp(self):
        '''Setup mechanisms'''

        # Try to figure out (or guess) what port the XSP2 server is on
        self.port = 8082
        try:
            for line in file('/etc/default/mono-xsp2').read().splitlines():
                if line.find('port=') >= 0:
                    self.port = line.split('=', 2)[1]
        except IOError:
            # Ignore failures
            return

        if os.path.exists("/usr/share/asp.net2-demos/"):
            self.test_page = "/usr/share/asp.net2-demos/test.aspx"
        else:
            self.test_page = "/usr/share/asp.net-demos/test.aspx"
        self.test_url = "/samples/test.aspx"

        self.daemon = testlib.TestDaemon("/etc/init.d/mono-xsp2")
        self.xsp2_pid = "/var/run/mono-xsp2.pid"
        self.daemon.start()
コード例 #16
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.daemon = testlib.TestDaemon("/etc/init.d/freeradius")
        self.tmpdir = tempfile.mkdtemp(prefix='freeradius-', dir='/tmp')
        self.auth_approved = "code 2"
        self.auth_denied = "code 3"

        # Add a default user
        self.users_file = "/etc/freeradius/users"
        self.test_user = "******"
        self.test_pass = "******"
        config_line = '%s Cleartext-Password := "******"' % (self.test_user, self.test_pass)
        testlib.config_replace(self.users_file, config_line, append=True)

        # Enable Unix auth
        self.default_site = "/etc/freeradius/sites-available/default"
        testlib.config_replace(self.default_site, "", append=True)
        subprocess.call(['sed', '-i', 's/^#\tunix/\tunix/', self.default_site])

        # Create a test user
        self.user = testlib.TestUser()

        self._restart_daemon()
コード例 #17
0
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.zope_instance = "/var/lib/zope3/instance/testinstance"
        self.zope_zdaemon = os.path.join(self.zope_instance, 'etc/zdaemon.conf')
        self.zope_logfile = os.path.join(self.zope_instance, 'log/z3.log')
        self.zope_transcriptfile = os.path.join(self.zope_instance, 'log/transcript.log')
        self.zope_port = '8080'
        self.zope_admin_user = "******"
        self.zope_admin_pass = testlib.random_string(12)
        self.daemon = testlib.TestDaemon("/etc/init.d/zope3")

        # Make sure we're stopped
        rc, result = self.daemon.stop()

        # Empty out the instance directory if it already exists
        if os.path.exists(self.zope_instance):
            testlib.recursive_rm(self.zope_instance)

        # Create the instance
        (rc, report) = testlib.cmd(['/usr/lib/zope3/bin/mkzopeinstance', '-d', self.zope_instance,
                                    '-u', self.zope_admin_user + ':' + self.zope_admin_pass,
                                    '--service-port=' + self.zope_port, '-m', 'Plain Text'])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        # Work around bug #356137 in jaunty
        if self.lsb_release['Release'] == 9.04:
            subprocess.call(['sed', '-i', 's/^define ZOPE_USER/%define ZOPE_USER/', self.zope_zdaemon])

        # Start the instance
        rc, result = self.daemon.start()

        report = 'Init script reported no instances found.\n'
        self.assertFalse('no instances found' in result, result + report)
        time.sleep(2)
コード例 #18
0
    def setUp(self):
        '''Setup mechanisms'''
        if self.lsb_release['Release'] >= 13.10:
            self.testlib_conf = "/etc/apache2/conf-enabled/testlib.conf"
            self.default_site = "/etc/apache2/sites-available/000-default.conf"
            self.default_vhost_link = "/etc/apache2/sites-enabled/000-default.conf"
        else:
            self.testlib_conf = "/etc/apache2/conf.d/testlib"
            self.default_site = "/etc/apache2/sites-available/default"
            self.default_vhost_link = "/etc/apache2/sites-enabled/000-default"

        self._set_initscript("/etc/init.d/apache2")
        self.ports_file = "/etc/apache2/ports.conf"
        self.tomcat_daemon = testlib.TestDaemon("/etc/init.d/" + exe)
        self.server_file = "/etc/" + exe + "/server.xml"

        # Change the default port, so we can run in a schroot
        testlib.config_replace(self.ports_file, "", append=True)
        subprocess.call(['sed', '-i', 's/80/8000/g', self.ports_file])
        testlib.config_replace(self.default_site, "", append=True)
        if self.lsb_release['Release'] > 8.04:
            subprocess.call(['sed', '-i', 's/80/8000/g', self.default_site])
        else:
            subprocess.call([
                'sed', '-i', 's/\(VirtualHost \*\)/\\1\:8000/',
                self.default_site
            ])

        # Set up jk configuration
        if self.lsb_release['Release'] < 11.10:
            contents = '''
JkWorkersFile	/etc/libapache2-mod-jk/workers.properties
JkLogFile 	/var/log/apache2/mod_jk.log
JkLogLevel 	info
JkMount /*.jsp ajp13_worker
JkMount /*/servlet/ ajp13_worker
'''
            testlib.create_fill(self.testlib_conf, contents)
        subprocess.call([
            'sed', '-i',
            's#^</VirtualHost>#JkMount /examples* ajp13_worker\\n</VirtualHost>#',
            self.default_site
        ])

        testlib.config_replace(self.server_file, "", append=True)
        subprocess.call([
            'sed', '-i',
            's#</Service>#<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />\\n</Service>#',
            self.server_file
        ])

        self.tomcat_daemon.restart()

        # ensure sites-enabled/000-default is a symlink to
        # sites-available/default, or else tests will fail.
        try:
            if os.path.abspath(
                    os.path.join(
                        '/etc/apache2/sites-enabled/',
                        os.readlink(
                            self.default_vhost_link))) == self.default_site:
                pass
        except OSError, e:
            if e.errno == errno.ENOENT or e.errno == errno.EINVAL:
                if os.path.exists(self.default_vhost_link):
                    testlib._save_backup(self.default_vhost_link)
                    os.unlink(self.default_vhost_link)
                os.symlink(self.default_site, self.default_vhost_link)
            else:
                raise e
コード例 #19
0
    def setUp(self):
        '''Set up prior to each test_* function'''

        self.sshd_config = '/etc/ssh/sshd_config'
        self.sshd_rsa_private_keyfile = '/etc/ssh/ssh_host_rsa_key'
        self.sshd_rsa_private_key = \
'''-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAs7PQMZkt6/s3ibdNW6C4ZUr6k1uSE0XZ5RK2cfdh0Ug1+DkJ
Rp8WTdsIKOVY69No1k3zKGm7EFvx5JhmSXxFcPqMj1/+NYw+JeT8q18JzPrhvEmI
KhP3+ydW+B+6w8PP2uEIpOS9OX7ISQgsgJ2J2M48aP2aAkdAjtO61JepJ6d+UHtD
cFyRS7P/17/o1QfWalAgbdLpZuq0eguRedVO6OTugTLu96g3w7Tk7watLO0GRStG
PlXRNRyZW4ER6xnUrG5lbEYICTYISA5yLSYBb3TTPyfQv6flD9SD64Xa8kgktGkD
AbMx7wa6BiRMeshNM+uFRJ/ZimcAKdUJMyYf4QIDAQABAoIBAQCt+W+eFQZ4aAYk
temWw8rBhg2BjC2nqwCA3dT0EOQKkTZu0glA7dPSHDOSJDgqV8ovb9fxUCticyGE
hmbAzicMcgSS6gRaIyQn28EiyCfc4yaX+zhwRFTYOgXgwhc2X+Rjq2mK+kiX2T5e
NiOfgOVrmH6zxpHLkt/VZvaByzJgyA2deH3KT9W/O+Mm52dDaer3ZKNKy/orpxbo
Ip4SbNIEdTylX9DoBZQzn6AKBkc/S8Qok3xGT/uM/mbj2IruwHwrkFURYQyzbcmQ
jDX1T3AJz92+LbiW8kKw8uODfoVdxv91ooTmST4z6izU6shpNGsHOHtV/rsOfvGs
H/fNYqSBAoGBAO9ULRjWeWcyMO/M+dLc4z4+LQ4QWPMVChuxjNVKIX4HycrXbIo4
uEZYhIDYDW7tIJp7Jp4YPzpbAGQldR//3EW3Pr9t4e7Y7TT2EDutNpFn+2a+cr2J
Qn+k0aO458V0vNXofpThIPyZppCF6y2ass/LG/RrIx+4XeIhprFzFlmtAoGBAMA4
Wc5GCaPbh+URejTptbE/WCBolUgt6gMDuEMvwVrdRJSP/7HTy5SdCzEExn8S86AY
S3TBGq5c5Pa+S8vuGXWaVidsVr4tf50yNTBkmyMazzi8cM+q0BHWFqT5L5+wbfpW
ahS+vidFhoF+1jK14Gg4WMVfZubDX4aiRYC44s2FAoGAfgU3/eUpZhKCvDKVtdfD
/Mlmlgo7nDwO54g1XTY8ro1RT3Lh32KAfeIsW1/oqulICrAgJI0l9gdnDFTA+MmU
Zk1YSBqHJmqpdQLAh3vsyOIU+gP8jRsSnf3eubQqrsmKiaRzytdEtF3/3Af4Tzov
P8V2gdxMUW6WWPVZPgUY1r0CgYBoerilnAAFZn/5DITmWdn+W7Xk97Ocpgg6Vz1C
l6R7ZSWvso2C9OIFB09b94KE86IkdNAeyA9ekvOJAmpkkCiaeac2inajrEtfADlU
8no4nIviBNs0pV2vNDTeuusd22IL3giO+haVdf7kSDLZIW62d1oY/gAKkktL/MvW
aagtmQKBgFQJ8FhBmSU/pkl5cRLEySwFWv/SvK7/VPBB1KDnbqAFC3YV1J2EIghL
7Rq/s93NCBweb97e5SgH/IBPpWnlXzRGL5ApmwXuoPzp7PZokgw7Tv4X8SSjaOmP
ITfOx9KgntLukRe860E+CbkBxEhPD+2+GhtXL0d21o4JoS/YQb80
-----END RSA PRIVATE KEY-----
'''
        self.sshd_rsa_public_key = \
'''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzs9AxmS3r+zeJt01boLhlSvqTW5ITRdnlErZx92HRSDX4OQlGnxZN2wgo5Vjr02jWTfMoabsQW/HkmGZJfEVw+oyPX/41jD4l5PyrXwnM+uG8SYgqE/f7J1b4H7rDw8/a4Qik5L05fshJCCyAnYnYzjxo/ZoCR0CO07rUl6knp35Qe0NwXJFLs//Xv+jVB9ZqUCBt0ulm6rR6C5F51U7o5O6BMu73qDfDtOTvBq0s7QZFK0Y+VdE1HJlbgRHrGdSsbmVsRggJNghIDnItJgFvdNM/J9C/p+UP1IPrhdrySCS0aQMBszHvBroGJEx6yE0z64VEn9mKZwAp1QkzJh/h root@localhost
'''
        testlib.config_replace(self.sshd_rsa_private_keyfile,
                               self.sshd_rsa_private_key)
        testlib.config_replace(self.sshd_rsa_private_keyfile + ".pub",
                               self.sshd_rsa_public_key)

        self.daemon = testlib.TestDaemon("/etc/init.d/ssh")
        self.daemon.restart()

        self.current_dir = os.getcwd()
        self.tmpdir = tempfile.mkdtemp(prefix='testlib', dir='/tmp')
        os.chmod(self.tmpdir, 0777)

        # create first user
        self.userX = testlib.TestUser()
        os.mkdir(self.userX.home + "/.ssh", 0700)
        os.chown(self.userX.home + "/.ssh", self.userX.uid, self.userX.gid)
        testlib.create_fill(self.userX.home + "/.ssh/known_hosts",
                            "localhost,127.0.0.1 " + self.sshd_rsa_public_key)
        os.chown(self.userX.home + "/.ssh/known_hosts", self.userX.uid,
                 self.userX.gid)
        self.generate_ssh_keys(self.userX)

        # create second user
        self.userY = testlib.TestUser()
        os.mkdir(self.userY.home + "/.ssh", 0700)
        os.chown(self.userY.home + "/.ssh", self.userY.uid, self.userY.gid)
        testlib.create_fill(self.userY.home + "/.ssh/known_hosts",
                            "localhost,127.0.0.1 " + self.sshd_rsa_public_key)
        os.chown(self.userY.home + "/.ssh/known_hosts", self.userY.uid,
                 self.userY.gid)
        self.generate_ssh_keys(self.userY)
        # Make sure second user can ssh into the first users account
        shutil.copy2(self.userY.home + "/.ssh/id_rsa.pub",
                     self.userX.home + "/.ssh/authorized_keys")
        os.chown(self.userX.home + "/.ssh/authorized_keys", self.userX.uid,
                 self.userX.gid)

        # Hardy and older need to have users in the fuse group
        if self.lsb_release['Release'] <= 8.04:
            rc, out = self.shell_cmd(
                ["gpasswd", "-a", self.userX.login, "fuse"])
            self.assertEquals(rc, 0, "Could not add userX to fuse group!")
            rc, out = self.shell_cmd(
                ["gpasswd", "-a", self.userY.login, "fuse"])
            self.assertEquals(rc, 0, "Could not add userY to fuse group!")
コード例 #20
0
    def setUp(self):
        '''Set up prior to each test_* function'''

        self.plugindir = "/etc/puppet/plugins"
        self.classesdir = "/etc/puppet/manifests/classes"
        self.site_pp = "/etc/puppet/manifests/site.pp"
        self.fileserver_conf = "/etc/puppet/fileserver.conf"
        self.debian_version = "/etc/debian_version"
        self.hosts_file = "/etc/hosts"
        self.puppet_default = "/etc/default/puppet"

        self.testsuite = "/usr/share/puppet-testsuite"
        self.testsuite_disabled = []
        self.testsuite_edits = []
        self.tmpdir = tempfile.mkdtemp(prefix='testlib', dir='/tmp')

        # Create missing directories
        if not os.path.exists(self.plugindir):
            os.mkdir(self.plugindir)
        if not os.path.exists(self.classesdir):
            os.mkdir(self.classesdir)

        # Set up configuration file
        testlib.config_replace(self.fileserver_conf,
                               '''#
[files]
  path /etc/puppet/files
  allow *

[plugins]
  path /etc/puppet/plugins
  allow *
''',
                               append=False)

        # On Quantal+, we need to use mocha from gem since the one in
        # the archive is too new. Rename a few directories. There's
        # probably a better way of doing this.
        if self.lsb_release['Release'] == 12.10 or self.lsb_release[
                'Release'] == 13.04:
            rc, report = testlib.cmd([
                'mv', '/usr/lib/ruby/vendor_ruby/mocha',
                '/usr/lib/ruby/vendor_ruby/mocha-disabled'
            ])
            expected = 0
            self.assertEquals(rc, expected,
                              "directory rename failed:\n" + report)

            rc, report = testlib.cmd([
                'mv', '/usr/lib/ruby/vendor_ruby/mocha.rb',
                '/usr/lib/ruby/vendor_ruby/mocha.rb-disabled'
            ])
            expected = 0
            self.assertEquals(rc, expected,
                              "directory rename failed:\n" + report)

        # Enable the client service on lucid+
        testlib.config_replace(self.puppet_default, "", True)
        subprocess.call(
            ['sed', '-i', 's/^START=no/START=yes/', self.puppet_default])

        # Add puppet host to host file
        testlib.config_replace(self.hosts_file, "127.0.0.1 puppet", True)

        self.serverdaemon = testlib.TestDaemon("/etc/init.d/puppetmaster")
        self.clientdaemon = testlib.TestDaemon("/etc/init.d/puppet")

        self._restart()
コード例 #21
0
 def _set_initscript(self, initscript):
     self.daemon = testlib.TestDaemon(initscript)
コード例 #22
0
 def setUp(self):
     '''Set up prior to each test_* function'''
     self.daemon = testlib.TestDaemon("/etc/init.d/acpid")