How Do You Do a Code Review?

Question
How do you do a code review?

Answer
Look for consistency in style (adherence to a style guide), functionality, and ensure unit tests and end-to-end tests were performed. Keep an eye out for security issues or maintainability issues. Deploying the code should be straightforward or well documented.

Page 307 of Terraform: Up & Running, 2nd Edition by Yevgeniy Brikman (O’Reilly),

How Do You Tell If the .yaml File for a kubectl Command Will Work?

Problem scenario
You want to do some pre-testing on the .yaml file(s) you will use with kubectl. How do you validate a .yaml file has correct syntax for Kubernetes?

Possible Solution #1
Try this command:
kubectl apply –validate=true –dry-run=true –filename=nameofyourfile.yaml

Possible Solution #2
Try this website:
https://www.kubeyaml.com/

Possible Solution #3
Try kubeval: https://www.kubeval.com/

Possible Solution #4
Use Copper: http://copper.sh/

What Is The Difference between Unit Testing and Functional Testing?

Question
What is the difference between unit testing and functional testing in the context of professionals using one over the other?

Answer
A user wants to verify that the software behavior is correct from a black-box perspective; this more closely describes functional testing. A programmer is more concerned about the theoretical aspects of the code and its inner workings; this more closely describes unit testing.

How Do You Troubleshoot SonarQube Not Starting up Properly?

Problem scenario
SonarQube is not starting up properly. What should you do?

Possible Solution #1
For the sonar.properties file do not put “#” symbols on lines that are not completely commented out. They can cause you problems.

Possible Solution #2
You may want to click here to see more about re-installing it or troubleshooting the error.

How Do You Troubleshoot the sonar-scanner CLI Not Working?

Problem scenario
You run sonar-scanner from the command prompt, but you receive an error. The error looks like one of the following:

“Task ‘-x’ does not exist. Please use ‘list’ task to see all available tasks”

“You must define the folowing mandatory properties for ‘Unknown’: sonar.projectKey, sonar.sources”

What should you do to get sonar-scanner to work?

Solution
Run the sonar-scanner command from a local directory where you have sonar-project.properties.

How Do You Get SonarQube to Use a New Database Connection and Change It from the Previous One It Was Working with?

Problem scenario
You try to start an old SonarQube instance but with a new database connection. In the web.log file you see a message like this: “Can not connect to database. Please check connectivity and settings.” What should you do?

Solution
Go to sonar.properties. Find the connection string for the new database. It should look something like this:

sonar.jdbc.url=jdbc:oracle://FQDN:1521:XE

The default port for Oracle databases is 1521.

How Do You Get sonar-scanner to Work When You Seem to Have No Quality Profiles and Your Server Has No Internet Access?

Problem scenario
You run sonar-scanner, but it fails with an error such as this: “No quality profiles have been found, you probably don’t have any language plugin installed.”

You run sonar-scanner with the “-X” and see a Java stack trace like this: “Error during SonarQube Scanner execution java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.report.MetadataPublisher”

You log into the SonarQube web UI. You go to “Quality Profiles” but you see no profiles and no button or option to create one.

How Do You Get around The AccessDeniedException Error with SonarQube?

Problem scenario
You are trying to set up SonarQube for the first time. You run this command:

bash /opt/sonarqube/bin/linux-x86-64/sonar.sh console

You see this error:

“jvm 1 | java.nio.file.AccessDeniedException: /opt/sonarqube/temp/conf/es/elasticsearch.yml”

What do you do?

Solution
Make sure that the user who is running the command has the ability to execute files in the /opt/sonarqube/ directory (or wherever the destination is that you are installing Sonarqube).

How Do You Analyze Code with SonarQube?

Problem scenario
You want to utilize SonarQube to do some analysis of some code. What do you do?

Solution
Prerequisites
This assumes you have SonarQube and SonarQube Scanner (aka sonar-scanner) installed. If you need assistance with either of these, see this link to install SonarQube or this link to install sonar-scanner.

Procedures

  1. Place the source code file (e.g.,

How Do You Troubleshoot the SonarScanner Error “java.lang.IllegalStateException: Failed to create lock in /opt/app/sonar-scanner/conf/…sonar_locak…DirectoryLock…”?

Problem scenario
You try to run sonarscanner from a command prompt.  But you get this message:

“java.lang.IllegalStateException: Failed to create lock in /opt/app/sonar-scanner/conf/…sonar_locak…DirectoryLock…”

What should you do?

Solution
Become a different user to run the sonarscanner command or use “sudo ” before your command.