Andrew Bogott has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/368606 )

Change subject: get $::labsproject from the certname
......................................................................


get $::labsproject from the certname

If we enforce <host>.<project>.<site>.wmflabs
certnames then we can rely on the project being
in the certname so there's no need to call out
to the metadata service.

Bug: T171289
Change-Id: Ie23f221e9a2c7906820c37dcfbddd121c1212eba
---
M manifests/realm.pp
D modules/base/lib/facter/labsprojectfrommetadata.rb
2 files changed, 13 insertions(+), 23 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/manifests/realm.pp b/manifests/realm.pp
index 900ca27..d60e274 100644
--- a/manifests/realm.pp
+++ b/manifests/realm.pp
@@ -21,13 +21,21 @@
 }
 
 if $realm == 'labs' {
+    # Pull the project name from the certname.
+    # Labs certs are <hostname>.<projname>.<site>.wmflabs
+    $pieces = split($trusted['certname'], '[.]')
 
-    $labs_metal = hiera('labs_metal', {})
-    if has_key($labs_metal, $::hostname) {
-        $labsproject = $labs_metal[$::hostname]['project']
-    } else {
-        $labsproject = $::labsprojectfrommetadata
+    if $pieces[3] != 'wmflabs' {
+        fail("Badly-formed puppet certname: ${trusted['certname']}")
     }
+    if $pieces[2] != $site {
+        fail("Incorrect site in certname.  Should be ${site} but is 
${pieces[2]}")
+    }
+    if $pieces[0] != $::hostname {
+        fail("Cert hostname ${pieces[0]} does not match reported hostname 
${::hostname}")
+    }
+
+    $labsproject = $pieces[1]
 
     if $::labsproject == undef {
         fail('Failed to determine $::labsproject')
diff --git a/modules/base/lib/facter/labsprojectfrommetadata.rb 
b/modules/base/lib/facter/labsprojectfrommetadata.rb
deleted file mode 100644
index 8d738d3..0000000
--- a/modules/base/lib/facter/labsprojectfrommetadata.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# labsprojectfrommetadata.rb
-#
-# This fact pulls the labs project out of instance metadata
-
-require 'facter'
-
-Facter.add(:labsprojectfrommetadata) do
-  setcode do
-    domain = Facter::Util::Resolution.exec("hostname -d").chomp
-    if (domain.end_with? ".wmflabs") || (domain.end_with? ".labtest")
-      # query the nova metadata service at 169.254.169.254
-      metadata = Facter::Util::Resolution.exec("curl -f 
http://169.254.169.254/openstack/2015-10-15/meta_data.json/ 2> /dev/null | jq 
'.project_id'").chomp
-      metadata.slice(1, metadata.length - 2) # strip quotes
-    else
-      nil
-    end
-  end
-end

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie23f221e9a2c7906820c37dcfbddd121c1212eba
Gerrit-PatchSet: 4
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to