Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase of #683 / mock systemd fact properly #715

Merged
merged 8 commits into from
Sep 5, 2018

Conversation

bastelfreak
Copy link
Member

I'm trying things out here. #683 itself is working now, with the unreleased changes in puppet-systemd. However I'm running into one strange rspec issue where it seems to not properly mock the systemd/service_provider fact.

@bastelfreak
Copy link
Member Author

Line 152/159 in spec/classes/rabbitmq_spec.rb simply print nothing?!

"centos-6-x86_64"
{:partitions=>{"sdb1"=>{"filesystem"=>"LVM2_member", "size"=>"16771797"}, "sda1"=>{"mount"=>"/boot", "uuid"=>"c9b8c4a4-7c49-4cb0-b7ee-6dd795e27c87", "filesystem"=>"ext4", "size"=>"1024000"}, "sda2"=>{"filesystem"=>"LVM2_member", "size"=>"15751168"}}, :uuid=>"422273AE-E387-A0B8-0C01-7F02DAD1BB66", :blockdevice_sda_model=>"Virtual disk", :selinux_config_mode=>"enforcing", :sshfp_dsa=>"SSHFP 2 1 8ebb6d9078da9da416723cac88c46bca6fe0ec54\nSSHFP 2 2 fd2bf6b3b04a115a7c8368a7f7e7738cf41d9e4c3eaf13033a38a53fe119ac69", :swapsize=>"3.94 GB", :blockdevice_sr0_vendor=>"NECVMWar", :mtu_lo=>16436, :kernelversion=>"2.6.32", :selinux_current_mode=>"enforcing", :timezone=>"PDT", :kernelrelease=>"2.6.32-431.11.2.el6.x86_64", :kernel=>"Linux", :processor1=>"Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz", :hardwaremodel=>"x86_64", :id=>"root", :bios_version=>"6.00", :rubyplatform=>"x86_64-linux", :gid=>"root", :ipaddress=>"10.32.121.72", :architecture=>"x86_64", :uptime_hours=>0, :boardproductname=>"440BX Desktop Reference Platform", :memoryfree_mb=>"5695.45", :blockdevices=>"sda,sdb,sr0", :network_eth0=>"10.32.112.0", :operatingsystem=>"CentOS", :osfamily=>"RedHat", :blockdevice_sda_vendor=>"VMware", :physicalprocessorcount=>2, :blockdevice_sdb_model=>"Virtual disk", :operatingsystemmajrelease=>"6", :blockdevice_sda_size=>8589934592, :blockdevice_sr0_size=>1073741312, :operatingsystemrelease=>"6.5", :ipaddress_lo=>"127.0.0.1", :blockdevice_sr0_model=>"VMware IDE CDR10", :facterversion=>"2.5.0", :network_lo=>"127.0.0.0", :bios_vendor=>"Phoenix Technologies LTD", :netmask_eth0=>"255.255.240.0", :fqdn=>"foo.example.com", :manufacturer=>"VMware, Inc.", :processor0=>"Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz", :hostname=>"foo", :hardwareisa=>"x86_64", :selinux_policyversion=>"24", :sshfp_rsa=>"SSHFP 1 1 c48ea7d5f6f38b3797e1e672f98ddf4d31796456\nSSHFP 1 2 b953c17a0af98e6fb1f3d06f2cc1e386a54e4868b2ea688ff950f4b8c5ed354a", :rubyversion=>"2.5.1", :interfaces=>"eth0,lo", :bios_release_date=>"07/30/2013", :uptime_days=>0, :swapsize_mb=>"4031.99", :swapfree_mb=>"4031.99", :kernelmajversion=>"2.6", :boardmanufacturer=>"Intel Corporation", :selinux_enforced=>true, :virtual=>"vmware", :os=>{"release"=>{"full"=>"6.5", "major"=>"6", "minor"=>"5"}, "name"=>"CentOS", "family"=>"RedHat"}, :mtu_eth0=>1500, :uniqueid=>"200a4879", :selinux_config_policy=>"targeted", :ps=>"ps -ef", :boardserialnumber=>"None", :serialnumber=>"VMware-42 22 73 ae e3 87 a0 b8-0c 01 7f 02 da d1 bb 66", :netmask_lo=>"255.0.0.0", :system_uptime=>{"hours"=>0, "uptime"=>"0:27 hours", "seconds"=>1620, "days"=>0}, :selinux=>true, :ipaddress_eth0=>"10.32.121.72", :type=>"Other", :blockdevice_sdb_vendor=>"VMware", :is_virtual=>true, :processors=>{"models"=>["Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz", "Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz"], "physicalcount"=>2, "count"=>2}, :blockdevice_sdb_size=>8589934592, :uptime=>"0:27 hours", :netmask=>"255.255.240.0", :rubysitedir=>"/usr/lib/ruby/site_ruby/2.5.0", :swapfree=>"3.94 GB", :sshdsakey=>"AAAAB3NzaC1kc3MAAACBAJGJ+wHqAvYTv3VEzhPo3rwiaVxesMSstvufqZIYNLci54bEy7Dlq++scLFU7EjqhlnGG0HWZ+aHQpDY8TvvsRIw8Q9nyxHAonk0EtHu4RCF6MH1lo0IeAh12A0vEpaVgpQjKisfWuH/IQEi1wCCaVL0lsLc5CLe1wE+yKqWuyVrAAAAFQD+F89mMng0ZXHd9NKbsZO5LQ5vcQAAAIAN6ysU1N1SASyGwtWuAnkRKxusYgCpQ0L7hx7shXHiQ69WoQxzgUUb5AdF++kMQdplcqrD2MIf+6hk5o4kzkPTEJTpfl7l/qp2L6znDR5yjz+G4b499eD3UGmlLIOgb1R7v/mS7Q3Y0XYsh1nBJyupOiTIMT1g6f7pQkA/9eimgwAAAIAiqkmEyA+8HRxg02zyPVG3z0RBFQnqnjLO8GaVFLq+3j5HTYgHuyktn2Js2Qke0j8bJ7gs/9Zaxq2dxC9BCZV29VAtmp7DO6lZgh3qwvA1uUKraO2J5zzWZHhJ2c9/apGtySBeOD1lOgGiXLkn5x4R09kLs56f5n+ax2kVa4qs3A==", :memorysize_mb=>"5852.69", :productname=>"VMware Virtual Platform", :path=>"/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", :processorcount=>2, :macaddress=>"00:50:56:A2:81:EB", :memorysize=>"5.72 GB", :filesystems=>"ext4,iso9660", :domain=>"example.com", :sshrsakey=>"AAAAB3NzaC1yc2EAAAABIwAAAQEAr2ywcLVQDql7LcLz8DZvJLWuEdb86cwe/q8TVqd7E1V0fKvXhZBXUN1aGeuvY+ewfnlYh79ioDvslGCSh452caet3JljzhtU6mFtTpPm5FPofZ9a5SbR4oC5abFe8WH19KGI/HSsXEGqtNwNAcX6kfJSgcCRcPv+Jg0rO4Goncv8hLEv+ek+izVpuAPPBvgHN1QLlfSlN0rlYvn62WDs0ecYTGpmy03JisfYubefJ25roOFxakx8NAdajb1Ce5IV7GxEn5BSe9mjGPI4UvDFYtDEMeKhDl8eKxICfcei8X6uUfunr1N4kIjn3Q78aloCFhzn37OSI71rjmYISOq3JQ==", :uptime_seconds=>1620, :memoryfree=>"5.56 GB", :macaddress_eth0=>"00:50:56:A2:81:EB", :mco_version=>"2.12.1", :puppetversion=>"5.5.3"}
the systemd fact has this value: 
the systemd fact has this value: 
the systemd fact has this value: 
the systemd fact has this value: 
Coverage report generated for RSpec to /home/bastelfreak/modulesync_config/modules/puppet-rabbitmq/coverage. 0 / 1521 LOC (0.0%) covered.

@bastelfreak
Copy link
Member Author

This now works as soon as we have a new release of camptocamp/systemd

@bastelfreak bastelfreak changed the title WIP: Rebase of #683 / mock systemd fact properly Rebase of #683 / mock systemd fact properly Aug 29, 2018
@bastelfreak bastelfreak force-pushed the wip branch 4 times, most recently from b955458 to 431e65d Compare September 3, 2018 17:51
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I like the simplification

Boolean $stomp_ssl_only = $rabbitmq::params::stomp_ssl_only,
Boolean $wipe_db_on_cookie_change = $rabbitmq::params::wipe_db_on_cookie_change,
String $cluster_partition_handling = $rabbitmq::params::cluster_partition_handling,
Variant[Integer[-1],Enum['unlimited'],Pattern[/^(infinity|\d+(:(infinity|\d+))?)$/]] $file_limit = $rabbitmq::params::file_limit,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reason why I don't like the = alignment ;) I do wonder if puppet-systemd should have a type for this so you can reuse it in cases like these. Currently it's hidden in a struct so no reuse there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a reuse is possible, if we would use the type correctly.

  if $facts['systemd'] { # systemd fact provided by systemd module
    systemd::service_limits { 'rabbitmq.service':
      limits          => {'LimitNOFILE' => $file_limit},
      # The service will be notified when config changes
      restart_service => false,
    }   
  }

We could reuse the struct if we would allow people to pass the whole hash. What we could do: Create a new optional parameter with the struct from puppet-systemd. If it is set we pass it to $systemd::service_limits::limits, otherwise we use $rabbitmq::file_limit. This would be easier if $rabbitmq::file_limit would not be used for legacy /etc/limits entries as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: Alignment, it is way easier to read if you ignore whitespace changes in the diff.

when 'RedHat'
case facts[:os]['release']['major']
when '6'
{ service_provider: 'sysv', systemd: false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically EL6 was upstart. Probably won't matter.

case facts[:os]['release']['major']
when '6'
{ service_provider: 'sysv', systemd: false }
when '7'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this just be else? That way you're future proof.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see this as when '7'. I can see arguments for both ways - but in this case, probably makes most sense to have it be else.

case facts[:os]['release']['major']
when '7'
{ service_provider: 'sysv', systemd: false }
when '8'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can catch this as else as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

add_custom_fact :rabbitmq_version, '3.6.1' # puppet-rabbitmq
add_custom_fact :erl_ssl_path, '/usr/lib64/erlang/lib/ssl-7.3.3.1/ebin' # puppet-rabbitmq

def os_specific_facts(facts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative:

add_custom_fact :systemd, lambda do |os, facts|
  case facts[:os]['family']
  when 'Debian'
    case facts[:os]['name']
    when 'Debian'
      facts[:os]['release']['major'].to_i >= 8
    when 'Ubuntu'
      facts[:os]['release']['major'].to_i >= 16
    else
      true
    end
  when 'RedHat'
    facts[:os]['release']['major'].to_i >= 7
  else
    true
  end
end

The benefit is that you don't have to merge it into facts in every test but it's just present. You do need to duplicate it for service_provider if you want that to be present. We don't use that now AFAIK so I'd leave it out. If it's important, you could probably rewrite it to use the service_provider fact:

add_custom_fact :systemd, lambda { |os, facts| facts[:service_provider] == 'systemd' }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service_provider fact comes from stdlib and isn't available in facterdb :( I will update it to your first approach and also propose it to modulesync_config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now I would like to stick with the current version and implement something nice for both facts in modulsync_config. I am not sure where os and facts should come from in your code and it give me an error:

ArgumentError:
  tried to create Proc object without a block

end
end
end

[-42, '-42', 'foo', '42'].each do |value|
[-42, '-42', 'foo'].each do |value|
context "with file_limit => '#{value}'" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are positive numbers not supported (either as string or int) here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it took me a three times to read this code correctly, but this array lists unsupported values. quoted strings are now allowed.

case facts[:os]['release']['major']
when '6'
{ service_provider: 'sysv', systemd: false }
when '7'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see this as when '7'. I can see arguments for both ways - but in this case, probably makes most sense to have it be else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants