houcho 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile.lock +32 -0
- data/bin/houcho +3 -262
- data/houcho.gemspec +2 -1
- data/lib/houcho/attribute.rb +99 -0
- data/lib/houcho/ci.rb +18 -13
- data/lib/houcho/cli/attribute.rb +70 -0
- data/lib/houcho/cli/host.rb +46 -0
- data/lib/houcho/cli/outerrole.rb +53 -0
- data/lib/houcho/cli/role.rb +69 -0
- data/lib/houcho/cli/spec.rb +103 -0
- data/lib/houcho/cli.rb +52 -0
- data/lib/houcho/config.rb +28 -0
- data/lib/houcho/database.rb +99 -0
- data/lib/houcho/element.rb +79 -50
- data/lib/houcho/host.rb +30 -9
- data/lib/houcho/outerrole/cloudforecast.rb +94 -0
- data/{templates/role/cf_roles.yaml → lib/houcho/outerrole/yabitz.rb} +0 -0
- data/lib/houcho/outerrole.rb +52 -0
- data/lib/houcho/repository.rb +59 -0
- data/lib/houcho/role.rb +78 -91
- data/lib/houcho/spec/runner.rb +156 -85
- data/lib/houcho/spec.rb +72 -3
- data/lib/houcho/version.rb +1 -1
- data/lib/houcho.rb +10 -52
- data/spec/houcho_spec.rb +334 -91
- metadata +31 -22
- data/lib/houcho/cloudforecast/host.rb +0 -25
- data/lib/houcho/cloudforecast/role.rb +0 -25
- data/lib/houcho/cloudforecast.rb +0 -59
- data/lib/houcho/yamlhandle.rb +0 -31
- data/spec/spec_helper.rb +0 -15
- data/templates/conf/houcho.conf +0 -10
- data/templates/conf/kk.rb +0 -14
- data/templates/conf/rspec.conf +0 -1
- data/templates/master +0 -94
- data/templates/role/cloudforecast/.gitkeep +0 -0
- data/templates/role/cloudforecast.yaml +0 -0
- data/templates/role/hosts.yaml +0 -0
- data/templates/role/hosts_ignored.yaml +0 -0
- data/templates/role/roles.yaml +0 -0
- data/templates/role/specs.yaml +0 -0
- data/templates/spec/sample_spec.rb +0 -13
- data/templates/spec/spec_helper.rb +0 -29
| @@ -1,25 +0,0 @@ | |
| 1 | 
            -
            module Houcho
         | 
| 2 | 
            -
              module CloudForecast
         | 
| 3 | 
            -
                class Host
         | 
| 4 | 
            -
                  def initialize
         | 
| 5 | 
            -
                    @cf = YamlHandle::Loader.new('./role/cloudforecast.yaml')
         | 
| 6 | 
            -
                  end
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                  def roles(host)
         | 
| 9 | 
            -
                    @cf.data.select {|cfrole, cfhosts|cfhosts.include?(host)}.keys
         | 
| 10 | 
            -
                  end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                  def hosts(role)
         | 
| 13 | 
            -
                    @cf.data[role] || []
         | 
| 14 | 
            -
                  end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  def details(host)
         | 
| 17 | 
            -
                    CloudForecast::Role.details(roles(host))
         | 
| 18 | 
            -
                  end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  def all
         | 
| 21 | 
            -
                    @cf.data.values.flatten.uniq
         | 
| 22 | 
            -
                  end
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
            end
         | 
| @@ -1,25 +0,0 @@ | |
| 1 | 
            -
            module Houcho
         | 
| 2 | 
            -
              module CloudForecast
         | 
| 3 | 
            -
                class Role
         | 
| 4 | 
            -
                  @elements = YamlHandle::Editor.new('./role/cf_roles.yaml')
         | 
| 5 | 
            -
                  extend Element
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                  def self.details(cfroles)
         | 
| 8 | 
            -
                    result = {}
         | 
| 9 | 
            -
                    cfroles.each do |cfrole|
         | 
| 10 | 
            -
                      hosts = CloudForecast::Host.new.hosts(cfrole)
         | 
| 11 | 
            -
                      if ! hosts.empty?
         | 
| 12 | 
            -
                        result[cfrole] = {}
         | 
| 13 | 
            -
                        result[cfrole]['host'] = hosts
         | 
| 14 | 
            -
                      end
         | 
| 15 | 
            -
                    end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                    result
         | 
| 18 | 
            -
                  end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  def self.all
         | 
| 21 | 
            -
                    YamlHandle::Loader.new('./role/cloudforecast.yaml').data.keys
         | 
| 22 | 
            -
                  end
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
            end
         | 
    
        data/lib/houcho/cloudforecast.rb
    DELETED
    
    | @@ -1,59 +0,0 @@ | |
| 1 | 
            -
            module Houcho
         | 
| 2 | 
            -
              module CloudForecast
         | 
| 3 | 
            -
                module_function
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                def load_yaml
         | 
| 6 | 
            -
                  yaml_file = Tempfile.new('yaml')
         | 
| 7 | 
            -
                  File.open(yaml_file,'a') do |t|
         | 
| 8 | 
            -
                    Find.find('./role/cloudforecast') do |f|
         | 
| 9 | 
            -
                      t.write File.read(f) if f =~ /\.yaml$/
         | 
| 10 | 
            -
                    end
         | 
| 11 | 
            -
                  end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                  role_hosts = {}
         | 
| 14 | 
            -
                  elements    = {}
         | 
| 15 | 
            -
                  group       = []
         | 
| 16 | 
            -
                  File.open(yaml_file) do |f|
         | 
| 17 | 
            -
                    f.each do |l|
         | 
| 18 | 
            -
                      if l =~ /^---/
         | 
| 19 | 
            -
                        if l =~ /^---\s+#(.+)$/
         | 
| 20 | 
            -
                          group << $1.gsub(/\s/, '_')
         | 
| 21 | 
            -
                        else
         | 
| 22 | 
            -
                          group << 'NOGROUPNAME'
         | 
| 23 | 
            -
                        end
         | 
| 24 | 
            -
                      end
         | 
| 25 | 
            -
                    end
         | 
| 26 | 
            -
                  end
         | 
| 27 | 
            -
                  File.open(yaml_file) do |f|
         | 
| 28 | 
            -
                    i = 0
         | 
| 29 | 
            -
                    YAML.load_documents(f) do |data|
         | 
| 30 | 
            -
                      elements[group[i]] ||= []
         | 
| 31 | 
            -
                      elements[group[i]].concat data['servers']
         | 
| 32 | 
            -
                      i += 1
         | 
| 33 | 
            -
                    end
         | 
| 34 | 
            -
                  end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                  elements.each do |groupname, data|
         | 
| 37 | 
            -
                    current_label = 'NOCATEGORYNAME'
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                    data.each do |d|
         | 
| 40 | 
            -
                      if ! d['label'].nil?
         | 
| 41 | 
            -
                        label = d['label'].gsub(/\s/, '_')
         | 
| 42 | 
            -
                        current_label = label if current_label != label
         | 
| 43 | 
            -
                      end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                      d['hosts'].map! do |host|
         | 
| 46 | 
            -
                        host = host.split(' ')
         | 
| 47 | 
            -
                        host = host.size == 1 ? host[0] : host[1]
         | 
| 48 | 
            -
                      end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                      r = groupname + '::' + current_label + '::' + d['config'].sub(/\.yaml$/, '')
         | 
| 51 | 
            -
                      ary = (role_hosts[r] || []) | d['hosts']
         | 
| 52 | 
            -
                      role_hosts[r] = ary.uniq
         | 
| 53 | 
            -
                    end
         | 
| 54 | 
            -
                  end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                  File.write('./role/cloudforecast.yaml', role_hosts.to_yaml)
         | 
| 57 | 
            -
                end
         | 
| 58 | 
            -
              end
         | 
| 59 | 
            -
            end
         | 
    
        data/lib/houcho/yamlhandle.rb
    DELETED
    
    | @@ -1,31 +0,0 @@ | |
| 1 | 
            -
            module Houcho
         | 
| 2 | 
            -
              module YamlHandle
         | 
| 3 | 
            -
                class Loader
         | 
| 4 | 
            -
                  attr_reader :data
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                  def initialize(yaml_file)
         | 
| 7 | 
            -
                    begin
         | 
| 8 | 
            -
                      @data = YAML.load_file(yaml_file)
         | 
| 9 | 
            -
                    rescue
         | 
| 10 | 
            -
                      # I think it should describe the process when current directory has not ready for houcho
         | 
| 11 | 
            -
                    end
         | 
| 12 | 
            -
                    @data ||= {}
         | 
| 13 | 
            -
                  end
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                class Editor < Loader
         | 
| 17 | 
            -
                  attr_accessor :data
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                  def initialize(yaml_file)
         | 
| 20 | 
            -
                    super
         | 
| 21 | 
            -
                    @yaml_file = yaml_file
         | 
| 22 | 
            -
                  end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                  def save_to_file
         | 
| 25 | 
            -
                    open(@yaml_file, 'w') do |f|
         | 
| 26 | 
            -
                      YAML.dump(@data, f)
         | 
| 27 | 
            -
                    end
         | 
| 28 | 
            -
                  end
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
              end
         | 
| 31 | 
            -
            end
         | 
    
        data/spec/spec_helper.rb
    DELETED
    
    | @@ -1,15 +0,0 @@ | |
| 1 | 
            -
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         | 
| 2 | 
            -
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         | 
| 3 | 
            -
            require 'rspec'
         | 
| 4 | 
            -
            require 'houcho'
         | 
| 5 | 
            -
            require 'tmpdir'
         | 
| 6 | 
            -
            require 'tempfile'
         | 
| 7 | 
            -
            require 'fileutils'
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            # Requires supporting files with custom matchers and macros, etc,
         | 
| 10 | 
            -
            # in ./support/ and its subdirectories.
         | 
| 11 | 
            -
            Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            RSpec.configure do |config|
         | 
| 14 | 
            -
              
         | 
| 15 | 
            -
            end
         | 
    
        data/templates/conf/houcho.conf
    DELETED
    
    
    
        data/templates/conf/kk.rb
    DELETED
    
    
    
        data/templates/conf/rspec.conf
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            --format documentation
         | 
    
        data/templates/master
    DELETED
    
    | @@ -1,94 +0,0 @@ | |
| 1 | 
            -
            module Houcho
         | 
| 2 | 
            -
              module Initialize
         | 
| 3 | 
            -
                %W{conf role/cloudforecast spec}.each do |d|
         | 
| 4 | 
            -
                  FileUtils.mkdir_p d if ! Dir.exists? d
         | 
| 5 | 
            -
                end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                File.write('./role/cloudforecast/houcho_sample.yaml', <<EOH
         | 
| 8 | 
            -
            --- #houcho
         | 
| 9 | 
            -
            servers:
         | 
| 10 | 
            -
              - label: author
         | 
| 11 | 
            -
                config: studio3104
         | 
| 12 | 
            -
                hosts:
         | 
| 13 | 
            -
                  - studio3104.test
         | 
| 14 | 
            -
                  - studio3105.test
         | 
| 15 | 
            -
                  - studio3106.test
         | 
| 16 | 
            -
                  - studio3107.test
         | 
| 17 | 
            -
                  - studio3108.test
         | 
| 18 | 
            -
                  - studio3109.test
         | 
| 19 | 
            -
                  - studio3110.test
         | 
| 20 | 
            -
            EOH
         | 
| 21 | 
            -
                ) if ! File.exists? './role/cloudforecast/houcho_sample.yaml'
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                File.write('./spec/spec_helper.rb', <<EOH
         | 
| 24 | 
            -
            require 'serverspec'
         | 
| 25 | 
            -
            require 'pathname'
         | 
| 26 | 
            -
            require 'net/ssh'
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            include Serverspec::Helper::Ssh
         | 
| 29 | 
            -
            include Serverspec::Helper::DetectOS
         | 
| 30 | 
            -
             | 
| 31 | 
            -
            RSpec.configure do |c|
         | 
| 32 | 
            -
              if ENV['ASK_SUDO_PASSWORD']
         | 
| 33 | 
            -
                require 'highline/import'
         | 
| 34 | 
            -
                c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
         | 
| 35 | 
            -
              else
         | 
| 36 | 
            -
                c.sudo_password = ENV['SUDO_PASSWORD']
         | 
| 37 | 
            -
              end
         | 
| 38 | 
            -
              c.before :all do
         | 
| 39 | 
            -
                block = self.class.metadata[:example_group_block]
         | 
| 40 | 
            -
                if RUBY_VERSION.start_with?('1.8')
         | 
| 41 | 
            -
                  file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
         | 
| 42 | 
            -
                else
         | 
| 43 | 
            -
                  file = block.source_location.first
         | 
| 44 | 
            -
                end
         | 
| 45 | 
            -
                c.ssh.close if c.ssh
         | 
| 46 | 
            -
                c.host  = ENV['TARGET_HOST']
         | 
| 47 | 
            -
                options = Net::SSH::Config.for(c.host)
         | 
| 48 | 
            -
                user    = options[:user] || Etc.getlogin
         | 
| 49 | 
            -
                c.ssh   = Net::SSH.start(c.host, user, options)
         | 
| 50 | 
            -
                c.os    = backend(Serverspec::Commands::Base).check_os
         | 
| 51 | 
            -
              end
         | 
| 52 | 
            -
            end
         | 
| 53 | 
            -
            EOH
         | 
| 54 | 
            -
                ) if ! File.exists? './spec/spec_helper.rb'
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                File.write('./spec/houcho_sample_spec.rb', <<EOH
         | 
| 57 | 
            -
            require 'spec_helper'
         | 
| 58 | 
            -
             | 
| 59 | 
            -
            describe user('studio3104') do
         | 
| 60 | 
            -
              it { should exist }
         | 
| 61 | 
            -
              it { should have_uid 3104 }
         | 
| 62 | 
            -
              it { should have_home_directory '/home/studio3104' }
         | 
| 63 | 
            -
              it { should have_login_shell '/bin/zsh' }
         | 
| 64 | 
            -
              it { should belong_to_group 'studio3104' }
         | 
| 65 | 
            -
            end
         | 
| 66 | 
            -
            describe group('studio3104') do
         | 
| 67 | 
            -
              it { should exist }
         | 
| 68 | 
            -
              it { should have_gid 3104 }
         | 
| 69 | 
            -
            end
         | 
| 70 | 
            -
            EOH
         | 
| 71 | 
            -
               ) if ! File.exists? './spec/houcho_sample_spec.rb'
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                File.write('./conf/houcho.conf', {
         | 
| 74 | 
            -
                  'ukigumo' => {'host' => nil, 'port' => nil,},
         | 
| 75 | 
            -
                  'ikachan' => {'host' => nil, 'port' => nil, 'channel' => [nil],},
         | 
| 76 | 
            -
                  'git'     => {'uri'  => nil,},
         | 
| 77 | 
            -
                }.to_yaml) if ! File.exists? './conf/houcho.conf'
         | 
| 78 | 
            -
             | 
| 79 | 
            -
                File.write('./conf/rspec.conf', '--format documentation') if ! File.exists? './conf/rspec.conf'
         | 
| 80 | 
            -
                File.symlink('./conf/rspec.conf', './.rspec') if ! File.exists? './.rspec'
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                %w{
         | 
| 83 | 
            -
                  runlists.yaml
         | 
| 84 | 
            -
                  roles.yaml
         | 
| 85 | 
            -
                  hosts.yaml
         | 
| 86 | 
            -
                  specs.yaml
         | 
| 87 | 
            -
                  cf_roles.yaml
         | 
| 88 | 
            -
                  hosts_ignored.yaml
         | 
| 89 | 
            -
                  cloudforecast.yaml
         | 
| 90 | 
            -
                }.each do |f|
         | 
| 91 | 
            -
                  f = 'role/' + f
         | 
| 92 | 
            -
                  File.write(f, '') if ! File.exists? f
         | 
| 93 | 
            -
              end
         | 
| 94 | 
            -
            end
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
    
        data/templates/role/hosts.yaml
    DELETED
    
    | 
            File without changes
         | 
| 
            File without changes
         | 
    
        data/templates/role/roles.yaml
    DELETED
    
    | 
            File without changes
         | 
    
        data/templates/role/specs.yaml
    DELETED
    
    | 
            File without changes
         | 
| @@ -1,13 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe user('studio3104') do
         | 
| 4 | 
            -
              it { should exist }
         | 
| 5 | 
            -
              it { should have_uid 3104 }
         | 
| 6 | 
            -
              it { should have_home_directory '/home/studio3104' }
         | 
| 7 | 
            -
              it { should have_login_shell '/bin/zsh' }
         | 
| 8 | 
            -
              it { should belong_to_group 'studio3104' }
         | 
| 9 | 
            -
            end
         | 
| 10 | 
            -
            describe group('studio3104') do
         | 
| 11 | 
            -
              it { should exist }
         | 
| 12 | 
            -
              it { should have_gid 3104 }
         | 
| 13 | 
            -
            end
         | 
| @@ -1,29 +0,0 @@ | |
| 1 | 
            -
            require 'serverspec'
         | 
| 2 | 
            -
            require 'pathname'
         | 
| 3 | 
            -
            require 'net/ssh'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            include Serverspec::Helper::Ssh
         | 
| 6 | 
            -
            include Serverspec::Helper::DetectOS
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            RSpec.configure do |c|
         | 
| 9 | 
            -
              if ENV['ASK_SUDO_PASSWORD']
         | 
| 10 | 
            -
                require 'highline/import'
         | 
| 11 | 
            -
                c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
         | 
| 12 | 
            -
              else
         | 
| 13 | 
            -
                c.sudo_password = ENV['SUDO_PASSWORD']
         | 
| 14 | 
            -
              end
         | 
| 15 | 
            -
              c.before :all do
         | 
| 16 | 
            -
                block = self.class.metadata[:example_group_block]
         | 
| 17 | 
            -
                if RUBY_VERSION.start_with?('1.8')
         | 
| 18 | 
            -
                  file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
         | 
| 19 | 
            -
                else
         | 
| 20 | 
            -
                  file = block.source_location.first
         | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
                c.ssh.close if c.ssh
         | 
| 23 | 
            -
                c.host  = ENV['TARGET_HOST']
         | 
| 24 | 
            -
                options = Net::SSH::Config.for(c.host)
         | 
| 25 | 
            -
                user    = options[:user] || Etc.getlogin
         | 
| 26 | 
            -
                c.ssh   = Net::SSH.start(c.host, user, options)
         | 
| 27 | 
            -
                c.os    = backend(Serverspec::Commands::Base).check_os
         | 
| 28 | 
            -
              end
         | 
| 29 | 
            -
            end
         |