puppetfactory 0.5.3 → 0.5.4
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/lib/puppetfactory/dashboard/rake_tasks.rb +8 -3
- data/lib/puppetfactory/dashboard/spec_helper.rb +5 -1
- data/lib/puppetfactory/plugins/dashboard.rb +20 -6
- data/lib/puppetfactory/plugins/gitea.rb +68 -0
- data/lib/puppetfactory/plugins/user_environment.rb +3 -1
- data/views/logs.erb +9 -2
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6f21eff79fdd9ffaded59f986834a49490379cf2
         | 
| 4 | 
            +
              data.tar.gz: d38bc62908bcbace5d0155f9a1c77adf8dac0965
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0a4543c5d601cc2478e21088024b991e2afcdd13fe3fc2db1c3b915f8794f54a03416e952554d70851ff86e23b31681bc48c00967f632accd256ece149be86d9
         | 
| 7 | 
            +
              data.tar.gz: e68ef55d635a24b24b97283cf8fe53b0a543a2d65d4ee2fb720eab471dbdaffef0b99a301d2f91294c6d12232bab9e2cd56cd6ac0aed9548d743301ee59406e9
         | 
| @@ -36,9 +36,11 @@ namespace :spec do | |
| 36 36 | 
             
              targets = []
         | 
| 37 37 | 
             
              Dir.glob('/etc/puppetlabs/code/environments/*').each do |dir|
         | 
| 38 38 | 
             
                next unless File.directory?(dir)
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                 | 
| 41 | 
            -
                 | 
| 39 | 
            +
             | 
| 40 | 
            +
                dir = File.basename(dir)
         | 
| 41 | 
            +
                next if dir == 'production'
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                targets << dir.sub('_production', '')
         | 
| 42 44 | 
             
              end
         | 
| 43 45 | 
             
              task :all_agents => targets
         | 
| 44 46 |  | 
| @@ -47,10 +49,12 @@ namespace :spec do | |
| 47 49 | 
             
                html    = "output/html/#{test}"
         | 
| 48 50 | 
             
                json    = "output/json/#{test}"
         | 
| 49 51 | 
             
                pattern = "spec/#{test}_spec.rb"
         | 
| 52 | 
            +
                puts "Running the #{test} test suite..."
         | 
| 50 53 | 
             
              else
         | 
| 51 54 | 
             
                html    = "output/html"
         | 
| 52 55 | 
             
                json    = "output/json"
         | 
| 53 56 | 
             
                pattern = "spec/*_spec.rb"
         | 
| 57 | 
            +
                puts "Running all test suites..."
         | 
| 54 58 | 
             
              end
         | 
| 55 59 |  | 
| 56 60 | 
             
              FileUtils.mkdir_p html
         | 
| @@ -59,6 +63,7 @@ namespace :spec do | |
| 59 63 | 
             
              targets.each do |target|
         | 
| 60 64 | 
             
                desc "Run Puppetfactory tests for #{target}"
         | 
| 61 65 | 
             
                RSpec::Core::RakeTask.new(target.to_sym) do |t|
         | 
| 66 | 
            +
                  puts " * #{target}"
         | 
| 62 67 | 
             
                  ENV['TARGET_HOST'] = target
         | 
| 63 68 | 
             
                  t.verbose = false
         | 
| 64 69 | 
             
                  t.fail_on_error = false
         | 
| @@ -6,10 +6,14 @@ environmentpath = "/etc/puppetlabs/code/environments" | |
| 6 6 |  | 
| 7 7 | 
             
            if File.directory? "#{environmentpath}/#{username}_production"
         | 
| 8 8 | 
             
              environment = "#{username}_production"
         | 
| 9 | 
            -
             | 
| 9 | 
            +
            elsif File.directory? "#{environmentpath}/#{username}"
         | 
| 10 10 | 
             
              environment = username
         | 
| 11 | 
            +
            else
         | 
| 12 | 
            +
              raise "No environment exists for #{username}"
         | 
| 11 13 | 
             
            end
         | 
| 12 14 |  | 
| 15 | 
            +
            puts "   - Testing environment #{environment}"
         | 
| 16 | 
            +
             | 
| 13 17 | 
             
            RSpec.configure do |c|
         | 
| 14 18 | 
             
              c.environmentpath = environmentpath
         | 
| 15 19 | 
             
              c.module_path     = "#{environmentpath}/#{environment}/site"
         | 
| @@ -43,10 +43,15 @@ class Puppetfactory::Plugins::Dashboard < Puppetfactory::Plugins | |
| 43 43 | 
             
                @server.get '/dashboard/update' do
         | 
| 44 44 | 
             
                  $logger.info "Triggering dashboard update."
         | 
| 45 45 |  | 
| 46 | 
            -
                   | 
| 46 | 
            +
                  case plugin(:Dashboard, :update_results)
         | 
| 47 | 
            +
                  when :running
         | 
| 48 | 
            +
                    {'status' => 'fail', 'message' => 'Already running'}.to_json
         | 
| 49 | 
            +
                  when :success
         | 
| 47 50 | 
             
                    {'status' => 'success'}.to_json
         | 
| 51 | 
            +
                  when :fail
         | 
| 52 | 
            +
                    {'status' => 'fail', 'message' => "Tests failed to execute. Please see logs"}.to_json
         | 
| 48 53 | 
             
                  else
         | 
| 49 | 
            -
                    {'status' => 'fail', 'message' =>  | 
| 54 | 
            +
                    {'status' => 'fail', 'message' => "Unknown status"}.to_json
         | 
| 50 55 | 
             
                  end
         | 
| 51 56 | 
             
                end
         | 
| 52 57 |  | 
| @@ -67,20 +72,29 @@ class Puppetfactory::Plugins::Dashboard < Puppetfactory::Plugins | |
| 67 72 | 
             
              end
         | 
| 68 73 |  | 
| 69 74 | 
             
              def update_results()
         | 
| 70 | 
            -
                return  | 
| 75 | 
            +
                return :running if @test_running
         | 
| 71 76 | 
             
                @test_running = true
         | 
| 72 77 |  | 
| 78 | 
            +
                output = nil
         | 
| 79 | 
            +
                status = nil
         | 
| 80 | 
            +
             | 
| 73 81 | 
             
                Dir.chdir(@path) do
         | 
| 74 82 | 
             
                  case @current_test
         | 
| 75 83 | 
             
                  when 'all', 'summary'
         | 
| 76 | 
            -
                     | 
| 84 | 
            +
                    output, status = Open3.capture2e('rake', 'generate')
         | 
| 77 85 | 
             
                  else
         | 
| 78 | 
            -
                     | 
| 86 | 
            +
                    output, status = Open3.capture2e('rake', 'generate', "current_test=#{@current_test}")
         | 
| 79 87 | 
             
                  end
         | 
| 80 88 | 
             
                end
         | 
| 81 89 |  | 
| 90 | 
            +
                if status.success?
         | 
| 91 | 
            +
                  $logger.info output
         | 
| 92 | 
            +
                else
         | 
| 93 | 
            +
                  $logger.error output
         | 
| 94 | 
            +
                end
         | 
| 95 | 
            +
             | 
| 82 96 | 
             
                @test_running = false
         | 
| 83 | 
            -
                 | 
| 97 | 
            +
                return status.success? ? :success : :fail
         | 
| 84 98 | 
             
              end
         | 
| 85 99 |  | 
| 86 100 | 
             
              def available_tests()
         | 
| @@ -0,0 +1,68 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
            require 'fileutils'
         | 
| 3 | 
            +
            require 'puppetfactory'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            class Puppetfactory::Plugins::Gitea < Puppetfactory::Plugins
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def initialize(options)
         | 
| 8 | 
            +
                super(options)
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                @suffix         = options[:usersuffix]
         | 
| 11 | 
            +
                @gitea_path     = options[:gitea_path] || '/home/git/go/bin/gitea'
         | 
| 12 | 
            +
                @admin_username = options[:gitea_admin_username] || 'root'
         | 
| 13 | 
            +
                @admin_password = options[:gitea_admin_password] || 'puppetlabs'
         | 
| 14 | 
            +
                @gitea_port     = options[:gitea_port] || '3000'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                begin
         | 
| 17 | 
            +
                  `curl -su "#{@admin_username}:#{@admin_password}" --data 'clone_addr=https://github.com/puppetlabs-education/classroom-control-vf.git&uid=1&repo_name=classroom-control-vf' http://localhost:#{@gitea_port}/api/v1/repos/migrate`
         | 
| 18 | 
            +
                  FileUtils::mkdir_p '/var/cache/puppetfactory/gitea'
         | 
| 19 | 
            +
                  Dir.chdir('/var/cache/puppetfactory/gitea') do
         | 
| 20 | 
            +
                    `git clone --depth 1 http://#{@admin_username}:#{@admin_password}@localhost:#{@gitea_port}/#{@admin_username}/classroom-control-vf.git`
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                rescue => e
         | 
| 23 | 
            +
                  $logger.error "Error migrating repository: #{e.message}"
         | 
| 24 | 
            +
                  return false
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def add_collaborator(owner, repo, username, permission)
         | 
| 30 | 
            +
                `curl -su "#{@admin_username}:#{@admin_password}" -X PUT -H "Content-Type: application/json" -d '{"permissions":"#{permission}"}' http://localhost:#{@gitea_port}/api/v1/repos/#{owner}/#{repo}/collaborators/#{username}`
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def make_branch(username)
         | 
| 34 | 
            +
                Dir.chdir('/var/cache/puppetfactory/gitea/classroom-control-vf') do
         | 
| 35 | 
            +
                  `git checkout -b #{username} && git push origin #{username}`
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              def create(username, password)
         | 
| 40 | 
            +
                begin
         | 
| 41 | 
            +
                  if password.length < 8
         | 
| 42 | 
            +
                    raise "Password must be at least 8 characters"
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                  `su git -c "cd && #{@gitea_path} admin create-user --name #{username} --password #{password} --email #{username}.#{@suffix}"`
         | 
| 45 | 
            +
                  add_collaborator(@admin_username, 'classroom-control-vf', username, 'write')
         | 
| 46 | 
            +
                  make_branch(username)
         | 
| 47 | 
            +
                  $logger.info "Created Gitea user #{username}."
         | 
| 48 | 
            +
                rescue => e
         | 
| 49 | 
            +
                  $logger.error "Error creating Gitea user #{username}: #{e.message}"
         | 
| 50 | 
            +
                  return false
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                true
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              def delete(username)
         | 
| 57 | 
            +
                begin
         | 
| 58 | 
            +
                  `curl -su "#{@admin_username}:#{@admin_password}" -X "DELETE" http://localhost:#{@gitea_port}/api/v1/admin/users/#{username}`
         | 
| 59 | 
            +
                  $logger.info "Removed GitLab user #{username}."
         | 
| 60 | 
            +
                rescue => e
         | 
| 61 | 
            +
                  $logger.error "Error removing GitLab user #{username}: #{e.message}"
         | 
| 62 | 
            +
                  return false
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                true
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            end
         | 
| @@ -38,7 +38,7 @@ class Puppetfactory::Plugins::UserEnvironment < Puppetfactory::Plugins | |
| 38 38 |  | 
| 39 39 | 
             
                  # make sure the user and pe-puppet can access all the needful
         | 
| 40 40 | 
             
                  FileUtils.chown_R(username, 'pe-puppet', environment)
         | 
| 41 | 
            -
                  FileUtils. | 
| 41 | 
            +
                  FileUtils.chmod_R(0750, environment)
         | 
| 42 42 |  | 
| 43 43 | 
             
                  deploy(username)
         | 
| 44 44 |  | 
| @@ -60,6 +60,8 @@ class Puppetfactory::Plugins::UserEnvironment < Puppetfactory::Plugins | |
| 60 60 | 
             
              end
         | 
| 61 61 |  | 
| 62 62 | 
             
              def deploy(username)
         | 
| 63 | 
            +
                # TODO: temporary hack to keep this from disrupting current deliveries.
         | 
| 64 | 
            +
                return if @codestage == @environments
         | 
| 63 65 | 
             
                environment = Puppetfactory::Helpers.environment_name(username)
         | 
| 64 66 |  | 
| 65 67 | 
             
                FileUtils.cp_r("#{@codestage}/#{environment}/.", "#{@environments}/#{environment}")
         | 
    
        data/views/logs.erb
    CHANGED
    
    | @@ -4,8 +4,13 @@ | |
| 4 4 | 
             
            </div>
         | 
| 5 5 |  | 
| 6 6 | 
             
            <script type="text/javascript">
         | 
| 7 | 
            -
              function loadLogs() {
         | 
| 7 | 
            +
              function loadLogs(force) {
         | 
| 8 8 | 
             
                $("#logs .data").load("logs/data", function() {
         | 
| 9 | 
            +
                  var elem = $(this)[0]
         | 
| 10 | 
            +
                  // track the bottom of the logs, unless we've scrolled away
         | 
| 11 | 
            +
                  if(force || (elem.scrollHeight - elem.scrollTop - elem.clientHeight < 100)) {
         | 
| 12 | 
            +
                    $(this).animate({scrollTop: elem.scrollHeight}, 500);
         | 
| 13 | 
            +
                  }
         | 
| 9 14 |  | 
| 10 15 | 
             
                  // use timeout instead of an interval so that in case of network error
         | 
| 11 16 | 
             
                  // we don't end up with a queue of requests stacked up.
         | 
| @@ -14,7 +19,7 @@ | |
| 14 19 | 
             
              }
         | 
| 15 20 |  | 
| 16 21 | 
             
              $(document).ready(function() {
         | 
| 17 | 
            -
                loadLogs();
         | 
| 22 | 
            +
                loadLogs(true);
         | 
| 18 23 | 
             
              });
         | 
| 19 24 | 
             
            </script>
         | 
| 20 25 |  | 
| @@ -22,5 +27,7 @@ | |
| 22 27 | 
             
              #logs .data {
         | 
| 23 28 | 
             
                font-family: monospace;
         | 
| 24 29 | 
             
                white-space: pre-wrap;
         | 
| 30 | 
            +
                height: 500px;
         | 
| 31 | 
            +
                overflow-y: scroll;
         | 
| 25 32 | 
             
              }
         | 
| 26 33 | 
             
            </style>
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: puppetfactory
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.5. | 
| 4 | 
            +
              version: 0.5.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ben Ford
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2016- | 
| 12 | 
            +
            date: 2016-12-12 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: sinatra
         | 
| @@ -155,6 +155,7 @@ files: | |
| 155 155 | 
             
            - lib/puppetfactory/plugins/dashboard.rb
         | 
| 156 156 | 
             
            - lib/puppetfactory/plugins/docker.rb
         | 
| 157 157 | 
             
            - lib/puppetfactory/plugins/example.rb
         | 
| 158 | 
            +
            - lib/puppetfactory/plugins/gitea.rb
         | 
| 158 159 | 
             
            - lib/puppetfactory/plugins/github.rb
         | 
| 159 160 | 
             
            - lib/puppetfactory/plugins/gitlab.rb
         | 
| 160 161 | 
             
            - lib/puppetfactory/plugins/gitviz.rb
         | 
| @@ -259,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 259 260 | 
             
                  version: '0'
         | 
| 260 261 | 
             
            requirements: []
         | 
| 261 262 | 
             
            rubyforge_project: 
         | 
| 262 | 
            -
            rubygems_version: 2. | 
| 263 | 
            +
            rubygems_version: 2.4.5.1
         | 
| 263 264 | 
             
            signing_key: 
         | 
| 264 265 | 
             
            specification_version: 4
         | 
| 265 266 | 
             
            summary: Stands up a graphical classroom manager with containerized puppet agents.
         |