KEMBAR78
Devops Lab Manual | PDF | Software Development Process | Agile Software Development
0% found this document useful (0 votes)
9 views17 pages

Devops Lab Manual

Uploaded by

KLVGK MURTHY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views17 pages

Devops Lab Manual

Uploaded by

KLVGK MURTHY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

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.

In Agile software development, four main values are emphasized:


 Individual and team interactions over processes and tools;
 Working software over comprehensive documentation;
 Customer collaboration over contract negotiation;
 Responding to change over following a plan.

How Does Agile Work in Software Development?


Many people think that Agile is restricted only to software development. This is not true. Agile is a
mindset that can be used in any project that requires working together to get better results. It can be
applied in any sector, from healthcare or construction to the manufacturing field.
Enterprises that deal with software development companies use Agile in their projects to be focused on
incremental delivery, continual planning, collaboration, and learning.
The method can provide amazing results by including multiple feedback instances throughout the
development cycle. Agile software development is focused on creating MVPs (minimum viable
products) that pass through iterations, each of which provides incremental value.

What Are the Roots of the Agile Software Development Concept?


Agile SDLC
Agile software development lifecycle (SDLC) requires collaborative decision-making and development
over several short cycles or sprints.
Agile SDLC is based on a cyclical development approach to software in iterations instead of all in one
shot. Teams usually work in multiple cycles that last for 2-4 weeks. Developers are focused on the
essential features at any given moment instead of going ―according to plan.‖
Agile software development is represented with various methodologies, including:
 Agile Modeling
 Kanban
 Scrum
 XP – Extreme Programming

VLITS, Vadlamudi. Page 1


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

 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

Agile Software Development Process Flow:


 Concept: The project should be envisioned and thoroughly prioritized.
 Inception: We should determine team members, provide funds, and discuss initial environments
and requirements.
 Iteration (construction): Developers deliver working software based on feedback and iteration
requirements.
 Release: This stage includes QA testing, training (internal and external), documentation,
development, and the final release of the iteration.
 Production with the ongoing support of the software.

VLITS, Vadlamudi. Page 2


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

 Retirement includes completing activities and customer notification.

Agile Iteration Workflow:


During the software development lifecycle in Agile, multiple iterations take place. Each of them follows
its own workflow. It is important during every iteration that the business stakeholders and clients provide
feedback to guarantee that features meet their needs.
The Agile iteration process flow may look like:
 Requirements: we have to determine them for the iteration based on the product backlog, sprint
backlog, feedback of customers and stakeholders.
 Development and design start based on the defined requirements.
 Testing includes QA testing, internal and external training, and documentation development.
 Delivery is time to deliver the working iteration into production.
 Feedback: At this stage, we should accept customer and stakeholder feedback and work it into
the requirements of the next iteration.

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.

VLITS, Vadlamudi. Page 3


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

How is Agile Methodology used in Testing?


Agile Testing is specified as an advanced and dynamic type of Testing that is performed regularly
throughout every iteration of the SDLC (Software Development Life Cycle) by the agile test engineers.
If we deliver the software quickly with the best of the attributes, and the customer satisfaction is the
primary concern at some stage in the agile testing process.
Agile Testing Methodologies
When we are executing the agile testing, the team takes help from several agile methodologies, which
support them in accomplishing the precise results.
Some of the effective agile testing methodologies are:

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.

VLITS, Vadlamudi. Page 4


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

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.

Example 1: A simple calculator program developed using TDD

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:

VLITS, Vadlamudi. Page 5


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

def add(self, a, b):


return a + b

def subtract(self, a, b):


return a - b

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 add_item(self, name, price):


self.items.append((name, price))

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

VLITS, Vadlamudi. Page 6


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

class ShoppingCart:
def __init__(self, discount_strategy=DiscountStrategy()):
self.items = []
self.discount_strategy = discount_strategy

def add_item(self, item):


self.items.append(item)

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()}")

To run this program in Eclipse, you'll need to follow these steps:

1. Create a new Python project in Eclipse.


2. Create two new Python files in your project: "test_calculator.py" and "calculator.py".
3. Copy the provided code into each respective file.
4. To run the unit tests:
o Right-click on the "test_calculator.py" file in the Project Explorer.
o Select "Run As" > "Python unit-test".

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:

 Right-click on the "calculator.py" file.


 Select "Run As" > "Python Run".

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.

VLITS, Vadlamudi. Page 7


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

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.

Test and test data management automation:


• Functionality test
• Test and test data management
• Performance test
• Security test
They are the different tests done by development and delivery pipeline.

Continuous delivery and automation:


CD allows constant flow of changes into production through automated software production pipeline
called CD pipeline.

Infrastructure layer and environment management:


This provides required infrastructure for development. This infrastructure can be managed by tool called
as chef.
Chef: helps in spinning of virtual machine synchronized them and made changes across multiple servers.

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.

Tools stack and its implementation:


1. Continuous integration and activities involved.

Tools: Continuous integration lifecycle stage:


 Version control: Git

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.

VLITS, Vadlamudi. Page 8


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

 Unit test: unit


As it is integrated with the eclipse IDE

 Build automation: Maven


Very powerful, integrated with eclipse IDE used for coding and helps write Compact scripts. It is
compactable with the tools mentioned.

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.

In the context of DevOps and modern software development:


 Configuring your web application properly ensures that it runs efficiently and securely across
different environments.
 Using Git for version control is crucial for managing code changes, facilitating team collaboration,
and enabling practices like continuous integration and deployment.

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

echo "# Ignore compiled files


*.class
*.jar
*.war

VLITS, Vadlamudi. Page 9


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

# Ignore build directories


/target/
/build/

# Ignore IDE files


.idea/
*.iml
.vscode/" > .gitignore

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

Then add these files to Git:


git add .
This command tells Git to track all files in the current directory and all subdirectories, staging any new,
modified, or deleted files for the next commit.

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.

VLITS, Vadlamudi. Page 10


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

8. Make some changes: Edit your index.html file:


index.html
echo "<html><body><h1>My Web App</h1><p>Welcome to my web app!</p></body></html>"

9. Commit these changes:


git add index.html
git commit -m "Added welcome message to homepage"

10. Push the development branch:


git push -u origin development

11. Create a feature branch:


git checkout -b feature/add-footer

12. Make changes in this feature branch:


index.html
echo "<html><body><h1>My Web App</h1><p>Welcome to my web app!</p><footer>Copyright
2024</footer></body></html>"
13. Commit these changes:
git add index.html
git commit -m "Added footer to homepage"

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

16. Prepare for release:


git checkout master
git merge development
git push origin master

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

VLITS, Vadlamudi. Page 11


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

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;

VLITS, Vadlamudi. Page 12


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, CI/CD!";
}
}

Step 3: Create a test class: Create HelloControllerTest.java in src/test/java/com/example/cicddemo:


package com.example.cicddemo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@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!"));
}
}

Step 4: Maven Build Script (pom.xml):


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>

VLITS, Vadlamudi. Page 13


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

<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>

VLITS, Vadlamudi. Page 14


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

</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>

Step 6: Jenkins Pipeline Script (Jenkinsfile):


pipeline {
agent any

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 7: Create Sample Application(Main method class) Code:


package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

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

VLITS, Vadlamudi. Page 17

You might also like