crowbar-core icon indicating copy to clipboard operation
crowbar-core copied to clipboard

refactor provisioner::base and autogenerate /etc/profile.d/crowbar-vars.sh

Open aspiers opened this issue 10 years ago • 19 comments

Split up the enormous base.rb into manageable chunks, and add a new provisioner::shell_vars recipe which auto-generates /etc/profile.d/crowbar-vars.sh. For each machine alias, it defines shell variables mapping to that machine's node and role. For example, if you have a machine with alias controller1, it means that you can type stuff like:

knife node show $controller1
knife role show $controller1r
less +F /var/log/crowbar/chef-client/$controller1.log

rather than having to endure the pain of tedious messing around with MAC addresses.

This idea originates from https://github.com/SUSE-Cloud/suse-cloud-vagrant/blob/master/vagrant/provisioning/admin/node-sh-vars and @dirkmueller suggested that some of the tweaks in the appliances / Vagrant boxes should be ported into the product. So this is the second step towards that, the first being: https://github.com/crowbar/crowbar-openstack/pull/20

aspiers avatar Sep 07 '15 01:09 aspiers

You know that it is bad behavior to use dashes instead of underscores for filenames in ruby?

tboerger avatar Sep 07 '15 09:09 tboerger

@tboerger Excellent point - I forgot about that since I was thinking of the files as recipes not Ruby files. Will fix!

aspiers avatar Sep 07 '15 10:09 aspiers

@tboerger BTW I found another reason to prefer underscores:

WARNING Cookbooks with dashes (hyphens) are difficult to test with ChefSpec because of how Chef classifies objects. We recommend naming cookbooks with underscores (_) instead of dashes (-).

aspiers avatar Sep 07 '15 10:09 aspiers

Oh, that's talking about cookbooks not recipes. Never mind :-)

aspiers avatar Sep 07 '15 10:09 aspiers

For the record, I found a way to automatically change all .rb files affected by this PR to have underscores instead of hyphens:

base_commit=`git upstream` # commit on which this PR is based

# Find and store all files affected by this PR
git diff --name-only $base_commit..HEAD > ~/touched-files.txt

git filter-branch --index-filter '
  # get the current index
  git ls-files -s > index.txt

  # Replace any hyphens in the affected files with underscores
  grep "\.rb$" ~/touched-files.txt | while read file; do
    perl -pi -e "m%\t\Q$file\E\$% && s/-/_/g" index.txt
  done

  # Convert index.txt to a new (binary) index and then replace the old one.
  # We cannot use git-update-index directly on .git/index because then the
  # files pre-rename would persist.
  cat index.txt | \
    GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && \
  mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
  ' $base_commit..HEAD

This was based off this blog post.

aspiers avatar Sep 08 '15 12:09 aspiers

+1

vuntz avatar Sep 10 '15 12:09 vuntz

Rebased because it looks like the gate failed due to the PR being based on master from before the change regarding digest authentication.

aspiers avatar Sep 10 '15 23:09 aspiers

And now the gate fails for some weird reason which looks unrelated :-(

aspiers avatar Sep 11 '15 13:09 aspiers

@aspiers not sure since when, but this needs a rebase :/

vuntz avatar Oct 31 '15 09:10 vuntz

@aspiers ping for the rebase

vuntz avatar Mar 16 '16 08:03 vuntz

@vuntz Rebased. I also locally backported to 3.0 and tested on my c19 which is currently running SOC6 - seemed to work fine, but I didn't test on SOC7 yet.

aspiers avatar Mar 16 '16 23:03 aspiers

@tboerger I ran rubocop -c .hound.ruby.yaml against the files changed by this PR, and it didn't generate any of the Style/DotPosition violations Hound is complaining about - any ideas why?

aspiers avatar Mar 16 '16 23:03 aspiers

That was with rubocop 0.33. I upgraded to 0.38 and now it complains:

Error: obsolete parameter RunRailsCops (for AllCops) found in /home/adam/SUSE/cloud/crowbar/git/crowbar/barclamps/crowbar-core/.hound.ruby.yml
Use the following configuration instead:
Rails:
  Enabled: true

but if I fix that, I still can't reproduce the errors Hound is generating.

aspiers avatar Mar 16 '16 23:03 aspiers

Hound is not complaining anymore :)

tboerger avatar Mar 21 '16 08:03 tboerger

@tboerger That's because of the last commit, but the Style/DotPosition question still needs to be answered.

aspiers avatar Mar 21 '16 13:03 aspiers

Rebased.

aspiers avatar Mar 24 '16 12:03 aspiers

Rebased again.

aspiers avatar Mar 28 '16 22:03 aspiers

+1

vuntz avatar Mar 29 '16 08:03 vuntz

+1

rsalevsky avatar Apr 04 '16 09:04 rsalevsky