29 Commits

Author SHA1 Message Date
dc3a3a9337 Release 0.4.0 2017-03-13 21:14:16 +00:00
e4df1583df Add executable bits on sabayon.sh operatingsytem fact 2017-03-13 21:00:12 +00:00
Alexander "Ace" Olofsson
0bc87f0cbf Replace custom fact with executable fact
Should solve #4
2017-03-12 23:46:36 +01:00
c87ceb824b Add CircleCI badge 2016-11-12 18:44:20 +00:00
Ben Roberts
55da9601b0 Merge pull request #3 from ace13/patch-1
Update operatingsystem.rb
2016-11-01 21:39:40 +00:00
Alexander "Ace" Olofsson
c46c360eb0 Update operatingsystem.rb
Use additional confines instead of checks in setcode to detect the distribution ID
2016-10-31 09:31:41 +01:00
9d89654211 Document requirement for lsb-release 2016-10-24 15:19:57 +01:00
d8b9a1b4a5 Add circle.yml to run automated tests on github push 2016-10-19 21:35:30 +01:00
9f8cc61cf1 [blacksmith] Bump version to 0.3.1 2016-10-16 13:44:51 +01:00
e962f31411 Release 0.3.0 2016-10-16 13:43:39 +01:00
97c1cc97e6 Add entropy_repos fact 2016-10-16 13:42:47 +01:00
bd1fd54bbb Handle unexpected boolean type conversion 2016-10-16 13:35:09 +01:00
3a4c1c85ad Add entropy_repo type/provider, with tests and docs 2016-10-16 00:40:35 +01:00
0c3db36c4d [blacksmith] Bump version to 0.2.1 2016-10-13 22:19:22 +01:00
9115033d04 [blacksmith] Bump version to 0.2.0 2016-10-13 22:18:18 +01:00
cabc5c19ce Update changelog for 0.2.0 release 2016-10-13 22:17:13 +01:00
7dca7dad51 Update README with information about bundled facts 2016-10-13 22:14:32 +01:00
53bbad2eb1 Fix entropy providers use of equo with locale
Previous attempt didn't work properly. This version uses the proper
`provider.has_command` api to specify the env vars which should be used.

Also catches the exit 1 thrown when `equo match --installed` doesn't
find anything, now that the wrapper script is no longer hiding the exit
code behind an explicit `exit 0`.
2016-10-13 22:08:04 +01:00
80644b6813 Update changelog 2016-10-13 18:56:38 +01:00
4020627a15 Remove obsolete has_entropy fact 2016-10-13 18:55:24 +01:00
a265caa979 Update entropy package provider to use locale without shelling out 2016-10-13 18:55:07 +01:00
7ce45a207f Add a locale fact which uses eselect locale to retrieve system default 2016-10-13 18:54:28 +01:00
6d9b130f9d Update changelog version to 0.1.2, workaround blacksmith problem 2016-10-13 17:07:04 +01:00
f2565cccc1 [blacksmith] Bump version to 0.1.3 2016-10-13 17:05:36 +01:00
f4bdac2266 [blacksmith] Bump version to 0.1.2 2016-10-13 17:04:51 +01:00
f90c0fb9ef Update changelog for release 0.1.1 2016-10-13 17:04:28 +01:00
5e5d056025 Remove required attribute validation
Previously, the entropy types would require that either package, tag, or repo
were provided, since that makes sense for the entropy files. Having a resource
that could not provide any of these would leave a malformed entry in the files.

I've had to remove that due to a deficiency in Puppet that's taken a long time
to track down. While the validation works fine for resources specified in
manifests, it breaks when parsing the records back in. Here's why:

- The provider instances method is called to retrieve a list of all entries
  in the entropy files. This correctly parses the name and properties into the
  provider instance object
- Puppet's type.rb enumerates through each of these, and tries to create a new
  Type insance using just the name and provider parameters from the provider
  instance. It then intends to iterate through the properties and add them one
  at a time.
  0c2157974a/lib/puppet/type.rb (L1180)
- The problem is that the top-level validation function is called when the
  object is first created, and at this time, none of the properties have been
  set, so the required properties have not been set and validation fails.

The top-level validation block cannot mandate a property be set, only other
types of condition.
2016-10-13 16:52:29 +01:00
0e774c77d5 Improve category/package regex, validation and add spec tests 2016-10-13 16:51:22 +01:00
f45895e8dd [blacksmith] Bump version to 0.1.1 2016-10-13 01:06:01 +01:00
28 changed files with 405 additions and 98 deletions

View File

@@ -1,3 +1,3 @@
--- ---
BUNDLE_PATH: vendor/bundle BUNDLE_PATH: "vendor/bundle"
BUNDLE_DISABLE_SHARED_GEMS: true BUNDLE_DISABLE_SHARED_GEMS: "true"

View File

@@ -1,3 +1,26 @@
## 2017-03-13 Release 0.4.0
- Replace operatingsystem.rb native fact with executable fact to workaround
[https://tickets.puppetlabs.com/browse/FACT-1528](FACT-1528) (ace13)
## 2016-10-16 Release 0.3.0
- Add `entropy_repo` type to enable/disable repositories
- Add `entropy_repos` fact
## 2016-10-13 Release 0.2.0
- Add `locale` fact
- Remove obsolete `has_entropy` fact
- Improve `entropy` package provider to set locale envvar directly
and not shell out to a distributed script to set locale.
## 2016-10-13 Release 0.1.2
- Improved package regexes for valdiation and parsing
(now following the Gentoo EAPI6 PMS document to ensure correctness)
- Removed validation for required parameters in `entropy_*` types
## 2016-10-13 Release 0.1.0 ## 2016-10-13 Release 0.1.0
- Added support for additional types: - Added support for additional types:

View File

@@ -1,5 +1,7 @@
# Sabayon # Sabayon
[![CircleCI](https://circleci.com/gh/Sabayon/puppet-sabayon.svg?style=shield)](https://circleci.com/gh/Sabayon/puppet-sabayon)
#### Table of Contents #### Table of Contents
1. [Description](#description) 1. [Description](#description)
@@ -18,7 +20,9 @@ This module extends puppet with support for the Sabayon Linux distribution.
It adds support for: It adds support for:
* The Entropy package manager * The Entropy package manager
* Managing `Sabayon Community Repository (SCR)` definitions using `enman` * Managing `Sabayon Community Repository (SCR)` definitions using `enman`
* Enabling and disabling entropy repositories
* Entropy package masks and unmasks * Entropy package masks and unmasks
* Splitdebug installs for packages
* Using systemd as the default service provider * Using systemd as the default service provider
## Setup ## Setup
@@ -35,6 +39,10 @@ It adds support for:
This module overrides the default provider for `package` resources to This module overrides the default provider for `package` resources to
force use of `entropy` force use of `entropy`
### Prerequisites
* `sys-apps/lsb-release` is required for the operatingsystem fact to work
### Beginning with sabayon ### Beginning with sabayon
The types and providers within this module can be used without any special The types and providers within this module can be used without any special
@@ -78,12 +86,41 @@ not install 'mysql' since there's no way to disambiguate between
### Managing enman repositories ### Managing enman repositories
Install an available SCR repository using enman. The title is taken to be the
repository name by default, and must be available via enman. Use an `ensure`
value of `present` to install the repo, and `absent` to remove it.
```puppet ```puppet
enman_repo { 'community': enman_repo { 'community':
ensure => present, ensure => present,
} }
``` ```
### Enabling and disabling entropy repositories
Installed repositories (whether system or SCR repositories) can be enabled and
disabled using the `entropy_repo` type.
To enable a repository, use:
```puppet
entropy_repo { 'sabayon-limbo':
enabled => 'true',
}
```
To disable a repository (only if present), use:
```puppet
if 'sabayon-limbo' in $facts['entropy_repos'] {
entropy_repo { 'sabayon-limbo':
enabled => 'false',
}
}
```
This type cannot currently install or remove repositories, only control the
enabled state of existing repositories. The repository being managed must
already exist on the system.
### Masking packages ### Masking packages
Entropy is very flexible in how to specify which packages can be masked, Entropy is very flexible in how to specify which packages can be masked,
@@ -238,11 +275,45 @@ For more info on package keywords, see https://wiki.gentoo.org/wiki/KEYWORDS
### Types ### Types
* `enman_repo`: Manages SCR repositories using enman * `enman_repo`: Manages SCR repositories using enman
* `entropy_repo`: Enables/Disables repositories
* `entropy_mask`: Manages entropy package masks * `entropy_mask`: Manages entropy package masks
* `entropy_unmask`: Manages entropy package unmasks * `entropy_unmask`: Manages entropy package unmasks
* `entropy_splitdebug` Manages entropy package debug information * `entropy_splitdebug` Manages entropy package debug information
* `entropy_splitdebug_mask` Manages entropy package debug information masks * `entropy_splitdebug_mask` Manages entropy package debug information masks
### Facts
#### `entropy_repos`
Provides a structured fact identifying the entropy repos present on the system
including their enabled/disabled state, and whether they are enman or entropy
repositories.
Example (in yaml format for readability):
```yaml
---
sabayonlinux.org:
repo_type: "entropy"
enabled: "true"
sabayon-limbo:
repo_type: "entropy"
enabled: "false"
community:
repo_type: "enman"
enabled: "true"
```
#### `locale`
Identifies the system-wide default locale, as set by `eselect`.
This is used internally by the entropy package provider to run `equo` commands
using the correct locale.
#### `operatingsystem`
Overrides the detection of the operating system on Sabayon systems to `Sabayon`.
## Limitations ## Limitations
This module is actively used by the developer against current Sabayon versions. This module is actively used by the developer against current Sabayon versions.
@@ -254,3 +325,7 @@ best-efforts basis.
Pull requests welcome! Pull requests welcome!
## Contributors
* [https://github.com/ace13](ace13)

3
circle.yml Normal file
View File

@@ -0,0 +1,3 @@
test:
override:
- bundle exec rake test

5
facts.d/sabayon.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
if [ -f /etc/sabayon-release ]; then
echo "operatingsystem=Sabayon"
fi

View File

@@ -0,0 +1,22 @@
Facter.add('entropy_repos') do
confine :operatingsystem => :Sabayon
setcode do
# Use the types/providers to do the heavy lifting here
repos = {}
Puppet::Type.type(:entropy_repo).provider(:file).instances().each do |repo|
Facter.debug(repo.enabled)
r = {
:repo_type => repo.repo_type,
:enabled => repo.enabled,
}
repos[repo.name] = r
end
repos
end
end

View File

@@ -1,7 +0,0 @@
Facter.add(:has_entropy) do
confine :kernel => :linux
setcode do
FileTest.exists?("/usr/bin/equo")
end
end

7
lib/facter/locale.rb Normal file
View File

@@ -0,0 +1,7 @@
Facter.add(:locale) do
confine :osfamily => :gentoo
setcode do
Facter::Core::Execution.exec('eselect --colour=no --brief locale show').strip
end
end

View File

@@ -1,14 +0,0 @@
Facter.add(:operatingsystem) do
# Sabayon Linux is a variant of Gentoo so this resolution needs to come
# before the Gentoo resolution.
has_weight(100)
confine :kernel => :linux
setcode do
distid = Facter.value(:lsbdistid)
if distid == "Sabayon"
'Sabayon'
end
end
end

View File

@@ -18,11 +18,11 @@ Puppet::Type.type(:entropy_keywords).provide(:parsed,
:match => /^\s*#/ :match => /^\s*#/
text_line :unmanaged, text_line :unmanaged,
:match => %r{^(\S+)\s+([<>]?=)?(?:([a-zA-Z+\/-]+)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?)?(?:\s*repo=([a-zA-Z0-9\._-]+))?\s*$} :match => %r{^(\S+)\s+([<>]?=)?(?:((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?)?(?:\s*repo=([a-zA-Z0-9\._-]+))?\s*$}
record_line :parsed, record_line :parsed,
:fields => %w{keyword operator package version repo name}, :fields => %w{keyword operator package version repo name},
:match => %r{^(\S+)\s+([<>]?=)?(?:([a-zA-Z+\/-]+)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?)?(?:\s*repo=([a-zA-Z0-9\._-]+))?\s+## Puppet Name: (.*)\s*$}, :match => %r{^(\S+)\s+([<>]?=)?(?:((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?)?(?:\s*repo=([a-zA-Z0-9\._-]+))?\s+## Puppet Name: (.*)\s*$},
:to_line => proc { |record| :to_line => proc { |record|
line = record[:keyword] + " " line = record[:keyword] + " "
line += record[:operator] if record[:operator] line += record[:operator] if record[:operator]

View File

@@ -18,11 +18,11 @@ Puppet::Type.type(:entropy_mask).provide(:parsed,
:match => /^\s*#/ :match => /^\s*#/
text_line :unmanaged, text_line :unmanaged,
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s*$} :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s*$}
record_line :parsed, record_line :parsed,
:fields => %w{operator package version slot use tag repo name}, :fields => %w{operator package version slot use tag repo name},
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s+#+ Puppet Name: (.*)\s*$}, :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s+#+ Puppet Name: (.*)\s*$},
:to_line => proc { |record| :to_line => proc { |record|
line = "" line = ""
line += record[:operator] if record[:operator] line += record[:operator] if record[:operator]

View File

@@ -0,0 +1,74 @@
Puppet::Type.type(:entropy_repo).provide(:file) do
desc "File provider for Entropy Repositories"
defaultfor :operatingsystem => :sabayon
mk_resource_methods
def type_prefix
if @property_hash[:repo_type] == 'enman'
'enman_'
else
''
end
end
def enabled=(value)
enabled_filename = "/etc/entropy/repositories.conf.d/entropy_#{type_prefix}#{@property_hash[:name]}"
disabled_filename = "/etc/entropy/repositories.conf.d/_entropy_#{type_prefix}#{@property_hash[:name]}"
if value == 'true' || value == :true
if File.exists?(disabled_filename)
File.rename(disabled_filename, enabled_filename)
end
else
if File.exists?(enabled_filename)
File.rename(enabled_filename, disabled_filename)
end
end
@property_hash[:enabled] = value
end
def self.instances
repos = Dir.entries('/etc/entropy/repositories.conf.d/')
repos.collect do |r|
if r == '.' || r == '..'
nil
elsif r =~ /\.example$/
nil
elsif r !~ /^_?entropy_/
nil
else
matches = /^(_)?entropy_(enman_)?(.*)$/.match(r)
enabled = matches[1].nil? ? 'true' : 'false'
type = matches[2] == 'enman_' ? 'enman' : 'entropy'
name = matches[3]
repo = {
:name => name,
:repo_type => type,
:enabled => enabled,
:provider => :entropy_repo,
}
new(repo)
end
end.compact
end
def self.prefetch(resources)
repos = self.instances()
resources.each do |name, resource|
if provider = repos.find { |r| r.name == name }
resources[name].provider = provider
end
end
end
end
# vim: set ts=2 shiftwidth=2 expandtab :

View File

@@ -18,11 +18,11 @@ Puppet::Type.type(:entropy_splitdebug).provide(:parsed,
:match => /^\s*#/ :match => /^\s*#/
text_line :unmanaged, text_line :unmanaged,
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9\._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9\._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s*$} :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9\._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9\._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s*$}
record_line :parsed, record_line :parsed,
:fields => %w{operator package version slot use tag repo name}, :fields => %w{operator package version slot use tag repo name},
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9\._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9\._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s+#+ Puppet Name: (.*)\s*$}, :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9\._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9\._-]+))?(?:::([a-zA-Z0-9\._-]+))?\s+#+ Puppet Name: (.*)\s*$},
:to_line => proc { |record| :to_line => proc { |record|
line = "" line = ""
line += record[:operator] if record[:operator] line += record[:operator] if record[:operator]

View File

@@ -18,11 +18,11 @@ Puppet::Type.type(:entropy_splitdebug_mask).provide(:parsed,
:match => /^\s*#/ :match => /^\s*#/
text_line :unmanaged, text_line :unmanaged,
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9\._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s*$} :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9\._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s*$}
record_line :parsed, record_line :parsed,
:fields => %w{operator package version slot use tag repo name}, :fields => %w{operator package version slot use tag repo name},
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s+#+ Puppet Name: (.*)\s*$}, :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s+#+ Puppet Name: (.*)\s*$},
:to_line => proc { |record| :to_line => proc { |record|
line = "" line = ""
line += record[:operator] if record[:operator] line += record[:operator] if record[:operator]

View File

@@ -18,11 +18,11 @@ Puppet::Type.type(:entropy_unmask).provide(:parsed,
:match => /^\s*#/ :match => /^\s*#/
text_line :unmanaged, text_line :unmanaged,
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s*$} :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s*$}
record_line :parsed, record_line :parsed,
:fields => %w{operator package version slot use tag repo name}, :fields => %w{operator package version slot use tag repo name},
:match => %r{^([<>]?=)?([a-zA-Z+\/-]*)(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s+#+ Puppet Name: (.*)\s*$}, :match => %r{^([<>]?=)?((?:[A-Za-z0-9+_.-]+/)?[a-zA-Z0-9+_-]+)?(?:-(\d+(?:\.\d+)*[a-z]*(?:_(?:alpha|beta|pre|p|rc)\d*)?(?:-r\d+)?))?(?::([a-zA-Z0-9._-]+))?(?:\[([^\]]*)\])?(?:#([a-zA-Z0-9._-]+))?(?:::([a-zA-Z0-9._-]+))?\s+#+ Puppet Name: (.*)\s*$},
:to_line => proc { |record| :to_line => proc { |record|
line = "" line = ""
line += record[:operator] if record[:operator] line += record[:operator] if record[:operator]

View File

@@ -1,7 +1,7 @@
require 'puppet/provider/package' require 'puppet/provider/package'
require 'fileutils' require 'fileutils'
Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Package do Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Package) do
desc "Provides packaging support for Sabayon's entropy system." desc "Provides packaging support for Sabayon's entropy system."
has_feature :versionable has_feature :versionable
@@ -9,18 +9,27 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
has_feature :uninstallable has_feature :uninstallable
has_feature :upgradeable has_feature :upgradeable
commands :equo => "#{File.dirname(__FILE__)}/entropy/equo_locale" has_command(:equo, "equo") do
locale = Facter.value(:locale)
environment({
:LANG => locale,
:LC_ALL => locale,
:LANGUAHE => locale,
})
end
confine :has_entropy => true # Require the locale fact exist
confine :false => Facter.value(:locale).nil?
confine :osfamily => :Gentoo
defaultfor :has_entropy => :true, :osfamily => :Gentoo defaultfor :operatingsystem => :Sabayon
def self.instances def self.instances
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_?(?:a(?:lpha)?|b(?:eta)?|pre|rc|p)\d*)?(?:-r\d+)?)(?:#(\S+))?$/ result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_?(?:a(?:lpha)?|b(?:eta)?|pre|rc|p)\d*)?(?:-r\d+)?)(?:#(\S+))?$/
result_fields = [:category, :name, :ensure] result_fields = [:category, :name, :ensure]
begin begin
search_output = equo "query", "list", "installed", "--quiet", "--verbose" search_output = equo("query", "list", "installed", "--quiet", "--verbose").chomp
packages = [] packages = []
search_output.each_line do |search_result| search_output.each_line do |search_result|
@@ -32,6 +41,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
package[field] = value unless !value or value.empty? package[field] = value unless !value or value.empty?
end end
package[:provider] = :entropy package[:provider] = :entropy
packages << new(package) packages << new(package)
end end
end end
@@ -70,13 +80,12 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
end end
def query def query
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_(?:alpha|beta|pre|rc|p)\d+)?(?:-r\d+)?)(?:#(\S+))?$/ result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_(?:alpha|beta|pre|rc|p)\d+)?(?:-r\d+)?)(?::[^#]+)?(?:#(\S+))?$/
result_fields = [:category, :name, :version_available] result_fields = [:category, :name, :version_available]
begin begin
# Look for an installed package from a known repository # Look for an installed package from a known repository
search_output = equo "match", "--quiet", "--verbose", package_name search_output = equo("match", "--quiet", "--verbose", package_name).chomp
search_output.chomp
search_match = search_output.match(result_format) search_match = search_output.match(result_format)
if search_match if search_match
@@ -85,14 +94,18 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
package[field] = value unless !value or value.empty? package[field] = value unless !value or value.empty?
end end
installed_output = equo 'match', '--quiet', '--verbose', '--installed', package_name
installed_output.chomp
installed_match = installed_output.match(result_format)
if installed_match begin
installed_match_fields = Hash[result_fields.zip(installed_match.captures)] installed_output = equo('match', '--quiet', '--verbose', '--installed', package_name).chomp
package[:ensure] = installed_match_fields[:version_available] installed_match = installed_output.match(result_format)
else
if installed_match
installed_match_fields = Hash[result_fields.zip(installed_match.captures)]
package[:ensure] = installed_match_fields[:version_available]
else
package[:ensure] = :absent
end
rescue Puppet::ExecutionFailure
package[:ensure] = :absent package[:ensure] = :absent
end end
@@ -101,8 +114,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
else else
# List all installed packages and try and find if it's installed from outside a repository # List all installed packages and try and find if it's installed from outside a repository
# If so, assume the installed version is the latest available # If so, assume the installed version is the latest available
all_installed = equo "query", "list", "installed", "--quiet", "--verbose" all_installed = equo("query", "list", "installed", "--quiet", "--verbose").chomp
all_installed.chomp
all_installed.split("\n").each do |installed_package| all_installed.split("\n").each do |installed_package|

View File

@@ -1,6 +0,0 @@
#!/bin/bash
source /etc/profile
/usr/bin/equo $@
exit 0

View File

@@ -26,14 +26,12 @@ Puppet::Type.newtype(:entropy_keywords) do
newproperty(:package) do newproperty(:package) do
desc "Name of the package being keyworded" desc "Name of the package being keyworded"
newvalues(%r{^(?:[A-Za-z0-9+_.-]+\/)?[a-zA-Z0-9+_-]+$})
end end
newproperty(:version) do newproperty(:version) do
desc "Version of the package" desc "Version of the package"
newvalues(%r{^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$})
validate do |value|
raise(ArgumentError, "") if value !~ /^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$/
end
end end
newproperty(:repo) do newproperty(:repo) do
@@ -53,8 +51,6 @@ Puppet::Type.newtype(:entropy_keywords) do
end end
validate do validate do
raise(ArgumentError, "At least one of package or repo is required") if self[:package].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil? raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil? raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -13,14 +13,12 @@ Puppet::Type.newtype(:entropy_mask) do
newproperty(:package) do newproperty(:package) do
desc "Name of the package being masked" desc "Name of the package being masked"
newvalues(%r{^(?:[A-Za-z0-9+_.-]+\/)?[a-zA-Z0-9+_-]+$})
end end
newproperty(:version) do newproperty(:version) do
desc "Version of the package" desc "Version of the package"
newvalues(%r{^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$})
validate do |value|
raise(ArgumentError, "") if value !~ /^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$/
end
end end
newproperty(:slot) do newproperty(:slot) do
@@ -52,8 +50,6 @@ Puppet::Type.newtype(:entropy_mask) do
end end
validate do validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil? raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil? raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -0,0 +1,22 @@
require 'puppet/property/boolean'
Puppet::Type.newtype(:entropy_repo) do
@desc = "Manages Entropy Repositories"
newparam(:name) do
desc "Name of the Entropy Repository"
end
newproperty(:repo_type, :readonly => true) do
desc "What type of repository this is (enman or entropy)"
end
newproperty(:enabled) do
desc "Whether the repository is enabled or not"
newvalues('true', 'false')
end
end
# vim: set ts=2 shiftwidth=2 expandtab :

View File

@@ -13,14 +13,12 @@ Puppet::Type.newtype(:entropy_splitdebug) do
newproperty(:package) do newproperty(:package) do
desc "Name of the package with splitdebug" desc "Name of the package with splitdebug"
newvalues(%r{^(?:[A-Za-z0-9+_.-]+\/)?[a-zA-Z0-9+_-]+$})
end end
newproperty(:version) do newproperty(:version) do
desc "Version of the package" desc "Version of the package"
newvalues(%r{^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$})
validate do |value|
raise(ArgumentError, "") if value !~ /^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$/
end
end end
newproperty(:slot) do newproperty(:slot) do
@@ -52,8 +50,6 @@ Puppet::Type.newtype(:entropy_splitdebug) do
end end
validate do validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil? raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil? raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -13,14 +13,12 @@ Puppet::Type.newtype(:entropy_splitdebug_mask) do
newproperty(:package) do newproperty(:package) do
desc "Name of the package with splitdebug mask" desc "Name of the package with splitdebug mask"
newvalues(%r{^(?:[A-Za-z0-9+_.-]+\/)?[a-zA-Z0-9+_-]+$})
end end
newproperty(:version) do newproperty(:version) do
desc "Version of the package" desc "Version of the package"
newvalues(%r{^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$})
validate do |value|
raise(ArgumentError, "") if value !~ /^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$/
end
end end
newproperty(:slot) do newproperty(:slot) do
@@ -52,8 +50,6 @@ Puppet::Type.newtype(:entropy_splitdebug_mask) do
end end
validate do validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil? raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil? raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -13,14 +13,12 @@ Puppet::Type.newtype(:entropy_unmask) do
newproperty(:package) do newproperty(:package) do
desc "Name of the package being masked" desc "Name of the package being masked"
newvalues(%r{^(?:[A-Za-z0-9+_.-]+\/)?[a-zA-Z0-9+_-]+$})
end end
newproperty(:version) do newproperty(:version) do
desc "Version of the package" desc "Version of the package"
newvalues(%r{^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$})
validate do |value|
raise(ArgumentError, "") if value !~ /^(\d*(?:\.\d+[a-zA-Z]*)*)(?:_((?:alpha|beta|pre|rc)\d*))?(-r\d+)?$/
end
end end
newproperty(:slot) do newproperty(:slot) do
@@ -52,8 +50,6 @@ Puppet::Type.newtype(:entropy_unmask) do
end end
validate do validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil? raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil? raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -1,6 +1,6 @@
{ {
"name": "optiz0r-sabayon", "name": "optiz0r-sabayon",
"version": "0.1.0", "version": "0.4.0",
"author": "Ben Roberts", "author": "Ben Roberts",
"license": "MIT", "license": "MIT",
"summary": "Extends Puppet with support for the Sabayon Linux distribution", "summary": "Extends Puppet with support for the Sabayon Linux distribution",

View File

@@ -0,0 +1,61 @@
require 'spec_helper'
describe Puppet::Type.type(:entropy_repo).provider(:file) do
describe 'when fetching existing resources' do
let(:instances) do
described_class.instances
end
let(:repos) do
[
{:name => 'sabayonlinux.org', :type => 'entropy', :enabled => 'true'},
{:name => 'sabayon-limbo', :type => 'entropy', :enabled => 'false'},
{:name => 'community', :type => 'enman', :enabled => 'true'},
]
end
before do
Dir.stubs(:entries).with('/etc/entropy/repositories.conf.d/').returns([
'.', '..', 'README',
'entropy_sabayonlinux.org',
'_entropy_sabayon-limbo',
'entropy_enman_community',
'entropy_foobar.example',
])
end
it 'should identify the correct number of repos' do
expect(instances.size).to eq(repos.size)
end
it 'should identify the correct repo name' do
repos.each_with_index do |repo, index|
expect(instances[index].name).to eq(repo[:name])
end
end
it 'should identify the correct enabled state' do
repos.each_with_index do |repo, index|
expect(instances[index].enabled).to eq(repo[:enabled])
end
end
end
describe 'when enabling a repository' do
it 'should enable a disabled repository' do
File.stubs(:exists?).with('/etc/entropy/repositories.conf.d/entropy_sabayonlinux.org').returns(true).once
File.stubs(:rename).with('/etc/entropy/repositories.conf.d/entropy_sabayonlinux.org', '/etc/entropy/repositories.conf.d/_entropy_sabayonlinux.org').once
instance = described_class.new(:name => 'sabayonlinux.org', :enabled => 'true', :type => 'entropy')
instance.enabled = 'false'
end
end
describe 'when disabling a repository' do
it 'should disable an enabled repository' do
File.stubs(:exists?).with('/etc/entropy/repositories.conf.d/_entropy_sabayon-limbo').returns(true).once
File.stubs(:rename).with('/etc/entropy/repositories.conf.d/_entropy_sabayon-limbo', '/etc/entropy/repositories.conf.d/entropy_sabayon-limbo').once
instance = described_class.new(:name => 'sabayon-limbo', :enabled => 'false', :type => 'entropy')
instance.enabled = 'true'
end
end
end

View File

@@ -40,12 +40,6 @@ describe Puppet::Type.type(:entropy_keywords) do
end end
describe "when validating required properties" do describe "when validating required properties" do
it "should raise an error when no required attributes are passed" do
expect {
described_class.new(:name => "test")
}.to raise_error(Puppet::Error, /At least one of (.*) is required/)
end
it "should raise an error when a version is passed with no package" do it "should raise an error when a version is passed with no package" do
expect { expect {
described_class.new(:name => "test", :repo => "test", :version => "1.2.3") described_class.new(:name => "test", :repo => "test", :version => "1.2.3")

View File

@@ -0,0 +1,32 @@
describe Puppet::Type.type(:entropy_repo) do
before do
@provider = stub 'provider'
@provider.stubs(:name).returns(:file)
described_class.stubs(:defaultprovider).returns(@provider)
end
it "should be an instance of Puppet::Type::Entropy_repo" do
expect(described_class.new(:name => "test")).to be_an_instance_of Puppet::Type::Entropy_repo
end
describe "when validating attributes" do
params = [:name]
properties = [:repo_type, :enabled]
params.each do |param|
it "should have the #{param} param" do
expect(described_class.attrtype(param)).to eq :param
end
end
properties.each do |property|
it "should have the #{property} property" do
expect(described_class.attrtype(property)).to eq :property
end
end
end
it "should have name as the namevar" do
expect(described_class.key_attributes).to eq [:name]
end
end

View File

@@ -54,10 +54,34 @@ types.each do |type_name, type|
end end
describe "when validating required properties" do describe "when validating required properties" do
it "should raise an error when no required attributes are passed" do packages = [
expect { 'virtual/package',
described_class.new(:name => "test") 'package',
}.to raise_error(Puppet::Error, /At least one of (.*) is required/) 'package-with-dash',
'package_with_underscores',
'category-123/package2',
'category.with.dots/package'
]
packages.each do |package|
it "should accept valid package name #{package}" do
expect {
described_class.new(:name => 'test', :package => package)
}.not_to raise_error
end
end
packages = [
'two/category/package',
'invalid-package-1.2',
'/no-category-package',
'no-package-category/',
]
packages.each do |package|
it "should reject invalid package name #{package}" do
expect {
described_class.new(:name => 'test', :package => package)
}.to raise_error(Puppet::Error)
end
end end
it "should raise an error when a version is passed with no package" do it "should raise an error when a version is passed with no package" do