diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000000..8920b19df4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,25 @@ +# We allow longer lines in our style +Metrics/LineLength: + Max: 150 + +# TODO/FIXME: +# At some point, we might just want to do the changes and get rid of those + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 128 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 17 + +# Offense count: 2 +Style/Documentation: + Enabled: false + +# Offense count: 1 +# Configuration parameters: Methods. +Style/SingleLineBlockParams: + Enabled: false diff --git a/Gemfile b/Gemfile index eac2ef94fb..6290bf04cb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ -source "https://rubygems.org" +source 'https://rubygems.org' gem 'addressable' gem 'colorize' gem 'httparty' gem 'rake' +gem 'rubocop' diff --git a/Rakefile b/Rakefile index da928719fa..5f51e77743 100755 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ # encoding: utf-8 require 'rake/clean' +require 'rubocop/rake_task' # Flavored Travis CI jobs require './ci/apache' @@ -53,17 +54,17 @@ end desc 'Setup a development environment for the Agent' task 'setup_env' do - `mkdir -p venv` - `wget -O venv/virtualenv.py https://raw.github.com/pypa/virtualenv/1.11.6/virtualenv.py` - `python venv/virtualenv.py --no-site-packages --no-pip --no-setuptools venv/` - `wget -O venv/ez_setup.py https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py` - `venv/bin/python venv/ez_setup.py` - `wget -O venv/get-pip.py https://raw.github.com/pypa/pip/master/contrib/get-pip.py` - `venv/bin/python venv/get-pip.py` - `venv/bin/pip install -r requirements.txt` - # These deps are not really needed, so we ignore failures - ENV['PIP_COMMAND'] = 'venv/bin/pip' - `./utils/pip-allow-failures.sh requirements-opt.txt` + `mkdir -p venv` + `wget -O venv/virtualenv.py https://raw.github.com/pypa/virtualenv/1.11.6/virtualenv.py` + `python venv/virtualenv.py --no-site-packages --no-pip --no-setuptools venv/` + `wget -O venv/ez_setup.py https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py` + `venv/bin/python venv/ez_setup.py` + `wget -O venv/get-pip.py https://raw.github.com/pypa/pip/master/contrib/get-pip.py` + `venv/bin/python venv/get-pip.py` + `venv/bin/pip install -r requirements.txt` + # These deps are not really needed, so we ignore failures + ENV['PIP_COMMAND'] = 'venv/bin/pip' + `./utils/pip-allow-failures.sh requirements-opt.txt` end namespace :test do @@ -91,8 +92,13 @@ namespace :test do task 'coverage' => 'ci:default:coverage' end +RuboCop::RakeTask.new(:rubocop) do |t| + t.patterns = ['ci/**/*.rb', 'Gemfile', 'Rakefile'] +end + desc 'Lint the code through pylint' -task 'lint' => 'ci:default:lint' +task 'lint' => ['ci:default:lint'] do +end desc 'Run the Agent locally' task 'run' do @@ -101,12 +107,12 @@ end namespace :ci do desc 'Run integration tests' - task :run, :flavor do |t, args| - puts "Assuming you are running these tests locally" unless ENV['TRAVIS'] + task :run, :flavor do |_, args| + puts 'Assuming you are running these tests locally' unless ENV['TRAVIS'] flavor = args[:flavor] || ENV['TRAVIS_FLAVOR'] || 'default' flavors = flavor.split(',') - flavors.each { |f| Rake::Task["ci:#{f}:execute"].invoke} + flavors.each { |f| Rake::Task["ci:#{f}:execute"].invoke } end end -task :default => [:test] +task default: ['lint', 'ci:run'] diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 6f5e7e3315..0000000000 --- a/Vagrantfile +++ /dev/null @@ -1,76 +0,0 @@ -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = "2" - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - # All Vagrant configuration is done here. The most common configuration - # options are documented and commented below. For a complete reference, - # please see the online documentation at vagrantup.com. - - # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "dd-agent" - - # The url from where the 'config.vm.box' box will be fetched if it - # doesn't already exist on the user's system. - config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-amd64-vagrant-disk1.box" - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - # config.vm.network :forwarded_port, guest: 80, host: 8080 - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - #config.vm.network :private_network, ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network :public_network - - # If true, then any SSH connections made will enable agent forwarding. - # Default value: false - config.ssh.forward_agent = true - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - config.vm.synced_folder ".", "/src" #, nfs: true - - # Debian 7 box - config.vm.define "debian" do |deb| - deb.vm.box = "debagent" - deb.vm.box_url = "https://dl.dropboxusercontent.com/s/xymcvez85i29lym/vagrant-debian-wheezy64.box" - deb.vm.synced_folder ".", "/src" - deb.vm.provider :virtualbox do |vb| - # Use VBoxManage to customize the VM. For example to change memory: - vb.customize ["modifyvm", :id, "--memory", "512"] - end - - # Manual set-up - deb.vm.provision "shell", inline: "sudo apt-get update" - deb.vm.provision "shell", inline: "sudo apt-get -y install ruby" - deb.vm.provision "shell", inline: "sudo apt-get -y install ruby-dev" - deb.vm.provision "shell", inline: "sudo apt-get -y install python" - deb.vm.provision "shell", inline: "sudo gem install --no-ri --no-rdoc fpm" - end - - # Centos 6 box - config.vm.define "redhat" do |rh| - rh.vm.box = "rhagent" - rh.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box" - rh.vm.synced_folder ".", "/src" - rh.vm.provider :virtualbox do |vb| - # Use VBoxManage to customize the VM. For example to change memory: - vb.customize ["modifyvm", :id, "--memory", "512"] - end - - # Manual set-up - rh.vm.provision "shell", inline: "sudo yum -y update" - rh.vm.provision "shell", inline: "sudo yum -y install ruby" - rh.vm.provision "shell", inline: "sudo yum -y install ruby-devel" - rh.vm.provision "shell", inline: "sudo yum -y install rubygems" - rh.vm.provision "shell", inline: "sudo gem install --no-ri --no-rdoc fpm" - rh.vm.provision "shell", inline: "sudo yum -y localinstall http://yum.datadoghq.com/rpm/supervisor-3.0-0.5.a10.el6.noarch.rpm" - end -end diff --git a/ci/activemq.rb b/ci/activemq.rb index 938b073e4e..e407488312 100644 --- a/ci/activemq.rb +++ b/ci/activemq.rb @@ -9,7 +9,7 @@ def activemq_rootdir end namespace :ci do - namespace :my_new_flavor do |flavor| + namespace :activemq do |flavor| task before_install: ['ci:common:before_install'] task install: ['ci:common:install'] do diff --git a/ci/common.rb b/ci/common.rb index b01e7a6af0..cb860a184d 100644 --- a/ci/common.rb +++ b/ci/common.rb @@ -18,6 +18,7 @@ def section(name) puts '' end +# helper class to wait for TCP/HTTP services to boot class Wait DEFAULT_TIMEOUT = 10 @@ -158,12 +159,12 @@ def self.for(smth, max_timeout = DEFAULT_TIMEOUT) task :run_tests, :flavor do |t, attr| flavors = attr[:flavor] filter = ENV['NOSE_FILTER'] || '1' - if flavors.include? 'default' || flavors.include? 'checks_mock' + if flavors.include?('default') || flavors.include?('checks_mock') nose = "(not requires) and #{filter}" else nose = "(requires in #{flavors}) and #{filter}" end - if flavors.include? 'default' || flavors.include? 'core_integration' + if flavors.include?('default') || flavors.include?('core_integration') tests_directory = 'tests/core' else tests_directory = 'tests/checks' diff --git a/ci/default.rb b/ci/default.rb index e8305ad82c..a67372d833 100644 --- a/ci/default.rb +++ b/ci/default.rb @@ -41,7 +41,7 @@ task before_script: ['ci:common:before_script'] - task :lint do + task lint: ['rubocop'] do sh %(flake8) end diff --git a/ci/resources/cache.rb b/ci/resources/cache.rb index 1ae569b4c6..ca939ebafb 100644 --- a/ci/resources/cache.rb +++ b/ci/resources/cache.rb @@ -124,7 +124,7 @@ def push_url(branch = 'master') def fold(message = nil) @fold_count ||= 0 - @fold_count += 1 + @fold_count += 1 puts `echo #{message}` if message yield diff --git a/ci/resources/cache/aws4_signature.rb b/ci/resources/cache/aws4_signature.rb index 2827779347..25cd736903 100644 --- a/ci/resources/cache/aws4_signature.rb +++ b/ci/resources/cache/aws4_signature.rb @@ -109,7 +109,7 @@ def signing_key end def recursive_hmac(*args) - args.reduce { |key, data| OpenSSL::HMAC.digest('sha256', key, data) } + args.reduce { |k, d| OpenSSL::HMAC.digest('sha256', k, d) } end end end diff --git a/ci/riak.rb b/ci/riak.rb index 9e7d173231..72acb3811d 100644 --- a/ci/riak.rb +++ b/ci/riak.rb @@ -18,7 +18,8 @@ def riak_rootdir sh %(chmod a+x $VOLATILE_DIR/kerl) sh %($VOLATILE_DIR/kerl build git git://github.com/basho/otp.git OTP_R16B02 R16B02) sh %($VOLATILE_DIR/kerl install R16B02 $VOLATILE_DIR/erlang/R16B02) - sh %(curl -o $VOLATILE_DIR/riak.tar.gz http://s3.amazonaws.com/downloads.basho.com/riak/#{riak_version[0..2]}/#{riak_version}/riak-#{riak_version}.tar.gz) + sh %(curl -o $VOLATILE_DIR/riak.tar.gz\ + http://s3.amazonaws.com/downloads.basho.com/riak/#{riak_version[0..2]}/#{riak_version}/riak-#{riak_version}.tar.gz) sh %(mkdir -p $VOLATILE_DIR/riak) sh %(tar zxvf $VOLATILE_DIR/riak.tar.gz -C $VOLATILE_DIR/riak --strip-components=1) sh %(cd $VOLATILE_DIR/riak\ diff --git a/ci/sysstat.rb b/ci/sysstat.rb index cef4e10343..d4ca2cb5ca 100644 --- a/ci/sysstat.rb +++ b/ci/sysstat.rb @@ -25,7 +25,8 @@ def sysstat_rootdir sh %(tar Jxf $VOLATILE_DIR/sysstat-#{sysstat_version}.tar.xz\ -C $VOLATILE_DIR/sysstat --strip-components=1) sh %(cd $VOLATILE_DIR/sysstat\ - && conf_dir=#{sysstat_rootdir}/etc/sysconfig sa_dir=#{sysstat_rootdir}/var/log/sa ./configure --prefix=#{sysstat_rootdir} --disable-man-group\ + && conf_dir=#{sysstat_rootdir}/etc/sysconfig sa_dir=#{sysstat_rootdir}/var/log/sa\ + ./configure --prefix=#{sysstat_rootdir} --disable-man-group\ && make\ && make install) end