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

WIP: [HELP needed] first attempt based on sonar-puppet module to parse generic-test-data #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

witjoh
Copy link

@witjoh witjoh commented Feb 6, 2018

Just trying to make this plugin parse generic-test-date. Just copied the relevant files from sonar-puppet, but since I'm a noob with java/groovy I'm stcuk ....
I guessed building is done executing ./gradlew build ...
But always get error which I dont find a way to solve them

 /vagrant/playground/workflow/sonar-puppet/sonar-puppet-plugin/src/main/java/com/iadams/sonarqube/puppet/xunit/PuppetXUnitSensor.java:36: error: cannot find symbol
import org.sonar.api.config.Configuration;
                           ^
  symbol:   class Configuration
  location: package org.sonar.api.config
/vagrant/playground/workflow/sonar-puppet/sonar-puppet-plugin/src/main/java/com/iadams/sonarqube/puppet/PuppetReportSensor.java:31: error: cannot find symbol
import org.sonar.api.config.Configuration;
                           ^
  symbol:   class Configuration
  location: package org.sonar.api.config
/vagrant/playground/workflow/sonar-puppet/sonar-puppet-plugin/src/main/java/com/iadams/sonarqube/puppet/xunit/PuppetXUnitSensor.java:50: error: cannot find symbol
  public PuppetXUnitSensor(Configuration conf, FileSystem fileSystem) {

Maybe I'm just messing everything up ..... so any guidance is very welcome.

@iwarapter
Copy link
Owner

I thought most people were using the generic test coverage plugin for this?

@witjoh
Copy link
Author

witjoh commented Feb 6, 2018

that plugin is removed in the 6.7.1LTS version ....
Sonar is parsing the xml file, but just ignores its content ...

@iwarapter
Copy link
Owner

Yeah I seen the plugin was removed as is now part of core: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data (i haven't tested it however) so are you saying when you pass in test reports sonar.testExecutionReportPaths it's not picked up?

@witjoh
Copy link
Author

witjoh commented Feb 6, 2018

from the logs ...

14:02:02.078 DEBUG: Sensors : Generic Test Executions Report -> Puppet Squid Sensor -> SonarJavaXmlFileSensor -> Analyzer for "php.ini" files -> Zero Coverage Sensor -> CPD Block Indexer
14:02:02.078 INFO: Sensor Generic Test Executions Report
14:02:02.079 WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.
14:02:02.079 INFO: Parsing /opt/jenkins-slave/workspace/PMT_Demo/puppet_modules/vdab_ntp_demo/junit/reports_sonar.xml
14:02:02.159 INFO: Imported test execution data for 0 files
14:02:02.159 INFO: Test execution data ignored for 4 unknown files, including:
./spec/classes/chrony_spec.rb
./spec/classes/monitoring_spec.rb
./spec/classes/ntp_spec.rb
./spec/classes/vdab_ntp_spec.rb
14:02:02.159 INFO: Sensor Generic Test Executions Report (done) | time=81ms
14:02:02.159 INFO: Sensor Puppet Squid Sensor [puppet]

@iwarapter
Copy link
Owner

Can you share the demo project so I can reproduce the issue please?

@witjoh
Copy link
Author

witjoh commented Feb 6, 2018

Have to remove company specific dependencies first .. I used the most crapy module to introduce puppet testing :) Will setup a quick demo ....
In short .. I think one just need the following to add to your module ....
in your Gemfile :
```
gem "rspec_sonar_formatter", :git => "https://github.com/witjoh/rspec_sonar_formatter.git", :branch => "master"
#gem "rspec_sonar_formatter", :path => "../rspec_sonar_formatter"

  (custom rspec formatter i wrote that generates the generic-test-data format)
and then in tour spec/spec_helper.rb 
 ` c.add_formatter('RSpec::RspecSonarFormatter::Formatter', 'junit/reports_sonar.xml')`
and start jenkins with following options (in a Jenkinsfile)  ...

      /opt/sonar-scanner/bin/sonar-scanner -X \
        --define "sonar.projectKey=puppet:${gitlabSourceRepoName}" \
        --define "sonar.projectName=${gitlabSourceRepoName}" \
        --define "sonar.projectVersion=${BUILD_ID}-${gitlabMergeRequestIid}" \
        --define "sonar.exclusions=Jenkinsfile*,junit/**/*,spec/**/*" \
        --define "sonar.testExecutionReportPaths=junit/reports_sonar.xml" \
        --define "sonar.import_unknown_files=true" \
        --define "sonar.sources=."
As soon as I get a demo project i will come back

@witjoh
Copy link
Author

witjoh commented Feb 6, 2018

@iwarapter demo project :
https://github.com/witjoh/puppetlabs-ntp.git
branch sonarqube

@witjoh
Copy link
Author

witjoh commented Feb 7, 2018

@witjoh
Copy link
Author

witjoh commented Feb 12, 2018

One of the reasons coverage is not parsed is due to the different languages puppet uses to wirite tests, namely _spec.rb files. Sonar is not able to map the tests files against the corresponding pp file.
I looked at the sonar-ruby-plugin, but this gives no solution out of the box. At least we do have coverage overview in jenkins using the junit coverage reporting. https://github.com/hersonalfaro/ruby-sonar-plugin seems the most up-to-date.

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.

2 participants