adding fake driver

This commit is contained in:
2013-07-25 16:14:38 -04:00
parent 266b0722f1
commit 5a69517c0b
24 changed files with 1740 additions and 1230 deletions

View File

@@ -1 +1 @@
95b6de96-61ef-4e5a-be3f-94376f3c2dce d996d7ab-63be-42e1-bfe7-9b4057251598

View File

@@ -1 +1 @@
00a9efde-6e58-48d9-a88f-9dca39ab7655 4048e90a-240a-4146-8ac7-729aa0e0b530

View File

@@ -1 +1 @@
ad9a456c-c5dc-432f-a3b1-a3e464e5e9d1 2adeff38-b5e2-468e-a3c7-e74fae8e02ab

121
Vagrantfile vendored
View File

@@ -1,60 +1,61 @@
# -*- mode: ruby -*- # -*- mode: ruby -*-
# vi: set ft=ruby : # vi: set ft=ruby :
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration # All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference, # options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com. # please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of. # Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "Centos64Puppet" config.vm.box = "Centos64Puppet"
config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210.box" config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210.box"
#config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-i386-v20130427.box" #config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-i386-v20130427.box"
config.vm.define :puppet do |puppet_config| config.vm.define :puppet do |puppet_config|
puppet_config.vm.hostname = "puppet.vagrant.info" puppet_config.vm.hostname = "puppet.vagrant.info"
puppet_config.vm.network :private_network, ip: "192.168.33.10" #eth1 MGMT puppet_config.vm.network :private_network, ip: "192.168.33.10" #eth1 MGMT
end end
config.vm.define :controller do |controller_config| config.vm.define :controller do |controller_config|
controller_config.vm.hostname = "controller.vagrant.info" controller_config.vm.hostname = "controller.vagrant.info"
controller_config.vm.network :private_network, ip: "192.168.33.11" #eth1 MGMT controller_config.vm.network :private_network, ip: "192.168.33.11" #eth1 MGMT
controller_config.vm.network :private_network, ip: "10.10.1.11" #eth2 VM Traffic controller_config.vm.network :private_network, ip: "10.10.1.11" #eth2 VM Traffic
controller_config.vm.network :private_network, ip: "10.10.2.11" #eth3 floating controller_config.vm.network :private_network, ip: "10.10.2.11" #eth3 floating
controller_config.vm.network :forwarded_port, guest: 80, host: 8080 controller_config.vm.network :forwarded_port, guest: 80, host: 8080
controller_config.vm.provision :shell, :inline => "ip link set mtu 1546 dev eth2" controller_config.vm.provision :shell, :inline => "ip link set mtu 1546 dev eth2"
controller_config.vm.provider "virtualbox" do |controller_vbox| controller_config.vm.provider "virtualbox" do |controller_vbox|
controller_vbox.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"] # eth3 controller_vbox.customize ["modifyvm", :id, "--nicpromisc4", "allow-all", "--nictype4", "Am79C973"] # eth4
controller_vbox.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"] # eth3 controller_vbox.customize ["modifyvm", :id, "--nicpromisc3", "allow-all", "--nictype3", "Am79C973"] # eth3
end end
end end
config.vm.define :compute1 do |compute1_config| config.vm.define :compute1 do |compute1_config|
compute1_config.vm.hostname = "compute1.vagrant.info" compute1_config.vm.hostname = "compute1.vagrant.info"
compute1_config.vm.network :private_network, ip: "192.168.33.12" #eth1 MGMT compute1_config.vm.network :private_network, ip: "192.168.33.12" #eth1 MGMT
compute1_config.vm.network :private_network, ip: "10.10.1.12" #eth2 VM Traffic compute1_config.vm.network :private_network, ip: "10.10.1.12" #eth2 VM Traffic
compute1_config.vm.provision :shell, :inline => "ip link set mtu 1546 dev eth2" #compute1_config.vm.provision :shell, :inline => "ip link set mtu 1546 dev eth2"
compute1_config.vm.provision :shell, :inline => "ip link set eth2 promisc on" #compute1_config.vm.provision :shell, :inline => "ip link set eth2 promisc on"
compute1_config.vm.provider "virtualbox" do |compute1_vbox| compute1_config.vm.provider "virtualbox" do |compute1_vbox|
compute1_vbox.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"] # eth2 compute1_vbox.customize ["modifyvm", :id, "--nicpromisc2", "allow-all", "--nictype2", "Am79C973"] # eth2
compute1_vbox.customize ["modifyvm", :id, "--cpus", 4] compute1_vbox.customize ["modifyvm", :id, "--nicpromisc3", "allow-all", "--nictype3", "Am79C973"] # eth3
compute1_vbox.customize ["modifyvm", :id, "--memory", 2048] compute1_vbox.customize ["modifyvm", :id, "--cpus", 4]
end compute1_vbox.customize ["modifyvm", :id, "--memory", 2048]
end
end
end
config.vm.provider "virtualbox" do |vbox|
vbox.gui = false config.vm.provider "virtualbox" do |vbox|
end vbox.gui = false
end
config.vm.provision :puppet do |puppet|
puppet.module_path = "modules" config.vm.provision :puppet do |puppet|
puppet.module_path = "modules"
puppet.manifest_file = "site.pp"
puppet.options = "--verbose --debug" puppet.manifest_file = "site.pp"
end puppet.options = "--verbose --debug"
end
end
end

503
manifests/fake.py Normal file
View File

@@ -0,0 +1,503 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# Copyright (c) 2010 Citrix Systems, 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.
"""
A fake (in-memory) hypervisor+api.
Allows nova testing w/o a hypervisor. This module also documents the
semantics of real hypervisor connections.
"""
from oslo.config import cfg
import os
from nova.compute import power_state
from nova.compute import task_states
from nova import db
from nova import exception
from nova.openstack.common import log as logging
from nova.virt import driver
from nova.virt import virtapi
from nova.virt import images
CONF = cfg.CONF
CONF.import_opt('host', 'nova.netconf')
LOG = logging.getLogger(__name__)
_FAKE_NODES = None
def set_nodes(nodes):
"""Sets FakeDriver's node.list.
It has effect on the following methods:
get_available_nodes()
get_available_resource
get_host_stats()
To restore the change, call restore_nodes()
"""
global _FAKE_NODES
_FAKE_NODES = nodes
def restore_nodes():
"""Resets FakeDriver's node list modified by set_nodes().
Usually called from tearDown().
"""
global _FAKE_NODES
_FAKE_NODES = [CONF.host]
class FakeInstance(object):
def __init__(self, name, state):
self.name = name
self.state = state
def __getitem__(self, key):
return getattr(self, key)
class FakeDriver(driver.ComputeDriver):
capabilities = {
"has_imagecache": True,
"supports_recreate": True,
}
"""Fake hypervisor driver."""
def __init__(self, virtapi, read_only=False):
super(FakeDriver, self).__init__(virtapi)
self.instances = {}
self.host_status_base = {
'host_name-description': 'Fake Host',
'host_hostname': CONF.host,
'host_memory_total': 8000000000,
'host_memory_overhead': 10000000,
'host_memory_free': 7900000000,
'host_memory_free_computed': 7900000000,
'host_other_config': {},
'host_ip_address': '192.168.1.109',
'host_cpu_info': {},
'disk_available': 500000000000,
'disk_total': 600000000000,
'disk_used': 100000000000,
'host_uuid': 'cedb9b39-9388-41df-8891-c5c9a0c0fe5f',
'host_name_label': 'fake-host',
'hypervisor_hostname': CONF.host,
}
self._mounts = {}
self._interfaces = {}
if not _FAKE_NODES:
set_nodes([CONF.host])
def init_host(self, host):
return
def list_instances(self):
return self.instances.keys()
def plug_vifs(self, instance, network_info):
"""Plug VIFs into networks."""
pass
def unplug_vifs(self, instance, network_info):
"""Unplug VIFs from networks."""
pass
def spawn(self, context, instance, image_meta, injected_files,
admin_password, network_info=None, block_device_info=None):
name = instance['name']
state = power_state.RUNNING
fake_instance = FakeInstance(name, state)
self.instances[name] = fake_instance
if 'image_ref' in instance:
image_href = instance['image_ref']
if 'user_id' in instance:
user_id = instance['user_id']
if 'project_id' in instance:
project_id = instance['user_id']
size = instance['root_gb']
path = "%s%s%s" % (CONF.instances_path, '/_base/',image_href)
#LOG.warning("Fake DriverMSG: image_meta type = %s" % type(image_meta))
#LOG.warning("Fake DriverMSG: image_meta = %s" % image_meta)
#LOG.warning("Fake DriverMSG: instance type = %s" % type(instance))
#LOG.warning("Fake DriverMSG: instance = %s" % instance)
cmd = "qemu-img', 'create', '-f', 'raw %s %s" % (path, size)
LOG.warning("Fake Driver: base instances_path = %s" % path)
os.system(cmd)
#images.fetch_to_raw(context, image_href, path, user_id, project_id)
images.fetch(context, image_href, path, user_id, project_id)
def live_snapshot(self, context, instance, name, update_task_state):
if instance['name'] not in self.instances:
raise exception.InstanceNotRunning(instance_id=instance['uuid'])
update_task_state(task_state=task_states.IMAGE_UPLOADING)
def snapshot(self, context, instance, name, update_task_state):
if instance['name'] not in self.instances:
raise exception.InstanceNotRunning(instance_id=instance['uuid'])
update_task_state(task_state=task_states.IMAGE_UPLOADING)
def reboot(self, context, instance, network_info, reboot_type,
block_device_info=None, bad_volumes_callback=None):
pass
@staticmethod
def get_host_ip_addr():
return '192.168.0.1'
def set_admin_password(self, instance, new_pass):
pass
def inject_file(self, instance, b64_path, b64_contents):
pass
def resume_state_on_host_boot(self, context, instance, network_info,
block_device_info=None):
pass
def rescue(self, context, instance, network_info, image_meta,
rescue_password):
pass
def unrescue(self, instance, network_info):
pass
def poll_rebooting_instances(self, timeout, instances):
pass
def migrate_disk_and_power_off(self, context, instance, dest,
instance_type, network_info,
block_device_info=None):
pass
def finish_revert_migration(self, instance, network_info,
block_device_info=None, power_on=True):
pass
def post_live_migration_at_destination(self, context, instance,
network_info,
block_migration=False,
block_device_info=None):
pass
def power_off(self, instance):
pass
def power_on(self, context, instance, network_info, block_device_info):
pass
def soft_delete(self, instance):
pass
def restore(self, instance):
pass
def pause(self, instance):
pass
def unpause(self, instance):
pass
def suspend(self, instance):
pass
def resume(self, instance, network_info, block_device_info=None):
pass
def destroy(self, instance, network_info, block_device_info=None,
destroy_disks=True):
key = instance['name']
if key in self.instances:
del self.instances[key]
else:
LOG.warning(_("Key '%(key)s' not in instances '%(inst)s'") %
{'key': key,
'inst': self.instances}, instance=instance)
def attach_volume(self, connection_info, instance, mountpoint):
"""Attach the disk to the instance at mountpoint using info."""
instance_name = instance['name']
if instance_name not in self._mounts:
self._mounts[instance_name] = {}
self._mounts[instance_name][mountpoint] = connection_info
return True
def detach_volume(self, connection_info, instance, mountpoint):
"""Detach the disk attached to the instance."""
try:
del self._mounts[instance['name']][mountpoint]
except KeyError:
pass
return True
def attach_interface(self, instance, image_meta, network_info):
for (network, mapping) in network_info:
if mapping['vif_uuid'] in self._interfaces:
raise exception.InterfaceAttachFailed('duplicate')
self._interfaces[mapping['vif_uuid']] = mapping
def detach_interface(self, instance, network_info):
for (network, mapping) in network_info:
try:
del self._interfaces[mapping['vif_uuid']]
except KeyError:
raise exception.InterfaceDetachFailed('not attached')
def get_info(self, instance):
if instance['name'] not in self.instances:
raise exception.InstanceNotFound(instance_id=instance['name'])
i = self.instances[instance['name']]
return {'state': i.state,
'max_mem': 0,
'mem': 0,
'num_cpu': 2,
'cpu_time': 0}
def get_diagnostics(self, instance_name):
return {'cpu0_time': 17300000000,
'memory': 524288,
'vda_errors': -1,
'vda_read': 262144,
'vda_read_req': 112,
'vda_write': 5778432,
'vda_write_req': 488,
'vnet1_rx': 2070139,
'vnet1_rx_drop': 0,
'vnet1_rx_errors': 0,
'vnet1_rx_packets': 26701,
'vnet1_tx': 140208,
'vnet1_tx_drop': 0,
'vnet1_tx_errors': 0,
'vnet1_tx_packets': 662,
}
def get_all_bw_counters(self, instances):
"""Return bandwidth usage counters for each interface on each
running VM.
"""
bw = []
return bw
def get_all_volume_usage(self, context, compute_host_bdms):
"""Return usage info for volumes attached to vms on
a given host.
"""
volusage = []
return volusage
def block_stats(self, instance_name, disk_id):
return [0L, 0L, 0L, 0L, None]
def interface_stats(self, instance_name, iface_id):
return [0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L]
def get_console_output(self, instance):
return 'FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE'
def get_vnc_console(self, instance):
return {'internal_access_path': 'FAKE',
'host': 'fakevncconsole.com',
'port': 6969}
def get_spice_console(self, instance):
return {'internal_access_path': 'FAKE',
'host': 'fakespiceconsole.com',
'port': 6969,
'tlsPort': 6970}
def get_console_pool_info(self, console_type):
return {'address': '127.0.0.1',
'username': 'fakeuser',
'password': 'fakepassword'}
def refresh_security_group_rules(self, security_group_id):
return True
def refresh_security_group_members(self, security_group_id):
return True
def refresh_instance_security_rules(self, instance):
return True
def refresh_provider_fw_rules(self):
pass
def get_available_resource(self, nodename):
"""Updates compute manager resource info on ComputeNode table.
Since we don't have a real hypervisor, pretend we have lots of
disk and ram.
"""
if nodename not in _FAKE_NODES:
return {}
dic = {'vcpus': 1,
'memory_mb': 8192,
'local_gb': 1028,
'vcpus_used': 0,
'memory_mb_used': 0,
'local_gb_used': 0,
'hypervisor_type': 'fake',
'hypervisor_version': '1.0',
'hypervisor_hostname': nodename,
'cpu_info': '?'}
return dic
def ensure_filtering_rules_for_instance(self, instance_ref, network_info):
"""This method is supported only by libvirt."""
raise NotImplementedError('This method is supported only by libvirt.')
def get_instance_disk_info(self, instance_name):
return
def live_migration(self, context, instance_ref, dest,
post_method, recover_method, block_migration=False,
migrate_data=None):
return
def check_can_live_migrate_destination_cleanup(self, ctxt,
dest_check_data):
return
def check_can_live_migrate_destination(self, ctxt, instance_ref,
src_compute_info, dst_compute_info,
block_migration=False,
disk_over_commit=False):
return {}
def check_can_live_migrate_source(self, ctxt, instance_ref,
dest_check_data):
return
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
block_device_info=None, power_on=True):
return
def confirm_migration(self, migration, instance, network_info):
return
def pre_live_migration(self, context, instance_ref, block_device_info,
network_info, disk, migrate_data=None):
return
def unfilter_instance(self, instance_ref, network_info):
"""This method is supported only by libvirt."""
raise NotImplementedError('This method is supported only by libvirt.')
def test_remove_vm(self, instance_name):
"""Removes the named VM, as if it crashed. For testing."""
self.instances.pop(instance_name)
def get_host_stats(self, refresh=False):
"""Return fake Host Status of ram, disk, network."""
stats = []
for nodename in _FAKE_NODES:
host_status = self.host_status_base.copy()
host_status['hypervisor_hostname'] = nodename
host_status['host_hostname'] = nodename
host_status['host_name_label'] = nodename
stats.append(host_status)
if len(stats) == 0:
raise exception.NovaException("FakeDriver has no node")
elif len(stats) == 1:
return stats[0]
else:
return stats
def host_power_action(self, host, action):
"""Reboots, shuts down or powers up the host."""
return action
def host_maintenance_mode(self, host, mode):
"""Start/Stop host maintenance window. On start, it triggers
guest VMs evacuation.
"""
if not mode:
return 'off_maintenance'
return 'on_maintenance'
def set_host_enabled(self, host, enabled):
"""Sets the specified host's ability to accept new instances."""
if enabled:
return 'enabled'
return 'disabled'
def get_disk_available_least(self):
pass
def get_volume_connector(self, instance):
return {'ip': '127.0.0.1', 'initiator': 'fake', 'host': 'fakehost'}
def get_available_nodes(self):
return _FAKE_NODES
def instance_on_disk(self, instance):
return False
def list_instance_uuids(self):
return []
def legacy_nwinfo(self):
return True
class FakeVirtAPI(virtapi.VirtAPI):
def instance_update(self, context, instance_uuid, updates):
return db.instance_update_and_get_original(context,
instance_uuid,
updates)
def aggregate_get_by_host(self, context, host, key=None):
return db.aggregate_get_by_host(context, host, key=key)
def aggregate_metadata_add(self, context, aggregate, metadata,
set_delete=False):
return db.aggregate_metadata_add(context, aggregate['id'], metadata,
set_delete=set_delete)
def aggregate_metadata_delete(self, context, aggregate, key):
return db.aggregate_metadata_delete(context, aggregate['id'], key)
def security_group_get_by_instance(self, context, instance):
return db.security_group_get_by_instance(context, instance['uuid'])
def security_group_rule_get_by_security_group(self, context,
security_group):
return db.security_group_rule_get_by_security_group(
context, security_group['id'])
def provider_fw_rule_get_all(self, context):
return db.provider_fw_rule_get_all(context)
def agent_build_get_by_triple(self, context, hypervisor, os, architecture):
return db.agent_build_get_by_triple(context,
hypervisor, os, architecture)
def instance_type_get(self, context, instance_type_id):
return db.instance_type_get(context, instance_type_id)

View File

@@ -1,157 +1,163 @@
node puppet { node puppet {
#ensure git is installed #ensure git is installed
package { 'puppetlabs-release-6-7': package { 'puppetlabs-release-6-7':
provider => 'rpm', provider => 'rpm',
ensure => installed, ensure => installed,
source => "http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm"; source => "http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm";
'git': 'git':
ensure => 'present'; ensure => 'present';
'puppet-server': 'puppet-server':
require => Package["puppetlabs-release-6-7"], require => Package["puppetlabs-release-6-7"],
ensure => 'present'; ensure => 'present';
'rubygem-rake': 'rubygem-rake':
ensure => 'present'; ensure => 'present';
} }
vcsrepo { '/etc/puppet/modules/openstack': vcsrepo {
require => Package["puppet-server"], '/etc/puppet/modules/openstack':
ensure => latest, require => Package["puppet-server"],
provider => git, ensure => latest,
source => 'https://sstent:farscape5@github.com/stratustech/puppet-openstack.git', provider => git,
notify => File["/etc/puppet/modules/openstack"]; source => 'https://sstent:farscape5@github.com/stratustech/puppet-openstack.git',
'/etc/puppet/manifests': notify => File["/etc/puppet/modules/openstack"];
require => [Package["puppet-server"],File['/etc/puppet/manifests']], '/etc/puppet/modules/stratus':
ensure => latest, require => Package["puppet-server"],
provider => git, ensure => latest,
source => 'https://sstent:farscape5@github.com/stratustech/POC_ALPHA.git'; provider => git,
'/etc/puppet/modules/rabbitmq': source => 'https://sstent:farscape5@github.com/stratustech/POC_ALPHA_stratusmodule.git';
require => Package["puppet-server"], '/etc/puppet/manifests':
ensure => latest, require => [Package["puppet-server"],File['/etc/puppet/manifests']],
provider => git, ensure => latest,
source => 'https://github.com/gergnz/puppetlabs-rabbitmq.git'; provider => git,
'/etc/puppet/modules/horizon': source => 'https://sstent:farscape5@github.com/stratustech/POC_ALPHA_puppet_manifests.git';
require => Package["puppet-server"], '/etc/puppet/modules/rabbitmq':
ensure => latest, require => Package["puppet-server"],
provider => git, ensure => latest,
source => 'https://sstent:farscape5@github.com/stratustech/puppet-horizon.git'; provider => git,
} source => 'https://github.com/gergnz/puppetlabs-rabbitmq.git';
'/etc/puppet/modules/horizon':
file { "/etc/puppet/modules/openstack": require => Package["puppet-server"],
require => Package["puppet-server"], ensure => latest,
ensure => "directory", provider => git,
owner => "root", source => 'https://sstent:farscape5@github.com/stratustech/puppet-horizon.git';
group => "root", }
mode => 755,
recurse => true, file { "/etc/puppet/modules/openstack":
notify => Exec["sudo rake modules:clone"]; require => Package["puppet-server"],
"/etc/puppet/manifests": ensure => "directory",
require => Package["puppet-server"], owner => "root",
before => Vcsrepo['/etc/puppet/manifests'], group => "root",
force => true, mode => 755,
backup => false, recurse => true,
ensure => "absent"; notify => Exec["sudo rake modules:clone"];
"/etc/puppet/autosign.conf": "/etc/puppet/manifests":
require => Package["puppet-server"], require => Package["puppet-server"],
owner => "root", before => Vcsrepo['/etc/puppet/manifests'],
group => "root", force => true,
mode => 0644, backup => false,
content => "*"; ensure => "absent";
} "/etc/puppet/autosign.conf":
require => Package["puppet-server"],
exec {"sudo rake modules:clone": owner => "root",
require => [Package["rubygem-rake"],Vcsrepo['/etc/puppet/modules/horizon','/etc/puppet/modules/rabbitmq','/etc/puppet/manifests','/etc/puppet/modules/openstack']], group => "root",
cwd => "/etc/puppet/modules/openstack", mode => 0644,
path => ["/usr/local/bin","/bin","/usr/bin","/usr/local/sbin","/usr/sbin","/sbin","/home/vagrant/bin"]; content => "*";
} }
service { "iptables": exec {"sudo rake modules:clone":
ensure => "stopped", require => [Package["rubygem-rake"],Vcsrepo['/etc/puppet/modules/horizon','/etc/puppet/modules/rabbitmq','/etc/puppet/manifests','/etc/puppet/modules/openstack']],
enable => false; cwd => "/etc/puppet/modules/openstack",
"puppetmaster": path => ["/usr/local/bin","/bin","/usr/bin","/usr/local/sbin","/usr/sbin","/sbin","/home/vagrant/bin"];
require => [File["/etc/puppet/autosign.conf"],Exec["sudo rake modules:clone"]], }
ensure => "running",
enable => true; service { "iptables":
} ensure => "stopped",
enable => false;
host { 'controller.vagrant.info': "puppetmaster":
ip => '192.168.33.11', require => [File["/etc/puppet/autosign.conf"],Exec["sudo rake modules:clone"]],
host_aliases => 'controller'; ensure => "running",
'compute1.vagrant.info': enable => true;
ip => '192.168.33.12', }
host_aliases => 'compute1';
} host { 'controller.vagrant.info':
ip => '192.168.33.11',
host_aliases => 'controller';
} 'compute1.vagrant.info':
ip => '192.168.33.12',
host_aliases => 'compute1';
}
node controller {
#ensure git is installed }
package { 'puppetlabs-release-6-7':
provider => 'rpm',
ensure => installed,
source => "http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm"; node controller {
'puppet':
require => Package["puppetlabs-release-6-7"], #ensure git is installed
ensure => 'present'; package { 'puppetlabs-release-6-7':
} provider => 'rpm',
ensure => installed,
service { "iptables": source => "http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm";
ensure => "stopped", 'puppet':
enable => false; require => Package["puppetlabs-release-6-7"],
"puppet": ensure => 'present';
require => Package["puppet"], }
ensure => "running",
enable => true; service { "iptables":
} ensure => "stopped",
enable => false;
"puppet":
require => Package["puppet"],
host { 'puppet.vagrant.info': ensure => "running",
ip => '192.168.33.10', enable => true;
host_aliases => 'puppet'; }
'compute1.vagrant.info':
ip => '192.168.33.12',
host_aliases => 'compute1';
} host { 'puppet.vagrant.info':
ip => '192.168.33.10',
host_aliases => 'puppet';
} 'compute1.vagrant.info':
ip => '192.168.33.12',
host_aliases => 'compute1';
node compute1 { }
#ensure git is installed
package { 'puppetlabs-release-6-7': }
provider => 'rpm',
ensure => installed,
source => "http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm"; node compute1 {
'puppet':
require => Package["puppetlabs-release-6-7"], #ensure git is installed
ensure => 'present'; package { 'puppetlabs-release-6-7':
} provider => 'rpm',
ensure => installed,
service { "puppet": source => "http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm";
require => Package["puppet"], 'puppet':
ensure => "running", require => Package["puppetlabs-release-6-7"],
enable => true; ensure => 'present';
} }
service { "puppet":
require => Package["puppet"],
host { 'puppet.vagrant.info': ensure => "running",
ip => '192.168.33.10', enable => true;
host_aliases => 'puppet'; }
'controller.vagrant.info':
ip => '192.168.33.11',
host_aliases => 'controller';
} host { 'puppet.vagrant.info':
ip => '192.168.33.10',
host_aliases => 'puppet';
} 'controller.vagrant.info':
ip => '192.168.33.11',
host_aliases => 'controller';
}
}

View File

@@ -1,180 +1,180 @@
require 'pathname' require 'pathname'
Puppet::Type.newtype(:vcsrepo) do Puppet::Type.newtype(:vcsrepo) do
desc "A local version control repository" desc "A local version control repository"
feature :gzip_compression, feature :gzip_compression,
"The provider supports explicit GZip compression levels" "The provider supports explicit GZip compression levels"
feature :basic_auth, feature :basic_auth,
"The provider supports HTTP Basic Authentication" "The provider supports HTTP Basic Authentication"
feature :bare_repositories, feature :bare_repositories,
"The provider differentiates between bare repositories "The provider differentiates between bare repositories
and those with working copies", and those with working copies",
:methods => [:bare_exists?, :working_copy_exists?] :methods => [:bare_exists?, :working_copy_exists?]
feature :filesystem_types, feature :filesystem_types,
"The provider supports different filesystem types" "The provider supports different filesystem types"
feature :reference_tracking, feature :reference_tracking,
"The provider supports tracking revision references that can change "The provider supports tracking revision references that can change
over time (eg, some VCS tags and branch names)" over time (eg, some VCS tags and branch names)"
feature :ssh_identity, feature :ssh_identity,
"The provider supports a configurable SSH identity file" "The provider supports a configurable SSH identity file"
feature :user, feature :user,
"The provider can run as a different user" "The provider can run as a different user"
feature :modules, feature :modules,
"The repository contains modules that can be chosen of" "The repository contains modules that can be chosen of"
feature :multiple_remotes, feature :multiple_remotes,
"The repository tracks multiple remote repositories" "The repository tracks multiple remote repositories"
ensurable do ensurable do
attr_accessor :latest attr_accessor :latest
def insync?(is) def insync?(is)
@should ||= [] @should ||= []
case should case should
when :present when :present
return true unless [:absent, :purged, :held].include?(is) return true unless [:absent, :purged, :held].include?(is)
when :latest when :latest
if is == :latest if is == :latest
return true return true
else else
return false return false
end end
when :bare when :bare
return is == :bare return is == :bare
end end
end end
newvalue :present do newvalue :present do
notice "Creating repository from present" notice "Creating repository from present"
provider.create provider.create
end end
newvalue :bare, :required_features => [:bare_repositories] do newvalue :bare, :required_features => [:bare_repositories] do
if !provider.exists? if !provider.exists?
provider.create provider.create
end end
end end
newvalue :absent do newvalue :absent do
provider.destroy provider.destroy
end end
newvalue :latest, :required_features => [:reference_tracking] do newvalue :latest, :required_features => [:reference_tracking] do
if provider.exists? if provider.exists?
if provider.respond_to?(:update_references) if provider.respond_to?(:update_references)
provider.update_references provider.update_references
end end
if provider.respond_to?(:latest?) if provider.respond_to?(:latest?)
reference = provider.latest || provider.revision reference = provider.latest || provider.revision
else else
reference = resource.value(:revision) || provider.revision reference = resource.value(:revision) || provider.revision
end end
notice "Updating to latest '#{reference}' revision" notice "Updating to latest '#{reference}' revision"
provider.revision = reference provider.revision = reference
else else
notice "Creating repository from latest" notice "Creating repository from latest"
provider.create provider.create
end end
end end
def retrieve def retrieve
prov = @resource.provider prov = @resource.provider
if prov if prov
if prov.working_copy_exists? if prov.working_copy_exists?
(@should.include?(:latest) && prov.latest?) ? :latest : :present (@should.include?(:latest) && prov.latest?) ? :latest : :present
elsif prov.class.feature?(:bare_repositories) and prov.bare_exists? elsif prov.class.feature?(:bare_repositories) and prov.bare_exists?
:bare :bare
else else
:absent :absent
end end
else else
raise Puppet::Error, "Could not find provider" raise Puppet::Error, "Could not find provider"
end end
end end
end end
newparam :path do newparam :path do
desc "Absolute path to repository" desc "Absolute path to repository"
isnamevar isnamevar
validate do |value| validate do |value|
path = Pathname.new(value) path = Pathname.new(value)
unless path.absolute? unless path.absolute?
raise ArgumentError, "Path must be absolute: #{path}" raise ArgumentError, "Path must be absolute: #{path}"
end end
end end
end end
newparam :source do newparam :source do
desc "The source URI for the repository" desc "The source URI for the repository"
end end
newparam :fstype, :required_features => [:filesystem_types] do newparam :fstype, :required_features => [:filesystem_types] do
desc "Filesystem type" desc "Filesystem type"
end end
newproperty :revision do newproperty :revision do
desc "The revision of the repository" desc "The revision of the repository"
newvalue(/^\S+$/) newvalue(/^\S+$/)
end end
newparam :owner do newparam :owner do
desc "The user/uid that owns the repository files" desc "The user/uid that owns the repository files"
end end
newparam :group do newparam :group do
desc "The group/gid that owns the repository files" desc "The group/gid that owns the repository files"
end end
newparam :user do newparam :user do
desc "The user to run for repository operations" desc "The user to run for repository operations"
end end
newparam :excludes do newparam :excludes do
desc "Files to be excluded from the repository" desc "Files to be excluded from the repository"
end end
newparam :force do newparam :force do
desc "Force repository creation, destroying any files on the path in the process." desc "Force repository creation, destroying any files on the path in the process."
newvalues(:true, :false) newvalues(:true, :false)
defaultto false defaultto false
end end
newparam :compression, :required_features => [:gzip_compression] do newparam :compression, :required_features => [:gzip_compression] do
desc "Compression level" desc "Compression level"
validate do |amount| validate do |amount|
unless Integer(amount).between?(0, 6) unless Integer(amount).between?(0, 6)
raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)" raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)"
end end
end end
end end
newparam :basic_auth_username, :required_features => [:basic_auth] do newparam :basic_auth_username, :required_features => [:basic_auth] do
desc "HTTP Basic Auth username" desc "HTTP Basic Auth username"
end end
newparam :basic_auth_password, :required_features => [:basic_auth] do newparam :basic_auth_password, :required_features => [:basic_auth] do
desc "HTTP Basic Auth password" desc "HTTP Basic Auth password"
end end
newparam :identity, :required_features => [:ssh_identity] do newparam :identity, :required_features => [:ssh_identity] do
desc "SSH identity file" desc "SSH identity file"
end end
newparam :module, :required_features => [:modules] do newparam :module, :required_features => [:modules] do
desc "The repository module to manage" desc "The repository module to manage"
end end
newparam :remote, :required_features => [:multiple_remotes] do newparam :remote, :required_features => [:multiple_remotes] do
desc "The remote repository to track" desc "The remote repository to track"
defaultto "origin" defaultto "origin"
end end
end end

View File

@@ -1,5 +1,5 @@
revision-id: menesis@pov.lt-20100309191856-4wmfqzc803fj300x revision-id: menesis@pov.lt-20100309191856-4wmfqzc803fj300x
date: 2010-03-09 21:18:56 +0200 date: 2010-03-09 21:18:56 +0200
build-date: 2010-03-14 00:42:43 -0800 build-date: 2010-03-14 00:42:43 -0800
revno: 2634 revno: 2634
branch-nick: mytest branch-nick: mytest

View File

@@ -1,14 +1,14 @@
feature/foo feature/foo
feature/bar feature/bar
feature/baz feature/baz
feature/quux feature/quux
only/local only/local
* master * master
refactor/foo refactor/foo
origin/HEAD origin/HEAD
origin/feature/foo origin/feature/foo
origin/feature/bar origin/feature/bar
origin/feature/baz origin/feature/baz
origin/feature/quux origin/feature/quux
origin/only/remote origin/only/remote
origin/master origin/master

View File

@@ -1,6 +1,6 @@
changeset: 3:34e6012c783a changeset: 3:34e6012c783a
parent: 2:21ea4598c962 parent: 2:21ea4598c962
parent: 1:9d0ff0028458 parent: 1:9d0ff0028458
user: Test User <test.user@example.com> user: Test User <test.user@example.com>
date: Fri Aug 07 13:13:02 2009 -0400 date: Fri Aug 07 13:13:02 2009 -0400
summary: merge summary: merge

View File

@@ -1,18 +1,18 @@
tip 1019:bca3f20b249b tip 1019:bca3f20b249b
0.9.1 1017:76ce7cca95d8 0.9.1 1017:76ce7cca95d8
0.9 1001:dbaa6f4ec585 0.9 1001:dbaa6f4ec585
0.8 839:65b66ac0fc83 0.8 839:65b66ac0fc83
0.7.1 702:e1357f00129f 0.7.1 702:e1357f00129f
0.7 561:7b2af3b4c968 0.7 561:7b2af3b4c968
0.6.3 486:e38077f4e4aa 0.6.3 486:e38077f4e4aa
0.6.2 405:07bb099b7b10 0.6.2 405:07bb099b7b10
0.6.1 389:93750f3fbbe2 0.6.1 389:93750f3fbbe2
0.6 369:34e6012c783a 0.6 369:34e6012c783a
0.5.3 321:5ffa6ae7e699 0.5.3 321:5ffa6ae7e699
0.5.2 318:fdc2c2e4cebe 0.5.2 318:fdc2c2e4cebe
0.5.1 315:33a5ea0cbe7a 0.5.1 315:33a5ea0cbe7a
0.5 313:47490716f4c9 0.5 313:47490716f4c9
0.4 240:47fa3a14cc63 0.4 240:47fa3a14cc63
0.3.1 132:bc231db18e1c 0.3.1 132:bc231db18e1c
0.3 130:661615e510dd 0.3 130:661615e510dd
0.2 81:f98d13b442f6 0.2 81:f98d13b442f6

View File

@@ -1,10 +1,10 @@
Path: . Path: .
URL: http://example.com/svn/trunk URL: http://example.com/svn/trunk
Repository Root: http://example.com/svn Repository Root: http://example.com/svn
Repository UUID: 75246ace-e253-0410-96dd-a7613ca8dc81 Repository UUID: 75246ace-e253-0410-96dd-a7613ca8dc81
Revision: 4 Revision: 4
Node Kind: directory Node Kind: directory
Schedule: normal Schedule: normal
Last Changed Author: jon Last Changed Author: jon
Last Changed Rev: 3 Last Changed Rev: 3
Last Changed Date: 2008-08-07 11:34:25 -0700 (Thu, 07 Aug 2008) Last Changed Date: 2008-08-07 11:34:25 -0700 (Thu, 07 Aug 2008)

View File

@@ -1,6 +1,6 @@
--format --format
s s
--colour --colour
--loadby --loadby
mtime mtime
--backtrace --backtrace

View File

@@ -1,25 +1,25 @@
require 'pathname' require 'pathname'
dir = Pathname.new(__FILE__).parent dir = Pathname.new(__FILE__).parent
$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') $LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
require 'test/unit' require 'test/unit'
require 'mocha' require 'mocha'
require 'puppet' require 'puppet'
gem 'rspec', '>= 1.2.9' gem 'rspec', '>= 1.2.9'
require 'spec/autorun' require 'spec/autorun'
Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file| Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file|
require support_file require support_file
end end
Spec::Runner.configure do |config| Spec::Runner.configure do |config|
config.mock_with :mocha config.mock_with :mocha
config.include(FixtureHelpers) config.include(FixtureHelpers)
config.include(FilesystemHelpers) config.include(FilesystemHelpers)
end end
# We need this because the RAL uses 'should' as a method. This # We need this because the RAL uses 'should' as a method. This
# allows us the same behaviour but with a different method name. # allows us the same behaviour but with a different method name.
class Object class Object
alias :must :should alias :must :should
end end

View File

@@ -1,18 +1,18 @@
module FilesystemHelpers module FilesystemHelpers
def expects_chdir(path = resource.value(:path)) def expects_chdir(path = resource.value(:path))
Dir.expects(:chdir).with(path).at_least_once.yields Dir.expects(:chdir).with(path).at_least_once.yields
end end
def expects_mkdir(path = resource.value(:path)) def expects_mkdir(path = resource.value(:path))
Dir.expects(:mkdir).with(path).at_least_once Dir.expects(:mkdir).with(path).at_least_once
end end
def expects_rm_rf(path = resource.value(:path)) def expects_rm_rf(path = resource.value(:path))
FileUtils.expects(:rm_rf).with(path) FileUtils.expects(:rm_rf).with(path)
end end
def expects_directory?(returns = true, path = resource.value(:path)) def expects_directory?(returns = true, path = resource.value(:path))
File.expects(:directory?).with(path).returns(returns) File.expects(:directory?).with(path).returns(returns)
end end
end end

View File

@@ -1,7 +1,7 @@
module FixtureHelpers module FixtureHelpers
def fixture(name, ext = '.txt') def fixture(name, ext = '.txt')
File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name.to_s + ext)) File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name.to_s + ext))
end end
end end

View File

@@ -1,80 +1,80 @@
class ProviderExampleGroup < Spec::Example::ExampleGroup class ProviderExampleGroup < Spec::Example::ExampleGroup
# Allow access to the current resource # Allow access to the current resource
attr_reader :resource attr_reader :resource
# Build up the values for the resource in this scope # Build up the values for the resource in this scope
before :each do before :each do
resource_hash = example_group_hierarchy.inject({}) do |memo, klass| resource_hash = example_group_hierarchy.inject({}) do |memo, klass|
memo.merge(klass.options[:resource] || {}) memo.merge(klass.options[:resource] || {})
end end
full_hash = resource_hash.merge(:provider => described_class.name) full_hash = resource_hash.merge(:provider => described_class.name)
@resource = described_class.resource_type.new(full_hash) @resource = described_class.resource_type.new(full_hash)
end end
# Build the provider # Build the provider
subject { described_class.new(@resource) } subject { described_class.new(@resource) }
# Allow access to it via +provider+ # Allow access to it via +provider+
alias :provider :subject alias :provider :subject
# Generate a context for a provider operating on a resource with: # Generate a context for a provider operating on a resource with:
# #
# call-seq: # call-seq:
# #
# # A parameter/property set (when the value isn't important) # # A parameter/property set (when the value isn't important)
# resource_with :source do # resource_with :source do
# # ... # # ...
# end # end
# #
# # A parameter/property set to a specific value # # A parameter/property set to a specific value
# resource_with :source => 'a-specific-value' do # resource_with :source => 'a-specific-value' do
# # ... # # ...
# end # end
# #
# Note: Choose one or the other (mixing will create two separate contexts) # Note: Choose one or the other (mixing will create two separate contexts)
# #
def self.resource_with(*params, &block) def self.resource_with(*params, &block)
params_with_values = params.last.is_a?(Hash) ? params.pop : {} params_with_values = params.last.is_a?(Hash) ? params.pop : {}
build_value_context(params_with_values, &block) build_value_context(params_with_values, &block)
build_existence_context(*params, &block) build_existence_context(*params, &block)
end end
def self.build_existence_context(*params, &block) #:nodoc: def self.build_existence_context(*params, &block) #:nodoc:
unless params.empty? unless params.empty?
text = params.join(', ') text = params.join(', ')
placeholders = params.inject({}) { |memo, key| memo.merge(key => 'an-unimportant-value') } placeholders = params.inject({}) { |memo, key| memo.merge(key => 'an-unimportant-value') }
context("and with a #{text}", {:resource => placeholders}, &block) context("and with a #{text}", {:resource => placeholders}, &block)
end end
end end
def self.build_value_context(params = {}, &block) #:nodoc: def self.build_value_context(params = {}, &block) #:nodoc:
unless params.empty? unless params.empty?
text = params.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ') text = params.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ')
context("and with #{text}", {:resource => params}, &block) context("and with #{text}", {:resource => params}, &block)
end end
end end
# Generate a context for a provider operating on a resource without # Generate a context for a provider operating on a resource without
# a given parameter/property. # a given parameter/property.
# #
# call-seq: # call-seq:
# #
# resource_without :source do # resource_without :source do
# # ... # # ...
# end # end
# #
def self.resource_without(field, &block) def self.resource_without(field, &block)
context("and without a #{field}", &block) context("and without a #{field}", &block)
end end
end end
Spec::Example::ExampleGroupFactory.register(:provider, ProviderExampleGroup) Spec::Example::ExampleGroupFactory.register(:provider, ProviderExampleGroup)
# Outside wrapper to lookup a provider and start the spec using ProviderExampleGroup # Outside wrapper to lookup a provider and start the spec using ProviderExampleGroup
def describe_provider(type_name, provider_name, options = {}, &block) def describe_provider(type_name, provider_name, options = {}, &block)
provider_class = Puppet::Type.type(type_name).provider(provider_name) provider_class = Puppet::Type.type(type_name).provider(provider_name)
describe(provider_class, options.merge(:type => :provider), &block) describe(provider_class, options.merge(:type => :provider), &block)
end end

View File

@@ -1,90 +1,90 @@
require 'spec_helper' require 'spec_helper'
describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do describe 'creating' do
resource_with :source do resource_with :source do
resource_with :revision do resource_with :revision do
it "should execute 'bzr clone -r' with the revision" 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.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path))
provider.create provider.create
end end
end end
resource_without :revision do resource_without :revision do
it "should just execute 'bzr clone' without a revision" do it "should just execute 'bzr clone' without a revision" do
provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path)) provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path))
provider.create provider.create
end end
end end
end end
resource_without :source do resource_without :source do
it "should execute 'bzr init'" do it "should execute 'bzr init'" do
provider.expects(:bzr).with('init', resource.value(:path)) provider.expects(:bzr).with('init', resource.value(:path))
provider.create provider.create
end end
end end
end end
describe 'destroying' do describe 'destroying' do
it "it should remove the directory" do it "it should remove the directory" do
expects_rm_rf expects_rm_rf
provider.destroy provider.destroy
end end
end end
describe "checking existence" do describe "checking existence" do
it "should check for the directory" do it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.bzr')) expects_directory?(true, File.join(resource.value(:path), '.bzr'))
provider.exists? provider.exists?
end end
end end
describe "checking the revision property" do describe "checking the revision property" do
before do before do
expects_chdir expects_chdir
provider.expects(:bzr).with('version-info').returns(fixture(:bzr_version_info)) provider.expects(:bzr).with('version-info').returns(fixture(:bzr_version_info))
@current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' @current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
end end
context "when given a non-revid as the resource revision", :resource => {:revision => '2634'} do context "when given a non-revid as the resource revision", :resource => {:revision => '2634'} do
context "when its revid is not different than the current revid" do context "when its revid is not different than the current revid" do
before do before do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("#{resource.value(:revision)} menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("#{resource.value(:revision)} menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n")
end end
it "should return the ref" do it "should return the ref" do
provider.revision.should == resource.value(:revision) provider.revision.should == resource.value(:revision)
end end
end end
context "when its revid is different than the current revid", :resource => {:revision => '2636'} do context "when its revid is different than the current revid", :resource => {:revision => '2636'} do
it "should return the current revid" do it "should return the current revid" do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n") provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n")
provider.revision.should == @current_revid provider.revision.should == @current_revid
end end
end end
end end
context "when given a revid as the resource revision" do context "when given a revid as the resource revision" do
context "when it is the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'} do context "when it is the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'} do
before do before do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n")
end end
it "should return it" do it "should return it" do
provider.revision.should == resource.value(:revision) provider.revision.should == resource.value(:revision)
end end
end end
context "when it is not the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'} do context "when it is not the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'} do
it "should return the current revid" do it "should return the current revid" do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n") provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n")
provider.revision.should == @current_revid provider.revision.should == @current_revid
end end
end end
end end
end end
describe "setting the revision property" do describe "setting the revision property" do
it "should use 'bzr update -r' with the revision" do it "should use 'bzr update -r' with the revision" do
expects_chdir expects_chdir
provider.expects(:bzr).with('update', '-r', 'somerev') provider.expects(:bzr).with('update', '-r', 'somerev')
provider.revision = 'somerev' provider.revision = 'somerev'
end end
end end
end end

View File

@@ -1,100 +1,100 @@
require 'spec_helper' require 'spec_helper'
describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do describe 'creating' do
context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do
resource_with :revision do resource_with :revision do
it "should execute 'cvs checkout' and 'cvs update -r'" do it "should execute 'cvs checkout' and 'cvs update -r'" do
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'vcsrepo', 'bar') provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'vcsrepo', 'bar')
expects_chdir(File.dirname(resource.value(:path))) expects_chdir(File.dirname(resource.value(:path)))
#provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.') #provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.')
provider.create provider.create
end end
end end
resource_without :revision do resource_without :revision do
it "should just execute 'cvs checkout' without a revision" do it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create provider.create
end end
end end
context "with a compression", :resource => {:compression => '3'} do context "with a compression", :resource => {:compression => '3'} do
it "should just execute 'cvs checkout' without a revision" do it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create provider.create
end end
end end
end end
context "when a source is not given" do context "when a source is not given" do
it "should execute 'cvs init'" do it "should execute 'cvs init'" do
provider.expects(:cvs).with('-d', resource.value(:path), 'init') provider.expects(:cvs).with('-d', resource.value(:path), 'init')
provider.create provider.create
end end
end end
end end
describe 'destroying' do describe 'destroying' do
it "it should remove the directory" do it "it should remove the directory" do
expects_rm_rf expects_rm_rf
provider.destroy provider.destroy
end end
end end
describe "checking existence" do describe "checking existence" do
resource_with :source do resource_with :source do
it "should check for the CVS directory" do it "should check for the CVS directory" do
File.expects(:directory?).with(File.join(resource.value(:path), 'CVS')) File.expects(:directory?).with(File.join(resource.value(:path), 'CVS'))
provider.exists? provider.exists?
end end
end end
resource_without :source do resource_without :source do
it "should check for the CVSROOT directory" do it "should check for the CVSROOT directory" do
File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT')) File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT'))
provider.exists? provider.exists?
end end
end end
end end
describe "checking the revision property" do describe "checking the revision property" do
before do before do
@tag_file = File.join(resource.value(:path), 'CVS', 'Tag') @tag_file = File.join(resource.value(:path), 'CVS', 'Tag')
end end
context "when CVS/Tag exists" do context "when CVS/Tag exists" do
before do before do
@tag = 'TAG' @tag = 'TAG'
File.expects(:exist?).with(@tag_file).returns(true) File.expects(:exist?).with(@tag_file).returns(true)
end end
it "should read CVS/Tag" do it "should read CVS/Tag" do
File.expects(:read).with(@tag_file).returns("T#{@tag}") File.expects(:read).with(@tag_file).returns("T#{@tag}")
provider.revision.should == @tag provider.revision.should == @tag
end end
end end
context "when CVS/Tag does not exist" do context "when CVS/Tag does not exist" do
before do before do
File.expects(:exist?).with(@tag_file).returns(false) File.expects(:exist?).with(@tag_file).returns(false)
end end
it "assumes HEAD" do it "assumes HEAD" do
provider.revision.should == 'HEAD' provider.revision.should == 'HEAD'
end end
end end
end end
describe "when setting the revision property" do describe "when setting the revision property" do
before do before do
@tag = 'SOMETAG' @tag = 'SOMETAG'
end end
it "should use 'cvs update -dr'" do it "should use 'cvs update -dr'" do
expects_chdir expects_chdir
provider.expects(:cvs).with('update', '-dr', @tag, '.') provider.expects(:cvs).with('update', '-dr', @tag, '.')
provider.revision = @tag provider.revision = @tag
end end
end end
end end

View File

@@ -1,17 +1,17 @@
require 'spec_helper' require 'spec_helper'
describe_provider :vcsrepo, :dummy, :resource => {:path => '/tmp/vcsrepo'} do describe_provider :vcsrepo, :dummy, :resource => {:path => '/tmp/vcsrepo'} do
context 'dummy' do context 'dummy' do
resource_with :source do resource_with :source do
resource_with :ensure => :present do resource_with :ensure => :present do
context "with nothing doing", :resource => {:revision => 'foo'} do context "with nothing doing", :resource => {:revision => 'foo'} do
it "should raise an exception" do it "should raise an exception" do
proc { provider.working_copy_exists? }.should raise_error(RuntimeError) proc { provider.working_copy_exists? }.should raise_error(RuntimeError)
end end
end end
end end
end end
end end
end end

View File

@@ -1,248 +1,248 @@
require 'spec_helper' require 'spec_helper'
describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
context 'creating' do context 'creating' do
resource_with :source do resource_with :source do
resource_with :ensure => :present do resource_with :ensure => :present do
context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do
it "should execute 'git clone' and 'git checkout -b'" do it "should execute 'git clone' and 'git checkout -b'" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
expects_chdir('/') expects_chdir('/')
expects_chdir expects_chdir
provider.expects(:update_submodules) provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create provider.create
end end
end end
context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do
it "should execute 'git clone' and 'git reset --hard'" do it "should execute 'git clone' and 'git reset --hard'" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
expects_chdir('/') expects_chdir('/')
expects_chdir expects_chdir
provider.expects(:update_submodules) provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create provider.create
end end
end end
resource_without :revision do resource_without :revision do
it "should execute 'git clone' and submodule commands" do it "should execute 'git clone' and submodule commands" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules) provider.expects(:update_submodules)
provider.create provider.create
end end
end end
end end
resource_with :ensure => :bare do resource_with :ensure => :bare do
resource_with :revision do resource_with :revision do
it "should just execute 'git clone --bare'" do it "should just execute 'git clone --bare'" do
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
provider.create provider.create
end end
end end
resource_without :revision do resource_without :revision do
it "should just execute 'git clone --bare'" do it "should just execute 'git clone --bare'" do
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
provider.create provider.create
end end
end end
end end
end end
context "when a source is not given" do context "when a source is not given" do
resource_with :ensure => :present do resource_with :ensure => :present do
context "when the path does not exist" do context "when the path does not exist" do
it "should execute 'git init'" do it "should execute 'git init'" do
expects_mkdir expects_mkdir
expects_chdir expects_chdir
expects_directory?(false) expects_directory?(false)
provider.expects(:bare_exists?).returns(false) provider.expects(:bare_exists?).returns(false)
provider.expects(:git).with('init') provider.expects(:git).with('init')
provider.create provider.create
end end
end end
context "when the path is a bare repository" do context "when the path is a bare repository" do
it "should convert it to a working copy" do it "should convert it to a working copy" do
provider.expects(:bare_exists?).returns(true) provider.expects(:bare_exists?).returns(true)
provider.expects(:convert_bare_to_working_copy) provider.expects(:convert_bare_to_working_copy)
provider.create provider.create
end end
end end
context "when the path is not a repository" do context "when the path is not a repository" do
it "should raise an exception" do it "should raise an exception" do
provider.expects(:path_exists?).returns(true) provider.expects(:path_exists?).returns(true)
proc { provider.create }.should raise_error(Puppet::Error) proc { provider.create }.should raise_error(Puppet::Error)
end end
end end
end end
resource_with :ensure => :bare do resource_with :ensure => :bare do
context "when the path does not exist" do context "when the path does not exist" do
it "should execute 'git init --bare'" do it "should execute 'git init --bare'" do
expects_chdir expects_chdir
expects_mkdir expects_mkdir
expects_directory?(false) expects_directory?(false)
provider.expects(:working_copy_exists?).returns(false) provider.expects(:working_copy_exists?).returns(false)
provider.expects(:git).with('init', '--bare') provider.expects(:git).with('init', '--bare')
provider.create provider.create
end end
end end
context "when the path is a working copy repository" do context "when the path is a working copy repository" do
it "should convert it to a bare repository" do it "should convert it to a bare repository" do
provider.expects(:working_copy_exists?).returns(true) provider.expects(:working_copy_exists?).returns(true)
provider.expects(:convert_working_copy_to_bare) provider.expects(:convert_working_copy_to_bare)
provider.create provider.create
end end
end end
context "when the path is not a repository" do context "when the path is not a repository" do
it "should raise an exception" do it "should raise an exception" do
expects_directory?(true) expects_directory?(true)
proc { provider.create }.should raise_error(Puppet::Error) proc { provider.create }.should raise_error(Puppet::Error)
end end
end end
end end
end end
end end
context 'destroying' do context 'destroying' do
it "it should remove the directory" do it "it should remove the directory" do
expects_rm_rf expects_rm_rf
provider.destroy provider.destroy
end end
end end
context "checking the revision property" do context "checking the revision property" do
resource_with :revision do resource_with :revision do
before do before do
expects_chdir expects_chdir
provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha') provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha')
end end
context "when its SHA is not different than the current SHA" do context "when its SHA is not different than the current SHA" do
it "should return the ref" do it "should return the ref" do
provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin') # FIXME provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello") provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision) provider.revision.should == resource.value(:revision)
end end
end end
context "when its SHA is different than the current SHA" do context "when its SHA is different than the current SHA" do
it "should return the current SHA" do it "should return the current SHA" do
provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin') # FIXME provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
provider.expects(:git).with('tag', '-l').returns("Hello") provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == 'currentsha' provider.revision.should == 'currentsha'
end end
end end
context "when the source is modified" do context "when the source is modified" do
resource_with :source => 'git://git@foo.com/bar.git' do resource_with :source => 'git://git@foo.com/bar.git' do
it "should update the origin url" do it "should update the origin url" do
provider.expects(:git).with('config', 'remote.origin.url').returns('old') provider.expects(:git).with('config', 'remote.origin.url').returns('old')
provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git') provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git')
provider.expects(:git).with('fetch', 'origin') # FIXME provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello") provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision) provider.revision.should == resource.value(:revision)
end end
end end
end end
end end
end end
context "setting the revision property" do context "setting the revision property" do
before do before do
expects_chdir expects_chdir
end end
context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do
it "should use 'git fetch' and 'git reset'" do it "should use 'git fetch' and 'git reset'" do
provider.expects(:update_submodules) provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision) provider.revision = resource.value(:revision)
end end
end end
context "when it's a remote branch", :resource => {:revision => 'only/remote'} do context "when it's a remote branch", :resource => {:revision => 'only/remote'} do
it "should use 'git fetch' and 'git reset'" do it "should use 'git fetch' and 'git reset'" do
provider.expects(:update_submodules) provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision) provider.revision = resource.value(:revision)
end end
end end
context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do
it "should use 'git fetch' and 'git reset'" do it "should use 'git fetch' and 'git reset'" do
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('checkout', '--force', resource.value(:revision)) 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', 'init') provider.expects(:git).with('submodule', 'init')
provider.expects(:git).with('submodule', 'update') provider.expects(:git).with('submodule', 'update')
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', 'foreach', 'git', 'submodule', 'init') provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'init')
provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'update') provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'update')
provider.revision = resource.value(:revision) provider.revision = resource.value(:revision)
end end
end end
end end
context "updating references" do context "updating references" do
it "should use 'git fetch --tags'" do it "should use 'git fetch --tags'" do
expects_chdir expects_chdir
provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin') provider.expects(:git).with('fetch', 'origin')
provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('fetch', '--tags', 'origin')
provider.update_references provider.update_references
end end
end end
context "checking if revision" do context "checking if revision" do
before do before do
expects_chdir expects_chdir
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
end end
context "is a local branch" do context "is a local branch" do
context "when it's listed in 'git branch -a'", :resource => {:revision => 'feature/foo'} do context "when it's listed in 'git branch -a'", :resource => {:revision => 'feature/foo'} do
it "should return true" do it "should return true" do
provider.should be_local_branch_revision provider.should be_local_branch_revision
end end
end end
context "when it's not listed in 'git branch -a'" , :resource => {:revision => 'feature/notexist'}do context "when it's not listed in 'git branch -a'" , :resource => {:revision => 'feature/notexist'}do
it "should return false" do it "should return false" do
provider.should_not be_local_branch_revision provider.should_not be_local_branch_revision
end end
end end
end end
context "is a remote branch" do context "is a remote branch" do
context "when it's listed in 'git branch -a' with an 'origin/' prefix", :resource => {:revision => 'only/remote'} do context "when it's listed in 'git branch -a' with an 'origin/' prefix", :resource => {:revision => 'only/remote'} do
it "should return true" do it "should return true" do
provider.should be_remote_branch_revision provider.should be_remote_branch_revision
end end
end end
context "when it's not listed in 'git branch -a' with an 'origin/' prefix" , :resource => {:revision => 'only/local'}do context "when it's not listed in 'git branch -a' with an 'origin/' prefix" , :resource => {:revision => 'only/local'}do
it "should return false" do it "should return false" do
provider.should_not be_remote_branch_revision provider.should_not be_remote_branch_revision
end end
end end
end end
end end
end end

View File

@@ -1,104 +1,104 @@
require 'spec_helper' require 'spec_helper'
describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do describe 'creating' do
resource_with :source do resource_with :source do
resource_with :revision do resource_with :revision do
it "should execute 'hg clone -u' with the revision" do it "should execute 'hg clone -u' with the revision" do
provider.expects(:hg).with('clone', '-u', provider.expects(:hg).with('clone', '-u',
resource.value(:revision), resource.value(:revision),
resource.value(:source), resource.value(:source),
resource.value(:path)) resource.value(:path))
provider.create provider.create
end end
end end
resource_without :revision do resource_without :revision do
it "should just execute 'hg clone' without a revision" do it "should just execute 'hg clone' without a revision" do
provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path)) provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path))
provider.create provider.create
end end
end end
end end
context "when a source is not given" do context "when a source is not given" do
it "should execute 'hg init'" do it "should execute 'hg init'" do
provider.expects(:hg).with('init', resource.value(:path)) provider.expects(:hg).with('init', resource.value(:path))
provider.create provider.create
end end
end end
end end
describe 'destroying' do describe 'destroying' do
it "it should remove the directory" do it "it should remove the directory" do
expects_rm_rf expects_rm_rf
provider.destroy provider.destroy
end end
end end
describe "checking existence" do describe "checking existence" do
it "should check for the directory" do it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.hg')) expects_directory?(true, File.join(resource.value(:path), '.hg'))
provider.exists? provider.exists?
end end
end end
describe "checking the revision property" do describe "checking the revision property" do
before do before do
expects_chdir expects_chdir
end end
context "when given a non-SHA as the resource revision" do context "when given a non-SHA as the resource revision" do
before do before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
end end
context "when its SHA is not different than the current SHA", :resource => {:revision => '0.6'} do context "when its SHA is not different than the current SHA", :resource => {:revision => '0.6'} do
it "should return the ref" do it "should return the ref" do
provider.revision.should == '0.6' provider.revision.should == '0.6'
end end
end end
context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do
it "should return the current SHA" do it "should return the current SHA" do
provider.revision.should == '34e6012c783a' provider.revision.should == '34e6012c783a'
end end
end end
end end
context "when given a SHA as the resource revision" do context "when given a SHA as the resource revision" do
before do before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
end end
context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do
it "should return it" do it "should return it" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
provider.revision.should == resource.value(:revision) provider.revision.should == resource.value(:revision)
end end
end end
context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do
it "should return the current SHA" do it "should return the current SHA" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
provider.revision.should == '34e6012c783a' provider.revision.should == '34e6012c783a'
end end
end end
end end
end end
describe "setting the revision property" do describe "setting the revision property" do
before do before do
@revision = '6aa99e9b3ab1' @revision = '6aa99e9b3ab1'
end end
it "should use 'hg update ---clean -r'" do it "should use 'hg update ---clean -r'" do
expects_chdir expects_chdir
provider.expects(:hg).with('pull') provider.expects(:hg).with('pull')
provider.expects(:hg).with('merge') provider.expects(:hg).with('merge')
provider.expects(:hg).with('update', '--clean', '-r', @revision) provider.expects(:hg).with('update', '--clean', '-r', @revision)
provider.revision = @revision provider.revision = @revision
end end
end end
end end

View File

@@ -1,78 +1,78 @@
require 'spec_helper' require 'spec_helper'
describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do describe 'creating' do
resource_with :source do resource_with :source do
resource_with :revision do resource_with :revision do
it "should execute 'svn checkout' with a revision" do it "should execute 'svn checkout' with a revision" do
provider.expects(:svn).with('--non-interactive', 'checkout', '-r', provider.expects(:svn).with('--non-interactive', 'checkout', '-r',
resource.value(:revision), resource.value(:revision),
resource.value(:source), resource.value(:source),
resource.value(:path)) resource.value(:path))
provider.create provider.create
end end
end end
resource_without :revision do resource_without :revision do
it "should just execute 'svn checkout' without a revision" do it "should just execute 'svn checkout' without a revision" do
provider.expects(:svn).with('--non-interactive', 'checkout', provider.expects(:svn).with('--non-interactive', 'checkout',
resource.value(:source), resource.value(:source),
resource.value(:path)) resource.value(:path))
provider.create provider.create
end end
end end
end end
resource_without :source do resource_without :source do
resource_with :fstype do resource_with :fstype do
it "should execute 'svnadmin create' with an '--fs-type' option" do it "should execute 'svnadmin create' with an '--fs-type' option" do
provider.expects(:svnadmin).with('create', '--fs-type', provider.expects(:svnadmin).with('create', '--fs-type',
resource.value(:fstype), resource.value(:fstype),
resource.value(:path)) resource.value(:path))
provider.create provider.create
end end
end end
resource_without :fstype do resource_without :fstype do
it "should execute 'svnadmin create' without an '--fs-type' option" do it "should execute 'svnadmin create' without an '--fs-type' option" do
provider.expects(:svnadmin).with('create', resource.value(:path)) provider.expects(:svnadmin).with('create', resource.value(:path))
provider.create provider.create
end end
end end
end end
end end
describe 'destroying' do describe 'destroying' do
it "it should remove the directory" do it "it should remove the directory" do
expects_rm_rf expects_rm_rf
provider.destroy provider.destroy
end end
end end
describe "checking existence" do describe "checking existence" do
it "should check for the directory" do it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.svn')) expects_directory?(true, File.join(resource.value(:path), '.svn'))
provider.exists? provider.exists?
end end
end end
describe "checking the revision property" do describe "checking the revision property" do
before do before do
provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info)) provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info))
end end
it "should use 'svn info'" do it "should use 'svn info'" do
expects_chdir expects_chdir
provider.revision.should == '3' # From 'Last Changed Rev', not 'Revision' provider.revision.should == '3' # From 'Last Changed Rev', not 'Revision'
end end
end end
describe "setting the revision property" do describe "setting the revision property" do
before do before do
@revision = '30' @revision = '30'
end end
it "should use 'svn update'" do it "should use 'svn update'" do
expects_chdir expects_chdir
provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision) provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
provider.revision = @revision provider.revision = @revision
end end
end end
end end

View File

@@ -1,4 +1,4 @@
Resource Type Specs Resource Type Specs
=================== ===================
Define specs for your resource types in this directory. Define specs for your resource types in this directory.