Devops Lab Manual
Devops Lab Manual
Exercise 1:
Get an understanding of the stages in software development lifecycle, the process models, values and
principles of agility and the need for agile software development. This will enable you to work in
projects following an agile approach to software development.
Agile software development is one of the most effective and reliable processes to turn a vision for
business needs into software solutions. The term ―Agile‖ describes software development approaches
that employ continual planning, improvement, learning, evolutionary development, team collaboration,
and early delivery. The method encourages flexible responses to change.
Scrumban
Adaptive Software Development
DAD – Disciplined Agile Delivery
DSDM – Dynamic Systems Development
Feature Driven Development
Lean Software Development
Every methodology has its own goal but the main goal for all is to adapt to change and deliver working
software — as quickly as possible.
Waterfall SDLC versus Agile SDLC: defining the difference between two approaches.
Waterfall
The traditional Waterfall life cycle contains 5 stages:
Requirement analysis
Design
Implementation
Verification
Maintenance
All these stages may last any amount of time. Before reaching the implementation stage, it may take
weeks or months. The Waterfall SDLC isn‘t designed with speed in mind. It looks quite a rationale for
complex software projects, where we strive to avoid a brand destroying fiasco.
Agile
The key characteristic of the Agile model is that the development process breaks larger projects
down into smaller sprints. Something valuable is produced at the end of each iteration.
Any product solution produced during a sprint should have a chance to be introduced to the world
to receive users‘ or stakeholders‘ feedback. This process should be repeated with every sprint.
Agile is strictly sequenced in comparison with the traditional model. We cannot start design until
research is complete as well as development cannot commence until all designs are approved.
In Agile, business people, developers, and designers work together simultaneously. The Agile
development cycle looks like this:
Project planning
Creating a product roadmap
Release planning
Sprint planning
Daily meetings
Sprint Review
Exercise 2:
Get a working knowledge of using extreme automation through XP programming practices of test first
development, refactoring and automating test case writing.
In agile testing, the word "Agile" primarily signifies something that can be performed quickly and
immediately, but also in the area of software development.
The core-functional agile team implements it in order to test the software product and its several modules.
The implementation of agile testing makes sure to deliver a high quality product as bugs or defects get
deleted in the initial stage of the project itself.
Unlike the Waterfall model, Agile Testing can create at the beginning of the project with endless
incorporation between development and testing. It is not a sequential but the continuous process.
The agile testing process is a smart way of testing complicated software, which accepts more effective
results as compared to the traditional testing procedures.
The execution of agile testing will help us identify the initial error and elimination, giving better results in
less development time and costs.
Principles of Agile Testing
Agile Testing includes various different principles that help us to increase the productivity of our
software.
1. Extreme Programming (XP) is an agile software development methodology that aims to produce
higher quality software and improve the quality of life for the development team. It's related to
Agile as one of its implementations, sharing core values like flexibility, customer focus, and
iterative development.
2. Test-first development in XP means writing tests before writing the actual code. This differs
from traditional approaches where testing often comes after coding. It ensures that code is testable
from the start and helps developers focus on requirements.
3. Test-Driven Development (TDD) involves: a) Write a failing test b) Write the minimum code to
pass the test c) Refactor the code. This cycle is repeated for each new feature or functionality.
4. Continuous integration in XP involves frequently merging code changes into a central
repository, after which automated builds and tests are run. This helps detect and address
integration issues early.
5. Refactoring is the process of restructuring existing code without changing its external behavior.
It's important for improving code readability, reducing complexity, and facilitating future changes.
6. Pair programming involves two programmers working together at one workstation. Benefits
include improved code quality, knowledge sharing, and reduced errors.
7. User stories in XP are simple descriptions of a feature told from the perspective of the user. They
guide development and form the basis for creating acceptance tests.
8. Automated testing in XP involves using software tools to execute pre-scripted tests on a software
application. Types typically automated include unit tests, integration tests, and acceptance tests.
9. Unit testing focuses on testing individual components or functions in isolation, while acceptance
testing verifies that the software meets the customer's requirements and works as a whole.
10. XP handles changing requirements through short development cycles, continuous customer
involvement, and maintaining a flexible codebase through practices like refactoring.
11. Common tools for automating test case writing include JUnit for Java, NUnit for .NET, Selenium
for web applications, and frameworks like Robot Framework or Cucumber for behavior-driven
development.
12. Continuous refactoring involves regularly cleaning and improving code. It's crucial for
maintaining code quality, preventing technical debt, and keeping the codebase adaptable to
changes.
13. XP addresses technical debt through practices like continuous refactoring, pair programming, and
maintaining coding standards, which help prevent debt accumulation and facilitate its repayment.
14. Coding standards in XP ensure consistency across the codebase, making it easier to understand,
maintain, and refactor. They also facilitate automated testing by promoting clean, well-structured
code.
15. Sustainable pace in XP refers to working at a pace that the team can maintain indefinitely without
burnout. It's crucial for long-term productivity, code quality, and team morale.
test_calculator.py
import unittest
from calculator import Calculator
class TestCalculator(unittest.TestCase):
def setUp(self):
self.calc = Calculator()
def test_add(self):
self.assertEqual(self.calc.add(2, 3), 5)
self.assertEqual(self.calc.add(-1, 1), 0)
def test_subtract(self):
self.assertEqual(self.calc.subtract(5, 3), 2)
self.assertEqual(self.calc.subtract(1, 5), -4)
calculator.py
class Calculator:
Example 2: A simple program that calculates the total price of items in a shopping cart, including a
discount if applicable.
class ShoppingCart:
def __init__(self):
self.items = []
def calculate_total(self):
total = 0
for item in self.items:
total += item[1]
if total > 100:
total = total * 0.9
return total
# Test
cart = ShoppingCart()
cart.add_item("Book", 50)
cart.add_item("Laptop", 1000)
print(f"Total: ${cart.calculate_total()}")
Now, let's refactor this code to improve its design and make it more flexible:
class Item:
def __init__(self, name, price):
self.name = name
self.price = price
class DiscountStrategy:
def apply_discount(self, total):
if total > 100:
return total * 0.9
return total
class ShoppingCart:
def __init__(self, discount_strategy=DiscountStrategy()):
self.items = []
self.discount_strategy = discount_strategy
def calculate_total(self):
total = sum(item.price for item in self.items)
return self.discount_strategy.apply_discount(total)
# Test
cart = ShoppingCart()
cart.add_item(Item("Book", 50))
cart.add_item(Item("Laptop", 1000))
print(f"Total: ${cart.calculate_total()}")
Eclipse should then execute the unit tests and show you the results in the console and in the "Python Unit
Test" view.
If you want to run the Calculator class directly (though in this case, there's no main method to execute),
you would:
However, since there's no main method or direct execution code in the Calculator class, you won't see any
output from running it this way.
Exercise 3:
It is important to comprehend the need to automate the software development lifecycle stages
through DevOps. Gain an understanding of the capabilities required to implement DevOps,
continuous integration and continuous delivery practices.
Procedure:
Dev-ops Adoption in Projects:
It is the important to comprehend the need to automate the software development lifecycle stages through
Devops, gain an understanding of the capabilities required to implement Devops, CI, and CD.
Devops:
It is the combination of development team and operational team.
Version source code
Code quality analysis
Unit testing
Code coverage
Create executable
Baseline the executable
These activities are done in continuous integration of pipeline.
Operations team:
Operational team contains 2 types of dash boards to measure devops adoption and health of pipeline.
1. Business performance dashboard
• Depict the revenue and speed of deployment defect status.
2. End user dashboard
• Provide code as well as API to executable.
It is an open-source tool which is free of cost, eclipse IDE also open-source tool which contain e-git plug-
in.
Static code analysis: SonarQube
It is an Open source, free and powerful tool.
Artifact repository: artifact repository supports Maven free and open source.
➤ Continuous Integration: Jenkins free, open source, powerful and
➤ integrates with all the tools mentioned.
Exercise 4:
Module name : Implementation of CICD with Java and open source stack
Configure the web application and Version control using Git commands and version control
operations.
The process of configuring a web application and setting up version control using Git: This process
includes creating branches for development and features, making changes, committing those changes, and
merging them back into the main line of development.
1. Set up your project: First, create a directory for your web application.
mkdir my-web-app
cd my-web-app
2. Initialize Git: Initializing Git, creates a new Git repository in your current directory. This sets up
a .git directory in your project folder, which is where Git stores all the necessary metadata for
version control.
git init
3. Create a .gitignore file: A .gitignore file specifies intentionally untracked files that Git should
ignore. This is useful for several reasons:
Prevent cluttering your repository with unnecessary files
Avoid committing sensitive information (like API keys)
Improve performance by not tracking large or frequently changing files
Prevent conflicts with files that are machine-specific
This creates a basic .gitignore file to exclude common files and directories you don't want in version
control.
4. Add your project files: Create some initial files for your project.
Example:
index.html
echo "<html><body><h1>My Web App</h1></body></html>" > index.html
Here echo command is used to print a string, ‗>‘ to redirect the output to a file in the current working
directory.
Main.java
echo "public class Main { public static void main(String[] args) { } }" > Main.java
5. Make your first commit: This command will create a new commit with all the changes you
previously staged (using commands like git add). The commit will be labeled with the message you
provided, which should briefly describe what changes are included in this commit.
git commit -m "Initial commit with basic project structure"
6. Set up a remote repository: Go to GitHub (or your preferred Git hosting service) and create a new
repository. Then link your local repository to it:
git remote add origin https://github.com/your-username/my-web-app.git
git push -u origin master
Replace 'your-username' with your actual username. These commands are used to connect your local Git
repository to a remote repository on GitHub and push your local commits to it. ‗-u‘ sets up tracking,
linking your local master branch to the remote master branch.
7. Create a development branch: The command creates a new branch called ‗development‘ in your
Git repository and immediately switches to it.
git checkout -b development
After running this command, any new commits you make will be on the "development" branch
instead of the "master" (or "main") branch.
14. Push the feature branch: It is creating a more specifically named feature branch. Using this naming
convention helps organize branches, especially in larger projects with multiple ongoing features or
fixes.
git push -u origin feature/add-footer
15. Merge the feature into development: This command is used to merge the changes from the
‗feature/add-footer‘ branch into the current branch(development).
git checkout development
git merge feature/add-footer
git push origin development
17. Create a release tag: These commands are used to create an annotated tag with some message in
your Git repository and push it to the remote repository.
git tag -a v1.0 -m "Version 1.0 release"
git push origin v1.0
Exercise 6: Module Name: Implementation of CICD with Java and open source stack. Write a
build script to build the application using a build automation tool like Maven. Create a folder
structure that will run the build script and invoke the various software development build stages.
This script should invoke the static analysis tool and unit test cases and deploy the application to a
web application server like Tomcat.
Step 1: Set up the project: a. Go to https://start.spring.io/
b. Choose the following options:
Project: Maven
Language: Java
Spring Boot: 2.5.5 (or the latest stable version)
Group: com.example
Artifact: cicd-demo
Packaging: Jar
Java: 8 (or your installed version) c. Add Dependencies: Spring Web d. Click "Generate" and
download the zip file e. Extract the zip file and import it into Eclipse as a Maven project
Folder Structure:
Cicd-Demo/
│
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/cicddemo
│ │ │ ├── Application.java
│ │ │ └── controller/
│ │ │ └── HelloController.java
│ │ └── resources/
│ │ └── application.properties
│ │
│ └── test/
│ └── java/
│ └── com/
│ └── example/cicddemo
│ └── HellowControllerTest.java
│
├── pom.xml
└── Jenkinsfile
Step 2: Create a simple REST controller: Create a new Java class HelloController.java in
src/main/java/com/example/cicddemo:
package com.example.cicddemo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, CI/CD!";
}
}
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void testHelloEndpoint() throws Exception {
mockMvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string("Hello, CI/CD!"));
}
}
<version>3.3.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>cicd-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cicd-demo</name>
<description>Demo project for Spring Boot</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Step 5: Add PMD plugin to pom.xml: Add the following inside the <build><plugins> section of your
pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Static Analysis') {
steps {
sh 'mvn pmd:check'
VLITS, Vadlamudi. Page 15
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab
}
}
stage('Unit Tests') {
steps {
sh 'mvn test'
}
}
stage('Deploy') {
steps {
sh 'java -jar target/demo-0.0.1-SNAPSHOT.jar &'
}
}
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
}
}
Step 8: Create a build script: Create a file named build.bat in the project root:
mvn clean compile
mvn pmd:check
mvn test
mvn package
Step 9: Run the build script: Open a terminal in your project directory and run: build.bat
Step 10: Run the application: After the build is successful, run:
mvn spring-boot:run
Step 11: Test the application: Open a web browser and go to http://localhost:8080/hello.
Output: "Hello, CI/CD!"
VLITS, Vadlamudi. Page 16
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab
Build stages:
1. mvn clean compile: Cleans the project and compiles the source code
2. mvn pmd:check: Runs the PMD static code analysis
3. mvn test: Executes the unit tests
4. mvn package: Packages the application into a JAR file