Giuseppe Lavagetto has submitted this change and it was merged.

Change subject: scap_source: use one provider, pass "origin" as a parameter
......................................................................


scap_source: use one provider, pass "origin" as a parameter

This has a couple of advantages:

- we don't abuse the provider concept for something that has not much to
  do with it
- puppet-compiler will work wherever scap_source is defined
- we can validate origins and add some easier.

Also, add some basic tests.

Change-Id: I09a8a7c462b644e1dbd344e0fdf986554379fb3f
---
R modules/scap/lib/puppet/provider/scap_source/default.rb
D modules/scap/lib/puppet/provider/scap_source/gerrit.rb
D modules/scap/lib/puppet/provider/scap_source/phabricator.rb
M modules/scap/lib/puppet/type/scap_source.rb
A modules/scap/spec/types/scap_source_spec.rb
5 files changed, 67 insertions(+), 68 deletions(-)

Approvals:
  Giuseppe Lavagetto: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/scap/lib/puppet/provider/scap_source.rb 
b/modules/scap/lib/puppet/provider/scap_source/default.rb
similarity index 91%
rename from modules/scap/lib/puppet/provider/scap_source.rb
rename to modules/scap/lib/puppet/provider/scap_source/default.rb
index 9e01921..7c1b8fa 100644
--- a/modules/scap/lib/puppet/provider/scap_source.rb
+++ b/modules/scap/lib/puppet/provider/scap_source/default.rb
@@ -1,4 +1,4 @@
-# Puppet base provider for type `scap_source`, which is needed to set up a
+# Puppet default provider for type `scap_source`, which is needed to set up a
 # base repository to use with the `scap3` deployment system
 #
 # Copyright (c) 2016 Giuseppe Lavagetto
@@ -25,6 +25,10 @@
 class Puppet::Provider::Scap_source < Puppet::Provider
   initvars
 
+  def self.default?
+    true
+  end
+
   has_command(:git, '/usr/bin/git')
 
   BASE_PATH = '/srv/deployment'
@@ -35,8 +39,13 @@
   end
 
   # The origin of the repository
-  def origin(*)
-    raise Puppet::Error "origin must be implemented by actual providers"
+  def origin(repo_name)
+    case resource[:origin]
+    when :gerrit
+      "https://gerrit.wikimedia.org/r/p/#{repo_name}.git";
+    when :phabricator
+      "https://phabricator.wikimedia.org/diffusion/#{repo_name}.git";
+    end
   end
 
   # The path to install the git clone to
diff --git a/modules/scap/lib/puppet/provider/scap_source/gerrit.rb 
b/modules/scap/lib/puppet/provider/scap_source/gerrit.rb
deleted file mode 100644
index 5395bab..0000000
--- a/modules/scap/lib/puppet/provider/scap_source/gerrit.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# Puppet gerrit provider for type `scap_source`, which is needed to set up a
-# base repository to use with the `scap3` deployment system
-#
-# Copyright (c) 2016 Giuseppe Lavagetto
-#
-# 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.
-#
-
-require 'puppet/provider/scap_source'
-
-Puppet::Type.type(:scap_source).provide(:gerrit, :parent => 
Puppet::Provider::Scap_source) do
-  desc 'Puppet provider for scap_source, for gerrit projects'
-
-  # Gerrit is the default independently of system facts, so this little hack
-  def self.default?
-    true
-  end
-
-  # The origin of the repository
-  def origin(repo_name)
-    "https://gerrit.wikimedia.org/r/p/#{repo_name}.git";
-  end
-
-
-end
diff --git a/modules/scap/lib/puppet/provider/scap_source/phabricator.rb 
b/modules/scap/lib/puppet/provider/scap_source/phabricator.rb
deleted file mode 100644
index c7b889d..0000000
--- a/modules/scap/lib/puppet/provider/scap_source/phabricator.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# Puppet phabricator provider for type `scap_source`, which is needed to set 
up a
-# base repository to use with the `scap3` deployment system
-#
-# Copyright (c) 2016 Giuseppe Lavagetto
-#
-# 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.
-#
-
-require 'puppet/provider/scap_source'
-
-Puppet::Type.type(:scap_source).provide(:phabricator, :parent => 
Puppet::Provider::Scap_source) do
-  desc 'Puppet provider for scap_source, for gerrit projects'
-
-  # The origin of the repository
-  def origin(repo_name)
-    "https://phabricator.wikimedia.org/diffusion/#{repo_name}.git";
-  end
-
-end
diff --git a/modules/scap/lib/puppet/type/scap_source.rb 
b/modules/scap/lib/puppet/type/scap_source.rb
index b57aeb1..3b5836e 100644
--- a/modules/scap/lib/puppet/type/scap_source.rb
+++ b/modules/scap/lib/puppet/type/scap_source.rb
@@ -41,6 +41,11 @@
 #   Group owner of cloned repository.
 #   Default: wikidev
 #
+# [*origin*]
+#   VCS to checkout from. Available values are gerrit and phabricator
+#
+#   Default: gerrit
+#
 # == Usage
 #
 #   # Clones the 'repo/without/external/scap' repsitory into
@@ -127,7 +132,7 @@
 repositories.
 Default: false.
 EOT
-    defaultto false
+    defaultto :false
     munge do |value|
       case value
       when false, :false
@@ -139,4 +144,10 @@
       end
     end
   end
+
+  newparam(:origin) do
+    desc "The VCS to fetch data from"
+    newvalues(:gerrit, :phabricator)
+    defaultto :gerrit
+  end
 end
diff --git a/modules/scap/spec/types/scap_source_spec.rb 
b/modules/scap/spec/types/scap_source_spec.rb
new file mode 100644
index 0000000..bb10dd6
--- /dev/null
+++ b/modules/scap/spec/types/scap_source_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+resource_class = Puppet::Type.type(:scap_source)
+
+describe resource_class do
+  describe 'when validating attributes' do
+    [:repository, :scap_repository, :origin, :owner, :group].each do |param|
+      it "should have a #{param} parameter" do
+        expect(described_class.attrtype(param)).to eq(:param)
+      end
+    end
+    [:ensure].each do |property|
+      it "should have a #{property} property" do
+        expect(described_class.attrtype(property)).to eq(:property)
+      end
+    end
+  end
+
+
+  context "Default values" do
+    subject do
+      resource_class.new(:name => 'test/deploy')
+    end
+
+    it "name variable should be test/deploy" do
+      expect(subject.name).to eq('test/deploy')
+    end
+
+    it "owner/group should be trebuchet/wikidev" do
+      expect(subject[:owner]).to eq('trebuchet')
+      expect(subject[:group]).to eq('wikidev')
+    end
+
+    it "repository should be equal to the title" do
+      expect(subject[:repository]).to eq('test/deploy')
+      expect(subject[:scap_repository]).to eq(false)
+    end
+
+    it "origin should be gerrit" do
+      expect(subject[:origin]).to eq(:gerrit)
+    end
+  end
+end

-- 
To view, visit https://gerrit.wikimedia.org/r/314295
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I09a8a7c462b644e1dbd344e0fdf986554379fb3f
Gerrit-PatchSet: 2
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to