Commit b1180249 by John Doe

added rails api

parent d1269290
Showing with 12129 additions and 3 deletions
source 'https://rubygems.org'
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 0.3.2'
gem 'facter', '>= 1.7.0'
# railsapi
#### Table of Contents
1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
3. [Setup - The basics of getting started with railsapi](#setup)
* [What railsapi affects](#what-railsapi-affects)
* [Setup requirements](#setup-requirements)
* [Beginning with railsapi](#beginning-with-railsapi)
4. [Usage - Configuration options and additional functionality](#usage)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)
## Overview
A one-maybe-two sentence summary of what the module does/what problem it solves.
This is your 30 second elevator pitch for your module. Consider including
OS/Puppet version it works with.
## Module Description
If applicable, this section should have a brief description of the technology
the module integrates with and what that integration enables. This section
should answer the questions: "What does this module *do*?" and "Why would I use
it?"
If your module has a range of functionality (installation, configuration,
management, etc.) this is the time to mention it.
## Setup
### What railsapi affects
* A list of files, packages, services, or operations that the module will alter,
impact, or execute on the system it's installed on.
* This is a great place to stick any warnings.
* Can be in list or paragraph form.
### Setup Requirements **OPTIONAL**
If your module requires anything extra before setting up (pluginsync enabled,
etc.), mention it here.
### Beginning with railsapi
The very basic steps needed for a user to get the module up and running.
If your most recent release breaks compatibility or requires particular steps
for upgrading, you may wish to include an additional section here: Upgrading
(For an example, see http://forge.puppetlabs.com/puppetlabs/firewall).
## Usage
Put the classes, types, and resources for customizing, configuring, and doing
the fancy stuff with your module here.
## Reference
Here, list the classes, types, providers, facts, etc contained in your module.
This section should include all of the under-the-hood workings of your module so
people know what the module is touching on their system but don't need to mess
with things. (We are working on automating this section!)
## Limitations
This is where you list OS compatibility, version compatibility, etc.
## Development
Since your module is awesome, other users will want to play with it. Let them
know what the ground rules for contributing are.
## Release Notes/Contributors/Etc **Optional**
If you aren't using changelog, put your release notes here (though you should
consider using changelog). You may also add any additional sections you feel are
necessary or important to include here. Please use the `## ` header.
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
# == Class: rails_api
#
# Install and bootstrap the rails api
#
class rails_api {
require nilmdb
$deps = ['ruby-dev','libsqlite3-dev','nodejs']
package {$deps:,
ensure => present
}
user{'rails':
ensure => present,
system => true
}
vcsrepo{'/opt/api':
ensure => latest,
provider => git,
source => 'https://git.wattsworth.net/wattsworth/control-api.git',
require => User['rails'],
notify => Exec['bundle_install','db_migrate','local_bootstrap'],
owner => 'rails'
}
package {'bundler':
ensure => present,
provider => gem,
require => Package[$deps]
}
#install the gems
exec {'bundle_install':
command => 'bundle install --without test development --path vendor/bundle',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
refreshonly => true,
user => 'rails',
require => [Vcsrepo['/opt/api'],Package['bundler']]
}
exec {'db_setup':
command => 'bundle exec rake db:setup',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
creates => '/opt/api/db/local.sqlite',
user => 'rails',
require => [Vcsrepo['/opt/api'],Package['bundler'],Exec['bundle_install']]
}
#migrate the database
exec {'db_migrate':
command => 'bundle exec rake db:migrate',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
user => 'rails',
refreshonly => true,
require => [Vcsrepo['/opt/api'],Package['bundler'],Exec['db_setup']]
}
#migrate the database
exec {'local_bootstrap':
command => 'bundle exec rake local:bootstrap',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
user => 'rails',
refreshonly => true,
require => [Vcsrepo['/opt/api'],Package['bundler'],Exec['db_migrate']]
}
}
{
"name": "jdonnal-railsapi",
"version": "0.1.0",
"author": "John Donnal",
"summary": null,
"license": "Apache 2.0",
"source": "",
"project_page": null,
"issues_url": null,
"dependencies": [
{"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}
]
}
require 'spec_helper'
describe 'railsapi' do
context 'with defaults for all parameters' do
it { should contain_class('railsapi') }
end
end
require 'puppetlabs_spec_helper/module_spec_helper'
# The baseline for module testing used by Puppet Labs is that each manifest
# should have a corresponding test manifest that declares that class or defined
# type.
#
# Tests are then run by using puppet apply --noop (to check for compilation
# errors and view a log of events) or by fully applying the test in a virtual
# environment (to compare the resulting system state to the desired state).
#
# Learn more about module testing here:
# http://docs.puppetlabs.com/guides/tests_smoke.html
#
include railsapi
<VirtualHost *:80>
ServerName wattsworth.local
DocumentRoot /var/www/frontend
Alias /api /opt/lumen/public
<Directory /opt/lumen/public>
Alias /api /opt/api/public
<Directory /opt/api/public>
Options +Indexes +FollowSymLinks -MultiViews
AllowOverride None
Order allow,deny
......@@ -11,7 +11,8 @@
</Directory>
<Location /api>
PassengerBaseURI /api
PassengerAppRoot /opt/lumen
PassengerAppRoot /opt/api
RailsEnv local
</Location>
<Directory /var/www/frontend>
Options Indexes FollowSymLinks MultiViews
......
# Change Log
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
## Supported Release [2.0.0]
### Summary
This is a major release that **drops support for Puppet 3** and addresses an issue with the subversion provider.
### Added
- Documentation for using an non-standard ssh port ([MODULES-1910](https://tickets.puppet.com/browse/MODULES-1910))
- Autorequire for the subversion package in the vcsrepo type ([MODULES-4722](https://tickets.puppetlabs.com/browse/MODULES-4722))
- Puppet 5 support in metadata ([MODULES-5144](https://tickets.puppet.com/browse/MODULES-5144))
### Changed
- Lower bound of Puppet requirement to 4.7.0 ([MODULES-4823](https://tickets.puppetlabs.com/browse/MODULES-4823))
### Fixed
- Solaris `SSH_AUTH_SOCKET` issue
- Issue with subversion provider ([MODULES-4280](https://tickets.puppetlabs.com/browse/MODULES-4280))
- `force` parameter to return a boolean instead of a string ([MODULES-4864](https://tickets.puppetlabs.com/browse/MODULES-4864))
## [1.5.0] - 2016-12-19 Supported Release
### Summary
Release featuring some refactoring and improvements around git's `ensurable`.
### Bugfixes
- `ensure => absent` fix
### Features
- `:source` property added
- Improved `ensure` handling for git provider
- General refactoring for all providers
- Various test improvements
## [1.4.0] - 2015-09-06 Supported Release
### Summary
Small release for a new feature and added compatibility.
### Features
- Git repositories can be cloned as mirror or bare repos.
- Added STDERR to Puppet's output.
- Added Debian 8 and Ubuntu 16.04 compatibility.
## [1.3.2] - 2015-12-08 Supported Release
### Summary
Small release for support of newer PE versions. This increments the version of PE in the metadata.json file.
## [1.3.1] - 2015-07-28 Supported Release
### Summary
This release includes a number of bugfixes and test updates.
### Fixed
- Fix for detached HEAD on git 2.4+.
- Git provider doesn't ignore revision property when depth is used (MODULES-2131).
- Tests fixed.
- Check if submodules == true before calling update_submodules.
## [1.3.0] - 2015-05-19 Supported Release
### Summary
This release adds git provider remote handling, svn conflict resolution, and fixes the git provider when /tmp is mounted noexec.
### Added
- `source` property now takes a hash of sources for the git provider's remotes.
- Added `submodules` parameter to skip submodule initialization for the git provider.
- Added `conflict` to the svn provider to resolve conflicts.
- Added `branch` parameter to specify clone branch.
- Readme rewritten.
### Fixed
- The git provider now works even if `/tmp` is noexec.
## [1.2.0] - 2014-11-04 Supported Release
### Summary
This release includes some improvements for git, mercurial, and cvs providers, and fixes the bug where there were warnings about multiple default providers.
### Added
- Update git and mercurial providers to set UID with `Puppet::Util::Execution.execute` instead of `su`
- Allow git excludes to be string or array
- Add `user` feature to cvs provider
### Fixed
- No more warnings about multiple default providers! (MODULES-428)
## [1.1.0] - 2014-07-14 Supported Release
### Summary
This release adds a Perforce provider\* and corrects the git provider behavior
when using `ensure => latest`.
\*(Only git provider is currently supported.)
### Added
- New Perforce provider.
### Fixed
- Fix behavior with `ensure => latest` and detached HEAD. (MODULES-660)
- Spec test fixes.
## [1.0.2] - 2014-06-30 Supported Release
### Summary
This supported release adds SLES 11 to the list of compatible OSs and
documentation updates for support.
## [1.0.1] - 2014-06-17 Supported Release
### Summary
This release is the first supported release of vcsrepo. The readme has been
greatly improved.
### Added
- Updated and expanded readme to follow readme template.
### Fixed
- Remove SLES from compatability metadata.
- Unpin rspec development dependencies.
- Update acceptance level testing.
## [1.0.0] - 2014-06-04
### Summary
This release focuses on a number of bugfixes, and also has some
new features for Bzr and Git.
### Added
- Bzr:
- Call set_ownership.
- Git:
- Add ability for shallow clones.
- Use -a and desired for HARD resets.
- Use rev-parse to get tag canonical revision.
### Fixed
- HG:
- Only add ssh options when it's talking to the network.
- Git:
- Fix for issue with detached HEAD.
- `force => true` will now destroy and recreate repo.
- Actually use the remote parameter.
- Use origin/master instead of origin/HEAD when on master.
- SVN:
- Fix svnlook behavior with plain directories.
## 0.2.0 - 2013-11-13
### Summary
This release mainly focuses on a number of bugfixes, which should
significantly improve the reliability of Git and SVN. Thanks to
our many contributors for all of these fixes!
### Added
- Git:
- Add autorequire for `Package['git']`.
- HG:
- Allow user and identity properties.
- Bzr:
- "ensure => latest" support.
- SVN:
- Added configuration parameter.
- Add support for master svn repositories.
- CVS:
- Allow for setting the CVS_RSH environment variable.
### Fixed
- Handle Puppet::Util[::Execution].withenv for 2.x and 3.x properly.
- Change path_empty? to not do full directory listing.
- Overhaul spec tests to work with rspec2.
- Git:
- Improve Git SSH usage documentation.
- Add ssh session timeouts to prevent network issues from blocking runs.
- Fix git provider checkout of a remote ref on an existing repo.
- Allow unlimited submodules (thanks to --recursive).
- Use git checkout --force instead of short -f everywhere.
- Update git provider to handle checking out into an existing (empty) dir.
- SVN:
- Handle force property.
- Adds support for changing upstream repo url.
- Check that the URL of the WC matches the URL from the manifest.
- Changed from using "update" to "switch".
- Handle revision update without source switch.
- Fix svn provider to look for '^Revision:' instead of '^Last Changed Rev:'.
- CVS:
- Documented the "module" attribute.
[2.0.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.5.0...2.0.0
[1.5.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.4.0...1.5.0
[1.4.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.3.2...1.4.0
[1.3.2]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.3.1...1.3.2
[1.3.1]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.3.0...1.3.1
[1.3.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.2.0...1.3.0
[1.2.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.1.0...1.2.0
[1.1.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.0.2...1.1.0
[1.0.2]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/0.2.0...1.0.0
Checklist (and a short version for the impatient)
=================================================
* Commits:
- Make commits of logical units.
- Check for unnecessary whitespace with "git diff --check" before
committing.
- Commit using Unix line endings (check the settings around "crlf" in
git-config(1)).
- Do not check in commented out code or unneeded files.
- The first line of the commit message should be a short
description (50 characters is the soft limit, excluding ticket
number(s)), and should skip the full stop.
- Associate the issue in the message. The first line should include
the issue number in the form "(#XXXX) Rest of message".
- The body should provide a meaningful commit message, which:
- uses the imperative, present tense: "change", not "changed" or
"changes".
- includes motivation for the change, and contrasts its
implementation with the previous behavior.
- Make sure that you have tests for the bug you are fixing, or
feature you are adding.
- Make sure the test suites passes after your commit:
`bundle exec rspec spec/acceptance` More information on [testing](#Testing) below
- When introducing a new feature, make sure it is properly
documented in the README.md
* Submission:
* Pre-requisites:
- Make sure you have a [GitHub account](https://github.com/join)
- [Create a ticket](https://tickets.puppet.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppet.com/browse/) you are patching for.
* Preferred method:
- Fork the repository on GitHub.
- Push your changes to a topic branch in your fork of the
repository. (the format ticket/1234-short_description_of_change is
usually preferred for this project).
- Submit a pull request to the repository in the puppetlabs
organization.
The long version
================
1. Make separate commits for logically separate changes.
Please break your commits down into logically consistent units
which include new or changed tests relevant to the rest of the
change. The goal of doing this is to make the diff easier to
read for whoever is reviewing your code. In general, the easier
your diff is to read, the more likely someone will be happy to
review it and get it into the code base.
If you are going to refactor a piece of code, please do so as a
separate commit from your feature or bug fix changes.
We also really appreciate changes that include tests to make
sure the bug is not re-introduced, and that the feature is not
accidentally broken.
Describe the technical detail of the change(s). If your
description starts to get too long, that is a good sign that you
probably need to split up your commit into more finely grained
pieces.
Commits which plainly describe the things which help
reviewers check the patch and future developers understand the
code are much more likely to be merged in with a minimum of
bike-shedding or requested changes. Ideally, the commit message
would include information, and be in a form suitable for
inclusion in the release notes for the version of Puppet that
includes them.
Please also check that you are not introducing any trailing
whitespace or other "whitespace errors". You can do this by
running "git diff --check" on your changes before you commit.
2. Sending your patches
To submit your changes via a GitHub pull request, we _highly_
recommend that you have them on a topic branch, instead of
directly on "master".
It makes things much easier to keep track of, especially if
you decide to work on another thing before your first change
is merged in.
GitHub has some pretty good
[general documentation](http://help.github.com/) on using
their site. They also have documentation on
[creating pull requests](http://help.github.com/send-pull-requests/).
In general, after pushing your topic branch up to your
repository on GitHub, you can switch to the branch in the
GitHub UI and click "Pull Request" towards the top of the page
in order to open a pull request.
3. Update the related GitHub issue.
If there is a GitHub issue associated with the change you
submitted, then you should update the ticket to include the
location of your branch, along with any other commentary you
may wish to make.
Testing
=======
Getting Started
---------------
Our puppet modules provide [`Gemfile`](./Gemfile)s which can tell a ruby
package manager such as [bundler](http://bundler.io/) what Ruby packages,
or Gems, are required to build, develop, and test this software.
Please make sure you have [bundler installed](http://bundler.io/#getting-started)
on your system, then use it to install all dependencies needed for this project,
by running
```shell
% bundle install
Fetching gem metadata from https://rubygems.org/........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.1.0)
Using builder (3.2.2)
-- 8><-- many more --><8 --
Using rspec-system-puppet (2.2.0)
Using serverspec (0.6.3)
Using rspec-system-serverspec (1.0.0)
Using bundler (1.3.5)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
```
NOTE some systems may require you to run this command with sudo.
If you already have those gems installed, make sure they are up-to-date:
```shell
% bundle update
```
With all dependencies in place and up-to-date we can now run the tests:
```shell
% bundle exec rake spec
```
This will execute all the [rspec tests](http://rspec-puppet.com/) tests
under [spec/defines](./spec/defines), [spec/classes](./spec/classes),
and so on. rspec tests may have the same kind of dependencies as the
module they are testing. While the module defines in its [Modulefile](./Modulefile),
rspec tests define them in [.fixtures.yml](./fixtures.yml).
Some puppet modules also come with [beaker](https://github.com/puppetlabs/beaker)
tests. These tests spin up a virtual machine under
[VirtualBox](https://www.virtualbox.org/)) with, controlling it with
[Vagrant](http://www.vagrantup.com/) to actually simulate scripted test
scenarios. In order to run these, you will need both of those tools
installed on your system.
You can run them by issuing the following command
```shell
% bundle exec rake spec_clean
% bundle exec rspec spec/acceptance
```
This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml),
install puppet, copy this module and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb)
and then run all the tests under [spec/acceptance](./spec/acceptance).
Writing Tests
-------------
XXX getting started writing tests.
If you have commit access to the repository
===========================================
Even if you have commit access to the repository, you will still need to
go through the process above, and have someone else review and merge
in your changes. The rule is that all changes must be reviewed by a
developer on the project (that did not write the code) to ensure that
all changes go through a code review process.
Having someone other than the author of the topic branch recorded as
performing the merge is the record that they performed the code
review.
Additional Resources
====================
* [Getting additional help](http://puppet.com/community/get-help)
* [Writing tests](https://docs.puppet.com/guides/module_guides/bgtm.html#step-three-module-testing)
* [General GitHub documentation](http://help.github.com/)
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
#This file is generated by ModuleSync, do not edit.
source ENV['GEM_SOURCE'] || "https://rubygems.org"
# Determines what type of gem is requested based on place_or_version.
def gem_type(place_or_version)
if place_or_version =~ /^git:/
:git
elsif place_or_version =~ /^file:/
:file
else
:gem
end
end
# Find a location or specific version for a gem. place_or_version can be a
# version, which is most often used. It can also be git, which is specified as
# `git://somewhere.git#branch`. You can also use a file source location, which
# is specified as `file://some/location/on/disk`.
def location_for(place_or_version, fake_version = nil)
if place_or_version =~ /^(git[:@][^#]*)#(.*)/
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
elsif place_or_version =~ /^file:\/\/(.*)/
['>= 0', { :path => File.expand_path($1), :require => false }]
else
[place_or_version, { :require => false }]
end
end
# Used for gem conditionals
supports_windows = false
ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
minor_version = "#{ruby_version_segments[0]}.#{ruby_version_segments[1]}"
group :development do
gem "puppet-module-posix-default-r#{minor_version}", :require => false, :platforms => "ruby"
gem "puppet-module-win-default-r#{minor_version}", :require => false, :platforms => ["mswin", "mingw", "x64_mingw"]
gem "puppet-module-posix-dev-r#{minor_version}", :require => false, :platforms => "ruby"
gem "puppet-module-win-dev-r#{minor_version}", :require => false, :platforms => ["mswin", "mingw", "x64_mingw"]
gem "json_pure", '<= 2.0.1', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
gem "fast_gettext", '1.1.0', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0')
gem "fast_gettext", :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
end
group :system_tests do
gem "puppet-module-posix-system-r#{minor_version}", :require => false, :platforms => "ruby"
gem "puppet-module-win-system-r#{minor_version}", :require => false, :platforms => ["mswin", "mingw", "x64_mingw"]
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '>= 3')
gem "beaker-pe", :require => false
gem "beaker-rspec", *location_for(ENV['BEAKER_RSPEC_VERSION'])
gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1')
end
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
# Only explicitly specify Facter/Hiera if a version has been specified.
# Otherwise it can lead to strange bundler behavior. If you are seeing weird
# gem resolution behavior, try setting `DEBUG_RESOLVER` environment variable
# to `1` and then run bundle install.
gem 'facter', *location_for(ENV['FACTER_GEM_VERSION']) if ENV['FACTER_GEM_VERSION']
gem 'hiera', *location_for(ENV['HIERA_GEM_VERSION']) if ENV['HIERA_GEM_VERSION']
# Evaluate Gemfile.local if it exists
if File.exists? "#{__FILE__}.local"
eval(File.read("#{__FILE__}.local"), binding)
end
# Evaluate ~/.gemfile if it exists
if File.exists?(File.join(Dir.home, '.gemfile'))
eval(File.read(File.join(Dir.home, '.gemfile')), binding)
end
# vim:ft=ruby
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
## Maintenance
Maintainers:
- Puppet Forge Modules Team `forge-modules |at| puppet |dot| com`
Tickets: https://tickets.puppet.com/browse/MODULES. Make sure to set component to `vcsrepo`.
Puppet Module - puppetlabs-vcsrepo
Copyright 2017 Puppet, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
# vcsrepo
#### Table of contents
1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
3. [Setup - The basics of getting started with vcsrepo](#setup)
* [Setup requirements](#setup-requirements)
* [Beginning with vcsrepo](#beginning-with-vcsrepo)
4. [Usage - Configuration options and additional functionality](#usage)
* [Git](#git)
* [Bazaar](#bazaar)
* [CVS](#cvs)
* [Mercurial](#mercurial)
* [Perforce](#perforce)
* [Subversion](#subversion)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
* [Type: vcsrepo](#type-vcsrepo)
* [Providers](#providers)
* [Features](#features)
* [Parameters](#parameters)
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)
## Overview
The vcsrepo module lets you use Puppet to easily deploy content from your version control system (VCS).
## Module description
The vcsrepo module provides a single type with providers to support the following version control systems:
* [Git](#git)
* [Bazaar](#bazaar)
* [CVS](#cvs)
* [Mercurial](#mercurial)
* [Perforce](#perforce)
* [Subversion](#subversion)
**Note:** `git` is the only vcs provider officially [supported by Puppet Inc.](https://forge.puppet.com/supported)
## Setup
### Setup requirements
The vcsrepo module does not install any VCS software for you. You must install a VCS before you can use this module.
Like Puppet in general, the vcsrepo module does not automatically create parent directories for the files it manages. Set up any needed directory structures before you start.
### Beginning with vcsrepo
To create and manage a blank repository, define the type `vcsrepo` with a path to your repository and supply the `provider` parameter based on the [VCS you're using](#usage).
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
}
~~~
## Usage
**Note:** `git` is the only vcsrepo provider officially [supported by Puppet Inc.](https://forge.puppet.com/supported)
### Git
#### Create a blank repository
To create a blank repository suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
}
~~~
If you're managing a central or official repository, you might want to make it a bare repository. To do this, set `ensure` to 'bare':
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => bare,
provider => git,
}
~~~
#### Clone/pull a repository
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
source => 'git://example.com/repo.git',
}
~~~
To clone your repository as bare or mirror, you can set `ensure` to 'bare' or 'mirror':
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => mirror,
provider => git,
source => 'git://example.com/repo.git',
}
~~~
By default, `vcsrepo` will use the HEAD of the source repository's master branch. To use another branch or a specific commit, set `revision` to either a branch name or a commit SHA or tag.
Branch name:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
source => 'git://example.com/repo.git',
revision => 'development',
}
~~~
SHA:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
source => 'git://example.com/repo.git',
revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
}
~~~
Tag:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
source => 'git://example.com/repo.git',
revision => '1.1.2rc1',
}
~~~
To check out a branch as a specific user, supply the `user` parameter:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
source => 'git://example.com/repo.git',
revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
user => 'someUser',
}
~~~
To keep the repository at the latest revision, set `ensure` to 'latest'.
**WARNING:** This overwrites any local changes to the repository.
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => git,
source => 'git://example.com/repo.git',
revision => 'master',
}
~~~
To clone the repository but skip initializing submodules, set `submodules` to 'false':
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => git,
source => 'git://example.com/repo.git',
submodules => false,
}
~~~
#### Use multiple remotes with a repository
In place of a single string, you can set `source` to a hash of one or more name => URL pairs:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
remote => 'origin'
source => {
'origin' => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git',
'other_remote' => 'https://github.com/other_user/puppetlabs-vcsrepo.git'
},
}
~~~
**Note:** If you set `source` to a hash, one of the names you specify must match the value of the `remote` parameter. That remote serves as the upstream of your managed repository.
#### Connect via SSH
To connect to your source repository via SSH (such as 'username@server:…'), we recommend managing your SSH keys with Puppet and using the [`require`](http://docs.puppet.com/references/stable/metaparameter.html#require) metaparameter to make sure they are present before the `vcsrepo` resource is applied.
To use SSH keys associated with a user, specify the username in the `user` parameter:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => git,
source => 'git://username@example.com/repo.git',
user => 'toto', #uses toto's $HOME/.ssh setup
require => File['/home/toto/.ssh/id_rsa'],
}
~~~
To use SSH over a nonstandard port, use the full SSH scheme and include the port number:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => git,
source => 'ssh://username@example.com:7999/repo.git',
}
~~~
### Bazaar
#### Create a blank repository
To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => bzr,
}
~~~
#### Branch from an existing repository
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => bzr,
source => '/some/path',
}
~~~
To branch from a specific revision, set `revision` to a valid [Bazaar revision spec](http://wiki.bazaar.canonical.com/BzrRevisionSpec):
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => bzr,
source => '/some/path',
revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x',
}
~~~
#### Connect via SSH
To connect to your source repository via SSH (such as `'bzr+ssh://...'` or `'sftp://...,'`), we recommend using the [`require`](http://docs.puppet.com/references/stable/metaparameter.html#require) metaparameter to make sure your SSH keys are present before the `vcsrepo` resource is applied:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => bzr,
source => 'bzr+ssh://bzr.example.com/some/path',
user => 'toto', #uses toto's $HOME/.ssh setup
require => File['/home/toto/.ssh/id_rsa'],
}
~~~
### CVS
#### Create a blank repository
To create a blank repository suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => cvs,
}
~~~
#### Checkout/update from a repository
~~~ puppet
vcsrepo { '/path/to/workspace':
ensure => present,
provider => cvs,
source => ':pserver:anonymous@example.com:/sources/myproj',
}
~~~
To get a specific module on the current mainline, supply the `module` parameter:
~~~ puppet
vcsrepo { '/vagrant/lockss-daemon-source':
ensure => present,
provider => cvs,
source => ':pserver:anonymous@lockss.cvs.sourceforge.net:/cvsroot/lockss',
module => 'lockss-daemon',
}
~~~
To set the GZIP compression levels for your repository history, use the `compression` parameter:
~~~ puppet
vcsrepo { '/path/to/workspace':
ensure => present,
provider => cvs,
compression => 3,
source => ':pserver:anonymous@example.com:/sources/myproj',
}
~~~
To get a specific revision, set `revision` to the revision number.
~~~ puppet
vcsrepo { '/path/to/workspace':
ensure => present,
provider => cvs,
compression => 3,
source => ':pserver:anonymous@example.com:/sources/myproj',
revision => '1.2',
}
~~~
You can also set `revision` to a tag:
~~~ puppet
vcsrepo { '/path/to/workspace':
ensure => present,
provider => cvs,
compression => 3,
source => ':pserver:anonymous@example.com:/sources/myproj',
revision => 'SOMETAG',
}
~~~
#### Connect via SSH
To connect to your source repository via SSH, we recommend using the [`require`](http://docs.puppet.com/references/stable/metaparameter.html#require) metaparameter to make sure your SSH keys are present before the `vcsrepo` resource is applied:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => cvs,
source => ':pserver:anonymous@example.com:/sources/myproj',
user => 'toto', #uses toto's $HOME/.ssh setup
require => File['/home/toto/.ssh/id_rsa'],
}
~~~
### Mercurial
#### Create a blank repository
To create a blank repository suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => hg,
}
~~~
#### Clone/pull and update a repository
To get the default branch tip:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => hg,
source => 'http://hg.example.com/myrepo',
}
~~~
For a specific changeset, use `revision`:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => hg,
source => 'http://hg.example.com/myrepo',
revision => '21ea4598c962',
}
~~~
You can also set `revision` to a tag:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => hg,
source => 'http://hg.example.com/myrepo',
revision => '1.1.2',
}
~~~
To check out as a specific user:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => hg,
source => 'http://hg.example.com/myrepo',
user => 'user',
}
~~~
To specify an SSH identity key:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => hg,
source => 'ssh://hg@hg.example.com/myrepo',
identity => '/home/user/.ssh/id_dsa1',
}
~~~
To specify a username and password for HTTP Basic authentication:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => hg,
source => 'http://hg.example.com/myrepo',
basic_auth_username => 'hgusername',
basic_auth_password => 'hgpassword',
}
~~~
#### Connect via SSH
To connect to your source repository via SSH (such as `'ssh://...'`), we recommend using the [`require` metaparameter](http://docs.puppet.com/references/stable/metaparameter.html#require) to make sure your SSH keys are present before the `vcsrepo` resource is applied:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => hg,
source => 'ssh://hg.example.com//path/to/myrepo',
user => 'toto', #uses toto's $HOME/.ssh setup
require => File['/home/toto/.ssh/id_rsa'],
}
~~~
### Perforce
#### Create an empty workspace
To set up the connection to your Perforce service, set `p4config` to the location of a valid Perforce [config file](http://www.perforce.com/perforce/doc.current/manuals/p4guide/chapter.configuration.html#configuration.process.configfiles) stored on the node:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => p4,
p4config => '/root/.p4config'
}
~~~
**Note:** If you don't include the `P4CLIENT` setting in your config file, the provider generates a workspace name based on the digest of `path` and the node's hostname (such as `puppet-91bc00640c4e5a17787286acbe2c021c`).
#### Create/update and sync a Perforce workspace
To sync a depot path to head, set `ensure` to 'latest':
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => p4,
source => '//depot/branch/...'
}
~~~
To sync to a specific changelist, specify its revision number with the `revision` parameter:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => p4,
source => '//depot/branch/...',
revision => '2341'
}
~~~
You can also set `revision` to a label:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => p4,
source => '//depot/branch/...',
revision => 'my_label'
}
~~~
### Subversion
#### Create a blank repository
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => svn,
}
~~~
#### Check out from an existing repository
Provide a `source` pointing to the branch or tag you want to check out:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => svn,
source => 'svn://svnrepo/hello/branches/foo',
}
~~~
You can also designate a specific revision:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => svn,
source => 'svn://svnrepo/hello/branches/foo',
revision => '1234',
}
~~~
####Checking out only specific paths
**Note:** The `includes` param is only supported when subversion client version is >= 1.6.
You can check out only specific paths in a particular repository by providing their relative paths to the `includes` parameter, like so:
~~~
vcsrepo { '/path/to/repo':
ensure => present,
provider => svn,
source => 'http://svnrepo/hello/trunk',
includes => [
'root-file.txt',
'checkout-folder',
'file/this-file.txt',
'folder/this-folder/',
]
}
~~~
This will create files `/path/to/repo/file-at-root-path.txt` and `/path/to/repo/file/nested/within/repo.jmx`, with folders `/path/to/repo/some-folder` and `/path/to/repo/nested/folder/to/checkout` completely recreating their corresponding working tree path.
When specified, the `depth` parameter will also be applied to the `includes` -- the root directory will be checked out using an `empty` depth, and the `includes` you specify will be checked out using the `depth` you provide.
To illustrate this point, using the above snippet (with the specified `includes`) and a remote repository layout like this:
~~~
.
├── checkout-folder
│   ├── file1
│   └── nested-1
│   ├── nested-2
│   │   └── nested-file-2
│   └── nested-file-1
├── file
│   ├── NOT-this-file.txt
│   └── this-file.txt
├── folder
│   ├── never-checked-out
│   └── this-folder
│   ├── deep-nested-1
│   │   ├── deep-nested-2
│   │   │   └── deep-nested-file-2
│   │   └── deep-nested-file-1
│   └── this-file.txt
├── NOT-this-file.txt
├── NOT-this-folder
│   ├── NOT-this-file.txt
│   └── NOT-this-one-either.txt
└── root-file.txt
~~~
With no `depth` given, your local folder `/path/to/repo` will look like this:
~~~
.
├── checkout-folder
│   ├── file1
│   └── nested-1
│   ├── nested-2
│   │   └── nested-file-2
│   └── nested-file-1
├── file
│   └── this-file.txt
├── folder
│   └── this-folder
│   ├── deep-nested-1
│   │   ├── deep-nested-2
│   │   │   └── deep-nested-file-2
│   │   └── deep-nested-file-1
│   └── this-file.txt
└── root-file.txt
~~~
And with a `depth` of `files` will look like this:
~~~
.
├── checkout-folder
│   └── file1
├── file
│   └── this-file.txt
├── folder
│   └── this-folder
│   └── this-file.txt
└── root-file.txt
~~~
####Use a specific Subversion configuration directory
Use the `configuration` parameter to designate the directory that contains your Subversion configuration files (typically, '/path/to/.subversion'):
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => present,
provider => svn,
source => 'svn://svnrepo/hello/branches/foo',
configuration => '/path/to/.subversion',
}
~~~
#### Connect via SSH
To connect to your source repository via SSH (such as `'svn+ssh://...'`), we recommend using the [`require` metaparameter](http://docs.puppet.com/references/stable/metaparameter.html#require) to make sure your SSH keys are present before the `vcsrepo` resource is applied:
~~~ puppet
vcsrepo { '/path/to/repo':
ensure => latest,
provider => svn,
source => 'svn+ssh://svnrepo/hello/branches/foo',
user => 'toto', #uses toto's $HOME/.ssh setup
require => File['/home/toto/.ssh/id_rsa'],
}
~~~
## Reference
### Type: vcsrepo
The vcsrepo module adds only one type with several providers. Each provider abstracts a different VCS, and each provider includes a set of features according to its needs.
#### Providers
**Note:** Not all features are available with all providers.
##### `git` - Supports the Git VCS.
Features: `bare_repositories`, `depth`, `multiple_remotes`, `reference_tracking`, `ssh_identity`, `submodules`, `user`
Parameters: `depth`, `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `remote`, `revision`, `source`, `user`
##### `bzr` - Supports the Bazaar VCS.
Features: `reference_tracking`
Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `path`, `provider`, `revision`, `source`
##### `cvs` - Supports the CVS VCS.
Features: `cvs_rsh`, `gzip_compression`, `modules`, `reference_tracking`, `user`
Parameters: `compression`, `cvs_rsh`, `ensure`, `excludes`, `force`, `group`, `module`, `owner`, `path`, `provider`
##### `hg` - Supports the Mercurial VCS.
Features: `reference_tracking`, `ssh_identity`, `user`
Parameters: `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `revision`, `source`, `user`
##### `p4` - Supports the Perforce VCS.
Features: `p4config`, `reference_tracking`
Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `p4config`, `path`, `provider`, `revision`, `source`
##### `svn` - Supports the Subversion VCS.
Features: `basic_auth`, `configuration`, `conflict`, `depth`, `filesystem_types`, `reference_tracking`
Parameters: `basic_auth_password`, `basic_auth_username`, `configuration`, `conflict`, `ensure`, `excludes`, `force`, `fstype`, `group`, `includes`, `owner`, `path`, `provider`, `revision`, `source`, `trust_server_cert`
#### Features
**Note:** Not all features are available with all providers.
* `bare_repositories` - Differentiates between bare repositories and those with working copies. (Available with `git`.)
* `basic_auth` - Supports HTTP Basic authentication. (Available with `svn`.)
* `conflict` - Lets you decide how to resolve any conflicts between the source repository and your working copy. (Available with `svn`.)
* `configuration` - Lets you specify the location of your configuration files. (Available with `svn`.)
* `cvs_rsh` - Understands the `CVS_RSH` environment variable. (Available with `cvs`.)
* `depth` - Supports shallow clones in `git` or sets the scope limit in `svn`. (Available with `git` and `svn`.)
* `filesystem_types` - Supports multiple types of filesystem. (Available with `svn`.)
* `gzip_compression` - Supports explicit GZip compression levels. (Available with `cvs`.)
* `include_paths` - Lets you checkout only certain paths. (Available with `svn`.)
* `modules` - Lets you choose a specific repository module. (Available with `cvs`.)
* `multiple_remotes` - Tracks multiple remote repositories. (Available with `git`.)
* `reference_tracking` - Lets you track revision references that can change over time (e.g., some VCS tags and branch names). (Available with all providers)
* `ssh_identity` - Lets you specify an SSH identity file. (Available with `git` and `hg`.)
* `user` - Can run as a different user. (Available with `git`, `hg` and `cvs`.)
* `p4config` - Supports setting the `P4CONFIG` environment. (Available with `p4`.)
* `submodules` - Supports repository submodules which can be optionally initialized. (Available with `git`.)
#### Parameters
All parameters are optional, except where specified otherwise.
##### `basic_auth_password`
Specifies the password for HTTP Basic authentication. (Requires the `basic_auth` feature.) Valid options: a string. Default: none.
##### `basic_auth_username`
Specifies the username for HTTP Basic authentication. (Requires the `basic_auth` feature.) Valid options: a string. Default: none.
##### `compression`
Sets the GZIP compression level for the repository history. (Requires the `gzip_compression` feature.) Valid options: an integer between 0 and 6. Default: none.
##### `configuration`
Sets the configuration directory to use. (Requires the `configuration` feature.) Valid options: a string containing an absolute path. Default: none.
##### `conflict`
Tells Subversion how to resolve any conflicts between the source repository and your working copy. (Requires the `conflict` feature.) Valid options: 'base', 'mine-full', 'theirs-full', and 'working'. Default: none.
##### `cvs_rsh`
Provides a value for the `CVS_RSH` environment variable. (Requires the `cvs_rsh` feature.) Valid options: a string. Default: none.
##### `depth`
In `git`, `depth` sets the number of commits to include when creating a shallow clone. (Requires the `depth` feature.) Valid options: an integer. Default: none.
In `svn`, `depth` limits the scope of an operation to the specified tree depth. (Requires the `depth` feature.) Valid options: 'empty', 'files', 'immediates', 'infinity'. Default: none.
##### `ensure`
Specifies whether the repository should exist. Valid options: 'present', 'bare', 'absent', and 'latest'. Default: 'present'.
##### `excludes`
Lists any files the repository shouldn't track (similar to .gitignore). Valid options: a string (separate multiple values with the newline character). Default: none.
##### `force`
Specifies whether to delete any existing files in the repository path if creating a new repository. **Use with care.** Valid options: 'true' and 'false'. Default: 'false'.
##### `fstype`
Sets the filesystem type. (Requires the `filesystem_types` feature.) Valid options: 'fsfs' or 'bdb'. Default: none.
##### `group`
Specifies a group to own the repository files. Valid options: a string containing a group name or GID. Default: none.
##### `identity`
Specifies an identity file to use for SSH authentication. (Requires the `ssh_identity` feature.) Valid options: a string containing an absolute path. Default: none.
##### `includes`
Tells Subversion which paths should be checked out at the specified depth; all other paths are not checked out. Default: none (checkout all paths).
##### `module`
Specifies the repository module to manage. (Requires the `modules` feature.) Valid options: a string containing the name of a CVS module. Default: none.
##### `owner`
Specifies a user to own the repository files. Valid options: a string containing a username or UID. Default: none.
##### `p4config`
Specifies a config file that contains settings for connecting to the Perforce service. (Requires the `p4config` feature.) Valid options: a string containing the absolute path to a valid [Perforce config file](http://www.perforce.com/perforce/doc.current/manuals/p4guide/chapter.configuration.html#configuration.process.configfiles). Default: none.
##### `path`
Specifies a location for the managed repository. Valid options: a string containing an absolute path. Default: the title of your declared resource.
##### `provider`
*Required.* Specifies the backend to use for this vcsrepo resource. Valid options: 'bzr', 'cvs', 'git', 'hg', 'p4', and 'svn'.
##### `remote`
Specifies the remote repository to track. (Requires the `multiple_remotes` feature.) Valid options: a string containing one of the remote names specified in `source`. Default: 'origin'.
##### `revision`
Sets the revision of the repository. Valid options vary by provider:
* `git` - A string containing a Git branch name, or a commit SHA or tag.
* `bzr` - A string containing a Bazaar [revision spec](http://wiki.bazaar.canonical.com/BzrRevisionSpec).
* `cvs` - A string containing a CVS [tag or revision number](http://www.thathost.com/wincvs-howto/cvsdoc/cvs_4.html).
* `hg` - A string containing a Mercurial [changeset ID](https://www.mercurial-scm.org/wiki/ChangeSetID) or [tag](https://www.mercurial-scm.org/wiki/Tag).
* `p4` - A string containing a Perforce [change number, label name, client name, or date spec](http://www.perforce.com/perforce/r12.1/manuals/cmdref/o.fspecs.html).
* `svn` - A string containing a Subversion [revision number](http://svnbook.red-bean.com/en/1.7/svn.basic.in-action.html#svn.basic.in-action.revs), [revision keyword, or revision date](http://svnbook.red-bean.com/en/1.7/svn.tour.revs.specifiers.html).
Default: none.
##### `source`
Specifies a source repository to serve as the upstream for your managed repository. Default: none. Valid options vary by provider:
* `git` - A string containing a [Git repository URL](https://www.kernel.org/pub/software/scm/git/docs/git-clone.html#_git_urls_a_id_urls_a) or a hash of `name => URL` mappings. See also [`remote`](#remote).
* `bzr` - A string containing a Bazaar branch location.
* `cvs` - A string containing a CVS root.
* `hg` - A string containing the local path or URL of a Mercurial repository.
* `p4` - A string containing a Perforce depot path.
* `svn` - A string containing a Subversion repository URL.
Default: none.
##### `submodules`
Specifies whether to initialize and update each submodule in the repository. (Requires the `submodules` feature.) Valid options: 'true' and 'false'. Default: 'true'.
##### `trust_server_cert`
Instructs Subversion to accept SSL server certificates issued by unknown certificate authorities. Valid options: 'true' and 'false'. Default: 'false'.
##### `user`
Specifies the user to run as for repository operations. (Requires the `user` feature.) Valid options: a string containing a username or UID. Default: none.
## Limitations
Git is the only VCS provider officially [supported by Puppet Inc.](https://forge.puppet.com/supported)
The includes parameter is only supported when SVN client version is >= 1.6.
This module has been tested with Puppet 2.7 and higher.
The module has been tested on:
* CentOS 5/6/7
* Debian 6/7/8
* Oracle 5/6/7
* Red Hat Enterprise Linux 5/6/7
* Scientific Linux 5/6/7
* SLES 10/11/12
* Ubuntu 10.04/12.04/14.04/16.04
Testing on other platforms has been light and cannot be guaranteed.
## Development
Puppet Inc. modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve.
We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
You can read the complete module contribution guide [on the Puppet documentation site.](https://docs.puppet.com/guides/module_guides/bgtm.html)
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.send('relative')
desc 'Generate pooler nodesets'
task :gen_nodeset do
require 'beaker-hostgenerator'
require 'securerandom'
require 'fileutils'
agent_target = ENV['TEST_TARGET']
if ! agent_target
STDERR.puts 'TEST_TARGET environment variable is not set'
STDERR.puts 'setting to default value of "redhat-64default."'
agent_target = 'redhat-64default.'
end
master_target = ENV['MASTER_TEST_TARGET']
if ! master_target
STDERR.puts 'MASTER_TEST_TARGET environment variable is not set'
STDERR.puts 'setting to default value of "redhat7-64mdcl"'
master_target = 'redhat7-64mdcl'
end
targets = "#{master_target}-#{agent_target}"
cli = BeakerHostGenerator::CLI.new([targets])
nodeset_dir = "tmp/nodesets"
nodeset = "#{nodeset_dir}/#{targets}-#{SecureRandom.uuid}.yaml"
FileUtils.mkdir_p(nodeset_dir)
File.open(nodeset, 'w') do |fh|
fh.print(cli.execute)
end
puts nodeset
end
{
"CHANGELOG.md": "65ebf04a50442d9a02acf6380092e3de",
"CONTRIBUTING.md": "77d0440d7cd4206497f99065c60bed46",
"Gemfile": "bedf635025b279d7c7732adcc8ae9a29",
"LICENSE": "b234ee4d69f5fce4486a80fdaf4a4263",
"MAINTAINERS.md": "ca51a3ba0e184f238453882b3ead112c",
"NOTICE": "06408d8f9c82a50f070a75cf499b8a0b",
"README.markdown": "54012363ec99415bc2d79c382dcc3d17",
"Rakefile": "3851f083966b9bbd6d46e50dba5aa52a",
"examples/bzr/branch.pp": "05c66419324a576b9b28df876673580d",
"examples/bzr/init_repo.pp": "fadd2321866ffb0aacff698d2dc1f0ca",
"examples/cvs/local.pp": "7fbde03a5c71edf168267ae42d0bbcbc",
"examples/cvs/remote.pp": "491f18f752752bec6133a88de242c44d",
"examples/git/bare_init.pp": "7cf56abffdf99f379153166f18f961f8",
"examples/git/clone.pp": "0e3181990c095efee1498ccfca5897fb",
"examples/git/shallow-clone-with-just-one-commit.pp": "457641c63a1ef28a655864b1fb785903",
"examples/git/working_copy_init.pp": "99d92d9957e78a0c03f9cbed989c79ca",
"examples/hg/clone.pp": "c92bbd704a4c2da55fff5f45955ce6d1",
"examples/hg/clone_basic_auth.pp": "62442bb1f978732a712a712f66f9adde",
"examples/hg/init_repo.pp": "bf5fa0ab48a2f5a1ccb63768d961413d",
"examples/p4/create_client.pp": "d49fc9c1dd55e01ee9344672ee890b13",
"examples/p4/delete_client.pp": "44fa9721fbb3ed469727856cddf34a9c",
"examples/p4/latest_client.pp": "4c9d7dc2cc629d2f108434c9f4b7df62",
"examples/p4/sync_client.pp": "ea6c5aea9d5acf7b39aa35e707848bab",
"examples/svn/checkout.pp": "9ef7a8fbd3a763fa3894efa864047023",
"examples/svn/server.pp": "94b26f6e50d5e411b33b1ded1bc2138a",
"lib/facter/vcsrepo_svn_ver.rb": "8f5209cf9afdfb5f56f44a1aa64054c3",
"lib/puppet/provider/vcsrepo/bzr.rb": "84406aa49dab4568c4b921f19e18ef09",
"lib/puppet/provider/vcsrepo/cvs.rb": "d1120b8b82984f0a42d4700ecaed7142",
"lib/puppet/provider/vcsrepo/dummy.rb": "4f4735047e53b95ee8562aae279a41d3",
"lib/puppet/provider/vcsrepo/git.rb": "ae2ffd4d9807926ca38e401410748301",
"lib/puppet/provider/vcsrepo/hg.rb": "cafa00c310fbcd8470c125a87f9dde1f",
"lib/puppet/provider/vcsrepo/p4.rb": "0fae3e6f0f13417d0fc8b21bc1bca706",
"lib/puppet/provider/vcsrepo/svn.rb": "bc929437ad8d9de6bab860c104987a30",
"lib/puppet/provider/vcsrepo.rb": "6847be7631b6ed335162b60d6bb020d6",
"lib/puppet/type/vcsrepo.rb": "23062d1ecbaafc80b9a167ed41576adb",
"locales/config.yaml": "644492f79bbcb5e77371dc14f19f86dc",
"metadata.json": "fbdd3b00769a26caad94406c0a752b22",
"spec/acceptance/beaker/git/basic_auth/basic_auth_checkout_http.rb": "eaa8419eff123dd15e1485d2462a7ba6",
"spec/acceptance/beaker/git/basic_auth/basic_auth_checkout_https.rb": "b7cb6c4c1852302ff2b37838548d4f22",
"spec/acceptance/beaker/git/basic_auth/negative/basic_auth_checkout_git.rb": "c2319ac03e26887ad4487ea3b582bbcb",
"spec/acceptance/beaker/git/branch_checkout/branch_checkout_file.rb": "a90df84a864354f445b5fe449ab88e1a",
"spec/acceptance/beaker/git/branch_checkout/branch_checkout_file_path.rb": "3f08ea8dfa28e4183e8eae53cea738d8",
"spec/acceptance/beaker/git/branch_checkout/branch_checkout_git.rb": "4281e7577a042387f7b6126627c5cf8e",
"spec/acceptance/beaker/git/branch_checkout/branch_checkout_http.rb": "f93372914141c2c7955a2f7ebae217ff",
"spec/acceptance/beaker/git/branch_checkout/branch_checkout_https.rb": "aef3ebf1d6178de6c279cb87d7f55df1",
"spec/acceptance/beaker/git/branch_checkout/branch_checkout_scp.rb": "71ea6210e1539ea08c50d09323f772e8",
"spec/acceptance/beaker/git/branch_checkout/branch_checkout_ssh.rb": "fdba3d8a380030fa21272c12ad688e0b",
"spec/acceptance/beaker/git/branch_checkout/negative/branch_checkout_not_exists.rb": "4a4039969737bd25133a5534f0a1bc3a",
"spec/acceptance/beaker/git/clone/clone_file.rb": "c78e7e176f86e5ee6e24e4fcf8bc319f",
"spec/acceptance/beaker/git/clone/clone_file_path.rb": "1f599d4780927d61c9f814cbad8b46db",
"spec/acceptance/beaker/git/clone/clone_git.rb": "6273e28d6bc5a677c664b5ee82c04c65",
"spec/acceptance/beaker/git/clone/clone_http.rb": "5c8c16aeb9dea9d7ebfc53f67538242a",
"spec/acceptance/beaker/git/clone/clone_https.rb": "f4f78dea68b6200dcb2c51d22fc05fcb",
"spec/acceptance/beaker/git/clone/clone_over_different_exiting_repo_with_force.rb": "d8ae7f754060108776e425c0ea135d85",
"spec/acceptance/beaker/git/clone/clone_repo_with_excludes_in_repo.rb": "5b04f4cb8dfd08bab991c5291d5cd92b",
"spec/acceptance/beaker/git/clone/clone_repo_with_excludes_not_in_repo.rb": "229cf2cc88a97a5ccaa519d2f53ecd01",
"spec/acceptance/beaker/git/clone/clone_scp.rb": "58cdf39fcd490b20f2a74e1b4dd8f26e",
"spec/acceptance/beaker/git/clone/clone_ssh.rb": "23801f8fd433361ceb90871168d84a80",
"spec/acceptance/beaker/git/clone/negative/clone_over_different_exiting_repo.rb": "d01c5e41b0ce9e664304e00afbfd4556",
"spec/acceptance/beaker/git/clone/negative/clone_repo_with_exec_excludes.rb": "0427368f2a3f740fdd34fee934f53a8a",
"spec/acceptance/beaker/git/compression/compression_0_checkout.rb": "5236bd53cdd40dca7af1fe126f5f36f7",
"spec/acceptance/beaker/git/compression/compression_1_checkout.rb": "8ec157b00fed76cfc491780024995578",
"spec/acceptance/beaker/git/compression/compression_2_checkout.rb": "6c282b8e167e63ae1726f3045b7f99f6",
"spec/acceptance/beaker/git/compression/compression_3_checkout.rb": "43d97bcc3cd3a48e8c73d20e71c324bb",
"spec/acceptance/beaker/git/compression/compression_4_checkout.rb": "96a8cba3585d0dd2c20acae67dbded29",
"spec/acceptance/beaker/git/compression/compression_5_checkout.rb": "21f944494b0f7dc2a902dddc2fbd445e",
"spec/acceptance/beaker/git/compression/compression_6_checkout.rb": "5462705b42e95be9e5ee7e5af3c7c0c0",
"spec/acceptance/beaker/git/compression/negative/compression_7_checkout.rb": "ea61e9642d9f03c44f060914e784ad87",
"spec/acceptance/beaker/git/compression/negative/compression_alpha_checkout.rb": "5f02f2a55386a53ea8919d010a12e390",
"spec/acceptance/beaker/git/compression/negative/compression_eval_checkout.rb": "168f9801155a478e948827d74dfcfaad",
"spec/acceptance/beaker/git/compression/negative/compression_exec_checkout.rb": "57ec765fd1af56c4349f9244ef285cc7",
"spec/acceptance/beaker/git/compression/negative/compression_negative_checkout.rb": "5c90e119f86e6d53713e20d86ae4a71d",
"spec/acceptance/beaker/git/create/create_bare_repo_that_already_exists.rb": "6d91f95ae93f00b3aa0ea8dac1557eb4",
"spec/acceptance/beaker/git/create/create_repo_that_already_exists.rb": "3184a82fc03408b3fc8fd468f184d5f1",
"spec/acceptance/beaker/git/create/negative/create_bare_repo_specifying_revision.rb": "79a6b9d96c39cd68d5480fa543d336b1",
"spec/acceptance/beaker/git/group_checkout/group_checkout_file.rb": "f2e75ec350f2e10b187ec2c1725c5307",
"spec/acceptance/beaker/git/group_checkout/group_checkout_file_path.rb": "d8d70e543ce770dc1233f266f17df761",
"spec/acceptance/beaker/git/group_checkout/group_checkout_git.rb": "e8a44d9fb3a2a938b3ca72cc05301455",
"spec/acceptance/beaker/git/group_checkout/group_checkout_http.rb": "9b288fb24803120d31802e6ced58bdfb",
"spec/acceptance/beaker/git/group_checkout/group_checkout_https.rb": "f4b82e2207808939bf0af441773d0eb5",
"spec/acceptance/beaker/git/group_checkout/group_checkout_scp.rb": "f0c3159f4e4a4a6422b406688693200d",
"spec/acceptance/beaker/git/group_checkout/group_checkout_ssh.rb": "f081ac9386aacae08e502009d621666b",
"spec/acceptance/beaker/git/group_checkout/negative/group_checkout_file_non_existent_group.rb": "0b950310690d479607a18c72bd4e73fc",
"spec/acceptance/beaker/git/revision_checkout/negative/revision_checkout_not_exists.rb": "4a797b38219cfbc01025d8307c41cb70",
"spec/acceptance/beaker/git/revision_checkout/revision_checkout_file.rb": "c9e8dfad4c4d1b22d813eb918f679fd9",
"spec/acceptance/beaker/git/revision_checkout/revision_checkout_file_path.rb": "eb9feef20d2757dfa460e968b0923a79",
"spec/acceptance/beaker/git/revision_checkout/revision_checkout_git.rb": "a4a90ce2433032509947893340f786c0",
"spec/acceptance/beaker/git/revision_checkout/revision_checkout_http.rb": "fb0a32d1c5f350e3dad9494f411ac0bf",
"spec/acceptance/beaker/git/revision_checkout/revision_checkout_https.rb": "8530db58c5a1692d609d074f543b6b89",
"spec/acceptance/beaker/git/revision_checkout/revision_checkout_scp.rb": "df666f26828a100784f15a62e0c61c82",
"spec/acceptance/beaker/git/revision_checkout/revision_checkout_ssh.rb": "4adca01a2eb1668c7896876b6f32baf1",
"spec/acceptance/beaker/git/shallow_clone/negative/shallow_clone_exec_depth.rb": "ff73d9c33f9a3f07ffb4ce176534af0d",
"spec/acceptance/beaker/git/shallow_clone/negative/shallow_clone_file_path.rb": "09ea9d79a74210a982c2e6854208a7b8",
"spec/acceptance/beaker/git/shallow_clone/negative/shallow_clone_http.rb": "8a3ab8bae36e8bde4f160e1fb2191912",
"spec/acceptance/beaker/git/shallow_clone/negative/shallow_clone_negative_depth.rb": "de8a77d5932965a835654524aea483f3",
"spec/acceptance/beaker/git/shallow_clone/negative/shallow_clone_overflow_depth.rb": "22e9b16579fe60030eee2b132d413b01",
"spec/acceptance/beaker/git/shallow_clone/shallow_clone_file.rb": "8b9636398a48b0c22e10cd40e7fdb8e2",
"spec/acceptance/beaker/git/shallow_clone/shallow_clone_git.rb": "c67049334bb0ef008d825f9eb6f47d92",
"spec/acceptance/beaker/git/shallow_clone/shallow_clone_https.rb": "647f5d426b7f42e1b24addf74aa4fc17",
"spec/acceptance/beaker/git/shallow_clone/shallow_clone_scp.rb": "9b95f36fea77397f8b4de154590b39c7",
"spec/acceptance/beaker/git/shallow_clone/shallow_clone_ssh.rb": "9b8e07b2555399d905d7a9eb14e62a2a",
"spec/acceptance/beaker/git/shallow_clone/shallow_clone_zero_depth.rb": "4cb6ced685b73b9aa21a7d2379918be8",
"spec/acceptance/beaker/git/tag_checkout/negative/tag_checkout_not_exists.rb": "4e0a1e818ef2293264cdfdd297f7d6dd",
"spec/acceptance/beaker/git/tag_checkout/tag_checkout_file.rb": "700ffaaf392ebb4088e462fb56828cad",
"spec/acceptance/beaker/git/tag_checkout/tag_checkout_file_path.rb": "208a30a54bd6bb8ae97d5e93fab03dc9",
"spec/acceptance/beaker/git/tag_checkout/tag_checkout_git.rb": "63d5b3f6311a2cc599c2aab6eba8b2bd",
"spec/acceptance/beaker/git/tag_checkout/tag_checkout_http.rb": "227c1314a2505bfb2b0c06d5ebfd23c3",
"spec/acceptance/beaker/git/tag_checkout/tag_checkout_https.rb": "933d84a7d785beae101da3a0d0cea644",
"spec/acceptance/beaker/git/tag_checkout/tag_checkout_scp.rb": "cc4c4ca339c528a7ee4462b5fa65eb4e",
"spec/acceptance/beaker/git/tag_checkout/tag_checkout_ssh.rb": "b07af48689c609df8adc1d4c9716405c",
"spec/acceptance/beaker/git/user_checkout/negative/user_checkout_file_non_existent_user.rb": "fad8e56f14d27105604f1f047bebcdf3",
"spec/acceptance/beaker/git/user_checkout/user_checkout_file.rb": "a083b3b630bda231b0af38af2f63b3c1",
"spec/acceptance/beaker/git/user_checkout/user_checkout_file_path.rb": "7a2825c0c8847521e5ab5b5867287ce2",
"spec/acceptance/beaker/git/user_checkout/user_checkout_git.rb": "4e987c30e9904722ab832c7d9f44ca44",
"spec/acceptance/beaker/git/user_checkout/user_checkout_http.rb": "f441c4c1e5ab019f068abacf6792b5cb",
"spec/acceptance/beaker/git/user_checkout/user_checkout_https.rb": "a24d41af6331bdb7108bf5211b8aa9f7",
"spec/acceptance/beaker/git/user_checkout/user_checkout_scp.rb": "ea2719ca08404d568570f2c3f6a049dc",
"spec/acceptance/beaker/git/user_checkout/user_checkout_ssh.rb": "6da26ed472baadce407ecfab47cadc0c",
"spec/acceptance/beaker_helper.rb": "400892d8f5c6b65846221cca26c15627",
"spec/acceptance/clone_repo_spec.rb": "f29da7ec7ea58788b030fb71af6e5ec5",
"spec/acceptance/create_repo_spec.rb": "a378660027d51129ab69709910c6727f",
"spec/acceptance/files/create_git_repo.sh": "7cf4087d6e850d439364826566e506ea",
"spec/acceptance/files/server.crt": "1ec3a38a53076275c8805c706c3e6249",
"spec/acceptance/files/server.key": "7c946c812b5b0d1bc60b470ffb61ee8d",
"spec/acceptance/modules_1596_spec.rb": "b5c6905859527a5c449a9a0ec45cf9de",
"spec/acceptance/modules_1800_spec.rb": "a9375fe802a5e2ef0713fbc1f623a186",
"spec/acceptance/modules_2326_spec.rb": "a895aca5234ccc92329e3f2fc4d4825f",
"spec/acceptance/modules_660_spec.rb": "8082e3f15301f4d26e8b4f82f57b1da2",
"spec/acceptance/modules_753_spec.rb": "5bc1a81386b20a2bc0db9189a141e975",
"spec/acceptance/nodesets/centos-7-x64.yml": "a713f3abd3657f0ae2878829badd23cd",
"spec/acceptance/nodesets/debian-8-x64.yml": "d2d2977900989f30086ad251a14a1f39",
"spec/acceptance/nodesets/default.yml": "b42da5a1ea0c964567ba7495574b8808",
"spec/acceptance/nodesets/docker/centos-7.yml": "8a3892807bdd62306ae4774f41ba11ae",
"spec/acceptance/nodesets/docker/debian-8.yml": "ac8e871d1068c96de5e85a89daaec6df",
"spec/acceptance/nodesets/docker/ubuntu-14.04.yml": "dc42ee922a96908d85b8f0f08203ce58",
"spec/acceptance/remove_repo_spec.rb": "1f3ebe0398e9a1b71e12f893b4a51c36",
"spec/acceptance/remove_repo_spec_noop.rb": "40b3b715cc7ed94e43c0109d8ac187e4",
"spec/acceptance/svn_paths_spec.rb": "1daebb0aa77f0a73157c7937531bd84c",
"spec/acceptance/svn_spec.rb": "9dddc62833c9362b262fbe7e5b29f006",
"spec/fixtures/bzr_version_info.txt": "5edb13429faf2f0b9964b4326ef49a65",
"spec/fixtures/git_branch_a.txt": "2371229e7c1706c5ab8f90f0cd57230f",
"spec/fixtures/git_branch_feature_bar.txt": "70903a4dc56f7300fbaa54c295b52c4f",
"spec/fixtures/git_branch_none.txt": "acaa61de6a7f0f5ca39b763799dcb9a6",
"spec/fixtures/hg_parents.txt": "efc28a1bd3f1ce7fb4481f76feed3f6e",
"spec/fixtures/hg_tags.txt": "8383048b15adb3d58a92ea0c8b887537",
"spec/fixtures/svn_info.txt": "978db25720a098e5de48388fe600c062",
"spec/spec_helper.rb": "ffb7ae05597bd18f74611afa37a88a0d",
"spec/spec_helper_acceptance.rb": "8679421651e1ecc9071c6175cd8080fc",
"spec/spec_helper_local.rb": "2dfe82e718310f9738849350e131f893",
"spec/support/filesystem_helpers.rb": "eb2a8eb3769865004c84e971ccb1396c",
"spec/support/fixture_helpers.rb": "61781d99ea201e9da6d23c64a25cc285",
"spec/unit/facter/vcsrepo_svn_ver_spec.rb": "2c48081f1564227e173550571e416bbb",
"spec/unit/puppet/provider/vcsrepo/bzr_spec.rb": "0922ef1b41b05adc7cb971aff939b007",
"spec/unit/puppet/provider/vcsrepo/cvs_spec.rb": "504d7250183d6ba38fcc371ea6e13142",
"spec/unit/puppet/provider/vcsrepo/git_spec.rb": "e87f744e5c5628831fde13ae5477c666",
"spec/unit/puppet/provider/vcsrepo/hg_spec.rb": "8dd938d4217c1dfdcb0084c4a5779c9b",
"spec/unit/puppet/provider/vcsrepo/p4_spec.rb": "3b8e73e5e1d9738d83de76914c9da640",
"spec/unit/puppet/provider/vcsrepo/svn_spec.rb": "1ad63a02d7b7e05f300cb49bb705817a",
"spec/unit/puppet/type/README.markdown": "de26a7643813abd6c2e7e28071b1ef94",
"spec/unit/puppet/type/vcsrepo_spec.rb": "6a36f6146dde240294cd54934296f0b5"
}
\ No newline at end of file
vcsrepo { '/tmp/vcstest-bzr-branch':
ensure => present,
provider => bzr,
source => 'lp:do',
revision => '1312',
}
vcsrepo { '/tmp/vcstest-bzr-init':
ensure => present,
provider => bzr,
}
vcsrepo { '/tmp/vcstest-cvs-repo':
ensure => present,
provider => cvs,
}
vcsrepo { '/tmp/vcstest-cvs-workspace-local':
ensure => present,
provider => cvs,
source => '/tmp/vcstest-cvs-repo',
require => Vcsrepo['/tmp/vcstest-cvs-repo'],
}
vcsrepo { '/tmp/vcstest-cvs-workspace-remote':
ensure => present,
provider => cvs,
source => ':pserver:anonymous@cvs.sv.gnu.org:/sources/leetcvrt',
}
vcsrepo { '/tmp/vcstest-git-bare':
ensure => bare,
provider => git,
}
vcsrepo { '/tmp/vcstest-git-clone':
ensure => present,
provider => git,
source => 'git://github.com/bruce/rtex.git',
}
vcsrepo { '/tmp/git':
ensure => 'present',
provider => 'git',
source => 'https://github.com/git/git.git',
branch => 'v2.2.0',
depth => 1,
}
vcsrepo { '/tmp/vcstest-git-wc':
ensure => present,
provider => git,
}
vcsrepo { '/tmp/vcstest-hg-clone':
ensure => present,
provider => hg,
source => 'http://hg.basho.com/riak',
revision => 'riak-0.5.3',
}
vcsrepo { '/path/to/repo':
ensure => latest,
provider => 'hg',
source => 'http://hg.example.com/myrepo',
basic_auth_username => 'hgusername',
basic_auth_password => 'hgpassword',
}
vcsrepo { '/tmp/vcstest-hg-init':
ensure => present,
provider => hg,
}
vcsrepo { '/tmp/vcstest/p4_client_root':
ensure => present,
provider => 'p4',
}
vcsrepo { '/tmp/vcstest/p4_client_root':
ensure => absent,
provider => 'p4',
}
vcsrepo { '/tmp/vcstest/p4_client_root':
ensure => latest,
provider => 'p4',
source => '//depot/...',
}
vcsrepo { '/tmp/vcstest/p4_client_root':
ensure => present,
provider => 'p4',
source => '//depot/...',
revision => '30',
}
vcsrepo { '/tmp/vcstest-svn-checkout':
ensure => present,
provider => svn,
source => 'http://svn.edgewall.org/repos/babel/trunk',
}
vcsrepo { '/tmp/vcstest-svn-server':
ensure => present,
provider => svn,
}
Facter.add(:vcsrepo_svn_ver) do
setcode do
begin
version = Facter::Core::Execution.execute('svn --version --quiet')
if Gem::Version.new(version) > Gem::Version.new('0.0.1')
version
else
''
end
rescue
''
end
end
end
\ No newline at end of file
require 'tmpdir'
require 'digest/md5'
require 'fileutils'
# Abstract
class Puppet::Provider::Vcsrepo < Puppet::Provider
def check_force
if path_exists? and not path_empty?
if @resource.value(:force)
notice "Removing %s to replace with desired repository." % @resource.value(:path)
destroy
else
raise Puppet::Error, "Path %s exists and is not the desired repository." % @resource.value(:path)
end
end
end
private
def set_ownership
owner = @resource.value(:owner) || nil
group = @resource.value(:group) || nil
FileUtils.chown_R(owner, group, @resource.value(:path))
end
def path_exists?
File.directory?(@resource.value(:path))
end
def path_empty?
# Path is empty if the only entries are '.' and '..'
d = Dir.new(@resource.value(:path))
d.read # should return '.'
d.read # should return '..'
d.read.nil?
end
# Note: We don't rely on Dir.chdir's behavior of automatically returning the
# value of the last statement -- for easier stubbing.
def at_path(&block) #:nodoc:
value = nil
Dir.chdir(@resource.value(:path)) do
value = yield
end
value
end
def tempdir
@tempdir ||= File.join(Dir.tmpdir, 'vcsrepo-' + Digest::MD5.hexdigest(@resource.value(:path)))
end
end
require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:bzr, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Bazaar repositories"
commands :bzr => 'bzr'
has_features :reference_tracking
def create
check_force
if !@resource.value(:source)
create_repository(@resource.value(:path))
else
clone_repository(@resource.value(:revision))
end
end
def working_copy_exists?
return false if not File.directory?(@resource.value(:path))
begin
bzr('status', @resource.value(:path))
return true
rescue Puppet::ExecutionFailure
return false
end
end
def exists?
working_copy_exists?
end
def destroy
FileUtils.rm_rf(@resource.value(:path))
end
def revision
at_path do
current_revid = bzr('version-info')[/^revision-id:\s+(\S+)/, 1]
desired = @resource.value(:revision)
begin
desired_revid = bzr('revision-info', desired).strip.split(/\s+/).last
rescue Puppet::ExecutionFailure
# Possible revid available during update (but definitely not current)
desired_revid = nil
end
if current_revid == desired_revid
desired
else
current_revid
end
end
end
def revision=(desired)
at_path do
begin
bzr('update', '-r', desired)
rescue Puppet::ExecutionFailure
bzr('update', '-r', desired, ':parent')
end
end
update_owner
end
def source
at_path do
bzr('info')[/^\s+parent branch:\s+(\S+?)$/m, 1]
end
end
def source=(desired)
create # recreate
end
def latest
at_path do
bzr('version-info', ':parent')[/^revision-id:\s+(\S+)/, 1]
end
end
def latest?
at_path do
return self.revision == self.latest
end
end
private
def create_repository(path)
bzr('init', path)
update_owner
end
def clone_repository(revision)
args = ['branch']
if revision
args.push('-r', revision)
end
args.push(@resource.value(:source),
@resource.value(:path))
bzr(*args)
update_owner
end
def update_owner
if @resource.value(:owner) or @resource.value(:group)
set_ownership
end
end
end
require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports CVS repositories/workspaces"
commands :cvs => 'cvs'
has_features :gzip_compression, :reference_tracking, :modules, :cvs_rsh, :user
def create
check_force
if !@resource.value(:source)
create_repository(@resource.value(:path))
else
checkout_repository
end
update_owner
end
def exists?
working_copy_exists?
end
def working_copy_exists?
if @resource.value(:source)
directory = File.join(@resource.value(:path), 'CVS')
return false if not File.directory?(directory)
begin
at_path { runcvs('-nqd', @resource.value(:path), 'status', '-l') }
return true
rescue Puppet::ExecutionFailure
return false
end
else
directory = File.join(@resource.value(:path), 'CVSROOT')
return false if not File.directory?(directory)
config = File.join(@resource.value(:path), 'CVSROOT', 'config,v')
return false if not File.exists?(config)
return true
end
end
def destroy
FileUtils.rm_rf(@resource.value(:path))
end
def latest?
Puppet.debug "Checking for updates because 'ensure => latest'"
at_path do
# We cannot use -P to prune empty dirs, otherwise
# CVS would report those as "missing", regardless
# if they have contents or updates.
is_current = (runcvs('-nq', 'update', '-d').strip == "")
if (!is_current) then Puppet.debug "There are updates available on the checkout's current branch/tag." end
return is_current
end
end
def latest
# CVS does not have a conecpt like commit-IDs or change
# sets, so we can only have the current branch name (or the
# requested one, if that differs) as the "latest" revision.
should = @resource.value(:revision)
current = self.revision
return should != current ? should : current
end
def revision
if !@rev
if File.exist?(tag_file)
contents = File.read(tag_file).strip
# Note: Doesn't differentiate between N and T entries
@rev = contents[1..-1]
else
@rev = 'HEAD'
end
Puppet.debug "Checkout is on branch/tag '#{@rev}'"
end
return @rev
end
def revision=(desired)
at_path do
runcvs('update', '-dr', desired, '.')
update_owner
@rev = desired
end
end
def source
File.read(File.join(@resource.value(:path), 'CVS', 'Root')).chomp
end
def source=(desired)
create # recreate
end
def module
File.read(File.join(@resource.value(:path), 'CVS', 'Repository')).chomp
end
def module=(desired)
create # recreate
end
private
def tag_file
File.join(@resource.value(:path), 'CVS', 'Tag')
end
def checkout_repository
dirname, basename = File.split(@resource.value(:path))
Dir.chdir(dirname) do
args = ['-d', @resource.value(:source)]
if @resource.value(:compression)
args.push('-z', @resource.value(:compression))
end
args.push('checkout')
if @resource.value(:revision)
args.push('-r', @resource.value(:revision))
end
args.push('-d', basename, module_name)
runcvs(*args)
end
end
# If no module is provided, use '.', the root of the repo
def module_name
@resource.value(:module) or '.'
end
def create_repository(path)
runcvs('-d', path, 'init')
end
def update_owner
if @resource.value(:owner) or @resource.value(:group)
set_ownership
end
end
def runcvs(*args)
if @resource.value(:cvs_rsh)
Puppet.debug "Using CVS_RSH = " + @resource.value(:cvs_rsh)
e = { :CVS_RSH => @resource.value(:cvs_rsh) }
else
e = {}
end
if @resource.value(:user) and @resource.value(:user) != Facter['id'].value
Puppet.debug "Running as user " + @resource.value(:user)
Puppet::Util::Execution.execute([:cvs, *args], :uid => @resource.value(:user), :custom_environment => e, :combine => true, :failonfail => true)
else
Puppet::Util::Execution.execute([:cvs, *args], :custom_environment => e, :combine => true, :failonfail => true)
end
end
end
require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:dummy, :parent => Puppet::Provider::Vcsrepo) do
desc "Dummy default provider"
defaultfor :feature => :posix
defaultfor :operatingsystem => :windows
def working_copy_exists?
providers = @resource.class.providers.map{|x| x.to_s}.sort.reject{|x| x == "dummy"}.join(", ") rescue "none"
raise("vcsrepo resource must have a provider, available: #{providers}")
end
end
require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Git repositories"
has_command(:git, 'git') do
environment({ 'HOME' => ENV['HOME'] })
end
has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes,
:user, :depth, :branch, :submodules
def create
check_force
if @resource.value(:revision) and ensure_bare_or_mirror?
fail("Cannot set a revision (#{@resource.value(:revision)}) on a bare repository")
end
if !@resource.value(:source)
if @resource.value(:ensure) == :mirror
fail("Cannot init repository with mirror option, try bare instead")
end
init_repository
else
clone_repository(default_url, @resource.value(:path))
update_remotes(@resource.value(:source))
set_mirror if @resource.value(:ensure) == :mirror and @resource.value(:source).is_a?(Hash)
if @resource.value(:revision)
checkout
end
if !ensure_bare_or_mirror? && @resource.value(:submodules) == :true
update_submodules
end
end
update_owner_and_excludes
end
def destroy
FileUtils.rm_rf(@resource.value(:path))
end
# Checks to see if the current revision is equal to the revision on the
# remote (whether on a branch, tag, or reference)
#
# @return [Boolean] Returns true if the repo is on the latest revision
def latest?
return revision == latest_revision
end
# Just gives the `should` value that we should be setting the repo to if
# latest? returns false
#
# @return [String] Returns the target sha/tag/branch
def latest
if not @resource.value(:revision) and branch = on_branch?
return branch
else
return @resource.value(:revision)
end
end
# Get the current revision of the repo (tag/branch/sha)
#
# @return [String] Returns the branch/tag if the current sha matches the
# remote; otherwise returns the current sha.
def revision
#HEAD is the default, but lets just be explicit here.
get_revision('HEAD')
end
# Is passed the desired reference, whether a tag, rev, or branch. Should
# handle transitions from a rev/branch/tag to a rev/branch/tag. Detached
# heads should be treated like bare revisions.
#
# @param [String] desired The desired revision to which the repo should be
# set.
def revision=(desired)
#just checkout tags and shas; fetch has already happened so they should be updated.
checkout(desired)
#branches require more work.
if local_branch_revision?(desired)
#reset instead of pull to avoid merge conflicts. assuming remote is
#updated and authoritative.
#TODO might be worthwhile to have an allow_local_changes param to decide
#whether to reset or pull when we're ensuring latest.
if @resource.value(:source)
at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") }
else
at_path { git_with_identity('reset', '--hard', "#{desired}") }
end
end
#TODO Would this ever reach here if it is bare?
if !ensure_bare_or_mirror? && @resource.value(:submodules) == :true
update_submodules
end
update_owner_and_excludes
end
def bare_exists?
bare_git_config_exists? && !working_copy_exists?
end
def ensure_bare_or_mirror?
[:bare, :mirror].include? @resource.value(:ensure)
end
# If :source is set to a hash (for supporting multiple remotes),
# we search for the URL for :remote. If it doesn't exist,
# we throw an error. If :source is just a string, we use that
# value for the default URL.
def default_url
if @resource.value(:source).is_a?(Hash)
if @resource.value(:source).has_key?(@resource.value(:remote))
@resource.value(:source)[@resource.value(:remote)]
else
fail("You must specify the URL for remote '#{@resource.value(:remote)}' in the :source hash")
end
else
@resource.value(:source)
end
end
def working_copy_exists?
# NOTE: a change in the `default_url` will tell the type that this repo
# doesn't exist (i.e. it triggers a "not the same repository" error).
# Thus, changing the `source` property from a string to a string (which
# changes the origin url), or if the @resource.value(:remote)'s url is
# changed, the provider will require force.
return false if not File.directory?(File.join(@resource.value(:path), '.git'))
at_path do
if @resource.value(:source)
begin
return git('config', '--get', "remote.#{@resource.value(:remote)}.url").chomp == default_url
rescue Puppet::ExecutionFailure
return false
end
else
begin
git('status')
return true
rescue Puppet::ExecutionFailure
return false
end
end
end
end
def exists?
working_copy_exists? || bare_exists?
end
def remove_remote(remote)
at_path do
git_with_identity('remote', 'remove', remote)
end
end
def update_remote_url(remote_name, remote_url)
current = git_with_identity('config', '-l')
unless remote_url.nil?
# Check if remote exists at all, regardless of URL.
# If remote doesn't exist, add it
if not current.include? "remote.#{remote_name}.url"
git_with_identity('remote','add', remote_name, remote_url)
return true
# If remote exists, but URL doesn't match, update URL
elsif not current.include? "remote.#{remote_name}.url=#{remote_url}"
git_with_identity('remote','set-url', remote_name, remote_url)
return true
else
return false
end
end
end
def source
at_path do
remotes = git('remote').split("\n")
if remotes.size == 1
return git('config', '--get', "remote.#{remotes[0]}.url").chomp
else
Hash[remotes.map { |remote|
[remote, git('config', '--get', "remote.#{remote}.url").chomp]
}]
end
end
end
def source=(desired)
# NOTE: a change in the `default_url` will tell the type that this repo
# doesn't exist (i.e. it triggers a "not the same repository" error).
# Thus, a change from a string to a string (which changes the origin url),
# or if the @resource.value(:remote)'s url is changed, the provider will
# require force, without ever reaching this block. The recreation is
# duplicated here in case something changes in the `working_copy_exists?`
# logic.
current = source
if current.is_a?(Hash)
current.keys.each { |remote|
remove_remote(remote) if desired.is_a?(Hash) and not desired.has_key?(remote)
remove_remote(remote) if desired.is_a?(String) and remote != @resource.value(:remote)
}
end
if current.is_a?(String) and desired.is_a?(String)
create # recreate
else
update_remotes(desired)
end
end
def update_remotes(remotes)
do_update = false
# If supplied source is a hash of remote name and remote url pairs, then
# we loop around the hash. Otherwise, we assume single url specified
# in source property
if remotes.is_a?(Hash)
remotes.keys.sort.each do |remote_name|
remote_url = remotes[remote_name]
at_path { do_update |= update_remote_url(remote_name, remote_url) }
end
else
at_path { do_update |= update_remote_url(@resource.value(:remote), remotes) }
end
# If at least one remote was added or updated, then we must
# call the 'git remote update' command
if do_update == true
at_path { git_with_identity('remote','update') }
end
end
def update_references
at_path do
git_with_identity('fetch', @resource.value(:remote))
git_with_identity('fetch', '--tags', @resource.value(:remote))
update_owner_and_excludes
end
end
# Convert working copy to bare
#
# Moves:
# <path>/.git
# to:
# <path>/
# and sets core.bare=true, and calls `set_mirror` if appropriate
def convert_working_copy_to_bare
return unless working_copy_exists? and not bare_exists?
notice "Converting working copy repository to bare repository"
FileUtils.mv(File.join(@resource.value(:path), '.git'), tempdir)
FileUtils.rm_rf(@resource.value(:path))
FileUtils.mv(tempdir, @resource.value(:path))
at_path do
git('config', '--local', '--bool', 'core.bare', 'true')
if @resource.value(:ensure) == :mirror
if !@resource.value(:source)
fail('Cannot have empty repository that is also a mirror.')
else
set_mirror
end
end
end
end
# Convert bare to working copy
#
# Moves:
# <path>/
# to:
# <path>/.git
# and sets core.bare=false, and calls `set_no_mirror` if appropriate
def convert_bare_to_working_copy
notice "Converting bare repository to working copy repository"
FileUtils.mv(@resource.value(:path), tempdir)
FileUtils.mkdir(@resource.value(:path))
FileUtils.mv(tempdir, File.join(@resource.value(:path), '.git'))
if has_commits?
at_path do
git('config', '--local', '--bool', 'core.bare', 'false')
reset('HEAD')
git_with_identity('checkout', '--force')
update_owner_and_excludes
end
end
set_no_mirror if mirror?
end
def mirror?
at_path do
begin
git('config', '--get-regexp', 'remote\..*\.mirror')
return true
rescue Puppet::ExecutionFailure
return false
end
end
end
def set_mirror
at_path do
if @resource.value(:source).is_a?(String)
git('config', "remote.#{@resource.value(:remote)}.mirror", 'true')
else
@resource.value(:source).keys.each { |remote|
git('config', "remote.#{remote}.mirror", 'true')
}
end
end
end
def set_no_mirror
at_path do
if @resource.value(:source).is_a?(String)
begin
git('config', '--unset', "remote.#{@resource.value(:remote)}.mirror")
rescue Puppet::ExecutionFailure
end
else
@resource.value(:source).keys.each { |remote|
begin
git('config', '--unset', "remote.#{remote}.mirror")
rescue Puppet::ExecutionFailure
end
}
end
end
end
private
# @!visibility private
def bare_git_config_exists?
return false if not File.exist?(File.join(@resource.value(:path), 'config'))
begin
at_path { git('config', '--list', '--file', 'config') }
return true
rescue Puppet::ExecutionFailure
return false
end
end
# @!visibility private
def clone_repository(source, path)
args = ['clone']
if @resource.value(:depth) and @resource.value(:depth).to_i > 0
args.push('--depth', @resource.value(:depth).to_s)
if @resource.value(:revision)
args.push('--branch', @resource.value(:revision).to_s)
end
end
if @resource.value(:branch)
args.push('--branch', @resource.value(:branch).to_s)
end
case @resource.value(:ensure)
when :bare then args << '--bare'
when :mirror then args << '--mirror'
end
if @resource.value(:remote) != 'origin'
args.push('--origin', @resource.value(:remote))
end
if !working_copy_exists?
args.push(source, path)
Dir.chdir("/") do
git_with_identity(*args)
end
else
notice "Repo has already been cloned"
end
end
# @!visibility private
def init_repository
if @resource.value(:ensure) == :bare && working_copy_exists?
convert_working_copy_to_bare
elsif @resource.value(:ensure) == :present && bare_exists?
convert_bare_to_working_copy
else
# normal init
FileUtils.mkdir(@resource.value(:path))
FileUtils.chown(@resource.value(:user), nil, @resource.value(:path)) if @resource.value(:user)
args = ['init']
if @resource.value(:ensure) == :bare
args << '--bare'
end
at_path do
git_with_identity(*args)
end
end
end
# @!visibility private
def has_commits?
at_path do
begin
commits = git_with_identity('rev-list', '--all', '--count').to_i
rescue Puppet::ExecutionFailure
commits = 0
end
return commits > 0
end
end
# Will checkout a rev/branch/tag using the locally cached versions. Does not
# handle upstream branch changes
# @!visibility private
def checkout(revision = @resource.value(:revision))
if !local_branch_revision?(revision) && remote_branch_revision?(revision)
#non-locally existant branches (perhaps switching to a branch that has never been checked out)
at_path { git_with_identity('checkout', '--force', '-b', revision, '--track', "#{@resource.value(:remote)}/#{revision}") }
else
#tags, locally existant branches (perhaps outdated), and shas
at_path { git_with_identity('checkout', '--force', revision) }
end
end
# @!visibility private
def reset(desired)
at_path do
git_with_identity('reset', '--hard', desired)
end
end
# @!visibility private
def update_submodules
at_path do
git_with_identity('submodule', 'update', '--init', '--recursive')
end
end
# Determins if the branch exists at the upstream but has not yet been locally committed
# @!visibility private
def remote_branch_revision?(revision = @resource.value(:revision))
# git < 1.6 returns '#{@resource.value(:remote)}/#{revision}'
# git 1.6+ returns 'remotes/#{@resource.value(:remote)}/#{revision}'
branch = at_path { branches.grep /(remotes\/)?#{@resource.value(:remote)}\/#{revision}$/ }
branch unless branch.empty?
end
# Determins if the branch is already cached locally
# @!visibility private
def local_branch_revision?(revision = @resource.value(:revision))
at_path { branches.include?(revision) }
end
# @!visibility private
def tag_revision?(revision = @resource.value(:revision))
at_path { tags.include?(revision) }
end
# @!visibility private
def branches
at_path { git_with_identity('branch', '-a') }.gsub('*', ' ').split(/\n/).map { |line| line.strip }
end
# git < 2.4 returns 'detached from'
# git 2.4+ returns 'HEAD detached at'
# @!visibility private
def on_branch?
at_path {
matches = git_with_identity('branch', '-a').match /\*\s+(.*)/
matches[1] unless matches[1].match /(\(detached from|\(HEAD detached at|\(no branch)/
}
end
# @!visibility private
def tags
at_path { git_with_identity('tag', '-l') }.split(/\n/).map { |line| line.strip }
end
# @!visibility private
def set_excludes
# Excludes may be an Array or a String.
at_path do
open('.git/info/exclude', 'w') do |f|
if @resource.value(:excludes).respond_to?(:each)
@resource.value(:excludes).each { |ex| f.puts ex }
else
f.puts @resource.value(:excludes)
end
end
end
end
# Finds the latest revision or sha of the current branch if on a branch, or
# of HEAD otherwise.
# @note Calls create which can forcibly destroy and re-clone the repo if
# force => true
# @see get_revision
#
# @!visibility private
# @return [String] Returns the output of get_revision
def latest_revision
#TODO Why is create called here anyway?
create if @resource.value(:force) && working_copy_exists?
create if !working_copy_exists?
if branch = on_branch?
return get_revision("#{@resource.value(:remote)}/#{branch}")
else
return get_revision
end
end
# Returns the current revision given if the revision is a tag or branch and
# matches the current sha. If the current sha does not match the sha of a tag
# or branch, then it will just return the sha (ie, is not in sync)
#
# @!visibility private
#
# @param [String] rev The revision of which to check if it is current
# @return [String] Returns the tag/branch of the current repo if it's up to
# date; otherwise returns the sha of the requested revision.
def get_revision(rev = 'HEAD')
if @resource.value(:source)
update_references
else
status = at_path { git_with_identity('status')}
is_it_new = status =~ /Initial commit/
if is_it_new
status =~ /On branch (.*)/
branch = $1
return branch
end
end
current = at_path { git_with_identity('rev-parse', rev).strip }
if @resource.value(:revision)
if tag_revision?
# git-rev-parse will give you the hash of the tag object itself rather
# than the commit it points to by default. Using tag^0 will return the
# actual commit.
canonical = at_path { git_with_identity('rev-parse', "#{@resource.value(:revision)}^0").strip }
elsif local_branch_revision?
canonical = at_path { git_with_identity('rev-parse', @resource.value(:revision)).strip }
elsif remote_branch_revision?
canonical = at_path { git_with_identity('rev-parse', "#{@resource.value(:remote)}/#{@resource.value(:revision)}").strip }
else
#look for a sha (could match invalid shas)
canonical = at_path { git_with_identity('rev-parse', '--revs-only', @resource.value(:revision)).strip }
end
fail("#{@resource.value(:revision)} is not a local or remote ref") if canonical.nil? or canonical.empty?
current = @resource.value(:revision) if current == canonical
end
return current
end
# @!visibility private
def update_owner_and_excludes
if @resource.value(:owner) or @resource.value(:group)
set_ownership
end
if @resource.value(:excludes)
set_excludes
end
end
# @!visibility private
def git_with_identity(*args)
if @resource.value(:identity)
Tempfile.open('git-helper', Puppet[:statedir]) do |f|
f.puts '#!/bin/sh'
f.puts 'SSH_AUTH_SOCKET='
f.puts 'export SSH_AUTH_SOCKET'
f.puts "exec ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -oConnectTimeout=120 -i #{@resource.value(:identity)} $*"
f.close
FileUtils.chmod(0755, f.path)
env_save = ENV['GIT_SSH']
ENV['GIT_SSH'] = f.path
ret = git(*args)
ENV['GIT_SSH'] = env_save
return ret
end
elsif @resource.value(:user) and @resource.value(:user) != Facter['id'].value
env = Etc.getpwnam(@resource.value(:user))
Puppet::Util::Execution.execute("git #{args.join(' ')}", :uid => @resource.value(:user), :failonfail => true, :custom_environment => {'HOME' => env['dir']}, :combine => true)
else
git(*args)
end
end
end
require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Mercurial repositories"
commands :hg => 'hg'
has_features :reference_tracking, :ssh_identity, :user, :basic_auth
def create
check_force
if !@resource.value(:source)
create_repository(@resource.value(:path))
else
clone_repository(@resource.value(:revision))
end
update_owner
end
def working_copy_exists?
return false if not File.directory?(@resource.value(:path))
begin
hg_wrapper('status', @resource.value(:path))
return true
rescue Puppet::ExecutionFailure
return false
end
end
def exists?
working_copy_exists?
end
def destroy
FileUtils.rm_rf(@resource.value(:path))
end
def latest?
at_path do
return self.revision == self.latest
end
end
def latest
at_path do
begin
hg_wrapper('incoming', '--branch', '.', '--newest-first', '--limit', '1', { :remote => true })[/^changeset:\s+(?:-?\d+):(\S+)/m, 1]
rescue Puppet::ExecutionFailure
# If there are no new changesets, return the current nodeid
self.revision
end
end
end
def revision
at_path do
current = hg_wrapper('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1]
desired = @resource.value(:revision)
if desired
# Return the tag name if it maps to the current nodeid
mapped = hg_wrapper('tags')[/^#{Regexp.quote(desired)}\s+\d+:(\S+)/m, 1]
if current == mapped
desired
else
current
end
else
current
end
end
end
def revision=(desired)
at_path do
begin
hg_wrapper('pull', { :remote => true })
rescue
end
begin
hg_wrapper('merge')
rescue Puppet::ExecutionFailure
# If there's nothing to merge, just skip
end
hg_wrapper('update', '--clean', '-r', desired)
end
update_owner
end
def source
at_path do
hg_wrapper('paths')[/^default = (.*)/, 1]
end
end
def source=(desired)
create # recreate
end
private
def create_repository(path)
hg_wrapper('init', path)
end
def clone_repository(revision)
args = ['clone']
if revision
args.push('-u', revision)
end
args.push(@resource.value(:source),
@resource.value(:path))
args.push({ :remote => true })
hg_wrapper(*args)
end
def update_owner
if @resource.value(:owner) or @resource.value(:group)
set_ownership
end
end
def hg_wrapper(*args)
options = { :remote => false }
if args.length > 0 and args[-1].is_a? Hash
options.merge!(args.pop)
end
if @resource.value(:basic_auth_username) && @resource.value(:basic_auth_password)
args += [
"--config", "\"auth.x.prefix=#{@resource.value(:source)}\"",
"--config", "\"auth.x.username=#{@resource.value(:basic_auth_username)}\"",
"--config", "\"auth.x.password=#{@resource.value(:basic_auth_password)}\"",
"--config", "\"auth.x.schemes=http https\""
]
end
if options[:remote] and @resource.value(:identity)
args += ["--ssh", "ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -i #{@resource.value(:identity)}"]
end
if @resource.value(:user) and @resource.value(:user) != Facter['id'].value
args.map! { |a| if a =~ /\s/ then "'#{a}'" else a end } # Adds quotes to arguments with whitespaces.
Puppet::Util::Execution.execute("hg #{args.join(' ')}", :uid => @resource.value(:user), :failonfail => true, :combine => true)
else
hg(*args)
end
end
end
require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Perforce depots"
has_features :filesystem_types, :reference_tracking, :p4config
def create
check_force
# create or update client
create_client(client_name)
# if source provided, sync client
source = @resource.value(:source)
if source
revision = @resource.value(:revision)
sync_client(source, revision)
end
update_owner
end
def working_copy_exists?
# Check if the server is there, or raise error
p4(['info'], {:marshal => false})
# Check if workspace is setup
args = ['where']
args.push(@resource.value(:path) + "/...")
hash = p4(args, {:raise => false})
return (hash['code'] != "error")
end
def exists?
working_copy_exists?
end
def destroy
args = ['client']
args.push('-d', '-f')
args.push(client_name)
p4(args)
FileUtils.rm_rf(@resource.value(:path))
end
def latest?
rev = self.revision
if rev
(rev >= self.latest)
else
true
end
end
def latest
args = ['changes']
args.push('-m1', @resource.value(:source))
hash = p4(args)
return hash['change'].to_i
end
def revision
args = ['cstat']
args.push(@resource.value(:source))
hash = p4(args, {:marshal => false})
hash = marshal_cstat(hash)
revision = 0
if hash && hash['code'] != 'error'
hash['data'].each do |c|
if c['status'] == 'have'
change = c['change'].to_i
revision = change if change > revision
end
end
end
return revision
end
def revision=(desired)
sync_client(@resource.value(:source), desired)
update_owner
end
def source
args = ['where']
args.push(@resource.value(:path) + "/...")
hash = p4(args, {:raise => false})
return hash['depotFile']
end
def source=(desired)
create # recreate
end
private
def update_owner
if @resource.value(:owner) or @resource.value(:group)
set_ownership
end
end
# Sync the client workspace files to head or specified revision.
# Params:
# +source+:: Depot path to sync
# +revision+:: Perforce change list to sync to (optional)
def sync_client(source, revision)
Puppet.debug "Syncing: #{source}"
args = ['sync']
if revision
args.push(source + "@#{revision}")
else
args.push(source)
end
p4(args)
end
# Returns the name of the Perforce client workspace
def client_name
p4config = @resource.value(:p4config)
# default (generated) client name
path = @resource.value(:path)
host = Facter.value('hostname')
default = "puppet-" + Digest::MD5.hexdigest(path + host)
# check config for client name
set_client = nil
if p4config && File.file?(p4config)
open(p4config) do |f|
m = f.grep(/^P4CLIENT=/).pop
p = /^P4CLIENT=(.*)$/
set_client = p.match(m)[1] if m
end
end
return set_client || ENV['P4CLIENT'] || default
end
# Create (or update) a client workspace spec.
# If a client name is not provided then a hash based on the path is used.
# Params:
# +client+:: Name of client workspace
# +path+:: The Root location of the Perforce client workspace
def create_client(client)
Puppet.debug "Creating client: #{client}"
# fetch client spec
hash = parse_client(client)
hash['Root'] = @resource.value(:path)
hash['Description'] = "Generated by Puppet VCSrepo"
# check is source is a Stream
source = @resource.value(:source)
if source
parts = source.split(/\//)
if parts && parts.length >= 4
source = "//" + parts[2] + "/" + parts[3]
streams = p4(['streams', source], {:raise => false})
if streams['code'] == "stat"
hash['Stream'] = streams['Stream']
notice "Streams" + streams['Stream'].inspect
end
end
end
# save client spec
save_client(hash)
end
# Fetches a client workspace spec from Perforce and returns a hash map representation.
# Params:
# +client+:: name of the client workspace
def parse_client(client)
args = ['client']
args.push('-o', client)
hash = p4(args)
return hash
end
# Saves the client workspace spec from the given hash
# Params:
# +hash+:: hash map of client spec
def save_client(hash)
spec = String.new
view = "\nView:\n"
hash.keys.sort.each do |k|
v = hash[k]
next if( k == "code" )
if(k.to_s =~ /View/ )
view += "\t#{v}\n"
else
spec += "#{k.to_s}: #{v.to_s}\n"
end
end
spec += view
args = ['client']
args.push('-i')
p4(args, {:input => spec, :marshal => false})
end
# Sets Perforce Configuration environment.
# P4CLIENT generated, but overwitten if defined in config.
def config
p4config = @resource.value(:p4config)
cfg = Hash.new
cfg.store 'P4CONFIG', p4config if p4config
cfg.store 'P4CLIENT', client_name
return cfg
end
def p4(args, options = {})
# Merge custom options with defaults
opts = {
:raise => true, # Raise errors
:marshal => true, # Marshal output
}.merge(options)
cmd = ['p4']
cmd.push '-R' if opts[:marshal]
cmd.push args
cmd_str = cmd.respond_to?(:join) ? cmd.join(' ') : cmd
Puppet.debug "environment: #{config}"
Puppet.debug "command: #{cmd_str}"
hash = Hash.new
Open3.popen3(config, cmd_str) do |i, o, e, t|
# Send input stream if provided
if(opts[:input])
Puppet.debug "input:\n" + opts[:input]
i.write opts[:input]
i.close
end
if(opts[:marshal])
hash = Marshal.load(o)
else
hash['data'] = o.read
end
# Raise errors, Perforce or Exec
if(opts[:raise] && !e.eof && t.value != 0)
raise Puppet::Error, "\nP4: #{e.read}"
end
if(opts[:raise] && hash['code'] == 'error' && t.value != 0)
raise Puppet::Error, "\nP4: #{hash['data']}"
end
end
Puppet.debug "hash: #{hash}\n"
return hash
end
# helper method as cstat does not Marshal
def marshal_cstat(hash)
data = hash['data']
code = 'error'
list = Array.new
change = Hash.new
data.each_line do |l|
p = /^\.\.\. (.*) (.*)$/
m = p.match(l)
if m
change[m[1]] = m[2]
if m[1] == 'status'
code = 'stat'
list.push change
change = Hash.new
end
end
end
hash = Hash.new
hash.store 'code', code
hash.store 'data', list
return hash
end
end
require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Subversion repositories"
commands :svn => 'svn',
:svnadmin => 'svnadmin',
:svnlook => 'svnlook'
has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration, :conflict, :depth,
:include_paths
def create
check_force
if !@resource.value(:source)
if @resource.value(:includes)
raise Puppet::Error, "Specifying include paths on a nonexistent repo."
end
create_repository(@resource.value(:path))
else
checkout_repository(@resource.value(:source),
@resource.value(:path),
@resource.value(:revision),
@resource.value(:depth))
end
if @resource.value(:includes)
validate_version
update_includes(@resource.value(:includes))
end
update_owner
end
def working_copy_exists?
return false if not File.directory?(@resource.value(:path))
if @resource.value(:source)
begin
svn('status', @resource.value(:path))
return true
rescue Puppet::ExecutionFailure
return false
end
else
begin
svnlook('uuid', @resource.value(:path))
return true
rescue Puppet::ExecutionFailure
return false
end
end
end
def exists?
working_copy_exists?
end
def destroy
FileUtils.rm_rf(@resource.value(:path))
end
def latest?
at_path do
(self.revision >= self.latest) and (@resource.value(:source) == self.source)
end
end
def buildargs
args = ['--non-interactive']
if @resource.value(:basic_auth_username) && @resource.value(:basic_auth_password)
args.push('--username', @resource.value(:basic_auth_username))
args.push('--password', @resource.value(:basic_auth_password))
args.push('--no-auth-cache')
end
if @resource.value(:configuration)
args.push('--config-dir', @resource.value(:configuration))
end
if @resource.value(:trust_server_cert) != :false
args.push('--trust-server-cert')
end
args
end
def latest
args = buildargs.push('info', '-r', 'HEAD')
at_path do
svn(*args)[/^Revision:\s+(\d+)/m, 1]
end
end
def source
args = buildargs.push('info')
at_path do
svn(*args)[/^URL:\s+(\S+)/m, 1]
end
end
def source=(desired)
args = buildargs.push('switch')
if @resource.value(:force)
args.push('--force')
end
if @resource.value(:revision)
args.push('-r', @resource.value(:revision))
end
if @resource.value(:conflict)
args.push('--accept', @resource.value(:conflict))
end
args.push(desired)
at_path do
svn(*args)
end
update_owner
end
def revision
args = buildargs.push('info')
at_path do
svn(*args)[/^Revision:\s+(\d+)/m, 1]
end
end
def revision=(desired)
args = if @resource.value(:source)
buildargs.push('switch', '-r', desired, @resource.value(:source))
else
buildargs.push('update', '-r', desired)
end
if @resource.value(:force)
args.push('--force')
end
if @resource.value(:conflict)
args.push('--accept', @resource.value(:conflict))
end
at_path do
svn(*args)
end
update_owner
end
def includes
return nil if Gem::Version.new(get_svn_client_version) < Gem::Version.new('1.6.0')
get_includes('.')
end
def includes=(desired)
validate_version
exists = includes
old_paths = exists - desired
new_paths = desired - exists
# Remove paths that are no longer specified
old_paths.each { |path| delete_include(path) }
update_includes(new_paths)
end
private
def get_includes(directory)
at_path do
args = buildargs.push('info', directory)
if svn(*args)[/^Depth:\s+(\w+)/m, 1] != 'empty'
return directory[2..-1].gsub(File::SEPARATOR, '/')
end
Dir.entries(directory).map { |entry|
next if entry == '.' or entry == '..' or entry == '.svn'
entry = File.join(directory, entry)
if File.directory?(entry)
get_includes(entry)
elsif File.file?(entry)
entry[2..-1].gsub(File::SEPARATOR, '/')
end
}.flatten.compact!
end
end
def delete_include(path)
at_path do
# svn version 1.6 has an incorrect implementation of the `exclude`
# parameter to `--set-depth`; it doesn't handle files, only
# directories. I know, I rolled my eyes, too.
svn_ver = get_svn_client_version
if Gem::Version.new(svn_ver) < Gem::Version.new('1.7.0') and not File.directory?(path)
# In the non-happy case, we delete the file, and check if the only
# thing left in that directory is the .svn folder. If that's the case,
# the loop below will take care of excluding the parent directory, and
# we're back to a happy case. But, if that's not the case, we need to
# fire off a warning telling the user the path can't be excluded.
Puppet.debug "Vcsrepo[#{@resource.name}]: Need to handle #{path} removal specially"
File.delete(path)
if Dir.entries(File.dirname(path)).sort != ['.', '..', '.svn']
Puppet.warning "Unable to exclude #{path} from Vcsrepo[#{@resource.name}]; update to subversion >= 1.7"
end
else
Puppet.debug "Vcsrepo[#{@resource.name}]: Can remove #{path} directly using svn"
args = buildargs.push('update', '--set-depth', 'exclude', path)
svn(*args)
end
# Keep walking up the parent directories of this include until we find
# a non-empty folder, excluding as we go.
while ((path = path.rpartition(File::SEPARATOR)[0]) != '') do
entries = Dir.entries(path).sort
break if entries != ['.', '..'] and entries != ['.', '..', '.svn']
args = buildargs.push('update', '--set-depth', 'exclude', path)
svn(*args)
end
end
end
def checkout_repository(source, path, revision, depth)
args = buildargs.push('checkout')
if revision
args.push('-r', revision)
end
if @resource.value(:includes)
# Make root checked out at empty depth to provide sparse directories
args.push('--depth', 'empty')
elsif depth
args.push('--depth', depth)
end
args.push(source, path)
svn(*args)
end
def create_repository(path)
args = ['create']
if @resource.value(:fstype)
args.push('--fs-type', @resource.value(:fstype))
end
args << path
svnadmin(*args)
end
def update_owner
if @resource.value(:owner) or @resource.value(:group)
set_ownership
end
end
def update_includes(paths)
at_path do
args = buildargs.push('update')
args.push('--depth', 'empty')
if @resource.value(:revision)
args.push('-r', @resource.value(:revision))
end
parents = paths.map { |path| File.dirname(path) }
parents = make_include_paths(parents)
args.push(*parents)
svn(*args)
args = buildargs.push('update')
if @resource.value(:revision)
args.push('-r', @resource.value(:revision))
end
if @resource.value(:depth)
args.push('--depth', @resource.value(:depth))
end
args.push(*paths)
svn(*args)
end
end
def make_include_paths(includes)
includes.map { |inc|
prefix = nil
inc.split("/").map { |path|
prefix = [prefix, path].compact.join('/')
}
}.flatten
end
def get_svn_client_version
return Facter.value('vcsrepo_svn_ver').dup
end
def validate_version
svn_ver = get_svn_client_version
if Gem::Version.new(svn_ver) < Gem::Version.new('1.6.0')
raise "Includes option is not available for SVN versions < 1.6. Version installed: #{svn_ver}"
end
end
end
require 'pathname'
require 'puppet/parameter/boolean'
Puppet::Type.newtype(:vcsrepo) do
desc "A local version control repository"
feature :gzip_compression,
"The provider supports explicit GZip compression levels"
feature :basic_auth,
"The provider supports HTTP Basic Authentication"
feature :bare_repositories,
"The provider differentiates between bare repositories
and those with working copies",
:methods => [:bare_exists?, :working_copy_exists?]
feature :filesystem_types,
"The provider supports different filesystem types"
feature :reference_tracking,
"The provider supports tracking revision references that can change
over time (eg, some VCS tags and branch names)"
feature :ssh_identity,
"The provider supports a configurable SSH identity file"
feature :user,
"The provider can run as a different user"
feature :modules,
"The repository contains modules that can be chosen of"
feature :multiple_remotes,
"The repository tracks multiple remote repositories"
feature :configuration,
"The configuration directory to use"
feature :cvs_rsh,
"The provider understands the CVS_RSH environment variable"
feature :depth,
"The provider can do shallow clones or set scope limit"
feature :branch,
"The name of the branch"
feature :p4config,
"The provider understands Perforce Configuration"
feature :submodules,
"The repository contains submodules which can be optionally initialized"
feature :conflict,
"The provider supports automatic conflict resolution"
feature :include_paths,
"The provider supports checking out only specific paths"
ensurable do
attr_accessor :latest
def insync?(is)
@should ||= []
case should
when :present
return true unless [:absent, :purged, :held].include?(is)
when :latest
if is == :latest
return true
else
return false
end
when :bare
return is == :bare
when :mirror
return is == :mirror
when :absent
return is == :absent
end
end
newvalue :present do
if !provider.exists?
provider.create
elsif provider.class.feature?(:bare_repositories) and provider.bare_exists?
provider.convert_bare_to_working_copy
end
end
newvalue :bare, :required_features => [:bare_repositories] do
if !provider.exists?
provider.create
elsif provider.working_copy_exists?
provider.convert_working_copy_to_bare
elsif provider.mirror?
provider.set_no_mirror
end
end
newvalue :mirror, :required_features => [:bare_repositories] do
if !provider.exists?
provider.create
elsif provider.working_copy_exists?
provider.convert_working_copy_to_bare
elsif !provider.mirror?
provider.set_mirror
end
end
newvalue :absent do
provider.destroy
end
newvalue :latest, :required_features => [:reference_tracking] do
if provider.exists? && !@resource.value(:force)
if provider.class.feature?(:bare_repositories) and provider.bare_exists?
provider.convert_bare_to_working_copy
end
if provider.respond_to?(:update_references)
provider.update_references
end
if provider.respond_to?(:latest?)
reference = provider.latest || provider.revision
else
reference = resource.value(:revision) || provider.revision
end
notice "Updating to latest '#{reference}' revision"
provider.revision = reference
else
notice "Creating repository from latest"
provider.create
end
end
def retrieve
prov = @resource.provider
if prov
if prov.working_copy_exists?
(@should.include?(:latest) && prov.latest?) ? :latest : :present
elsif prov.class.feature?(:bare_repositories) and prov.bare_exists?
if prov.mirror?
:mirror
else
:bare
end
else
:absent
end
else
raise Puppet::Error, "Could not find provider"
end
end
end
newparam :path do
desc "Absolute path to repository"
isnamevar
validate do |value|
path = Pathname.new(value)
unless path.absolute?
raise ArgumentError, "Path must be absolute: #{path}"
end
end
end
newproperty :source do
desc "The source URI for the repository"
# Tolerate versions/providers that strip/add trailing slashes
def insync?(is)
# unwrap @should
should = @should[0]
return true if is == should
begin
if should[-1] == '/'
return true if is == should[0..-2]
elsif is[-1] == '/'
return true if is[0..-2] == should
end
rescue
end
return false
end
end
newparam :fstype, :required_features => [:filesystem_types] do
desc "Filesystem type"
end
newproperty :revision do
desc "The revision of the repository"
newvalue(/^\S+$/)
end
newparam :owner do
desc "The user/uid that owns the repository files"
end
newparam :group do
desc "The group/gid that owns the repository files"
end
newparam :user do
desc "The user to run for repository operations"
end
newparam :excludes do
desc "Local paths which shouldn't be tracked by the repository"
end
newproperty :includes, :required_features => [:include_paths], :array_matching => :all do
desc "Paths to be included from the repository"
def insync?(is)
if is.is_a?(Array) and @should.is_a?(Array)
is.sort == @should.sort
else
is == @should
end
end
validate do |path|
if path[0..0] == '/'
raise Puppet::Error, "Include path '#{path}' starts with a '/'; remove it"
else
super(path)
end
end
end
newparam(:force, :boolean => true, :parent => Puppet::Parameter::Boolean) do
desc "Force repository creation, destroying any files on the path in the process."
defaultto false
end
newparam :compression, :required_features => [:gzip_compression] do
desc "Compression level"
validate do |amount|
unless Integer(amount).between?(0, 6)
raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)"
end
end
end
newparam :basic_auth_username, :required_features => [:basic_auth] do
desc "HTTP Basic Auth username"
end
newparam :basic_auth_password, :required_features => [:basic_auth] do
desc "HTTP Basic Auth password"
end
newparam :identity, :required_features => [:ssh_identity] do
desc "SSH identity file"
end
newproperty :module, :required_features => [:modules] do
desc "The repository module to manage"
end
newparam :remote, :required_features => [:multiple_remotes] do
desc "The remote repository to track"
defaultto "origin"
end
newparam :configuration, :required_features => [:configuration] do
desc "The configuration directory to use"
end
newparam :cvs_rsh, :required_features => [:cvs_rsh] do
desc "The value to be used for the CVS_RSH environment variable."
end
newparam :depth, :required_features => [:depth] do
desc "The value to be used to do a shallow clone."
end
newparam :branch, :required_features => [:branch] do
desc "The name of the branch to clone."
end
newparam :p4config, :required_features => [:p4config] do
desc "The Perforce P4CONFIG environment."
end
newparam :submodules, :required_features => [:submodules] do
desc "Initialize and update each submodule in the repository."
newvalues(:true, :false)
defaultto true
end
newparam :conflict do
desc "The action to take if conflicts exist between repository and working copy"
end
newparam :trust_server_cert do
desc "Trust server certificate"
newvalues(:true, :false)
defaultto :false
end
autorequire(:package) do
['git', 'git-core', 'mercurial', 'subversion']
end
end
---
# This is the project-specific configuration file for setting up
# fast_gettext for your project.
gettext:
# This is used for the name of the .pot and .po files; they will be
# called <project_name>.pot?
project_name: puppetlabs-vcsrepo
# This is used in comments in the .pot and .po files to indicate what
# project the files belong to and should bea little more desctiptive than
# <project_name>
package_name: puppetlabs-vcsrepo
# The locale that the default messages in the .pot file are in
default_locale: en
# The email used for sending bug reports.
bugs_address: docs@puppet.com
# The holder of the copyright.
copyright_holder: Puppet, Inc.
# This determines which comments in code should be eligible for translation.
# Any comments that start with this string will be externalized. (Leave
# empty to include all.)
comments_tag: TRANSLATOR
# Patterns for +Dir.glob+ used to find all files that might contain
# translatable content, relative to the project root directory
source_files:
{
"name": "puppetlabs-vcsrepo",
"version": "2.0.0",
"author": "Puppet Labs",
"summary": "Puppet module providing a type to manage repositories from various version control systems",
"license": "GPL-2.0+",
"source": "https://github.com/puppetlabs/puppetlabs-vcsrepo",
"project_page": "https://github.com/puppetlabs/puppetlabs-vcsrepo",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
"dependencies": [
],
"data_provider": null,
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "Scientific",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "SLES",
"operatingsystemrelease": [
"10 SP4",
"11 SP1",
"12"
]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"6",
"7",
"8"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"10.04",
"12.04",
"14.04",
"16.04"
]
}
],
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.7.0 < 6.0.0"
}
]
}
test_name 'C3492 - checkout with basic auth (http protocol)'
skip_test 'HTTP not supported yet for basic auth using git. See FM-1331'
# Globals
repo_name = 'testrepo_checkout'
user = 'foo'
password = 'bar'
http_server_script = 'basic_auth_http_daemon.rb'
hosts.each do |host|
ruby = '/opt/puppet/bin/ruby' if host.is_pe? || 'ruby'
gem = '/opt/puppet/bin/gem' if host.is_pe? || 'gem'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
script =<<-EOF
require 'sinatra'
set :bind, '0.0.0.0'
set :static, true
set :public_folder, '#{tmpdir}'
use Rack::Auth::Basic do |username, password|
username == '#{user}' && password == '#{password}'
end
EOF
create_remote_file(host, "#{tmpdir}/#{http_server_script}", script)
on(host, "#{gem} install sinatra")
on(host, "#{ruby} #{tmpdir}/#{http_server_script} &")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} #{tmpdir}/#{http_server_script}' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'checkout with puppet using basic auth' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:4567/testrepo.git",
provider => git,
basic_auth_username => '#{user}',
basic_auth_password => '#{password}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3493 - checkout with basic auth (https protocol)'
skip_test 'waiting for CA trust solution'
# Globals
repo_name = 'testrepo_checkout'
user = 'foo'
password = 'bar'
http_server_script = 'basic_auth_https_daemon.rb'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
script =<<-EOF
require 'webrick'
require 'webrick/https'
authenticate = Proc.new do |req, res|
WEBrick::HTTPAuth.basic_auth(req, res, '') do |user, password|
user == '#{user}' && password == '#{password}'
end
end
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:DocumentRootOptions=> {:HandlerCallback => authenticate},
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, "#{tmpdir}/#{http_server_script}", script)
on(host, "#{ruby} #{tmpdir}/#{http_server_script}")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} #{tmpdir}/#{http_server_script}' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'checkout with puppet using basic auth' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8443/testrepo.git",
provider => git,
basic_auth_username => '#{user}',
basic_auth_password => '#{password}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3494 - checkout with basic auth (git protocol)'
# Globals
repo_name = 'testrepo_checkout'
user = 'foo'
password = 'bar'
http_server_script = 'basic_auth_http_daemon.rb'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
end
step 'checkout with puppet using basic auth' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
basic_auth_username => '#{user}',
basic_auth_password => '#{password}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout (silent error for basic auth using git protocol)" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3438 - checkout a branch (file protocol)'
# Globals
repo_name = 'testrepo_branch_checkout'
branch = 'a_branch'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout a branch with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
revision => '#{branch}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the #{branch} branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
end
end
end
test_name 'C3437 - checkout a branch (file path)'
# Globals
repo_name = 'testrepo_branch_checkout'
branch = 'a_branch'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout a branch with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "#{tmpdir}/testrepo.git",
provider => git,
revision => '#{branch}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the #{branch} branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
end
end
end
test_name 'C3436 - checkout a branch (git protocol)'
# Globals
repo_name = 'testrepo_branch_checkout'
branch = 'a_branch'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
end
step 'checkout a branch with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
revision => '#{branch}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the #{branch} branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
end
end
end
test_name 'C3441 - checkout a branch (http protocol)'
# Globals
repo_name = 'testrepo_branch_checkout'
branch = 'a_branch'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
http_daemon =<<-EOF
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => "#{tmpdir}")
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/http_daemon.rb', http_daemon)
on(host, "#{ruby} /tmp/http_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/http_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'checkout a branch with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8000/testrepo.git",
provider => git,
revision => '#{branch}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the #{branch} branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
end
end
end
test_name 'C3442 - checkout a branch (https protocol)'
# Globals
repo_name = 'testrepo_branch_checkout'
branch = 'a_branch'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
https_daemon =<<-EOF
require 'webrick'
require 'webrick/https'
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
#on(host, "#{ruby} /tmp/https_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/https_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'checkout a branch with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "https://github.com/johnduarte/testrepo.git",
provider => git,
revision => '#{branch}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the #{branch} branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
end
end
end
test_name 'C3439 - checkout a branch (ssh protocol, scp syntax)'
# Globals
repo_name = 'testrepo_branch_checkout'
branch = 'a_branch'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'checkout a branch with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "root@#{host}:#{tmpdir}/testrepo.git",
provider => git,
revision => '#{branch}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the #{branch} branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
end
end
end
test_name 'C3440 - checkout a branch (ssh protocol)'
# Globals
repo_name = 'testrepo_branch_checkout'
branch = 'a_branch'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'checkout a branch with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "ssh://root@#{host}#{tmpdir}/testrepo.git",
provider => git,
revision => '#{branch}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the #{branch} branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
end
end
end
test_name 'C3609 - checkout a branch that does not exist'
# Globals
repo_name = 'testrepo_branch_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout branch that does not exist with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
revision => 'non_existent_branch',
}
EOS
apply_manifest_on(host, pp, :expect_failures => true)
end
step 'verify that master branch is checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3427 - clone (file protocol)'
# Globals
repo_name = 'testrepo_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'clone with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the master branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('master not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3426 - clone (file path)'
# Globals
repo_name = 'testrepo_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'clone with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "#{tmpdir}/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the master branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('master not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3425 - clone (git protocol)'
# Globals
repo_name = 'testrepo_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
end
step 'clone with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the master branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('master not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3430 - clone (http protocol)'
# Globals
repo_name = 'testrepo_clone'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
http_daemon =<<-EOF
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => "#{tmpdir}")
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/http_daemon.rb', http_daemon)
on(host, "#{ruby} /tmp/http_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/http_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'clone with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8000/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the master branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('master not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3431 - clone (https protocol)'
# Globals
repo_name = 'testrepo_clone'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
https_daemon =<<-EOF
require 'webrick'
require 'webrick/https'
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
#on(host, "#{ruby} /tmp/https_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/https_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'clone with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "https://github.com/johnduarte/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the master branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('master not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3511 - clone over an existing repo with force'
# Globals
repo_name = 'testrepo_already_exists'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
on(host, "mkdir #{tmpdir}/#{repo_name}")
on(host, "cd #{tmpdir}/#{repo_name} && git init")
on(host, "cd #{tmpdir}/#{repo_name} && touch a && git add a && git commit -m 'a'")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'clone over existing repo with force using puppet' do
on(host, "cd #{tmpdir}/#{repo_name} && git log --pretty=format:\"%h\"") do |res|
@existing_sha = res.stdout
end
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
force => true,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify new repo has replaced old one' do
on(host, "cd #{tmpdir}/#{repo_name} && git log --pretty=format:\"%h\"") do |res|
fail_test('original repo not replaced by force') if res.stdout.include? "#{@existing_sha}"
end
end
end
test_name 'C3507 - clone repo with excludes in repo'
# Globals
repo_name = 'testrepo_with_excludes_in_repo'
exclude1 = 'file1.txt'
exclude2 ='file2.txt'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'clone repo with excludes in repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
excludes => [ '#{exclude1}', '#{exclude2}' ],
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify exludes are known to git' do
on(host, "cat #{tmpdir}/#{repo_name}/.git/info/exclude") do |res|
fail_test('exclude not found') unless res.stdout.include? "#{exclude1}"
fail_test('exclude not found') unless res.stdout.include? "#{exclude2}"
end
end
end
test_name 'C3508 - clone repo with excludes not in repo'
# Globals
repo_name = 'testrepo_with_excludes_not_in_repo'
exclude1 = 'worh02o'
exclude2 ='ho398b'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'clone repo with excludes not in repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
excludes => [ '#{exclude1}', '#{exclude2}' ],
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify exludes are known to git' do
on(host, "cat #{tmpdir}/#{repo_name}/.git/info/exclude") do |res|
fail_test('exclude not found') unless res.stdout.include? "#{exclude1}"
fail_test('exclude not found') unless res.stdout.include? "#{exclude2}"
end
end
end
test_name 'C3428 - clone (ssh protocol, scp syntax)'
# Globals
repo_name = 'testrepo_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'clone with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "root@#{host}:#{tmpdir}/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the master branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('master not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3429 - clone (ssh protocol)'
# Globals
repo_name = 'testrepo_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'clone with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "ssh://root@#{host}#{tmpdir}/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is on the master branch" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('master not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3482 - clone over an existing repo'
# Globals
repo_name = 'testrepo_already_exists'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
on(host, "mkdir #{tmpdir}/#{repo_name}")
on(host, "cd #{tmpdir}/#{repo_name} && git init")
on(host, "cd #{tmpdir}/#{repo_name} && touch a && git add a && git commit -m 'a'")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'clone over existing repo using puppet' do
on(host, "cd #{tmpdir}/#{repo_name} && git log --pretty=format:\"%h\"") do |res|
@existing_sha = res.stdout
end
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
}
EOS
apply_manifest_on(host, pp, :expect_failures => true)
end
step 'verify original repo was not replaced' do
on(host, "cd #{tmpdir}/#{repo_name} && git log --pretty=format:\"%h\"") do |res|
fail_test('original repo was replaced without force') unless res.stdout.include? "#{@existing_sha}"
end
end
end
test_name 'C3509 - clone repo with excludes not in repo'
skip_test 'expectations not defined'
# Globals
repo_name = 'testrepo_with_excludes_not_in_repo'
exclude1 = "`exec \"rm -rf /tmp\"`"
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'clone repo with excludes not in repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
excludes => [ '#{exclude1}' ],
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify excludes are known to git' do
on(host, "cat #{tmpdir}/#{repo_name}/.git/info/exclude") do |res|
fail_test('exclude not found') unless res.stdout.include? "#{exclude1}"
end
end
end
test_name 'C3495 - checkout with compression 0'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 0 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 0,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3496 - checkout with compression 1'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 1 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3497 - checkout with compression 2'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 2 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 2,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3498 - checkout with compression 3'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 3 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 3,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3499 - checkout with compression 4'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 4 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 4,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3500 - checkout with compression 5'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 5 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 5,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3501 - checkout with compression 6'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 6 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 6,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3503 - checkout with compression 7'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 7 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 7,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3505 - checkout with compression alpha'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression alpha with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => abcde,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3504 - checkout with compression 10-5'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression 10-5 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => 10-5,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3506 - checkout with compression exec'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression exec with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => "exec 'rm -rf /tmp'",
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3502 - checkout with compression -1'
# Globals
repo_name = 'testrepo_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout with compression -1 with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
compression => -1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify git repo was checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
end
end
test_name 'C3472 - create bare repo that already exists'
# Globals
repo_name = 'testrepo_bare_repo_already_exists.git'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create bare repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
on(host, "mkdir #{tmpdir}/#{repo_name}")
on(host, "cd #{tmpdir}/#{repo_name} && git --bare init")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'create bare repo that already exists using puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => bare,
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify repo does not contain .git directory' do
on(host, "ls -al #{tmpdir}/#{repo_name}") do |res|
fail_test "found .git for #{repo_name}" if res.stdout.include? ".git"
end
end
end
test_name 'C3470 - create repo that already exists'
# Globals
repo_name = 'testrepo_already_exists'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
on(host, "cd #{tmpdir} && git clone file://#{tmpdir}/testrepo.git #{repo_name}")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'create repo that already exists using puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
provider => git,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify repo is on master branch' do
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
assert_match(/ref: refs\/heads\/master/, stdout, "Git checkout not on master on #{host}")
end
end
end
test_name 'C3473 - create bare repo specifying revision'
# Globals
repo_name = 'testrepo_bare.git'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'create bare repo specifying revision using puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => bare,
revision => master,
provider => git,
}
EOS
apply_manifest_on(host, pp, :expect_failures => true)
end
step 'verify repo does not contain .git directory' do
on(host, "ls -al #{tmpdir}") do |res|
fail_test "found repo for #{repo_name}" if res.stdout.include? repo_name
end
end
end
test_name 'C3487 - checkout as a group (file protocol)'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - create group' do
apply_manifest_on(host, "group { '#{group}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a group with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is own by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') unless res.stdout.include? ":#{group}"
end
end
end
test_name 'C3486 - checkout as a group (file path)'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - create group' do
apply_manifest_on(host, "group { '#{group}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
step 'checkout a group with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "#{tmpdir}/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is own by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') unless res.stdout.include? ":#{group}"
end
end
end
test_name 'C3485 - checkout as a group (git protocol)'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
step 'setup - create group' do
apply_manifest_on(host, "group { '#{group}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
step 'checkout a group with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is own by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') unless res.stdout.include? ":#{group}"
end
end
end
test_name 'C3490 - checkout as a group (http protocol)'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
http_daemon =<<-EOF
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => "#{tmpdir}")
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/http_daemon.rb', http_daemon)
on(host, "#{ruby} /tmp/http_daemon.rb")
end
step 'setup - create group' do
apply_manifest_on(host, "group { '#{group}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/http_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
step 'checkout a group with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8000/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is own by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') unless res.stdout.include? ":#{group}"
end
end
end
test_name 'C3491 - checkout as a group (https protocol)'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
https_daemon =<<-EOF
require 'webrick'
require 'webrick/https'
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
#on(host, "#{ruby} /tmp/https_daemon.rb")
end
step 'setup - create group' do
apply_manifest_on(host, "group { '#{group}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/https_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a group with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "https://github.com/johnduarte/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is own by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') unless res.stdout.include? ":#{group}"
end
end
end
test_name 'C3488 - checkout as a group (ssh protocol, scp syntax)'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
step 'setup - create group' do
apply_manifest_on(host, "group { '#{group}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a group with puppet (scp syntax)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "root@#{host}:#{tmpdir}/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is own by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') unless res.stdout.include? ":#{group}"
end
end
end
test_name 'C3489 - checkout as a group (ssh protocol)'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
step 'setup - create group' do
apply_manifest_on(host, "group { '#{group}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a group with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "ssh://root@#{host}#{tmpdir}/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is own by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') unless res.stdout.include? ":#{group}"
end
end
end
test_name 'C3484 - checkout as a group that is not on system'
# Globals
repo_name = 'testrepo_group_checkout'
group = 'mygroup'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - delete group' do
apply_manifest_on(host, "group { '#{group}': ensure => absent, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout as a group with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
group => '#{group}',
}
EOS
apply_manifest_on(host, pp, :expect_failures => true)
end
step "verify git checkout is NOT owned by group #{group}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by group') if res.stdout.include? ":#{group}"
end
end
end
test_name 'C3614 - checkout a revision that does not exist'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout revision that does not exist with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
revision => '11111111111111111',
}
EOS
apply_manifest_on(host, pp, :expect_failures => true)
end
step 'verify that master revision is checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3452 - checkout a revision (file protocol)'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'get revision sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a revision with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
revision => '#{@sha}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify repo is checked out to revision #{@sha}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "#{@sha}"
end
end
end
test_name 'C3451 - checkout a revision (file path)'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'get revision sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a revision with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "#{tmpdir}/testrepo.git",
provider => git,
revision => '#{@sha}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify repo is checked out to revision #{@sha}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "#{@sha}"
end
end
end
test_name 'C3450 - checkout a revision (git protocol)'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
end
step 'get revision sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a revision with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
revision => '#{@sha}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is set to revision #{@sha}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "#{@sha}"
end
end
end
test_name 'C3455 - checkout a revision (http protocol)'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
http_daemon =<<-EOF
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => "#{tmpdir}")
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/http_daemon.rb', http_daemon)
on(host, "#{ruby} /tmp/http_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/http_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'get revision sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a revision with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8000/testrepo.git",
provider => git,
revision => '#{@sha}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is set to revision #{@sha}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "#{@sha}"
end
end
end
test_name 'C3456 - checkout a revision (https protocol)'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
https_daemon =<<-EOF
require 'webrick'
require 'webrick/https'
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
#on(host, "#{ruby} /tmp/https_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/https_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'get revision sha from repo' do
on(host, "git clone https://github.com/johnduarte/testrepo.git #{tmpdir}/foo")
on(host, "git --git-dir=#{tmpdir}/foo/.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a revision with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "https://github.com/johnduarte/testrepo.git",
provider => git,
revision => '#{@sha}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is set to revision #{@sha}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "#{@sha}"
end
end
end
test_name 'C3453 - checkout a revision (ssh protocol, scp syntax)'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'get revision sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a revision with puppet (scp syntax)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "root@#{host}:#{tmpdir}/testrepo.git",
provider => git,
revision => '#{@sha}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is set to revision #{@sha}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "#{@sha}"
end
end
end
test_name 'C3454 - checkout a revision (ssh protocol)'
# Globals
repo_name = 'testrepo_revision_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'get revision sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a revision with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "ssh://root@#{host}#{tmpdir}/testrepo.git",
provider => git,
revision => '#{@sha}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout is set to revision #{@sha}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('revision not found') unless res.stdout.include? "#{@sha}"
end
end
end
test_name 'C3608 - shallow clone repo depth hostile input'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'shallow clone repo with puppet (bad input ignored, full clone checkedout)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
depth => "exec 'rm -rf /tmp'",
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is NOT shallow' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') if res.stdout.include? "shallow"
end
end
end
test_name 'C3475 - shallow clone repo minimal depth = 1 (file path protocol)'
skip_test 'Not currently supported. See FM-1285'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'shallow clone repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "#{tmpdir}/testrepo.git",
provider => git,
depth => 1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'git does not support shallow clone via file path: verify checkout is NOT created' do
on(host, "ls #{tmpdir}") do |res|
fail_test('checkout found') if res.stdout.include? "#{repo_name}"
end
end
end
test_name 'C3479 - shallow clone repo minimal depth = 1 (http protocol)'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
http_daemon =<<-EOF
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => "#{tmpdir}")
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/http_daemon.rb', http_daemon)
on(host, "#{ruby} /tmp/http_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'ps ax | grep "#{ruby} /tmp/http_daemon.rb" | grep -v grep | awk \'{print "kill -9 " $1}\' | sh ; sleep 1')
end
step 'shallow clone repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8000/testrepo.git",
provider => git,
depth => 1,
}
EOS
apply_manifest_on(host, pp, :expect_failures => true)
end
step 'git does not support shallow clone via HTTP: verify checkout is NOT created' do
on(host, "ls #{tmpdir}") do |res|
fail_test('checkout found') if res.stdout.include? "#{repo_name}"
end
end
end
test_name 'C3607 - shallow clone repo depth = -1'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'shallow clone repo with puppet (bad input ignored, full clone checkedout)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
depth => -1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is NOT shallow' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') if res.stdout.include? "shallow"
end
end
end
test_name 'C3606 - shallow clone repo depth overflow 64bit integer'
# Globals
repo_name = 'testrepo_shallow_clone'
pending_test("The overflow can't be handled on some git versions")
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'shallow clone repo with puppet (bad input ignored, full clone checkedout)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
depth => 18446744073709551616,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is NOT shallow' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') if res.stdout.include? "shallow"
end
end
end
test_name 'C3476 - shallow clone repo minimal depth = 1 (file protocol)'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'shallow clone repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
depth => 1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is shallow and of the correct depth' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') unless res.stdout.include? "shallow"
end
on(host, "wc -l #{tmpdir}/#{repo_name}/.git/shallow") do |res|
fail_test('shallow not found') unless res.stdout.include? "1 #{tmpdir}/#{repo_name}/.git/shallow"
end
end
end
test_name 'C3474 - shallow clone repo minimal depth = 1 (git protocol)'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
end
step 'shallow clone repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
depth => 1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is shallow and of the correct depth' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') unless res.stdout.include? "shallow"
end
on(host, "wc -l #{tmpdir}/#{repo_name}/.git/shallow") do |res|
fail_test('shallow not found') unless res.stdout.include? "1 #{tmpdir}/#{repo_name}/.git/shallow"
end
end
end
test_name 'C3480 - shallow clone repo minimal depth = 1 (https protocol)'
skip_test 'Not currently supported. See FM-1286'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
https_daemon =<<-EOF
require 'webrick'
require 'webrick/https'
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
#on(host, "#{ruby} /tmp/https_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'ps ax | grep "#{ruby} /tmp/https_daemon.rb" | grep -v grep | awk \'{print "kill -9 " $1}\' | sh ; sleep 1')
end
step 'shallow clone repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "https://github.com/johnduarte/testrepo.git",
provider => git,
depth => 1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is shallow and of the correct depth' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') unless res.stdout.include? "shallow"
end
on(host, "wc -l #{tmpdir}/#{repo_name}/.git/shallow") do |res|
fail_test('shallow not found') unless res.stdout.include? "1 #{tmpdir}/#{repo_name}/.git/shallow"
end
end
end
test_name 'C3478 - shallow clone repo minimal depth = 1 (ssh protocol, scp syntax)'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'shallow clone repo with puppet (scp syntax)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "root@#{host}:#{tmpdir}/testrepo.git",
provider => git,
depth => 1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is shallow and of the correct depth' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') unless res.stdout.include? "shallow"
end
on(host, "wc -l #{tmpdir}/#{repo_name}/.git/shallow") do |res|
fail_test('shallow not found') unless res.stdout.include? "1 #{tmpdir}/#{repo_name}/.git/shallow"
end
end
end
test_name 'C3477 - shallow clone repo minimal depth = 1 (ssh protocol)'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'shallow clone repo with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "ssh://root@#{host}#{tmpdir}/testrepo.git",
provider => git,
depth => 1,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is shallow and of the correct depth' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow not found') unless res.stdout.include? "shallow"
end
on(host, "wc -l #{tmpdir}/#{repo_name}/.git/shallow") do |res|
fail_test('shallow not found') unless res.stdout.include? "1 #{tmpdir}/#{repo_name}/.git/shallow"
end
end
end
test_name 'C3404 - shallow clone repo depth = 0 non shallow'
# Globals
repo_name = 'testrepo_shallow_clone'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'shallow clone repo with puppet (zero depth means not shallow)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
depth => 0,
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify checkout is NOT shallow' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('shallow found') if res.stdout.include? "shallow"
end
end
end
test_name 'C3612 - checkout a tag that does not exist'
# Globals
repo_name = 'testrepo_tag_checkout'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout tag that does not exist with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
tag => '11111111111111111',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step 'verify that master tag is checked out' do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "ref: refs/heads/master"
end
end
end
test_name 'C3445 - checkout a tag (file protocol)'
# Globals
repo_name = 'testrepo_tag_checkout'
tag = '0.0.2'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout a tag with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
revision => '#{tag}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout out tag is #{tag}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host,"git --git-dir=#{tmpdir}/#{repo_name}/.git name-rev HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "#{tag}"
end
end
end
test_name 'C3444 - checkout a tag (file path)'
# Globals
repo_name = 'testrepo_tag_checkout'
tag = '0.0.2'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout a tag with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "#{tmpdir}/testrepo.git",
provider => git,
revision => '#{tag}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout out tag is #{tag}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host,"git --git-dir=#{tmpdir}/#{repo_name}/.git name-rev HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "#{tag}"
end
end
end
test_name 'C3443 - checkout a tag (git protocol)'
# Globals
repo_name = 'testrepo_tag_checkout'
tag = '0.0.2'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
end
step 'get tag sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a tag with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
revision => '#{tag}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout out tag is #{tag}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host,"git --git-dir=#{tmpdir}/#{repo_name}/.git name-rev HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "#{tag}"
end
end
end
test_name 'C3448 - checkout a tag (http protocol)'
# Globals
repo_name = 'testrepo_tag_checkout'
tag = '0.0.2'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
http_daemon =<<-EOF
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => "#{tmpdir}")
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/http_daemon.rb', http_daemon)
on(host, "#{ruby} /tmp/http_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/http_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'get tag sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a tag with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8000/testrepo.git",
provider => git,
revision => '#{tag}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout out tag is #{tag}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host,"git --git-dir=#{tmpdir}/#{repo_name}/.git name-rev HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "#{tag}"
end
end
end
test_name 'C3449 - checkout a tag (https protocol)'
# Globals
repo_name = 'testrepo_tag_checkout'
tag = '0.0.2'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
https_daemon =<<-EOF
require 'webrick'
require 'webrick/https'
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
#on(host, "#{ruby} /tmp/https_daemon.rb")
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/https_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
end
step 'get tag sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a tag with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "https://github.com/johnduarte/testrepo.git",
provider => git,
revision => '#{tag}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout out tag is #{tag}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host,"git --git-dir=#{tmpdir}/#{repo_name}/.git name-rev HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "#{tag}"
end
end
end
test_name 'C3446 - checkout a tag (ssh protocol, scp syntax)'
# Globals
repo_name = 'testrepo_tag_checkout'
tag = '0.0.2'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'get tag sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a tag with puppet (scp syntax)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "root@#{host}:#{tmpdir}/testrepo.git",
provider => git,
revision => '#{tag}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout out tag is #{tag}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host,"git --git-dir=#{tmpdir}/#{repo_name}/.git name-rev HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "#{tag}"
end
end
end
test_name 'C3447 - checkout a tag (ssh protocol)'
# Globals
repo_name = 'testrepo_tag_checkout'
tag = '0.0.2'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
end
step 'get tag sha from repo' do
on(host, "git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1") do |res|
@sha = res.stdout.chomp
end
end
step 'checkout a tag with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "ssh://root@#{host}#{tmpdir}/testrepo.git",
provider => git,
revision => '#{tag}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify checkout out tag is #{tag}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host,"git --git-dir=#{tmpdir}/#{repo_name}/.git name-rev HEAD") do |res|
fail_test('tag not found') unless res.stdout.include? "#{tag}"
end
end
end
test_name 'C3483 - checkout as a user that is not on system'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - delete user' do
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
end
step 'checkout as a user with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :expect_failures => true)
end
step "verify git checkout is NOT owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') if res.stdout.include? "#{user}:"
end
end
end
test_name 'C3459 - checkout as a user (file protocol)'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - create user' do
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a user with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:"
end
end
end
test_name 'C3458 - checkout as a user (file path)'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - create user' do
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
step 'checkout a user with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "#{tmpdir}/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:"
end
end
end
test_name 'C3457 - checkout as a user (git protocol)'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start git daemon' do
install_package(host, 'git-daemon') unless host['platform'] =~ /debian|ubuntu/
on(host, "git daemon --base-path=#{tmpdir} --export-all --reuseaddr --verbose --detach")
end
step 'setup - create user' do
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, 'pkill -9 git-daemon ; sleep 1')
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
step 'checkout a user with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "git://#{host}/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:"
end
end
end
test_name 'C3462 - checkout as a user (http protocol)'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start http server' do
http_daemon =<<-EOF
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => "#{tmpdir}")
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/http_daemon.rb', http_daemon)
on(host, "#{ruby} /tmp/http_daemon.rb")
end
step 'setup - create user' do
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/http_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
step 'checkout a user with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "http://#{host}:8000/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:"
end
end
end
test_name 'C3463 - checkout as a user (https protocol)'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - start https server' do
https_daemon =<<-EOF
require 'webrick'
require 'webrick/https'
server = WEBrick::HTTPServer.new(
:Port => 8443,
:DocumentRoot => "#{tmpdir}",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("#{tmpdir}/server.crt").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("#{tmpdir}/server.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ])
WEBrick::Daemon.start
server.start
EOF
create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
#on(host, "#{ruby} /tmp/https_daemon.rb")
end
step 'setup - create user' do
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
on(host, "ps ax | grep '#{ruby} /tmp/https_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a user with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "https://github.com/johnduarte/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:"
end
end
end
test_name 'C3460 - checkout as a user (ssh protocol, scp syntax)'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
step 'setup - create user' do
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a user with puppet (scp syntax)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "root@#{host}:#{tmpdir}/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:"
end
end
end
test_name 'C3461 - checkout as a user (ssh protocol)'
# Globals
repo_name = 'testrepo_user_checkout'
user = 'myuser'
hosts.each do |host|
tmpdir = host.tmpdir('vcsrepo')
step 'setup - create repo' do
git_pkg = 'git'
if host['platform'] =~ /ubuntu-10/
git_pkg = 'git-core'
end
install_package(host, git_pkg)
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
on(host, "cd #{tmpdir} && ./create_git_repo.sh")
end
step 'setup - establish ssh keys' do
# create ssh keys
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config')
on(host, 'chown -R root:root /root/.ssh')
end
step 'setup - create user' do
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true)
end
teardown do
on(host, "rm -fr #{tmpdir}")
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true)
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true)
end
step 'checkout as a user with puppet' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/#{repo_name}":
ensure => present,
source => "ssh://root@#{host}#{tmpdir}/testrepo.git",
provider => git,
owner => '#{user}',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, :catch_changes => true)
end
step "verify git checkout is owned by user #{user}" do
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
fail_test('checkout not found') unless res.stdout.include? "HEAD"
end
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:"
end
end
end
test_name "Installing Puppet and vcsrepo module" do
step 'install puppet' do
if @options[:provision]
# This will fail if puppet is already installed, ie --no-provision
if hosts.first.is_pe?
install_pe
else
install_puppet
on hosts, "mkdir -p #{hosts.first['distmoduledir']}"
end
end
end
step 'Ensure we can install our module' do
hosts.each do |host|
# We ask the host to interpolate it's distmoduledir because we don't
# actually know it on Windows until we've let it redirect us (depending
# on whether we're running as a 32/64 bit process on 32/64 bit Windows
moduledir = on(host, "echo #{host['distmoduledir']}").stdout.chomp
on host, "mkdir -p #{moduledir}"
end
end
step 'install module' do
hosts.each do |host|
proj_root = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
# This require beaker 1.15
copy_module_to(host, :source => proj_root, :module_name => 'vcsrepo')
case fact_on(host, 'osfamily')
when 'RedHat'
install_package(host, 'git')
when 'Debian'
install_package(host, 'git-core')
else
if !check_for_package(host, 'git')
puts "Git package is required for this module"
exit
end
end
gitconfig = <<-EOS
[user]
email = root@localhost
name = root
EOS
create_remote_file(host, "/root/.gitconfig", gitconfig)
end
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'clones a remote repo' do
before(:all) do
my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
shell("mkdir -p #{tmpdir}") # win test
scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
shell("cd #{tmpdir} && ./create_git_repo.sh")
end
after(:all) do
shell("rm -rf #{tmpdir}/testrepo.git")
end
context 'get the current master HEAD' do
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo/.git") do
it { is_expected.to be_directory }
end
describe file("#{tmpdir}/testrepo/.git/HEAD") do
it { is_expected.to contain 'ref: refs/heads/master' }
end
end
context 'using a https source on github' do
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/httpstestrepo":
ensure => present,
provider => git,
source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/httpstestrepo/.git") do
it { is_expected.to be_directory }
end
describe file("#{tmpdir}/httpstestrepo/.git/HEAD") do
it { is_expected.to contain 'ref: refs/heads/master' }
end
end
context 'using a commit SHA' do
let (:sha) do
shell("git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1").stdout.chomp
end
after(:all) do
shell("rm -rf #{tmpdir}/testrepo_sha")
end
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_sha":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
revision => "#{sha}",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_sha/.git") do
it { is_expected.to be_directory }
end
describe file("#{tmpdir}/testrepo_sha/.git/HEAD") do
it { is_expected.to contain sha }
end
end
context 'using a tag' do
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_tag":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
revision => '0.0.2',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_tag/.git") do
it { is_expected.to be_directory }
end
it 'should have the tag as the HEAD' do
shell("git --git-dir=#{tmpdir}/testrepo_tag/.git name-rev HEAD | grep '0.0.2'")
end
end
context 'using a branch name' do
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_branch":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
revision => 'a_branch',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_branch/.git") do
it { is_expected.to be_directory }
end
describe file("#{tmpdir}/testrepo_branch/.git/HEAD") do
it { is_expected.to contain 'ref: refs/heads/a_branch' }
end
end
context 'ensure latest with branch specified' do
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_latest":
ensure => latest,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
revision => 'a_branch',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
it 'verifies the HEAD commit SHA on remote and local match' do
remote_commit = shell("git ls-remote file://#{tmpdir}/testrepo_latest HEAD | head -1").stdout
local_commit = shell("git --git-dir=#{tmpdir}/testrepo_latest/.git rev-parse HEAD").stdout.chomp
expect(remote_commit).to include(local_commit)
end
end
context 'ensure latest with branch unspecified' do
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_latest":
ensure => latest,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
it 'verifies the HEAD commit SHA on remote and local match' do
remote_commit = shell("git ls-remote file://#{tmpdir}/testrepo_latest HEAD | head -1").stdout
local_commit = shell("git --git-dir=#{tmpdir}/testrepo_latest/.git rev-parse HEAD").stdout.chomp
expect(remote_commit).to include(local_commit)
end
end
context 'with shallow clone' do
it 'does a shallow clone' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_shallow":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
depth => '1',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_shallow/.git/shallow") do
it { is_expected.to be_file }
end
end
context 'path is not empty and not a repository' do
before(:all) do
shell("mkdir #{tmpdir}/not_a_repo", :acceptable_exit_codes => [0,1])
shell("touch #{tmpdir}/not_a_repo/file1.txt", :acceptable_exit_codes => [0,1])
end
it 'should raise an exception' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/not_a_repo":
ensure => present,
provider => git
source => "file://#{tmpdir}/testrepo.git",
}
EOS
apply_manifest(pp, :expect_failures => true)
end
end
context 'with an owner' do
pp = <<-EOS
user { 'vagrant':
ensure => present,
}
EOS
apply_manifest(pp, :catch_failures => true)
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_owner":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
owner => 'vagrant',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_owner") do
it { is_expected.to be_directory }
it { is_expected.to be_owned_by 'vagrant' }
end
end
context 'with a group' do
pp = <<-EOS
group { 'vagrant':
ensure => present,
}
EOS
apply_manifest(pp, :catch_failures => true)
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "/#{tmpdir}/testrepo_group":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
group => 'vagrant',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_group") do
it { is_expected.to be_directory }
it { is_expected.to be_grouped_into 'vagrant' }
end
end
context 'with excludes' do
it 'clones a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_excludes":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
excludes => ['exclude1.txt', 'exclude2.txt'],
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_excludes/.git/info/exclude") do
describe '#content' do
subject { super().content }
it { is_expected.to match /exclude1.txt/ }
end
describe '#content' do
subject { super().content }
it { is_expected.to match /exclude2.txt/ }
end
end
end
context 'with force' do
before(:all) do
shell("mkdir -p #{tmpdir}/testrepo_force/folder")
shell("touch #{tmpdir}/testrepo_force/temp.txt")
end
it 'applies the manifest' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_force":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
force => true,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_force/folder") do
it { is_expected.not_to be_directory }
end
describe file("#{tmpdir}/testrepo_force/temp.txt") do
it { is_expected.not_to be_file }
end
describe file("#{tmpdir}/testrepo_force/.git") do
it { is_expected.to be_directory }
end
context 'and noop' do
before(:all) do
shell("mkdir #{tmpdir}/testrepo_already_exists")
shell("cd #{tmpdir}/testrepo_already_exists && git init")
shell("cd #{tmpdir}/testrepo_already_exists && touch a && git add a && git commit -m 'a'")
end
after(:all) do
shell("rm -rf #{tmpdir}/testrepo_already_exists")
end
it 'applies the manifest' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_already_exists":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
force => true,
noop => true,
}
EOS
apply_manifest(pp, :catch_changes => true)
end
end
end
context 'as a user' do
before(:all) do
shell("chmod 707 #{tmpdir}")
pp = <<-EOS
group { 'testuser':
ensure => present,
}
user { 'testuser':
ensure => present,
groups => 'testuser',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'applies the manifest' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_user":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
user => 'testuser',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_user") do
it { is_expected.to be_directory }
it { is_expected.to be_owned_by 'testuser' }
end
describe file("#{tmpdir}/testrepo_user") do
it { is_expected.to be_directory }
it { is_expected.to be_grouped_into 'testuser' }
end
after(:all) do
pp = 'user { "testuser": ensure => absent }'
apply_manifest(pp, :catch_failures => true)
end
end
context 'non-origin remote name' do
it 'applies the manifest' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_remote":
ensure => present,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
remote => 'testorigin',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
it 'remote name is "testorigin"' do
shell("git --git-dir=#{tmpdir}/testrepo_remote/.git remote | grep 'testorigin'")
end
end
context 'as a user with ssh' do
before(:all) do
# create user
pp = <<-EOS
group { 'testuser-ssh':
ensure => present,
}
user { 'testuser-ssh':
ensure => present,
groups => 'testuser-ssh',
managehome => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
# create ssh keys
shell('mkdir -p /home/testuser-ssh/.ssh')
shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
end
it 'applies the manifest' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_user_ssh":
ensure => present,
provider => git,
source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
user => 'testuser-ssh',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
after(:all) do
pp = <<-EOS
user { 'testuser-ssh':
ensure => absent,
managehome => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
end
context 'using an identity file' do
before(:all) do
# create user
pp = <<-EOS
user { 'testuser-ssh':
ensure => present,
managehome => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
# create ssh keys
shell('mkdir -p /home/testuser-ssh/.ssh')
shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
end
it 'applies the manifest' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_user_ssh_id":
ensure => present,
provider => git,
source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
identity => '/home/testuser-ssh/.ssh/id_rsa',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
end
context 'bare repo' do
it 'creates a bare repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_bare_repo":
ensure => bare,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_bare_repo/config") do
it { is_expected.to contain 'bare = true' }
end
describe file("#{tmpdir}/testrepo_bare_repo/.git") do
it { is_expected.not_to be_directory }
end
describe file("#{tmpdir}/testrepo_bare_repo/HEAD") do
it { is_expected.to contain 'ref: refs/heads/master' }
end
end
context 'mirror repo' do
it 'creates a mirror repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_mirror_repo":
ensure => mirror,
provider => git,
source => "file://#{tmpdir}/testrepo.git",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_mirror_repo/config") do
it { is_expected.to contain 'bare = true' }
it { is_expected.to contain 'mirror = true' }
end
describe file("#{tmpdir}/testrepo_mirror_repo/.git") do
it { is_expected.not_to be_directory }
end
describe file("#{tmpdir}/testrepo_mirror_repo/HEAD") do
it { is_expected.to contain 'ref: refs/heads/master' }
end
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'create a repo' do
context 'without a source' do
it 'creates a blank repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_blank_repo":
ensure => present,
provider => git,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_blank_repo/") do
it 'should have zero files' do
shell("ls -1 #{tmpdir}/testrepo_blank_repo | wc -l") do |r|
expect(r.stdout).to match(/^0\n$/)
end
end
end
describe file("#{tmpdir}/testrepo_blank_repo/.git") do
it { is_expected.to be_directory }
end
end
context 'no source but revision provided' do
it 'should not fail (MODULES-2125)' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_blank_with_revision_repo":
ensure => present,
provider => git,
revision => 'master'
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
end
context 'bare repo' do
it 'creates a bare repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_bare_repo":
ensure => bare,
provider => git,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/testrepo_bare_repo/config") do
it { is_expected.to contain 'bare = true' }
end
describe file("#{tmpdir}/testrepo_bare_repo/.git") do
it { is_expected.not_to be_directory }
end
end
context 'bare repo with a revision' do
it 'does not create a bare repo when a revision is defined' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_bare_repo_rev":
ensure => bare,
provider => git,
revision => 'master',
}
EOS
apply_manifest(pp, :expect_failures => true)
end
describe file("#{tmpdir}/testrepo_bare_repo_rev") do
it { is_expected.not_to be_directory }
end
end
context 'mirror repo' do
it 'does not create a mirror repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_mirror_repo":
ensure => mirror,
provider => git,
}
EOS
apply_manifest(pp, :expect_failures => true)
end
describe file("#{tmpdir}/testrepo_mirror_repo") do
it { is_expected.not_to be_directory }
end
end
end
#!/bin/bash
mkdir testrepo
cd testrepo
touch file1.txt file2.txt file3.txt
git init
echo 'change 1' > file1.txt
git add file1.txt
git commit -m 'add file1'
git tag 0.0.1
echo 'change 2' > file2.txt
git add file2.txt
git commit -m 'add file2'
git tag 0.0.2
echo 'change 3' > file3.txt
git add file3.txt
git commit -m 'add file3'
git tag 0.0.3
git checkout -b a_branch
echo 'change 4' > file4.txt
git add file4.txt
git commit -m 'add file4'
echo 'change 5' > file5.txt
git add file5.txt
git commit -m 'add file5'
echo 'change 6' > file6.txt
git add file6.txt
git commit -m 'add file6'
git checkout master
cd ..
git --git-dir=testrepo/.git config core.bare true
cp -r testrepo/.git testrepo.git
rm -rf testrepo
cd testrepo.git
touch git-daemon-export-ok
git update-server-info
-----BEGIN CERTIFICATE-----
MIICATCCAWoCCQDRobnOvvkStDANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
cyBQdHkgTHRkMB4XDTE1MDQwODE3MjM1NVoXDTI1MDQwNTE3MjM1NVowRTELMAkG
A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0
IFdpZGdpdHMgUHR5IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyRTv
uX6328aQ5Auc8PI+xNaCiE0UZNYcs+xq3AEkR/Tnz0HGXdx3+PnFG7MIRSS65hXA
VGenZk3wP4vNIe9gu+G9jtOFTJOgoOBUnJ/Hcs79Zgcmz3cAWQpqww+CZpyngUDS
msZ5HoEbNS+qaIron3IrYCgPsy1BHFs5ze7JrtcCAwEAATANBgkqhkiG9w0BAQUF
AAOBgQCaYVv8WbFbrnLMOcyjE7GjSmVh68fEN+AqntZa1Z5GOv6OQIN9mVSoNxWo
lb/9xmldfMQThgKckHHvB5Q9kf923nMQZOi8yxyaoeYWrkglkFFU/sdF6yuFBdUU
D+rXmHnS754FLTGDzESmlRVUCYuwVgrRdm+P+wu2+lZT3x85VA==
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDJFO+5frfbxpDkC5zw8j7E1oKITRRk1hyz7GrcASRH9OfPQcZd
3Hf4+cUbswhFJLrmFcBUZ6dmTfA/i80h72C74b2O04VMk6Cg4FScn8dyzv1mBybP
dwBZCmrDD4JmnKeBQNKaxnkegRs1L6poiuifcitgKA+zLUEcWznN7smu1wIDAQAB
AoGAQPnD8OOyk5DZVuctwmn0wHQ0X8jQczkAs18MtKSlzZ6knUM6zy+jkM9c0vOK
E5Wn0xtqN5v66sL6g/4vvex1DA5Q6YsXvZ48VpVliZXXK/1pdTv0qwMyHdlBhmgJ
MhnZbyNy61QHdOTsWDR1YrELpDyFMJ9cZZD0NOnsuhd2DbECQQDq7W/zlJBZPWNR
ab2dP+HLpm/PiEBT13SuEEskh3GEEfZlwz/cGu0Z8DHA4E3Z60KFjwgnc92GNFMg
m0t3hHtpAkEA2x5PsDxBk9sWwdIvu57vjQLdotvAfyb+W9puIaZS1JRSVLTsUVEj
Y0KxgsPHtcjrVoN//zGymn4ePxWOzlrQPwJBAN5thEuZY7o6dyiD9zVFYKGSqdZS
aKV5H04Wuy6Q1pd28lWTMYlSLR8b3d+B//PN3SPbMps4BoukSvhaUG+OjdECQFzF
KZIBAPa7pJftCH6UHPIDy5ifF5H+DWUQRt6CT8FnBrCMZR1MkAH/g65Me6pwZYsc
Y73E6cxVJzMoSmz9r/sCQQCOhPflFCxZ23ocsuRBo9O/mMUDaLoHZXWuJ2DqAUN2
mS6UUR/lpyc7Cmy0VOyhS8783D7MUfji5ddfVxb5tWgm
-----END RSA PRIVATE KEY-----
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'clones a remote repo' do
before(:all) do
my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
shell("mkdir -p #{tmpdir}") # win test
end
after(:all) do
shell("rm -rf #{tmpdir}/vcsrepo")
end
context 'force with a remote' do
it 'clones from remote' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/vcsrepo":
ensure => present,
provider => git,
source => 'https://github.com/puppetlabs/puppetlabs-vcsrepo',
force => true,
}
EOS
# Run it twice to test for idempotency
apply_manifest(pp, :catch_failures => true)
# need to create a file to make sure we aren't destroying the repo
# because fun fact, if you call destroy/create in 'retrieve' puppet won't
# register that any changes happen, because that method isn't supposed to
# be making any changes.
shell("touch #{tmpdir}/vcsrepo/foo")
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/vcsrepo/foo") do
it { is_expected.to be_file }
end
end
context 'force over an existing repo' do
it 'clones from remote' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/vcsrepo":
ensure => present,
provider => git,
source => 'https://github.com/puppetlabs/puppetlabs-vcsrepo',
force => true,
}
EOS
pp2 = <<-EOS
vcsrepo { "#{tmpdir}/vcsrepo":
ensure => present,
provider => git,
source => 'https://github.com/puppetlabs/puppetlabs-stdlib',
force => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
# create a file to make sure we're destroying the repo
shell("touch #{tmpdir}/vcsrepo/foo")
apply_manifest(pp2, :catch_failures => true)
end
describe file("#{tmpdir}/vcsrepo/foo") do
it { is_expected.to_not be_file }
end
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'clones a remote repo' do
before(:all) do
my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
shell("mkdir -p #{tmpdir}") # win test
end
after(:all) do
shell("rm -rf #{tmpdir}/vcsrepo")
end
context 'ensure latest with no revision' do
it 'clones from default remote' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/vcsrepo":
ensure => present,
provider => git,
source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git",
}
EOS
apply_manifest(pp, :catch_failures => true)
shell("cd #{tmpdir}/vcsrepo; /usr/bin/git reset --hard HEAD~2")
end
it 'updates' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/vcsrepo":
ensure => latest,
provider => git,
source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git",
}
EOS
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'clones with special characters' do
before(:all) do
my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
shell("mkdir -p #{tmpdir}") # win test
scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
shell("cd #{tmpdir} && ./create_git_repo.sh")
end
after(:all) do
shell("rm -rf #{tmpdir}/testrepo.git")
end
context 'as a user with ssh' do
before(:all) do
# create user
pp = <<-EOS
group { 'testuser-ssh':
ensure => present,
}
user { 'testuser-ssh':
ensure => present,
groups => 'testuser-ssh',
managehome => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
# create ssh keys
shell('mkdir -p /home/testuser-ssh/.ssh')
shell('echo -e \'y\n\'|ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
# copy public key to authorized_keys
shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
shell("chown testuser-ssh:testuser-ssh #{tmpdir}")
end
it 'applies the manifest' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_user_ssh":
ensure => present,
provider => git,
source => "git+ssh://testuser-ssh@localhost#{tmpdir}/testrepo.git",
user => 'testuser-ssh',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
after(:all) do
pp = <<-EOS
user { 'testuser-ssh':
ensure => absent,
managehome => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'MODULES-660' do
before(:all) do
# Create testrepo.git
my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
shell("mkdir -p #{tmpdir}") # win test
scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
shell("cd #{tmpdir} && ./create_git_repo.sh")
# Configure testrepo.git as upstream of testrepo
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo":
ensure => present,
provider => git,
revision => 'a_branch',
source => "file://#{tmpdir}/testrepo.git",
}
EOS
apply_manifest(pp, :catch_failures => true)
end
after(:all) do
shell("rm -rf #{tmpdir}/testrepo.git")
end
shared_examples 'switch to branch/tag/sha' do
it 'pulls the new branch commits' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo":
ensure => latest,
provider => git,
revision => 'a_branch',
source => "file://#{tmpdir}/testrepo.git",
}
EOS
apply_manifest(pp, :expect_changes => true)
apply_manifest(pp, :catch_changes => true)
end
it 'checks out the tag' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo":
ensure => latest,
provider => git,
revision => '0.0.3',
source => "file://#{tmpdir}/testrepo.git",
}
EOS
apply_manifest(pp, :expect_changes => true)
apply_manifest(pp, :catch_changes => true)
end
it 'checks out the sha' do
sha = shell("cd #{tmpdir}/testrepo && git rev-parse origin/master").stdout.chomp
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo":
ensure => latest,
provider => git,
revision => '#{sha}',
source => "file://#{tmpdir}/testrepo.git",
}
EOS
apply_manifest(pp, :expect_changes => true)
apply_manifest(pp, :catch_changes => true)
end
end
context 'on branch' do
before :each do
shell("cd #{tmpdir}/testrepo && git checkout a_branch")
shell("cd #{tmpdir}/testrepo && git reset --hard 0.0.2")
end
it_behaves_like 'switch to branch/tag/sha'
end
context 'on tag' do
before :each do
shell("cd #{tmpdir}/testrepo && git checkout 0.0.1")
end
it_behaves_like 'switch to branch/tag/sha'
end
context 'on detached head' do
before :each do
shell("cd #{tmpdir}/testrepo && git checkout 0.0.2")
shell("cd #{tmpdir}/testrepo && git checkout HEAD~1")
end
it_behaves_like 'switch to branch/tag/sha'
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'clones a remote repo' do
before(:all) do
my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
shell("mkdir -p #{tmpdir}") # win test
end
after(:all) do
shell("rm -rf #{tmpdir}/vcsrepo")
end
context 'clone with single remote' do
it 'clones from default remote' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/vcsrepo":
ensure => present,
provider => git,
source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git",
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it "git config output should contain the remote" do
shell("/usr/bin/git config -l -f #{tmpdir}/vcsrepo/.git/config") do |r|
expect(r.stdout).to match(/remote.origin.url=https:\/\/github.com\/puppetlabs\/puppetlabs-vcsrepo.git/)
end
end
after(:all) do
shell("rm -rf #{tmpdir}/vcsrepo")
end
end
context 'clone with multiple remotes' do
it 'clones from default remote and adds 2 remotes to config file' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/vcsrepo":
ensure => present,
provider => git,
source => {"origin" => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git", "test1" => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git"},
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it "git config output should contain the remotes" do
shell("/usr/bin/git config -l -f #{tmpdir}/vcsrepo/.git/config") do |r|
expect(r.stdout).to match(/remote.origin.url=https:\/\/github.com\/puppetlabs\/puppetlabs-vcsrepo.git/)
expect(r.stdout).to match(/remote.test1.url=https:\/\/github.com\/puppetlabs\/puppetlabs-vcsrepo.git/)
end
end
after(:all) do
shell("rm -rf #{tmpdir}/vcsrepo")
end
end
end
HOSTS:
centos-7-x64:
roles:
- agent
- default
platform: el-7-x86_64
hypervisor: vagrant
box: puppetlabs/centos-7.2-64-nocm
CONFIG:
type: foss
HOSTS:
debian-8-x64:
roles:
- agent
- default
platform: debian-8-amd64
hypervisor: vagrant
box: puppetlabs/debian-8.2-64-nocm
CONFIG:
type: foss
HOSTS:
ubuntu-1404-x64:
roles:
- agent
- default
platform: ubuntu-14.04-amd64
hypervisor: vagrant
box: puppetlabs/ubuntu-14.04-64-nocm
CONFIG:
type: foss
HOSTS:
centos-7-x64:
platform: el-7-x86_64
hypervisor: docker
image: centos:7
docker_preserve_image: true
docker_cmd: '["/usr/sbin/init"]'
# install various tools required to get the image up to usable levels
docker_image_commands:
- 'yum install -y crontabs tar wget openssl sysvinit-tools iproute which initscripts'
CONFIG:
trace_limit: 200
HOSTS:
debian-8-x64:
platform: debian-8-amd64
hypervisor: docker
image: debian:8
docker_preserve_image: true
docker_cmd: '["/sbin/init"]'
docker_image_commands:
- 'apt-get update && apt-get install -y net-tools wget locales strace lsof && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen'
CONFIG:
trace_limit: 200
HOSTS:
ubuntu-1404-x64:
platform: ubuntu-14.04-amd64
hypervisor: docker
image: ubuntu:14.04
docker_preserve_image: true
docker_cmd: '["/sbin/init"]'
docker_image_commands:
# ensure that upstart is booting correctly in the container
- 'rm /usr/sbin/policy-rc.d && rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl && apt-get update && apt-get install -y net-tools wget && locale-gen en_US.UTF-8'
CONFIG:
trace_limit: 200
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'remove a repo' do
it 'creates a blank repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_deleted":
ensure => present,
provider => git,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'removes a repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_deleted":
ensure => absent,
provider => git,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file("#{tmpdir}/testrepo_deleted") do
it { is_expected.not_to be_directory }
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'does not remove a repo if noop' do
it 'creates a blank repo' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_noop_deleted":
ensure => present,
provider => git,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'does not remove a repo if noop' do
pp = <<-EOS
vcsrepo { "#{tmpdir}/testrepo_noop_deleted":
ensure => absent,
provider => git,
force => true,
}
EOS
apply_manifest(pp, :catch_failures => true, :noop => true, :verbose => false)
end
describe file("#{tmpdir}/testrepo_noop_deleted") do
it { is_expected.to be_directory }
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'subversion :includes tests on SVN version >= 1.7', :unless => (
(fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') =~ /^(5|6)$/) or
(fact('osfamily') == 'Debian' && fact('operatingsystemmajrelease') =~ /^(6|7|10\.04|12\.04)$/) or
(fact('osfamily') == 'SLES')
) do
before(:all) do
shell("mkdir -p #{tmpdir}") # win test
end
after(:all) do
shell("rm -rf #{tmpdir}/svnrepo")
end
context "include paths" do
it "can checkout specific paths from svn" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/README', 'obsolete-notes',],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/difftools") do
it { should be_directory }
end
describe file("#{tmpdir}/svnrepo/difftools/README") do
its(:md5sum) { should eq '540241e9d5d4740d0ef3d27c3074cf93' }
end
describe file("#{tmpdir}/svnrepo/difftools/pics") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/obsolete-notes") do
it { should be_directory }
end
describe file("#{tmpdir}/svnrepo/obsolete-notes/draft-korn-vcdiff-01.txt") do
its(:md5sum) { should eq '37019f808e1af64864853a67526cfe19' }
end
describe file("#{tmpdir}/svnrepo/obsolete-notes/vcdiff-karlnotes") do
its(:md5sum) { should eq '26e23ff6a156de14aebd1099e23ac2d8' }
end
describe file("#{tmpdir}/svnrepo/guis") do
it { should_not exist }
end
end
context "add include paths" do
it "can add paths to includes" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/README', 'obsolete-notes', 'guis/pics', 'difftools/pics/README'],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/guis/pics/README") do
its(:md5sum) { should eq '62bdc9180684042fe764d89c9beda40f' }
end
describe file("#{tmpdir}/svnrepo/difftools/pics/README") do
its(:md5sum) { should eq 'bad02dfc3cb96bf5cadd59bf4fe3e00e' }
end
end
context "remove include paths" do
it "can remove paths (and empty parent directories) from includes" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/pics/README', 'obsolete-notes',],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/guis/pics/README") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/guis/pics") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/guis") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/difftools/pics/README") do
its(:md5sum) { should eq 'bad02dfc3cb96bf5cadd59bf4fe3e00e' }
end
describe file("#{tmpdir}/svnrepo/difftools/README") do
it { should_not exist }
end
end
context "changing revisions" do
it "can change revisions" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/README', 'obsolete-notes',],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1700000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe command("svn info #{tmpdir}/svnrepo") do
its(:stdout) { should match( /.*Revision: 1700000.*/ ) }
end
describe command("svn info #{tmpdir}/svnrepo/difftools/README") do
its(:stdout) { should match( /.*Revision: 1700000.*/ ) }
end
end
end
describe 'subversion :includes tests on SVN version == 1.6', :if => (
(fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') =~ /^(5|6)$/) or
(fact('osfamily') == 'Debian' && fact('operatingsystemmajrelease') =~ /^(6|7|10\.04|12\.04)$/)
) do
after(:all) do
shell("rm -rf #{tmpdir}/svnrepo")
end
context "include paths" do
it "can checkout specific paths from svn" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/README', 'obsolete-notes',],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/difftools") do
it { should be_directory }
end
describe file("#{tmpdir}/svnrepo/difftools/README") do
its(:md5sum) { should eq '540241e9d5d4740d0ef3d27c3074cf93' }
end
describe file("#{tmpdir}/svnrepo/difftools/pics") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/obsolete-notes") do
it { should be_directory }
end
describe file("#{tmpdir}/svnrepo/obsolete-notes/draft-korn-vcdiff-01.txt") do
its(:md5sum) { should eq '37019f808e1af64864853a67526cfe19' }
end
describe file("#{tmpdir}/svnrepo/obsolete-notes/vcdiff-karlnotes") do
its(:md5sum) { should eq '26e23ff6a156de14aebd1099e23ac2d8' }
end
describe file("#{tmpdir}/svnrepo/guis") do
it { should_not exist }
end
end
context "add include paths" do
it "can add paths to includes" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/README', 'obsolete-notes', 'guis/pics', 'difftools/pics/README'],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/guis/pics/README") do
its(:md5sum) { should eq '62bdc9180684042fe764d89c9beda40f' }
end
describe file("#{tmpdir}/svnrepo/difftools/pics/README") do
its(:md5sum) { should eq 'bad02dfc3cb96bf5cadd59bf4fe3e00e' }
end
end
context "remove include paths" do
it "can remove directory paths (and empty parent directories) from includes, but not files with siblings" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/pics/README', 'obsolete-notes',],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
end
describe file("#{tmpdir}/svnrepo/guis/pics/README") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/guis/pics") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/guis") do
it { should_not exist }
end
describe file("#{tmpdir}/svnrepo/difftools/pics/README") do
its(:md5sum) { should eq 'bad02dfc3cb96bf5cadd59bf4fe3e00e' }
end
describe file("#{tmpdir}/svnrepo/difftools/README") do
its(:md5sum) { should eq '540241e9d5d4740d0ef3d27c3074cf93' }
end
end
context "changing revisions" do
it "can change revisions" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/README', 'obsolete-notes',],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1700000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe command("svn info #{tmpdir}/svnrepo") do
its(:stdout) { should match( /.*Revision: 1700000.*/ ) }
end
describe command("svn info #{tmpdir}/svnrepo/difftools/README") do
its(:stdout) { should match( /.*Revision: 1700000.*/ ) }
end
end
end
describe 'subversion :includes tests on SVN version < 1.6', :if =>
(fact('osfamily') == 'SLES') do
context "include paths" do
it "fails when SVN version < 1.6" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
includes => ['difftools/README', 'obsolete-notes',],
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Expect error when svn < 1.6 and includes is used
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/Includes option is not available for SVN versions < 1.6. Version installed:/)
end
end
end
end
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('vcsrepo')
describe 'subversion tests' do
before(:each) do
shell("mkdir -p #{tmpdir}") # win test
end
context "plain checkout" do
it "can checkout svn" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
source => "http://svn.apache.org/repos/asf/subversion/svn-logos",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/.svn") do
it { is_expected.to be_directory }
end
describe file("#{tmpdir}/svnrepo/images/tyrus-svn2.png") do
its(:md5sum) { should eq '6b20cbc4a793913190d1548faad1ae80' }
end
after(:all) do
shell("rm -rf #{tmpdir}/svnrepo")
end
end
context "handles revisions" do
it "can checkout a specific revision of svn" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1000000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/.svn") do
it { is_expected.to be_directory }
end
describe command("svn info #{tmpdir}/svnrepo") do
its(:stdout) { should match( /.*Revision: 1000000.*/ ) }
end
describe file("#{tmpdir}/svnrepo/difftools/README") do
its(:md5sum) { should eq '540241e9d5d4740d0ef3d27c3074cf93' }
end
end
context "handles revisions" do
it "can switch revisions" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
source => "http://svn.apache.org/repos/asf/subversion/developer-resources",
revision => 1700000,
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/.svn") do
it { is_expected.to be_directory }
end
describe command("svn info #{tmpdir}/svnrepo") do
its(:stdout) { should match( /.*Revision: 1700000.*/ ) }
end
after(:all) do
shell("rm -rf #{tmpdir}/svnrepo")
end
end
context "switching sources" do
it "can checkout tag=1.9.0" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
source => "http://svn.apache.org/repos/asf/subversion/tags/1.9.0",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/.svn") do
it { is_expected.to be_directory }
end
describe file("#{tmpdir}/svnrepo/STATUS") do
its(:md5sum) { should eq '286708a30aea43d78bc2b11f3ac57fff' }
end
end
context "switching sources" do
it "can switch to tag=1.9.4" do
pp = <<-EOS
vcsrepo { "#{tmpdir}/svnrepo":
ensure => present,
provider => svn,
source => "http://svn.apache.org/repos/asf/subversion/tags/1.9.4",
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/svnrepo/.svn") do
it { is_expected.to be_directory }
end
describe file("#{tmpdir}/svnrepo/STATUS") do
its(:md5sum) { should eq '7f072a1c0e2ba37ca058f65e554de95e' }
end
end
end
revision-id: menesis@pov.lt-20100309191856-4wmfqzc803fj300x
date: 2010-03-09 21:18:56 +0200
build-date: 2010-03-14 00:42:43 -0800
revno: 2634
branch-nick: mytest
feature/foo
feature/bar
feature/baz
feature/quux
only/local
* master
refactor/foo
origin/HEAD
origin/feature/foo
origin/feature/bar
origin/feature/baz
origin/feature/quux
origin/only/remote
origin/master
feature/foo
* feature/bar
feature/baz
feature/quux
only/local
master
refactor/foo
origin/HEAD
origin/feature/foo
origin/feature/bar
origin/feature/baz
origin/feature/quux
origin/only/remote
origin/master
feature/foo
feature/bar
feature/baz
feature/quux
only/local
master
* (no branch)
refactor/foo
origin/HEAD
origin/feature/foo
origin/feature/bar
origin/feature/baz
origin/feature/quux
origin/only/remote
origin/master
changeset: 3:34e6012c783a
parent: 2:21ea4598c962
parent: 1:9d0ff0028458
user: Test User <test.user@example.com>
date: Fri Aug 07 13:13:02 2009 -0400
summary: merge
tip 1019:bca3f20b249b
0.9.1 1017:76ce7cca95d8
0.9 1001:dbaa6f4ec585
0.8 839:65b66ac0fc83
0.7.1 702:e1357f00129f
0.7 561:7b2af3b4c968
0.6.3 486:e38077f4e4aa
0.6.2 405:07bb099b7b10
0.6.1 389:93750f3fbbe2
0.6 369:34e6012c783a
0.5.3 321:5ffa6ae7e699
0.5.2 318:fdc2c2e4cebe
0.5.1 315:33a5ea0cbe7a
0.5 313:47490716f4c9
0.4 240:47fa3a14cc63
0.3.1 132:bc231db18e1c
0.3 130:661615e510dd
0.2 81:f98d13b442f6
Path: .
URL: http://example.com/svn/trunk
Repository Root: http://example.com/svn
Repository UUID: 75246ace-e253-0410-96dd-a7613ca8dc81
Revision: 4
Node Kind: directory
Schedule: normal
Last Changed Author: jon
Last Changed Rev: 3
Last Changed Date: 2008-08-07 11:34:25 -0700 (Thu, 07 Aug 2008)
#This file is generated by ModuleSync, do not edit.
require 'puppetlabs_spec_helper/module_spec_helper'
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
RSpec.configure do |c|
c.before :each do
Puppet.settings[:strict] = :error
end
end
end
# put local configuration and setup into spec_helper_local
begin
require 'spec_helper_local'
rescue LoadError
end
require 'beaker-rspec'
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'
run_puppet_install_helper
install_ca_certs unless ENV['PUPPET_INSTALL_TYPE'] =~ /pe/i
install_module_on(hosts)
install_module_dependencies_on(hosts)
RSpec.configure do |c|
# Readable test descriptions
c.formatter = :documentation
# Configure all nodes in nodeset
c.before :suite do
# ensure test dependencies are available on all hosts
hosts.each do |host|
case fact_on(host, 'osfamily')
when 'RedHat'
if fact_on(host, 'operatingsystemmajrelease') == '5'
will_install_git = on(host, 'which git', :acceptable_exit_codes => [0,1]).exit_code == 1
if will_install_git
on host, puppet('module install stahnma-epel')
apply_manifest_on( host, 'include epel' )
end
end
install_package(host, 'git')
install_package(host, 'subversion')
when 'Debian'
install_package(host, 'git-core')
install_package(host, 'subversion')
else
if !check_for_package(host, 'git')
puts "Git package is required for this module"
exit
end
if !check_for_package(host, 'subversion')
puts "Subversion package is required for this module"
exit
end
end
on host, 'git config --global user.email "root@localhost"'
on host, 'git config --global user.name "root"'
end
end
end
require 'support/filesystem_helpers'
require 'support/fixture_helpers'
RSpec.configure do |c|
c.include FilesystemHelpers
c.include FixtureHelpers
end
module FilesystemHelpers
def expects_chdir(path = resource.value(:path))
Dir.expects(:chdir).with(path).at_least_once.yields
end
def expects_mkdir(path = resource.value(:path))
Dir.expects(:mkdir).with(path).at_least_once
end
def expects_rm_rf(path = resource.value(:path))
FileUtils.expects(:rm_rf).with(path)
end
def expects_directory?(returns = true, path = resource.value(:path))
File.expects(:directory?).with(path).returns(returns)
end
end
module FixtureHelpers
def fixture(name, ext = '.txt')
File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name.to_s + ext))
end
end
require "spec_helper"
describe Facter::Util::Fact do
before {
Facter.clear
}
describe "vcsrepo_svn_ver" do
context 'with valid value' do
before :each do
Facter::Core::Execution
.stubs(:execute)
.with('svn --version --quiet')
.returns('1.7.23')
end
it {
expect(Facter.fact(:vcsrepo_svn_ver).value).to eq('1.7.23')
}
end
end
end
\ No newline at end of file
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:bzr) do
let(:resource) { Puppet::Type.type(:vcsrepo).new({
:name => 'test',
:ensure => :present,
:provider => :bzr,
:revision => '2634',
:source => 'lp:do',
:path => '/tmp/test',
})}
let(:provider) { resource.provider }
before :each do
Puppet::Util.stubs(:which).with('bzr').returns('/usr/bin/bzr')
end
describe 'creating' do
context 'with defaults' do
it "should execute 'bzr clone -r' with the revision" do
provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path))
provider.create
end
end
context 'without revision' do
it "should just execute 'bzr clone' without a revision" do
resource.delete(:revision)
provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path))
provider.create
end
end
context 'without source' do
it "should execute 'bzr init'" do
resource.delete(:source)
provider.expects(:bzr).with('init', resource.value(:path))
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
provider.destroy
end
end
describe "checking existence" do
it "should execute bzr status on the path" do
File.expects(:directory?).with(resource.value(:path)).returns(true)
provider.expects(:bzr).with('status', resource[:path])
provider.exists?
end
end
describe "checking the revision property" do
before do
expects_chdir
provider.expects(:bzr).with('version-info').returns(File.read(fixtures('bzr_version_info.txt')))
@current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
end
context "when given a non-revid as the resource revision" do
context "when its revid is not different than the current revid" do
it "should return the ref" do
resource[:revision] = '2634'
provider.expects(:bzr).with('revision-info', '2634').returns("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n")
expect(provider.revision).to eq(resource.value(:revision))
end
end
context "when its revid is different than the current revid" do
it "should return the current revid" do
resource[:revision] = '2636'
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n")
expect(provider.revision).to eq(@current_revid)
end
end
end
context "when given a revid as the resource revision" do
context "when it is the same as the current revid" do
it "should return it" do
resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n")
expect(provider.revision).to eq(resource.value(:revision))
end
end
context "when it is not the same as the current revid" do
it "should return the current revid" do
resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n")
expect(provider.revision).to eq(@current_revid)
end
end
end
end
describe "setting the revision property" do
it "should use 'bzr update -r' with the revision" do
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:bzr).with('update', '-r', 'somerev')
provider.revision = 'somerev'
end
end
describe "checking the source property" do
it "should use 'bzr info'" do
expects_chdir
resource[:source] = 'http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/'
provider.expects(:bzr).with('info').returns(' parent branch: http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/')
expect(provider.source).to eq(resource.value(:source))
end
end
describe "setting the source property" do
it "should call 'create'" do
resource[:source] = 'http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/'
provider.expects(:create)
provider.source = resource.value(:source)
end
end
end
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:cvs) do
let(:resource) { Puppet::Type.type(:vcsrepo).new({
:name => 'test',
:ensure => :present,
:provider => :cvs,
:revision => '2634',
:source => ':pserver:anonymous@cvs.sv.gnu.org:/sources/cvs/',
:path => '/tmp/test',
})}
let(:provider) { resource.provider }
before :each do
Puppet::Util.stubs(:which).with('cvs').returns('/usr/bin/cvs')
end
describe 'creating' do
context "with a source" do
it "should execute 'cvs checkout'" do
resource[:source] = ':ext:source@example.com:/foo/bar'
resource[:revision] = 'an-unimportant-value'
expects_chdir('/tmp')
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', '.'], :custom_environment => {}, :combine => true, :failonfail => true)
provider.create
end
it "should execute 'cvs checkout' as user 'muppet'" do
resource[:source] = ':ext:source@example.com:/foo/bar'
resource[:revision] = 'an-unimportant-value'
resource[:user] = 'muppet'
expects_chdir('/tmp')
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', '.'], :uid => 'muppet', :custom_environment => {}, :combine => true, :failonfail => true)
provider.create
end
it "should just execute 'cvs checkout' without a revision" do
resource[:source] = ':ext:source@example.com:/foo/bar'
resource.delete(:revision)
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), '.'], :custom_environment => {}, :combine => true, :failonfail => true)
provider.create
end
context "with a compression" do
it "should just execute 'cvs checkout' without a revision" do
resource[:source] = ':ext:source@example.com:/foo/bar'
resource[:compression] = '3'
resource.delete(:revision)
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), '.'], :custom_environment => {}, :combine => true, :failonfail => true)
provider.create
end
end
end
context "when a source is not given" do
it "should execute 'cvs init'" do
resource.delete(:source)
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:path), 'init'], :custom_environment => {}, :combine => true, :failonfail => true)
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
provider.destroy
end
end
describe "checking existence" do
context "with a source value" do
it "should run 'cvs status'" do
resource[:source] = ':ext:source@example.com:/foo/bar'
File.expects(:directory?).with(File.join(resource.value(:path), 'CVS')).returns(true)
expects_chdir
Puppet::Util::Execution.expects(:execute).with([:cvs, '-nqd', resource.value(:path), 'status', '-l'], :custom_environment => {}, :combine => true, :failonfail => true)
provider.exists?
end
end
context "without a source value" do
it "should check for the CVSROOT directory and config file" do
resource.delete(:source)
File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT')).returns(true)
File.expects(:exists?).with(File.join(resource.value(:path), 'CVSROOT', 'config,v')).returns(true)
provider.exists?
end
end
end
describe "checking the revision property" do
before do
@tag_file = File.join(resource.value(:path), 'CVS', 'Tag')
end
context "when CVS/Tag exists" do
before do
@tag = 'TAG'
File.expects(:exist?).with(@tag_file).returns(true)
end
it "should read CVS/Tag" do
File.expects(:read).with(@tag_file).returns("T#{@tag}")
expect(provider.revision).to eq(@tag)
end
end
context "when CVS/Tag does not exist" do
before do
File.expects(:exist?).with(@tag_file).returns(false)
end
it "assumes HEAD" do
expect(provider.revision).to eq('HEAD')
end
end
end
describe "when setting the revision property" do
before do
@tag = 'SOMETAG'
end
it "should use 'cvs update -dr'" do
expects_chdir
Puppet::Util::Execution.expects(:execute).with([:cvs, 'update', '-dr', @tag, '.'], :custom_environment => {}, :combine => true, :failonfail => true)
provider.revision = @tag
end
end
describe "checking the source property" do
it "should read the contents of file 'CVS/Root'" do
File.expects(:read).with(File.join(resource.value(:path), 'CVS', 'Root')).
returns(':pserver:anonymous@cvs.sv.gnu.org:/sources/cvs/')
expect(provider.source).to eq(resource.value(:source))
end
end
describe "setting the source property" do
it "should call 'create'" do
provider.expects(:create)
provider.source = resource.value(:source)
end
end
describe "checking the module property" do
before do
resource[:module] = 'ccvs'
end
it "should read the contents of file 'CVS/Repository'" do
File.expects(:read).with(File.join(resource.value(:path), 'CVS', 'Repository')).
returns('ccvs')
expect(provider.module).to eq(resource.value(:module))
end
end
describe "setting the module property" do
it "should call 'create'" do
provider.expects(:create)
provider.module = resource.value(:module)
end
end
end
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:git) do
def branch_a_list(include_branch = nil?)
<<branches
end
#{"* master" unless include_branch.nil?}
#{"* " + include_branch unless !include_branch}
remote/origin/master
remote/origin/foo
branches
end
let(:resource) { Puppet::Type.type(:vcsrepo).new({
:name => 'test',
:ensure => :present,
:provider => :git,
:revision => '2634',
:source => 'git@repo',
:path => '/tmp/test',
:force => false
})}
let(:provider) { resource.provider }
before :each do
Puppet::Util.stubs(:which).with('git').returns('/usr/bin/git')
end
context 'creating' do
context "with an ensure of present" do
context "with a revision that is a remote branch" do
it "should execute 'git clone' and 'git checkout -b'" do
resource[:revision] = 'only/remote'
Dir.expects(:chdir).with('/').at_least_once.yields
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
context "with a remote not named 'origin'" do
it "should execute 'git clone --origin not_origin" do
resource[:remote] = 'not_origin'
Dir.expects(:chdir).with('/').at_least_once.yields
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', '--origin', 'not_origin', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.expects(:update_remote_url).with("not_origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
context "with shallow clone enable" do
it "should execute 'git clone --depth 1'" do
resource[:revision] = 'only/remote'
resource[:depth] = 1
Dir.expects(:chdir).with('/').at_least_once.yields
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', '--depth', '1', '--branch', resource.value(:revision),resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
context "with a revision that is not a remote branch" do
it "should execute 'git clone' and 'git reset --hard'" do
resource[:revision] = 'a-commit-or-tag'
Dir.expects(:chdir).with('/').at_least_once.yields
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
it "should execute 'git clone' and submodule commands" do
resource.delete(:revision)
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.expects(:update_remotes)
provider.create
end
end
context "when a source is not given" do
context "when the path does not exist" do
it "should execute 'git init'" do
resource[:ensure] = :present
resource.delete(:source)
expects_mkdir
expects_chdir
expects_directory?(false)
provider.expects(:git).with('init')
provider.create
end
end
context "when the path is not empty and not a repository" do
it "should raise an exception" do
provider.expects(:path_exists?).returns(true)
provider.expects(:path_empty?).returns(false)
expect { provider.create }.to raise_error(Puppet::Error)
end
end
end
end
context "with an ensure of bare" do
context "with revision" do
it "should raise an error" do
resource[:ensure] = :bare
expect { provider.create }.to raise_error Puppet::Error, /cannot set a revision.+bare/i
end
end
context "without revision" do
it "should just execute 'git clone --bare'" do
resource[:ensure] = :bare
resource.delete(:revision)
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
provider.expects(:update_remotes)
provider.create
end
end
context "without a source" do
it "should execute 'git init --bare'" do
resource[:ensure] = :bare
resource.delete(:source)
resource.delete(:revision)
File.expects(:directory?).with(File.join(resource.value(:path), '.git'))
expects_chdir
expects_mkdir
expects_directory?(false)
provider.expects(:git).with('init', '--bare')
provider.create
end
end
end
context "with an ensure of mirror" do
context "with revision" do
it "should raise an error" do
resource[:ensure] = :mirror
expect { provider.create }.to raise_error Puppet::Error, /cannot set a revision.+bare/i
end
end
context "without revision" do
it "should just execute 'git clone --mirror'" do
resource[:ensure] = :mirror
resource.delete(:revision)
Dir.expects(:chdir).with('/').at_least_once.yields
provider.expects(:git).with('clone', '--mirror', resource.value(:source), resource.value(:path))
provider.expects(:update_remotes)
provider.create
end
end
context "without a source" do
it "should raise an exeption" do
resource[:ensure] = :mirror
resource.delete(:source)
resource.delete(:revision)
expect { provider.create }.to raise_error Puppet::Error, /cannot init repository with mirror.+try bare/i
end
end
end
context "with an ensure of mirror" do
context "with multiple remotes" do
it "should execute 'git clone --mirror' and set all remotes to mirror" do
resource[:ensure] = :mirror
resource[:source] = {"origin" => "git://git@foo.com/bar.git", "other" => "git://git@foo.com/baz.git"}
resource.delete(:revision)
Dir.expects(:chdir).with('/').at_least_once.yields
provider.expects(:git).with('clone', '--mirror', resource.value(:source)['origin'], resource.value(:path))
provider.expects(:update_remotes)
expects_chdir
provider.expects(:git).with('config', 'remote.origin.mirror', 'true')
provider.expects(:git).with('config', 'remote.other.mirror', 'true')
provider.create
end
end
end
context "when the path is a working copy repository" do
it "should clone overtop it using force" do
resource[:force] = true
Dir.expects(:chdir).with('/').at_least_once.yields
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:path_exists?).returns(true)
provider.expects(:path_empty?).returns(false)
provider.destroy
provider.expects(:git).with('clone',resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
context "when the path is not empty and not a repository" do
it "should raise an exception" do
provider.expects(:path_exists?).returns(true)
provider.expects(:path_empty?).returns(false)
## this test can never succeed due to logic in
## create/check_force
# provider.expects(:working_copy_exists?).returns(false)
expect { provider.create }.to raise_error(Puppet::Error)
end
end
end
context "converting repo type" do
context "from working copy to bare" do
it "should convert the repo" do
resource[:ensure] = :bare
provider.expects(:working_copy_exists?).returns(true)
provider.expects(:bare_exists?).returns(false)
FileUtils.expects(:mv).returns(true)
FileUtils.expects(:rm_rf).returns(true)
FileUtils.expects(:mv).returns(true)
expects_chdir
provider.expects(:git).with('config', '--local', '--bool', 'core.bare', 'true')
provider.instance_eval { convert_working_copy_to_bare }
end
end
context "from working copy to mirror" do
it "should convert the repo" do
resource[:ensure] = :mirror
provider.expects(:working_copy_exists?).returns(true)
provider.expects(:bare_exists?).returns(false)
FileUtils.expects(:mv).returns(true)
FileUtils.expects(:rm_rf).returns(true)
FileUtils.expects(:mv).returns(true)
expects_chdir
provider.expects(:git).with('config', '--local', '--bool', 'core.bare', 'true')
provider.expects(:git).with('config', 'remote.origin.mirror', 'true')
provider.instance_eval { convert_working_copy_to_bare }
end
end
context "from bare copy to working copy" do
it "should convert the repo" do
FileUtils.expects(:mv).returns(true)
FileUtils.expects(:mkdir).returns(true)
FileUtils.expects(:mv).returns(true)
expects_chdir
provider.expects(:has_commits?).returns(true)
# If you forget to stub these out you lose 3 hours of rspec work.
provider.expects(:git).
with('config', '--local', '--bool', 'core.bare', 'false').returns(true)
provider.expects(:reset).with('HEAD').returns(true)
provider.expects(:git_with_identity).with('checkout', '--force').returns(true)
provider.expects(:update_owner_and_excludes).returns(true)
provider.expects(:mirror?).returns(false)
provider.instance_eval { convert_bare_to_working_copy }
end
end
context "from mirror to working copy" do
it "should convert the repo" do
FileUtils.expects(:mv).returns(true)
FileUtils.expects(:mkdir).returns(true)
FileUtils.expects(:mv).returns(true)
expects_chdir
provider.expects(:has_commits?).returns(true)
provider.expects(:git).
with('config', '--local', '--bool', 'core.bare', 'false').returns(true)
provider.expects(:reset).with('HEAD').returns(true)
provider.expects(:git_with_identity).with('checkout', '--force').returns(true)
provider.expects(:update_owner_and_excludes).returns(true)
provider.expects(:git).with('config', '--unset', 'remote.origin.mirror')
provider.expects(:mirror?).returns(true)
provider.instance_eval { convert_bare_to_working_copy }
end
end
end
context 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
context "checking the revision property" do
before do
expects_chdir('/tmp/test')
resource[:revision] = 'currentsha'
resource[:source] = 'http://example.com'
provider.stubs(:git).with('config', 'remote.origin.url').returns('')
provider.stubs(:git).with('fetch', 'origin') # FIXME
provider.stubs(:git).with('fetch', '--tags', 'origin')
provider.stubs(:git).with('rev-parse', 'HEAD').returns('currentsha')
provider.stubs(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.stubs(:git).with('tag', '-l').returns("Hello")
end
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.expects(:update_references)
expect(provider.revision).to eq(resource.value(:revision))
end
end
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
provider.expects(:update_references)
expect(provider.revision).to eq(resource.value(:revision))
end
end
context "when its a ref to a remote head" do
it "should return the revision" do
provider.stubs(:git).with('branch', '-a').returns(" remotes/origin/#{resource.value(:revision)}")
provider.expects(:git).with('rev-parse', "origin/#{resource.value(:revision)}").returns("newsha")
provider.expects(:update_references)
expect(provider.revision).to eq(resource.value(:revision))
end
end
context "when its a ref to non existant remote head" do
it "should fail" do
provider.expects(:git).with('branch', '-a').returns(branch_a_list)
provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('')
provider.expects(:update_references)
expect { provider.revision }.to raise_error(Puppet::Error, /not a local or remote ref$/)
end
end
context "when there's no source" do
it 'should return the revision' do
resource.delete(:source)
provider.expects(:git).with('status')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
expect(provider.revision).to eq(resource.value(:revision))
end
end
end
context "setting the revision property" do
before do
expects_chdir
end
context "when it's an existing local branch" do
it "should use 'git fetch' and 'git reset'" do
resource[:revision] = 'feature/foo'
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').at_least_once.returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
context "when it's a remote branch" do
it "should use 'git fetch' and 'git reset'" do
resource[:revision] = 'only/remote'
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').at_least_once.returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
context "when it's a commit or tag" do
it "should use 'git fetch' and 'git reset'" do
resource[:revision] = 'a-commit-or-tag'
provider.expects(:git).with('branch', '-a').at_least_once.returns(fixture(:git_branch_a))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('submodule', 'update', '--init', '--recursive')
provider.revision = resource.value(:revision)
end
end
end
context "checking the source property" do
before do
expects_chdir('/tmp/test')
provider.stubs(:git).with('config', 'remote.origin.url').returns('')
provider.stubs(:git).with('fetch', 'origin') # FIXME
provider.stubs(:git).with('fetch', '--tags', 'origin')
provider.stubs(:git).with('rev-parse', 'HEAD').returns('currentsha')
provider.stubs(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.stubs(:git).with('tag', '-l').returns("Hello")
end
context "when there's a single remote 'origin'" do
it "should return the URL for the remote" do
resource[:source] = 'http://example.com'
provider.expects(:git).with('remote').returns("origin\n")
provider.expects(:git).with('config', '--get', 'remote.origin.url').returns('http://example.com')
expect(provider.source).to eq(resource.value(:source))
end
end
context "when there's more than one remote" do
it "should return the remotes as a hash" do
resource[:source] = {"origin" => "git://git@foo.com/bar.git", "other" => "git://git@foo.com/baz.git"}
provider.expects(:git).with('remote').returns("origin\nother\n")
provider.expects(:git).with('config', '--get', 'remote.origin.url').returns('git://git@foo.com/bar.git')
provider.expects(:git).with('config', '--get', 'remote.other.url').returns('git://git@foo.com/baz.git')
expect(provider.source).to eq(resource.value(:source))
end
end
end
context "updating remotes" do
context "from string to string" do
it "should fail" do
resource[:source] = 'git://git@foo.com/bar.git'
resource[:force] = false
provider.expects(:source).returns('git://git@foo.com/foo.git')
provider.expects(:path_exists?).returns(true)
provider.expects(:path_empty?).returns(false)
expect { provider.source = resource.value(:source) }.to raise_error(Puppet::Error)
end
end
context "from hash to hash" do
it "should add any new remotes, update any existing remotes, remove deleted remotes" do
expects_chdir
resource[:source] = {"origin" => "git://git@foo.com/bar.git", "new_remote" => "git://git@foo.com/baz.git"}
provider.expects(:source).returns(
{'origin' => 'git://git@foo.com/foo.git',
'old_remote' => 'git://git@foo.com/old.git'})
provider.expects(:git).at_least_once.with('config', '-l').returns("remote.old_remote.url=git://git@foo.com/old.git\n", "remote.origin.url=git://git@foo.com/foo.git\n")
provider.expects(:git).with('remote', 'remove', 'old_remote')
provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git')
provider.expects(:git).with('remote', 'add', 'new_remote', 'git://git@foo.com/baz.git')
provider.expects(:git).with('remote','update')
provider.source = resource.value(:source)
end
end
context "from string to hash" do
it "should add any new remotes, update origin remote" do
expects_chdir
resource[:source] = {"origin" => "git://git@foo.com/bar.git", "new_remote" => "git://git@foo.com/baz.git"}
provider.expects(:source).returns('git://git@foo.com/foo.git')
provider.expects(:git).at_least_once.with('config', '-l').returns("remote.origin.url=git://git@foo.com/foo.git\n")
provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git')
provider.expects(:git).with('remote', 'add', 'new_remote', 'git://git@foo.com/baz.git')
provider.expects(:git).with('remote','update')
provider.source = resource.value(:source)
end
end
context "from hash to string" do
it "should update origin remote, remove deleted remotes" do
expects_chdir
resource[:source] = "git://git@foo.com/baz.git"
provider.expects(:source).returns(
{'origin' => 'git://git@foo.com/foo.git',
'old_remote' => 'git://git@foo.com/old.git'})
provider.expects(:git).with('remote', 'remove', 'old_remote')
provider.expects(:git).at_least_once.with('config', '-l').returns("remote.origin.url=git://git@foo.com/foo.git\n", "remote.other.url=git://git@foo.com/bar.git\n")
provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/baz.git')
provider.expects(:git).with('remote','update')
provider.source = resource.value(:source)
end
end
end
context "updating references" do
it "should use 'git fetch --tags'" do
resource.delete(:source)
expects_chdir
provider.expects(:git).with('fetch', 'origin')
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.update_references
end
end
describe 'latest?' do
context 'when true' do
it do
provider.expects(:revision).returns('testrev')
provider.expects(:latest_revision).returns('testrev')
expect(provider.latest?).to be_truthy
end
end
context 'when false' do
it do
provider.expects(:revision).returns('master')
provider.expects(:latest_revision).returns('testrev')
expect(provider.latest?).to be_falsey
end
end
end
end
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:hg) do
let(:resource) { Puppet::Type.type(:vcsrepo).new({
:name => 'test',
:ensure => :present,
:provider => :hg,
:path => '/tmp/vcsrepo',
})}
let(:provider) { resource.provider }
before :each do
Puppet::Util.stubs(:which).with('hg').returns('/usr/bin/hg')
end
describe 'creating' do
context 'with source and revision' do
it "should execute 'hg clone -u' with the revision" do
resource[:source] = 'something'
resource[:revision] = '1'
provider.expects(:hg).with('clone', '-u',
resource.value(:revision),
resource.value(:source),
resource.value(:path))
provider.create
end
end
context 'without revision' do
it "should just execute 'hg clone' without a revision" do
resource[:source] = 'something'
provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path))
provider.create
end
end
context "when a source is not given" do
it "should execute 'hg init'" do
provider.expects(:hg).with('init', resource.value(:path))
provider.create
end
end
context "when basic auth is used" do
it "should execute 'hg clone'" do
resource[:source] = 'something'
resource[:basic_auth_username] = 'user'
resource[:basic_auth_password] = 'pass'
provider.expects(:hg).with('clone',
resource.value(:source),
resource.value(:path),
"--config","\"auth.x.prefix=" + resource.value(:source) + "\"",
"--config","\"auth.x.username=" + resource.value(:basic_auth_username) + "\"",
"--config","\"auth.x.password=" + resource.value(:basic_auth_password) + "\"",
"--config","\"auth.x.schemes=http https" + "\"")
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
expects_directory?(true, resource.value(:path))
provider.expects(:hg).with('status', resource.value(:path))
provider.exists?
end
end
describe "checking the revision property" do
before do
expects_chdir
end
context "when given a non-SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
end
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
resource[:revision] = '0.6'
expect(provider.revision).to eq('0.6')
end
end
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
resource[:revision] = '0.5.3'
expect(provider.revision).to eq('34e6012c783a')
end
end
end
context "when given a SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
end
context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do
it "should return it" do
resource[:revision] = '34e6012c783a'
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
expect(provider.revision).to eq(resource.value(:revision))
end
end
context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do
it "should return the current SHA" do
resource[:revision] = 'not-the-same'
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
expect(provider.revision).to eq('34e6012c783a')
end
end
end
end
describe "setting the revision property" do
before do
@revision = '6aa99e9b3ab1'
end
it "should use 'hg update ---clean -r'" do
expects_chdir
provider.expects(:hg).with('pull')
provider.expects(:hg).with('merge')
provider.expects(:hg).with('update', '--clean', '-r', @revision)
provider.revision = @revision
end
end
describe "checking the source property" do
it "should return the default path" do
resource[:source] = 'http://selenic.com/hg'
expects_chdir
provider.expects(:hg_wrapper).with('paths').returns('default = http://selenic.com/hg')
expect(provider.source).to eq(resource.value(:source))
end
end
describe "setting the source property" do
it "should call 'create'" do
resource[:source] = 'some-example'
provider.expects(:create)
provider.source = resource.value(:source)
end
end
end
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:p4) do
let(:resource) { Puppet::Type.type(:vcsrepo).new({
:name => 'test',
:ensure => :present,
:provider => :p4,
:path => '/tmp/vcsrepo',
})}
let(:provider) { resource.provider }
before :each do
Puppet::Util.stubs(:which).with('p4').returns('/usr/local/bin/p4')
end
spec = {
:input => "Description: Generated by Puppet VCSrepo\nRoot: /tmp/vcsrepo\n\nView:\n",
:marshal => false
}
describe 'creating' do
context 'with source and revision' do
it "should execute 'p4 sync' with the revision" do
resource[:source] = 'something'
resource[:revision] = '1'
ENV['P4CLIENT'] = 'client_ws1'
provider.expects(:p4).with(['client', '-o', 'client_ws1']).returns({})
provider.expects(:p4).with(['client', '-i'], spec)
provider.expects(:p4).with(['sync', resource.value(:source) + "@" + resource.value(:revision)])
provider.create
end
end
context 'without revision' do
it "should just execute 'p4 sync' without a revision" do
resource[:source] = 'something'
ENV['P4CLIENT'] = 'client_ws2'
provider.expects(:p4).with(['client', '-o', 'client_ws2']).returns({})
provider.expects(:p4).with(['client', '-i'], spec)
provider.expects(:p4).with(['sync', resource.value(:source)])
provider.create
end
end
context "when a client and source are not given" do
it "should execute 'p4 client'" do
ENV['P4CLIENT'] = nil
path = resource.value(:path)
host = Facter.value('hostname')
default = "puppet-" + Digest::MD5.hexdigest(path + host)
provider.expects(:p4).with(['client', '-o', default]).returns({})
provider.expects(:p4).with(['client', '-i'], spec)
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
ENV['P4CLIENT'] = 'test_client'
provider.expects(:p4).with(['client', '-d', '-f', 'test_client'])
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
provider.expects(:p4).with(['info'], {:marshal => false}).returns({})
provider.expects(:p4).with(['where', resource.value(:path) + "/..."], {:raise => false}).returns({})
provider.exists?
end
end
describe "checking the source property" do
it "should run 'p4 where'" do
resource[:source] = '//public/something'
provider.expects(:p4).with(['where', resource.value(:path) + '/...'],
{:raise => false}).returns({
'depotFile' => '//public/something'
})
expect(provider.source).to eq(resource.value(:source))
end
end
describe "setting the source property" do
it "should call 'create'" do
resource[:source] = '//public/something'
provider.expects(:create)
provider.source = resource.value(:source)
end
end
end
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:svn) do
let(:resource) { Puppet::Type.type(:vcsrepo).new({
:name => 'test',
:ensure => :present,
:provider => :svn,
:path => '/tmp/vcsrepo',
})}
let(:provider) { resource.provider }
let(:test_paths) { ['path1/file1', 'path2/nested/deep/file2'] }
let(:test_paths_parents) { ['path1', 'path2', 'path2/nested', 'path2/nested/deep'] }
before :each do
Puppet::Util.stubs(:which).with('svn').returns('/usr/bin/svn')
end
describe 'creation/checkout' do
context 'with source and revision' do
it "should execute 'svn checkout' with a revision" do
resource[:source] = 'exists'
resource[:revision] = '1'
provider.expects(:svn).with('--non-interactive', 'checkout', '-r',
resource.value(:revision),
resource.value(:source),
resource.value(:path))
provider.create
end
end
context 'with source' do
it "should just execute 'svn checkout' without a revision" do
resource[:source] = 'exists'
provider.expects(:svn).with('--non-interactive', 'checkout',
resource.value(:source),
resource.value(:path))
provider.create
end
end
context 'with fstype' do
it "should execute 'svnadmin create' with an '--fs-type' option" do
resource[:fstype] = 'ext4'
provider.expects(:svnadmin).with('create', '--fs-type',
resource.value(:fstype),
resource.value(:path))
provider.create
end
end
context 'without fstype' do
it "should execute 'svnadmin create' without an '--fs-type' option" do
provider.expects(:svnadmin).with('create', resource.value(:path))
provider.create
end
end
context "with depth" do
it "should execute 'svn checkout' with a depth" do
resource[:source] = 'exists'
resource[:depth] = 'infinity'
provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'infinity',
resource.value(:source),
resource.value(:path))
provider.create
end
end
context "with trust_server_cert" do
it "should execute 'svn checkout' without a trust-server-cert" do
resource[:source] = 'exists'
resource[:trust_server_cert] = :false
provider.expects(:svn).with('--non-interactive', 'checkout',
resource.value(:source),
resource.value(:path))
provider.create
end
it "should execute 'svn checkout' with a trust-server-cert" do
resource[:source] = 'exists'
resource[:trust_server_cert] = :true
provider.expects(:svn).with('--non-interactive', '--trust-server-cert', 'checkout',
resource.value(:source),
resource.value(:path))
provider.create
end
end
context "with specific include paths" do
it "should raise an error when trying to make a repo" do
resource[:includes] = test_paths
expect { provider.create }.to raise_error(Puppet::Error, /Specifying include paths on a nonexistent repo./)
end
it "should perform a sparse checkout" do
resource[:source] = 'exists'
resource[:includes] = test_paths
Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields
provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'empty',
resource.value(:source),
resource.value(:path))
provider.expects(:svn).with('--non-interactive', 'update', '--depth', 'empty',
*test_paths_parents)
provider.expects(:svn).with('--non-interactive', 'update',
*resource[:includes])
provider.create
end
it "should perform a sparse checkout at a specific revision" do
resource[:source] = 'exists'
resource[:revision] = 1
resource[:includes] = test_paths
Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields
provider.expects(:svn).with('--non-interactive', 'checkout', '-r',
resource.value(:revision),
'--depth', 'empty',
resource.value(:source),
resource.value(:path))
provider.expects(:svn).with('--non-interactive', 'update',
'--depth', 'empty',
'-r', resource.value(:revision),
*test_paths_parents)
provider.expects(:svn).with('--non-interactive', 'update', '-r',
resource.value(:revision),
*resource[:includes])
provider.create
end
it "should perform a sparse checkout with a specific depth" do
resource[:source] = 'exists'
resource[:depth] = 'files'
resource[:includes] = test_paths
Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields
provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'empty',
resource.value(:source),
resource.value(:path))
provider.expects(:svn).with('--non-interactive', 'update',
'--depth', 'empty',
*test_paths_parents)
provider.expects(:svn).with('--non-interactive', 'update',
'--depth', resource.value(:depth),
*resource[:includes])
provider.create
end
it "should perform a sparse checkout at a specific depth and revision" do
resource[:source] = 'exists'
resource[:revision] = 1
resource[:depth] = 'files'
resource[:includes] = test_paths
Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields
provider.expects(:svn).with('--non-interactive', 'checkout', '-r',
resource.value(:revision),
'--depth', 'empty',
resource.value(:source),
resource.value(:path))
provider.expects(:svn).with('--non-interactive', 'update',
'--depth', 'empty',
'-r', resource.value(:revision),
*test_paths_parents)
provider.expects(:svn).with('--non-interactive', 'update',
'-r', resource.value(:revision),
'--depth', resource.value(:depth),
*resource[:includes])
provider.create
end
end
end
describe 'destroying' do
it "should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should run `svn status` on the path when there's a source" do
resource[:source] = 'dummy'
expects_directory?(true, resource.value(:path))
provider.expects(:svn).with('status', resource[:path])
provider.exists?
end
it "should run `svnlook uuid` on the path when there's no source" do
expects_directory?(true, resource.value(:path))
provider.expects(:svnlook).with('uuid', resource[:path])
provider.exists?
end
end
describe "checking the revision property" do
before do
provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info))
end
it "should use 'svn info'" do
expects_chdir
expect(provider.revision).to eq('4') # From 'Revision', not 'Last Changed Rev'
end
end
describe "setting the revision property" do
before do
@revision = '30'
end
context 'with conflict' do
it "should use 'svn update'" do
resource[:conflict] = 'theirs-full'
expects_chdir
provider.expects(:svn).with('--non-interactive', 'update',
'-r', @revision,
'--accept', resource.value(:conflict))
provider.revision = @revision
end
end
context 'without conflict' do
it "should use 'svn update'" do
expects_chdir
provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
provider.revision = @revision
end
end
end
describe "setting the revision property and repo source" do
before do
@revision = '30'
end
context 'with conflict' do
it "should use 'svn switch'" do
resource[:source] = 'an-unimportant-value'
resource[:conflict] = 'theirs-full'
expects_chdir
provider.expects(:svn).with('--non-interactive', 'switch',
'-r', @revision, 'an-unimportant-value',
'--accept', resource.value(:conflict))
provider.revision = @revision
end
end
context 'without conflict' do
it "should use 'svn switch'" do
resource[:source] = 'an-unimportant-value'
expects_chdir
provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value')
provider.revision = @revision
end
it "should use 'svn switch'" do
resource[:source] = 'an-unimportant-value'
resource[:revision] = '30'
expects_chdir
provider.expects(:svn).with('--non-interactive', 'switch', '-r', resource.value(:revision), 'an-unimportant-value')
provider.source = resource.value(:source)
end
it "should use 'svn switch'" do
resource[:source] = 'an-unimportant-value'
resource[:revision] = '30'
expects_chdir
provider.expects(:svn).with('--non-interactive', 'switch', '-r', resource.value(:revision), 'an-unimportant-value')
provider.source = resource.value(:source)
end
end
end
describe "checking the source property" do
before do
provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info))
end
it "should use 'svn info'" do
expects_chdir
expect(provider.source).to eq('http://example.com/svn/trunk') # From URL
end
end
describe "setting the source property" do
context 'with conflict' do
it "should use 'svn switch'" do
resource[:source] = 'http://example.com/svn/tags/1.0'
resource[:conflict] = 'theirs-full'
expects_chdir
provider.expects(:svn).with('--non-interactive', 'switch', '--accept',
resource.value(:conflict),
resource.value(:source))
provider.source = resource.value(:source)
end
end
context 'without conflict' do
it "should use 'svn switch'" do
resource[:source] = 'http://example.com/svn/tags/1.0'
expects_chdir
provider.expects(:svn).with('--non-interactive', 'switch',
resource.value(:source))
provider.source = resource.value(:source)
end
end
end
end
Resource Type Specs
===================
Define specs for your resource types in this directory.
#! /usr/bin/env ruby
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo) do
before :each do
Puppet::Type.type(:vcsrepo).stubs(:defaultprovider).returns(providerclass)
end
let(:providerclass) do
described_class.provide(:fake_vcsrepo_provider) do
attr_accessor :property_hash
def create; end
def destroy; end
def exists?
get(:ensure) != :absent
end
mk_resource_methods
has_features :include_paths
end
end
let(:provider) do
providerclass.new(:name => 'fake-vcs')
end
let(:resource) do
described_class.new(:name => '/repo',
:ensure => :present,
:source => 'http://example.com/repo/',
:provider => provider)
end
let(:ensureprop) do
resource.property(:ensure)
end
let(:sourceprop) do
resource.property(:source)
end
properties = [ :ensure, :source ]
properties.each do |property|
it "should have a #{property} property" do
expect(described_class.attrclass(property).ancestors).to be_include(Puppet::Property)
end
end
parameters = [ :ensure ]
parameters.each do |parameter|
it "should have a #{parameter} parameter" do
expect(described_class.attrclass(parameter).ancestors).to be_include(Puppet::Parameter)
end
end
describe "with an include path that starts with a '/'" do
it "should raise a Puppet::ResourceError error" do
expect {
resource[:includes] = ['/path1/file1', '/path2/file2']
}.to raise_error(Puppet::ResourceError, /Include path '.*' starts with a '\/'/)
end
end
describe 'when using a provider that adds/removes a trailing / to the source' do
it "should stay in sync when it leaves it as-is" do
sourceprop.should = 'http://example.com/repo/'
expect(sourceprop.safe_insync?('http://example.com/repo/')).to eq(true)
end
it "should stay in sync when it adds a slash" do
sourceprop.should = 'http://example.com/repo'
expect(sourceprop.safe_insync?('http://example.com/repo/')).to eq(true)
end
it "should stay in sync when it removes a slash" do
sourceprop.should = 'http://example.com/repo/'
expect(sourceprop.safe_insync?('http://example.com/repo')).to eq(true)
end
it "should be out of sync with a different source" do
sourceprop.should = 'http://example.com/repo/asdf'
expect(sourceprop.safe_insync?('http://example.com/repo')).to eq(false)
end
end
describe 'default resource with required params' do
it 'should have a valid name parameter' do
expect(resource[:name]).to eq('/repo')
end
it 'should have ensure set to present' do
expect(resource[:ensure]).to eq(:present)
end
it 'should have path set to /repo' do
expect(resource[:path]).to eq('/repo')
end
defaults = {
:owner => nil,
:group => nil,
:user => nil,
:revision => nil,
}
defaults.each_pair do |param, value|
it "should have #{param} parameter set to #{value}" do
expect(resource[param]).to eq(value)
end
end
end
describe 'when changing the ensure' do
it 'should be in sync if it is :absent and should be :absent' do
ensureprop.should = :absent
expect(ensureprop.safe_insync?(:absent)).to eq(true)
end
it 'should be in sync if it is :present and should be :present' do
ensureprop.should = :present
expect(ensureprop.safe_insync?(:present)).to eq(true)
end
it 'should be out of sync if it is :absent and should be :present' do
ensureprop.should = :present
expect(ensureprop.safe_insync?(:absent)).not_to eq(true)
end
it 'should be out of sync if it is :present and should be :absent' do
ensureprop.should = :absent
expect(ensureprop.safe_insync?(:present)).not_to eq(true)
end
end
describe 'when running the type it should autorequire packages' do
before :each do
@catalog = Puppet::Resource::Catalog.new
['git', 'git-core', 'mercurial', 'subversion'].each do |pkg|
@catalog.add_resource(Puppet::Type.type(:package).new(:name => pkg))
end
end
it 'should require package packages' do
@resource = described_class.new(:name => '/foo', :provider => provider)
@catalog.add_resource(@resource)
req = @resource.autorequire
expect(req.size).to eq(4)
end
end
end
......@@ -3,4 +3,5 @@ node 'default' {
include nilmdb
include nilm
include static_sites
include rails_api
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment