예제 #1
0
    def install_and_configure_puppet(self):
        self._configure_fabric_for_build_node()
        build_node = self.build_node()
        sudo('echo %s %s %s puppet.%s puppet | tee --append /etc/hosts' % (build_node.internal_ip, build_node.fqdn, build_node.name, Configuration.get().domain))
        if 'manifest' in self.description:
            manifest_dir = utils.build_manifest_dir(self.description['manifest'],
                                                   {'job': self,
                                                    'config': Configuration.get(),
                                                    'nodes': self.nodes()})
            utils.put_recursive(manifest_dir, self.description['manifest'].get('destdir', '/etc/puppet/manifests'))

        for archive in self.description['archives']:
            sudo('apt-get install -y python-software-properties')
            sudo('add-apt-repository "%s"' % (archive['line'],))
            if 'key_data' in archive:
                with tempfile.NamedTemporaryFile() as tmpfile:
                    remote_name = '%s.key' % (archive['name'],)
                    tmpfile.write(archive['key_data'])
                    tmpfile.flush()
                    put(tmpfile.name, remote_name)
                    sudo('apt-key add %s' % (remote_name,))
            elif 'key_id' in archive:
                sudo('apt-key adv --keyserver keyserver.ubuntu.com --recv-keys %s' % (archive['key_id'],))
            if archive.get('proxy', False):
                parts = archive['line'].split(' ')
                if parts[0] == 'deb':
                    parsed_url = urlparse.urlparse(parts[1])
                    host = parsed_url.hostname
                    sudo('echo \'Acquire::http::Proxy::%s "%s";\' > /etc/apt/apt.conf.d/99proxy-%s.conf' % (host, archive['proxy'], archive['name']))

        sudo('apt-get update')
        sudo('apt-get install -y openssh-server puppetmaster-passenger puppet puppet-openstack-cisco')
        sudo('puppet apply /etc/puppet/manifests/site.pp')
        sudo('puppet agent -t || true')
        sudo("grep -q -- fence.*-z /etc/cobbler/power/power_ucs.template || sed -e '/fence/ s/$/ -z/' -i /etc/cobbler/power/power_ucs.template")
예제 #2
0
    def test_put_recursive(self):
        tmpdir = tempfile.mkdtemp()
        try:
            with file('%s/file1' % (tmpdir,), 'w') as fp:
                fp.write('file1 contents')
            with file('%s/file2' % (tmpdir,), 'w') as fp:
                fp.write('file2 contents')
            os.mkdir('%s/dir1' % (tmpdir,))
            with file('%s/dir1/file3' % (tmpdir,), 'w') as fp:
                fp.write('file3 contents')
            with mock.patch.multiple('greenfan.utils',
                                     put=mock.DEFAULT, sudo=mock.DEFAULT) as mocks:
                put, sudo = mocks['put'], mocks['sudo']

                # This is needed to check the order in which put calls were
                # made relative to sudo calls
                manager = mock.MagicMock()
                manager.attach_mock(put, 'put')
                manager.attach_mock(sudo, 'sudo')

                utils.put_recursive('%s/' % (tmpdir,), '/dst/dir')

                self.assertEquals(put.call_count, 3)

                topdir_mkdir = mock.call.sudo('mkdir -p /dst/dir')
                dir1_mkdir = mock.call.sudo('mkdir -p /dst/dir/dir1')
                file1_put = mock.call.put('%s/file1' % (tmpdir,), '/dst/dir/file1', use_sudo=True)
                file2_put = mock.call.put('%s/file2' % (tmpdir,), '/dst/dir/file2', use_sudo=True)
                file3_put = mock.call.put('%s/dir1/file3' % (tmpdir,), '/dst/dir/dir1/file3', use_sudo=True)

                self.assertIn(file1_put, manager.mock_calls)

                # Some ordering must be in place
                self.assertTrue(manager.mock_calls.index(topdir_mkdir) < manager.mock_calls.index(file1_put))
                self.assertTrue(manager.mock_calls.index(topdir_mkdir) < manager.mock_calls.index(file2_put))
                self.assertTrue(manager.mock_calls.index(topdir_mkdir) < manager.mock_calls.index(dir1_mkdir))
                self.assertTrue(manager.mock_calls.index(dir1_mkdir) < manager.mock_calls.index(file3_put))

                self.assertEquals(put.call_count, 3)
                self.assertEquals(sudo.call_count, 2)
        finally:
            shutil.rmtree(tmpdir)