0% found this document useful (0 votes)
75 views100 pages

DevOps Sem6 Labmanual

The document is a lab manual for a second-year DevOps course in the Department of Computer Engineering, outlining the institutional vision, mission, and quality policy. It details the departmental objectives, program outcomes, specific outcomes, and a list of experiments designed to teach students various DevOps practices and tools. The manual also includes a study and evaluation scheme, mapping of course outcomes with program outcomes, and practical guidelines for assessments.

Uploaded by

starsky9886
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)
75 views100 pages

DevOps Sem6 Labmanual

The document is a lab manual for a second-year DevOps course in the Department of Computer Engineering, outlining the institutional vision, mission, and quality policy. It details the departmental objectives, program outcomes, specific outcomes, and a list of experiments designed to teach students various DevOps practices and tools. The manual also includes a study and evaluation scheme, mapping of course outcomes with program outcomes, and practical guidelines for assessments.

Uploaded by

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

Department of Computer Engineering

Lab Manual
Second Year Semester-VI
Subject: DevOps

Even Semester

1
Institutional Vision and Mission

Our Vision

To foster and permeate higher and quality education with value added engineering, technology
programs, providing all facilities in terms of technology and platforms for all round development with
societal awareness and nurture the youth with international competencies and exemplary level of
employability even under highly competitive environment so that they are innovative adaptable and
capable of handling problems faced by our country and world at large.

Our Mission

The Institution is committed to mobilize the resources and equip itself with men and materials of
excellence thereby ensuring that the Institution becomes pivotal center of service to Industry, academia,
and society with the latest technology. RAIT engages different platforms such as technology enhancing
Student Technical Societies, Cultural platforms, Sports excellence centers, Entrepreneurial
Development Center and Societal Interaction Cell. To develop the college to become an autonomous
Institution & deemed university at the earliest with facilities for advanced research and development
programs on par with international standards. To invite international and reputed national Institutions
and Universities to collaborate with our institution on the issues of common interest of teaching and
learning sophistication.

Our Quality Policy

OurQualityPolicy

Itisourearnestendeavourtoproducehighqualityengineeringprofessionalswhoare
innovative and inspiring, thought and action leaders, competent to solve problems
facedbysociety,nationandworldatlargebystrivingtowardsveryhighstandardsinlearning,tea
chingandtrainingmethodologies.

OurMotto: If itis not of quality, itis NOTRAIT!

Dr. Vijay 2
Departmental VisionandMission

Vision
To impart higher and quality education in Computer Science with value added engineering and
technology programs to prepare technically sound, ethically strong engineers with social awareness.
To extend the facilities, to meet the fast changing requirements and nurture the youths with
international competencies and exemplary level of employability and research under highly
competitive environments.

Mission
To mobilize the resources and equip the department with men and materials of excellence to provide
knowledge in the thrust areas of Computer Science and Engineering. To provide learning ambiance
and exposure to the latest tools and technologies and the platforms to work on research and live
projects. To provide the diverse platforms of sports, technical, co-curricular and extracurricular
activities for the overall development of student with ethical attitude. To prepare the students to
sustain the impact of computer education for social needs encompassing industry, educational
institutions and public service. To collaborate with IITs, reputed universities and industries for the
technical and overall upliftment of students for continuing learning and entrepreneurship.

3
Departmental Program Educational
Objectives (PEOs)
1. Learn and Integrate
To provide Computer Engineering students with a strong foundation in the mathematical,
scientific and engineering fundamentals necessary to formulate, solve and analyze engineering
problems and to prepare them for graduate studies.

2. Think and Create


To develop an ability to analyze the requirements of the software and hardware, understand the
technical specifications, create a model, design, implement and verify a computing system to
meet specified requirements while considering real-world constraints to solve real world
problems.

3. Broad Base
To provide broad education necessary to understand the science of computer engineering and
the impact of it in a global and social context.

4. Techno-leader
To provide exposure to emerging cutting edge technologies, adequate training & opportunities
to work as teams on multidisciplinary projects with effective communication skills and
leadership qualities.

5. Practice citizenship
To provide knowledge of professional and ethical responsibility and to contribute to society
through active engagement with professional societies, schools, civic organizations or other
community activities.

6. Clarify Purpose and Perspective


To provide strong in-depth education through electives and to promote student awareness on
the life-long learning to adapt to innovation and change, and to be successful in their
professional work or graduate studies.

4
Departmental Program Outcomes (POs)

PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering problems.

PO2: Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3 : Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate consideration
for the public health and safety, and the cultural, societal, and environmental considerations.

PO4: Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.

PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.

PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.

PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.

PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.

PO9: Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.

PO10 : Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive clear
instructions.

PO11 : Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and leader
in a team, to manage projects and in multidisciplinary environments.

PO12 : Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

5
Program Specific Outcomes: PSO
PSO1: To build competencies towards problem solving with an ability to understand, identify, analyze
and design the problem, implement and validate the solution including both hardware and software.

PSO2: To build appreciation and knowledge acquiring of current computer techniques with an ability
to use skills and tools necessary for computing practice.

PSO3: To be able to match the industry requirements in the area of computer science and engineering.
To equip skills to adopt and imbibe new technologies.

6
Index
Sr. No. Contents Page No.
1. List of Experiments 8
Course Objective, Course Outcome &
2. 9
Experiment Plan
3. CO-PO,CO-PSO Mapping 11
4. Study and Evaluation Scheme 14
5. Experiment No. 1 15
6. Experiment No. 2
7. Experiment No. 3
8. Experiment No. 4
9. Experiment No. 5
10. Experiment No. 6
11. Experiment No. 7
12. Experiment No. 8
13. Experiment No. 9
14. Experiment No. 10

7
List of Experiments
Sr. No. Experiments Name
Git installation and basic Git Commands
Perform installation of Git Bash and Explore usage of basic Git Commands.
a. Git installation
1
b. Git configuration
c. Starting A Project
d. Day-To-Day Work
e. Git branching model
f. Review your work
Explore Git Commands to
a. Tagging known commits
2 b. Reverting changes.
c. Synchronizing repositories.
d. Reverting Changes
Installation of Jenkins
3 To install and configure Jenkins to setup a build Job.

Continuous Integration
4
To build the pipeline of jobs in Jenkins, create a pipeline script to deploy an
application over Server

Installation of Jenkins over Tomcat Server


5 To install Tomcat Server on Windows and run Jenkins over Tomcat Server

Test Software Applications


6
To Setup and Run Selenium Tests in Jenkins Using Maven

Containerization with Docker


7
To understand Docker Architecture, install docker and execute docker
commands to manage and interact with containers.

Build an image with Docker


8 To learn Dockerfile instructions, build an image for sample web application on
Docker Engine

To install and configure Pull based Software Configuration Management and


9 provisioning tools using Ansible/Chef/Puppet

Case Study
10
Comparative study of Software Development Life Cycle – Waterfall Cycle vs
Agile vs DevOps.

8
Course Objective, Course Outcome &
Experiment Plan
Course Objective:

1 To understand DevOps practices which aims to simplify Software Development


Life
2 To be aware of different Version Control tools like GIT, CVS or Mercurial

3 To Integrate and deploy tools like Jenkins and Maven, which is used to build, test
and deploy applications in DevOps environment

4 To be familiarized with selenium tool, which is used for continuous testing of


applications deployed.
5 To use Docker to Build, ship and manage applications using containerization
6 To understand the concept of Infrastructure as a code and install and configure
Ansible tool.

Course Outcomes:

CO1 To understand the fundamentals of DevOps engineering and be fully proficient with
DevOps terminologies, concepts, benefits, and deployment options to meet your
business requirements.
CO2 To obtain complete knowledge of the “version control system” to effectively track
changes augmented with Git and GitHub.
CO3 To understand the importance of Jenkins to Build and deploy Software Applications
on server environment.
CO4 Understand the importance of Selenium and Jenkins to test Software Applications.
CO5 To understand concept of containerization and Analyze the Containerization of OS
images and deployment of applications over Docker.
CO6 To Synthesize software configuration and provisioning using Ansible.

9
Experiment Plan:
Module Week Course Weightage
Experiments Name
No. No. Outcome
Git installation and basic Git Commands
Perform installation of Git Bash and Explore
usage of basic Git Commands.
a. Git installation CO2 05
1 W1 b. Git configuration
c. Starting A Project
d. Day-To-Day Work
e. Git branching model
f. Review your work
Explore Git Commands to
a. Tagging known commits
2 W2 b. Reverting changes. CO2 05
c. Synchronizing repositories.
d. Reverting Changes
Installation of Jenkins
3 W3 To install and configure Jenkins to setup a build CO3 04
Job.
Continuous Integration
W4, To build the pipeline of jobs in Jenkins, create CO3 04
4
W5 a pipeline script to deploy an application over
Server
Installation of Jenkins over Tomcat Server
5 W6 To install Tomcat Server on Windows and run CO3 02
Jenkins over Tomcat Server
W7, Test Software Applications
6 CO4 10
To Setup and Run Selenium Tests in Jenkins
W8
Using Maven
Containerization with Docker
7 W9 To understand Docker Architecture, install CO5 05
docker and execute docker commands to
manage and interact with containers.
Build an image with Docker
8 W10 CO5 05
To learn Dockerfile instructions, build an image
for sample web application on Docker Engine
To install and configure Pull based Software
9 W11 Configuration Management and provisioning CO6 10
tools using Ansible/Chef/Puppet
Case Study
Comparative study of Software Development CO1 10
10 W12 Life Cycle – Waterfall Cycle vs Agile vs
DevOps.

10
Mapping of COs with POs:
Subje Program Outcomes
Course Outcomes
ct PO PO PO PO PO PO PO PO PO PO PO PO
Weig (Weightage-100%) 1 2 3 4 5 6 7 8 9 10 11 12
ht
To understand the
CO1
fundamentals of
DevOps engineering
and be fully proficient
with DevOps 1 1 1 1 1 1 2 2
terminologies,
concepts, benefits, and
deployment options to
meet your business
requirements.
To obtain complete
CO2
knowledge of the
“version control
system” to effectively 1 1 1 1 1 2 2 1
track changes
augmented with Git
and GitHub.
To understand the
CO3
importance of Jenkins
PRATI
CAL to Build and deploy 2 2 2 2 2
100% Software Applications
on server
environment.
Understand the
CO4
importance of
Selenium and Jenkins 2 2 2 2 2
to test Software
Applications.
To understand concept
CO5
of containerization
and Analyze the
Containerization of 1 2 2 1 2 2
OS images and
deployment of
applications over
Docker.
To Synthesize
CO6
software configuration
2 2 2 2 2
and provisioning
using Ansible.

11
Mapping of Course outcomes with Program Specific Outcomes:

Course Outcomes Contribution to Program


Specific outcomes

PSO1 PSO2 PSO3


CO1 To understand the fundamentals of DevOps engineering
and be fully proficient with DevOps terminologies, 2 2 2
concepts, benefits, and deployment options to meet your
business requirements.
CO2 To obtain complete knowledge of the “version control
system” to effectively track changes augmented with Git 2 2 2
and GitHub.
CO3 To understand the importance of Jenkins to Build and 2 2 2
deploy Software Applications on server environment.
CO4 Understand the importance of Selenium and Jenkins to 2 2 2
test Software Applications.
CO5 To understand concept of containerization and Analyze
the Containerization of OS images and deployment of 2 2 2
applications over Docker.
CO6 To Synthesize software configuration and provisioning 2 2 2
using Ansible.

12
Study and Evaluation Scheme
Course Course
Teaching Scheme Credits Assigned
Code Name
CESL601 Skill Theory Practical Tutorial Theory Practical Tutorial Total
02+02* - - 02 - 02
Based
Lab IV –
DevOPs

Course Code Course Name Examination Scheme


CESL601 Skill Based Term Work Practical & Oral Total
Lab IV –
25 25 50
DevOPs

Term Work:

1. Term work should consist of at least 10 experiments on above content.


2. The final certification and acceptance of term work ensures that satisfactory
performance of laboratory work and minimum passing marks in term work.
3. Term Work: 25 Marks (Total) = 10 Marks (Experiments)+ 5 Marks (Mini
Project)+ 5 Marks (Assignments)+ 5 Marks (Theory + Practical Attendance).

Practical/Experiments:

1. The final certification and acceptance of term work ensures that satisfactory perfor
mance of laboratory work and minimum passing marks in term work.

2. Practical exam will be based on the above syllabus.

13
Skill Based Lab IV – DevOPs

Experiment No. : 1

Git installation and basic Git Commands

14
Experiment No. 1
1. Aim: Perform installation of Git Bash and explore usage of basic Git Commands.
a. Git installation
b. Git configuration
c. Starting A Project
d. Day-To-Day Work
e. Git branching model
f. Review your work

2. Objectives: From this experiment, the student will be able


• To understand DevOps practices which aims to simplify Software Development Life.
• To be aware of different Version Control tools like GIT, CVS or Mercurial

3. Outcomes: The learner will be able to


• To understand the fundamentals of DevOps engineering and be fully proficient with
DevOps terminologies, concepts, benefits, and deployment options to meet your
business requirements.
• To obtain complete knowledge of the “version control system” to effectively track
changes augmented with Git and GitHub.

4. Hardware / Software Required : Linux / Windows Operating System

5. Theory:

What is version control?

How version control helps high performing development and DevOps teams prosper

Version control, also known as source control, is the practice of tracking and managing
changes to software code. Version control systems are software tools that help software
teams manage changes to source code over time. As development environments have
accelerated, version control systems help software teams work faster and smarter. They are
especially useful for DevOps teams since they help them to reduce development time and
increase successful deployments.

Version control software keeps track of every modification to the code in a special kind of
database. If a mistake is made, developers can turn back the clock and compare earlier
versions of the code to help fix the mistake while minimizing disruption to all team
members.

Good version control software supports a developer's preferred workflow without imposing
one particular way of working. Ideally it also works on any platform, rather than dictate
what operating system or tool chain developers must use. Great version control systems
facilitate a smooth and continuous flow of changes to the code rather than the frustrating

15
and clumsy mechanism of file locking - giving the green light to one developer at the
expense of blocking the progress of others.

Git is the best choice for most software teams today.

a. Git Install

You can download Git for free from the following website: https://www.git-scm.com/

Git for Windows stand-alone installer

Download the latest Git for Windows installer from https://gitforwindows.org/

When you've successfully started the installer, you should see the Git Setup wizard screen.
Follow the Next and Finish prompts to complete the installation. The default options are
pretty sensible for most users.

Using Git with Command Line

To start using Git, we are first going to open up our Command shell.

For Windows, you can use Git bash, which comes included in Git for Windows. For Mac and
Linux you can use the built-in terminal.

The first thing we need to do, is to check if Git is properly installed:

Example

git --version

git version 2.30.2.windows.1

If Git is installed, it should show something like git version X.Y

b. Configure Git

Run the following commands to configure your Git username and email using the following
commands, replacing Emma's name with your own. These details will be associated with any
commits that you create:

$ git config --global user.name"Emma Paris" $ git config --


globaluser.email"[email protected]"

Now let Git know who you are. This is important for version control systems, as each Git
commit uses this information:

Example

git config --global user.name "pujagit"

git config --global user.email"[email protected]"


16
Change the user name and e-mail address to your own. You will probably also want to use
this when registering to GitHub later on.

Note: Use global to set the username and e-mail for every repository on your computer.

If you want to set the username/e-mail for just the current repo, you can remove global

c. Creating Git Folder (Starting a project)

Now, let's create a new folder for our project:

Example

mkdirmyproject

cdmyproject

mkdir makes a new directory.

cd changes the current working directory.

Now that we are in the correct directory. We can start by initializing Git!

Note: If you already have a folder/directory you would like to use for Git:

Navigate to it in command line, or open it in your file explorer, right-click and select "Git
Bash here"

Initialize Git

Once you have navigated to the correct folder, you can initialize Git on that folder:

Example

gitinit

Initialized empty Git repository in /Users/user/myproject/.git/

You just created your first Git Repository!

Note: Git now knows that it should watch the folder you initiated it on.

Git creates a hidden folder to keep track of changes.

Note: Create a new local repository. If [project name] is provided, Git will create a new
directory name [project name] and will initialize a repository inside it. If [project name] is not
provided, then a new repository is initialized in the current directory.

$ git clone [project url]

Downloads a project with the entire history from the remote repository.

d. Day-To-Day Work
17
$ git status
Displays the status of your working directory. Options include new, staged, and modified
files. It will retrieve branch name, current commit identifier, and changes pending commit.

$ git add [file]


Add a file to the staging area. Use in place of the full file path to add all changed files
from the current directory down into the directory tree

$ git diff [file]


Show changes between working directory and staging area.

$ git diff --staged [file]


Shows any changes between the staging area and the repository.

$ git checkout -- [file]


Discard changes in working directory. This operation is unrecoverable.

$ git reset [file]


Revert your repository to a previous known working state.

$ git commit
Create a new commit from changes added to the staging area. The commit must have a
message!

$ git rm [file]
Remove file from working directory and staging area.

e. Git branching model


$ git branch [-a]
List all local branches in repository. With -a: show all branches (with remote).

$ git branch [branch_name]


Create new branch, referencing the current HEAD.

$ git checkout [-b][branch_name]


Switch working directory to the specified branch. With -b: Git will create the specified
branch if it does not exist.

$ git merge [from name]


Join specified [from name] branch into your current branch (the one you are on currently).

$ git branch -d [name]


Remove selected branch, if it is already merged into any other. -D instead of -d forces
deletion.

18
f. Review your work
$ git log [-n count]
List commit history of current branch. -n count limits list to last n commits.

$ git log --oneline --graph --decorate


An overview with reference labels and history graph. One commit per line.

$ git log ref..


List commits that are present on the current branch and not merged into ref. A ref can be a
branch name or a tag name.
$ git log ..ref
List commit that are present on ref and not merged into current branch.

$ git reflog
List operations (e.g. checkouts or commits) made on local repository

6. Conclusion and Discussion:


Students are supposed to write your own conclusion

7. Viva Questions:
• What is version control?
• What is staging area?
• What do mean by repository?
• What care is to be taken when merging two branches?

8. References:

• Jon Loeliger and Matthew McCullough, Version Control with Git, O’Reilly Media,
Second Edition, 2012.
• Dennis Hutten, Git: Learn Version Control with Git A Step-By-Step Ultimate
Beginners Guide.
• Scott Chacon and Ben Straub, Pro Git_ Everything You Need to Know About Git,
apress, Second Edition

19
Skill Based Lab IV – DevOPs

Experiment No.: 2

Create and fork repositories in GitHub

20
Experiment No. 2
1. Aim: Create and fork repositories in GitHub
a. Creating a GitHub account
b. Synchronizing repositories.
c. Tagging known commits
d. Reverting changes

2. Objectives: From this experiment, the student will be able


• To understand DevOps practices which aims to simplify Software Development Life.
• To be aware of different Version Control tools like GIT, CVS or Mercurial

3. Outcomes: The learner will be able to


• To understand the fundamentals of DevOps engineering and be fully proficient with
DevOps terminologies, concepts, benefits, and deployment options to meet your
business requirements.
• To obtain complete knowledge of the “version control system” to effectively track
changes augmented with Git and GitHub.

4. Hardware / Software Required : Linux / Windows Operating System

5. Theory:

a. Creating a GitHub account

1. Step 1: Create a GitHub account

The easiest way to get started is to create an account on GitHub.com (it's free).

21
Pick a username (e.g., octocat123), enter your email address and a password, and click Sign
up for GitHub. Once you are in, it will look something like this:

2. Step 2: Create a new repository

A repository is like a place or a container where something is stored; in this case we're
creating a Git repository to store code. To create a new repository, select New
Repository from the + sign dropdown menu (you can see I've selected it in the upper-right
corner in the image above).

Enter a name for your repository (e.g, "Demo") and click Create Repository. Don't worry
about changing any other options on this page.

Congratulations! You have set up your first repo on GitHub.com.


22
3. Step 3: Create a file

Once your repo is created, it will look like this:

Don't panic, it's simpler than it looks. Stay with me. Look at the section that starts "...or create
a new repository on the command line," and ignore the rest for now.

Open the Terminal program on your computer.

Type git and hit Enter. If it says command bash: git: command not found, then install
Git with the command for your Linux operating system or distribution. Check the installation
by typing git and hitting Enter; if it's installed, you should see a bunch of information about
how you can use the command.

In the terminal, type:


23
mkdir Demo

This command will create a directory (or folder) named Demo.

Change your terminal to the Demo directory with the command:

cd Demo

Then enter:

echo "#Demo" >> README.md

This creates a file named README.md and writes #Demo in it. To check that the file was
created successfully, enter:

cat README.md

This will show you what is inside the README.md file, if the file was created correctly.
Your terminal will look like this:

To tell your computer that Demo is a directory managed by the Git program, enter:

git init

Then, to tell the Git program you care about this file and want to track any changes from this
point forward, enter:

git add README.md

4. Step 4: Make a commit

So far you've created a file and told Git about it, and now it's time to create a commit.
Commit can be thought of as a milestone. Every time you accomplish some work, you can
write a Git commit to store that version of your file, so you can go back later and see what it
looked like at that point in time. Whenever you make a change to your file, you create a new
version of that file, different from the previous one.

To make a commit, enter:

24
git commit -m "first commit"

That's it! You just created a Git commit and included a message that says first commit. You
must always write a message in commit; it not only helps you identify a commit, but it also
enables you to understand what you did with the file at that point. So tomorrow, if you add a
new piece of code in your file, you can write a commit message that says, Added new code,
and when you come back in a month to look at your commit history or Git log (the list of
commits), you will know what you changed in the files.

b. Synchronizing repositories

Step: Connect your GitHub repo with your computer

Now, it's time to connect your computer to GitHub with the command:

git remote add origin https://github.com/<your_username>/Demo.git

Let's look at this command step by step. We are telling Git to add a remote called origin with
the address https://github.com/<your_username>/Demo.git (i.e., the URL of your Git repo on
GitHub.com). This allows you to interact with your Git repository on GitHub.com by
typing origin instead of the full URL and Git will know where to send your code.
Why origin? Well, you can name it anything else if you'd like.

Now we have connected our local copy of the Demo repository to its remote counterpart on
GitHub.com. Your terminal looks like this:

Now that we have added the remote, we can push our code (i.e., upload
our README.md file) to GitHub.com.

$ git push [--tags] [remote]


Push local changes to the remote. Use --tags to push tags.

25
$ git push -u [remote] [branch]
Push local branch to remote repository. Set its copy as an upstream.

Once you are done, your terminal will look like this:

And if you go to https://github.com/<your_username>/Demo you will see something like


this:

That's it! You have created your first GitHub repo, connected it to your computer, and pushed
(or uploaded) a file from your computer to your repository called Demo on GitHub.com.

$ git fetch [remote]


26
Fetch changes from the remote, but not update tracking branches.

$ git fetch --prune [remote]


Delete remote Refs that were removed from the remote repository.

$ git pull [remote]


Fetch changes from the remote and merge current branch with its upstream.

c. Tagging known commits

$ git tag
List all tags.

$ git tag [name] [commit sha]


Create a tag reference named name for current commit. Add commit sha to tag a specific
commit instead of current one.

$ git tag -a [name] [commit sha]


Create a tag object named name for current commit.

$ git tag -d [name]


Remove a tag from local repository

d. Reverting changes

$ git reset [--hard] [target reference]


Switches the current branch to the target reference, leaving a difference as an uncommitted
change. When --hard is used, all changes are discarded.

$ git revert [commit sha]


Create a new commit, reverting changes from the specified commit. It generates an inversion
of changes.

6. Conclusion and Discussion:


Students are supposed to write your own conclusion.

7. Viva Questions:
• What is difference between git and github?
• How do you push your project into remote repository?
• Is it possible to revert changes after commit? Is so, how?

8. References:
• Jon Loeliger and Matthew McCullough, Version Control with Git, O’Reilly
Media, Second Edition, 2012.
• Dennis Hutten, Git: Learn Version Control with Git A Step-By-Step Ultimate
Beginners Guide.
• Scott Chacon and Ben Straub, Pro Git_ Everything You Need to Know About
Git, apress, Second Edition.
27
Skill Based Lab IV – DevOPs

Experiment No.: 3

Installation of Jenkins
To install and configure Jenkins to setup
a build Job.

28
Experiment No. 3
1. Aim: To install and configure Jenkins to setup a build Job.

2. Objectives: From this experiment, the student will be able


9. To install and build job in Jenkins for deploying application DevOps environment.

3. Outcomes: The learner will be able to


10. To understand the importance of Jenkins to Build and deploy Software Applications on
server environment.

4. Hardware / Software Required: Linux / Windows Operating System

5. Theory:

Jenkins is a Java-based open-source automation platform with built-in continuous


integration plugins. Jenkins is used to continuously build and test your software projects,
making it simpler for developers to incorporate changes to the project and for users to get a
new build. By interacting with a wide range of testing and deployment tools, it also enables
you to release your software continually.

Organizations can use Jenkins to automate and speed up the software development process.
Jenkins combines all stages of the development lifecycle, including build, document, test,
package, stage, deploy, static analysis, and many others.

Jenkins achieves Continuous Integration with the help of plugins. Plugins allow the
integration of Various DevOps stages. If you want to integrate a particular tool, you need
to install the plugins for that tool. For example: Git, Maven 2 project, Amazon EC2,
HTML publisher etc.

Advantages of Jenkins include:


• It is an open-source tool with great community support.
• It is easy to install.
• It has 1000+ plugins to ease your work. If a plugin does not exist, you can code it and
share it with the community.
• It is free of cost.
• It is built with Java and hence, it is portable to all the major platforms.

Jenkins Features:
11. Continuous Integration and Continuous Delivery: As an extensible automation
server, Jenkins can be used as a simple CI server or turned into the continuous delivery
hub for any project.

29
12. Easy configuration
Jenkins can be easily set up and configured via its web interface, which includes on-
the-fly error checks and built-in help.
13. Easy installation
Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with
packages for Windows, Linux, macOS and other Unix-like operating systems.
14. Plugins
With hundreds of plugins in the Update Center, Jenkins integrates with practically every
tool in the continuous integration and continuous delivery toolchain.
15. Extensible
Jenkins can be extended via its plugin architecture, providing nearly infinite
possibilities for what Jenkins can do.
16. Distributed
Jenkins can easily distribute work across multiple machines, helping drive builds, tests
and deployments across multiple platforms faster.

Steps for Installation of Jenkins:

1. Installation of JAVA: Download JDK 11/17 and choose windows 32-bit or 64-bit
according to your system configuration. Click on "accept the license agreement." Set
the Path for the Environmental Variable for JDK:
• Go to System Properties. Under the "Advanced" tab, select "Environment
Variables."
• Under system variables, select "new." Then copy the path of the JDK folder and
paste it in the corresponding value field. Similarly, do this for JRE.
• Under system variables, set up a bin folder for JDK in PATH variables.
• Go to command prompt and type the following to check if Java has been
successfully installed:
C:\Users\Aditi>java -version
2. Browse to the official Jenkins download page. Under the Downloading
Jenkins section is a list of installers for the long-term support (LTS) version of
Jenkins. Click the Windows link to begin the download.
Once the download is complete, run the jenkins.msi installation file.

30
3. The setup wizard starts. Click Next to proceed.

4. Select the install destination folder and click Next to continue.

31
5. Under the Run service as a local or domain user option, enter the domain username
and password for the user account you want to run Jenkins with. Click Test
Credentials to verify the login data, then click Next to proceed.
Or
Using the Run service as LocalSystem option doesn’t require you to enter user login
data. Instead, it grants Jenkins full access to your system and services. Note that this is a
less secure option and is thus not recommended.

32
6.Enter the port number you want Jenkins to run on. Click Test Port to check if the
selected port is available, then click Next to continue.

7. Select the directory where Java is installed on your system and click Next to proceed.

33
8. Select the features you want to install with Jenkins and click Next to continue.

9. Click Install to start the installation process.

34
10. Once the installation is complete, click Finish to exit the install wizard.

Unblock Jenkins
After completing the installation process, you have to unblock Jenkins before you can
customize and start using it.

1. In your web browser, navigate to the port number you selected during the installation
using the following address:

http://localhost:[port number]

2. Navigate to the location on your system specified by the Unblock Jenkins page.

35
3. Open the initialAdminPassword file using a text editor such as Notepad.

4. Copy the password from the initialAdminPassword file.

5. Paste the password in the Administrator password field on the Unblock Jenkins page
and click Continue to proceed.

Customize Jenkins
Once you unlock Jenkins, customize and prepare the Jenkins environment.

1. Click the Install suggested plugins button to have Jenkins automatically install the
most frequently used plugins.

36
2. After Jenkins finishes installing the plugins, enter the required information on
the Create First Admin User page. Click Save and Continue to proceed.

3. On the Instance Configuration page, confirm the port number you want Jenkins to use
and click Save and Finish to finish the initial customization.

37
4. Click the Start using Jenkins button to move to the Jenkins dashboard.

5. Using the Jenkins dashboard, click Create a job to build your first Jenkins software
project.

38
Students should build a job and execute in Jenkins environment.

6. Conclusion and Discussion:


Students are supposed to write your own conclusion

7. Viva Questions:
17. What is Continuous Integration?
18. What is CI/CD?
19. Which tools can be plugged with Jenkins?

8. References:
1. Jenkins: The Definitive Guide: Continuous Integration for the Masses, by John
Ferguson Smart Published by O'Reilly Media

2. Jenkins 2: Up and Running Authored by Brent Laster Published by O'Reilly Media

39
Skill Based Lab IV – DevOPs

Experiment No.: 4

To build the pipeline of jobs in Jenkins,


create a pipeline script to deploy an
application over Server

40
Experiment No. 4
1. Aim: To build the pipeline of jobs in Jenkins, create a pipeline script to deploy an application
overServer.

2. Objectives: From this experiment, the student will be able


20. To install and build job in Jenkins pipeline for deploying application DevOps
environment.

3. Outcomes: The learner will be able to


21. To understand the importance of Jenkins Pipelines for continuous integration and
continuous deployment CI/CD and deploy applications on server.

4. Hardware / Software Required: Linux / Windows Operating System, Jenkins

5. Theory:
A pipeline is a set of interconnected tasks that execute in a specific order. Additionally, Jenkins
Pipeline is a suite of plugins that help users implement and integrate continuous delivery pipelines
into Jenkins.Moreover, using Pipeline, you can create complex or straightforward delivery pipelines
as code via the Pipeline domain-specific language(DSL) syntax. Subsequently, the below states
represent a continuous delivery Pipeline: -

By using Jenkins pipeline continuous Integration, Testing, and Delivery is a seamless process, and
one can achieve all this using the Pipeline concept, which enables the project to be production-ready
always.

Jenkins Pipeline—1. Declarative Pipeline Syntax

The declarative syntax is a new feature that used code for the pipeline. It provides a limited pre-
defined structure. Thereby, it offers an easy & simple continuous delivery pipeline. Moreover, it uses
a pipeline block

2. Scripted Pipeline Syntax

Unlike declarative syntax, the scripted pipeline syntax is the old traditional way to write
the Jenkinsfile on Jenkins web UI. Moreover, it strictly follows the groovy syntax and helps to develop
a complex pipeline as code.

41
• Pipeline - A pipeline is a set of instructions that includes the processes of continuous delivery. For
example, creating an application, testing it, and deploying the same. Moreover, it is a critical
element in declarative pipeline syntax, which is a collection of all stages in a Jenkinsfile. We declare
Pipeline { }

different stages and steps in this block.

• Node - A node is a key element in scripted pipeline syntax. Moreover, it acts as a machine in Jenkins
that executes the Pipeline.
Node {}

• Stage - A stage consists of a set of processes that the Pipeline executes. Additionally, the tasks are
divided in each stage, implying that there can be multiple stages within a Pipeline.
pipeline{
agent any
stages{
stage('Build'){
........
}
stage('Test'){
........
}
stage('Deploy'){
........
}
stage('Monitor'){
........
}
}
}
Steps of execution:

How to create Jenkins Scripted Pipeline?

1. Firstly, from the Jenkins dashboard, click on New Item on the left panel.

42
2. Secondly, enter the name for your pipeline, select Pipeline from the list. After that, click OK.

3. After that, go to the Pipeline tab, and from the Definition, the dropdown selects the Pipeline script.

4. The next step is to write your pipeline code in the web UI provided by Jenkins. Let us see a sample
pipeline example as available in Jenkins-

5. You need to copy and paste the same in UI.

43
5. After that, click on Save. Conclusively, this finishes the process.

How to create a Declarative Jenkins Pipeline?

1. To create a declarative pipeline, you need to have a Jenkinsfile in place. Since I will be using the
project from my Github account, I have already placed the Jenkinsfile in my project.

2. For creating a Declarative Pipeline, you may follow step#1 and Step#2 from the scripted pipeline
creation steps stated above and then follow the below steps-
Go to the Pipeline tab, and from the Definition, the dropdown selects the Pipeline script from SCM

3. Go to the Pipeline tab, and from the Definition, the dropdown selects the Pipeline script from SCM

44
4. Now, you will get an option to input your Repository URL and credentials.

5. 4. Next, you may set the branch or let it be blank for any branch. In the script path, you need to
write the Jenkinsfile name that exists in your repository. Click on Save, and there you go, your
declarative pipeline is ready for use.

6. Now that you are all set with your pipelines, you can execute the same from your Jenkins UI. All you
need to do is select your pipeline and click on Build Now link on the left panel.

7. Once you run the pipeline, you will see the results displayed on the stage view as shown below-

45
Note: Students should build a pipeline job and demonstrate CI/CD in Jenkins
environment.

6. Conclusion and Discussion:


Students will be writing their own conclusion based on experiment performed.

7. Viva Questions:
• What is pipeline?
• What is declarative pipeline?
• What is scripted pipeline?

8. References:
• Jon Loeliger and Matthew McCullough, Version Control with Git, O’Reilly
Media, Second Edition, 2012.
• Dennis Hutten, Git: Learn Version Control with Git A Step-By-Step Ultimate
Beginners Guide.
• Scott Chacon and Ben Straub, Pro Git_ Everything You Need to Know About
Git, apress, Second Edition.

46
Skill Based Lab IV – DevOPs

Experiment No.: 5

To install Tomcat server on windows and


run Jenkins over Tomcat server.

Experiment No.5
Aim: To install Tomcat server on windows and run Jenkins over Tomcat server.

2. Objectives: From this experiment, the student will be able


• To understand DevOps practices which aims to simplify Software Development Life.
• To understand the working of web server

9. Outcomes: The learner will be able to


• To understand the fundamentals of DevOps engineering and be fully proficient with DevOps
terminologies, concepts, benefits, and deployment options to meet your business
requirements.
47
• To obtain complete knowledge of the “continuous integration” to effectively track and
manage changes.

10. Hardware / Software Required : Linux / Windows Operating System

11. Theory:

Tomcat server
It is an open-source Java servlet container that implements many Java Enterprise Specs such as
the Websites API, Java-Server Pages and last but not least, the Java Servlet. The complete name
of Tomcat is "Apache Tomcat" it was developed in an open, participatory environment and
released in 1998 for the very first time. It began as the reference implementation for the very
first Java-Server Pages and the Java Servlet API. However, it no longer works as the reference
implementation for both of these technologies, but it is considered as the first choice among the
users even after that. It is still one of the most widely used java-sever due to several capabilities
such as good extensibility, proven core engine, and well-test and durable. Here we used the
term "servlet" many times, so what is java servlet; it is a kind of software that enables the
webserver to handle the dynamic(java-based) content using the Http protocols.

Step 1: Environment Configuration for tomcat7 setup

• Example- tomcat7 setup


• Install Tomcat7 in CENTOS server at /apps/tomcat/tomcat7 directory and this is e.g
CATALINA_HOME
• Now you need to find your CATALINA_HOME before continuing with the next steps.

Step 2 : Go to the official Apache Tomcat website and choose the latest stable version, as we
chose Tomcat 9.

Step 3 : Choose the appropriate binary distribution according to your machine configuration,
as I am going to choose 64 bit Windows zip.

48
Step 4 : Download the zip file and store it in any of your working directories. Also, unzip this
file after storing it in the working directory.

Step 5 : Now, open the command prompt, go to bin folder path, and type the below
command:

startup.bat

49
Step 6 : As soon as the command will execute, a new window "Tomcat" will open in which
some processing will happen.

Step 7 : Once processing will be done, just for validation whether the tomcat server is
installed on our system, open the browser, and hit the URL http://localhost:8080/. After
hitting the URL, we will see below the window as shown below, if there is a successful
installation of tomcat on our machine.

50
Step 8 :Configure the Post-build Action and Specify the Tomcat Server Details

Step 9 :Build Jenkins Job

51
Step 10 :Testing the Application

12. Conclusion and Discussion:


Students are supposed to write your own conclusion

13. Viva Questions:


• What is Tomcat server?
• What is a web server?
• What are the other web servers available for deployment?

14. References:
• Tomcat: The Definitive Guide 2e Paperback – 6 November 2007by Jason
Brittain (Author), Ian F Darwin (Author)O’Reilly publication.
• https://www.jenkins.io/doc/book/

52
Skill Based Lab IV – DevOPs

Experiment No.: 6

Test Software Applications


To Setup and Run Selenium Tests in
Jenkins Using Maven

53
Experiment No.6
Aim: Test Software Applications: To Setup and Run Selenium Tests in Jenkins Using Maven

Objectives: From this experiment, the student will be able


• To setup and run Selenium tests in Jenkins using Maven for a web application.
• To setup and run Selenium tests with Python for a web application.

Outcomes: The learner will be able to


• To have a basic understanding of how to use Selenium with Python to test a web
application and will be able to write and run basic Selenium tests.

Hardware / Software Required: Linux / Windows Operating System, Python, Java JDK

Prerequisites with Python:

1. Python installed and set up on your machine.


2. Selenium and ChromeDriver installed on your machine.
3. A web application to test.

Theory:
Selenium WebDriver: Selenium WebDriver is a tool that allows interaction with web pages using
various programming languages, including Python. It enables the automation of web browsers, testing
web applications, and performing repetitive tasks.
Python Virtual Environment: A Python virtual environment is a self-contained directory that contains
all the necessary Python packages and modules for a project. It allows isolation of the project's
dependencies and avoids conflicts with other Python packages installed on the system.
Pytest: Pytest is a testing framework for Python that allows the creation of simple and scalable tests. It
provides various features like fixtures, parameterization, and plugins for writing complex tests.
Jenkins: Jenkins is a popular open-source automation server used for continuous integration and
continuous delivery (CI/CD) of software applications. It enables the automation of building, testing,
and deploying software applications.

General Steps-
Step 1: Install Selenium WebDriver for Python:
• Download and install Python on your machine.
• Install Selenium WebDriver for Python using pip.
Step 2: Create a Python virtual environment for Selenium tests:
• Create a new directory for your project.
• Change into the newly created directory.
• Create a new Python virtual environment for your project.
Step 3: Write basic Selenium tests using Python:
• Create a new Python file for your Selenium tests.
• Open the Python file and import the required packages.
• Create a new WebDriver instance and navigate to the web page you want to test.
• Find an element on the web page and interact with it.
• Use Pytest to write and run tests.
• Save the file and run the test locally to make sure it works.
Step 4: Integrate Selenium tests with Jenkins:

54
• Create a new Jenkins job.
• Add a new "Execute shell" step and enter the command to install Selenium and run Pytest.
• Save the job configuration and run the job to make sure it builds and runs the Selenium tests
successfully.

Detailed Steps:

1. Open a terminal or command prompt and create a new directory for your project using the
following command:

mkdir my-webapp-test

2. Change into the newly created directory using the following command:

cd my-webapp-test

3. Create a new Python virtual environment for your project using the following command:

python -m venv venv

4. Activate the virtual environment using the following command:

source venv/bin/activate

5. Install the Selenium WebDriver for Python using the following command:

pip install selenium

6. Download the appropriate WebDriver executable for your browser (Chrome, Firefox, etc.) and
operating system from the Selenium website and save it in your project directory.

7. Create a new Python file for your Selenium tests.

8. Open the Python file and import the required packages using the following code:

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

9. Create a new WebDriver instance using the following code:

driver = webdriver.Chrome()

10. Navigate to the web page you want to test using the following code
driver.get("https://www.example.com")
11. Find an element on the web page using the following code:

element = driver.find_element_by_name("q")

12. Enter text into the element using the following code:

element.send_keys("test")

13. Submit the form using the following code:

55
element.submit()

14. Close the browser using following code


driver.close()

Save the file and run the test locally to make sure it works. Optionally, you can use a testing
framework like Pytest to run and manage your Selenium tests. To run the tests in a continuous
integration environment like Jenkins, create a new Jenkins job by going to Jenkins home page -> New
Item -> Freestyle project. In the Build section, add a new "Execute shell" step and enter the following
command:

pip install selenium

pytest my-test-file.py

Save the job configuration and run the job to make sure it builds and runs the Selenium tests
successfully. That’s it! You now have a basic setup for running Selenium tests with Python. You can
expand on this by adding more tests, integrating with other tools, and configuring Jenkins to run tests
automatically on a schedule or when code changes are pushed to the repository.

To configure Selenium with the help of Python programing language:

Configure Selenium using Python

There are following steps to configure Selenium using Python:

• Download and install Python on Windows


• Install Selenium libraries in Python
• Download and install PyCharm
• Create a new project and write the Selenium test script
• Run and validate the test scripts.

Download and install Python for Windows

In this section, we will see how we download and install the Python for Windows platform.

Download the Python

To download the latest version of Python for Windows Platforms, refer the below
link: https://www.Python.org/downloads/

Once we clicked on the above link, the latest Release version list is shown, where we clicked on
the Python 3.8.1 version as we can see in the below screenshot:

56
o The Python-3.8.1 version window will appear on the screen, then scroll the page little-
bit and find the File section, and the click on the Windows x86-64 web-based
installer link for the Windows operating system as we can see in the below screenshot:

Install the Python

After downloading the Python for Windows-64 bit, we will be ready to install the
Python.

To install the Python, follow the below process:

57
o Once we double-click on the downloaded executable file, the Python 3.8.1(64-
bit) setup window will appear on the screen, where we have two options available to
install the Python, which are:
o Install Now
o Customize installation
o We will click on the Customize installation, and select Add Python 3.8 to
path checkbox as we can see in the below image:

o After, click on the customize installation, the Optional Features will appear on the
screen, where we can select and deselect the features according to our requirements.
o Then, click on the Next button, to proceed further as we can see in the below image:

58
o Once, we clicked on the Next button; we have a list of Advanced Options available,
where we can select the options based on our needs and also make sure that the Install
for all users is selected.
o We can also customize the install location according to our convenience by clicking
on the Browse
o After that, click on the Install button, to install the Python as we can see in the below
screenshot:

o The installing process is getting started after clicking on the Install button as we can
see in the below screenshot:

59
o When the installation is done, we got the confirmation message as Setup was
successful, which means that the Python is installed successfully for
the Windows operating system.
o Then, click on the Close button, to close the setup window as we can observe in the
below screenshot:

After that, we will check whether Python is installed successfully and working fine or
not.

So for this, we will open our command prompt, and type the command as Python and
press the Enter key, and it will open the Python interpreter shell where we can
implement the Python program as we can see in the below image:

Installing the Selenium libraries in Python

Once we successfully install the Python in our operation system, we will install the
Selenium libraries.

60
For this, we will execute the following command in our command prompt:

1. Python -m pip install -U Selenium

And, this command will successfully install the latest Selenium package i.e., Selenium
-3.141.0 added to the libraries as we can see in the below image:

After that executing the above command, it will create the Selenium
folder automatically having all the Selenium libraries as we can see in the below
screenshot:

Download and install PyCharm

Once we successfully install the Selenium libraries into Python, we are ready to
download Python IDE that is PyCharm.

To download the PyCharm, follow the below process:

61
o Refer the below link, to download the
PyCharm https://www.jetbrains.com/pycharm/download/#section=windows
o Once we clicked on the above link, we will get the below window, where will click on
the Download button under the Community section for the Windows

o After that, double-click on the executable file to install the PyCharm, and the PyCharm
Community Edition Setup window will appear on the screen, where we click on
the Next button to proceed further as we can see in the below image:

62
o In the next step, we can Choose Install location by clicking on the Browser button,
then click on the Next button for further process.

o In the next step, we have some Installation Options available, and we can select them
based on our requirements.
o After that, click on the Next button as we can see in the below image:

o Then, click on the Install button to install the PyCharm, as we can see in the below
screenshot:
63
o As we can see in the below image, the installation process is getting started.

o Then, click on the Finish button to finish the installation process as we can see in the
below image:

64
Create a new project and write the Selenium test script

Once we successfully install the PyCharm, we will open the PyCharm IDE for creating a
new project.

Create a New Project in PyCharm

Follow the below process, to create a new project in PyCharm:

o First, open the PyCharm by Double-click on it, and click on the Create New Project as
we can see in the below image:

65
o After that, we will provide the project name as SeleniumTest, and click on
the Create button as we can see in the below image:

o After clicking on the Create button, we will get the below window:

66
Adding Selenium Test Scripts

For adding the Selenium test scripts in the PyCharm, follow the below process:

o Right-click on the SeleniumTest project, then go to New, and we can add any of the
options in the given list according to our requirements.
o But, here we are adding the Python file, so for this, we will add the Directory which
helps us to manage them separately as we can see in the below screenshot:

o And, provide the Directory name, in our case we give it as Demo


o After that, press the Enter key as we can see in the below screenshot:

o After creating a Directory, we will right-click on the Demo Directory then go to New,
and select Python File from the pop-up menu as we can see in the below image:
Demo → New → Python File

67
o And, we provide a name to python file as Sample1.
o Then, press the Enter key as we can see in the below image:

o After that, we got the IDE where we can create or write our Selenium test Scripts.

Write the Selenium test script

For our testing purpose, we will first go to the Google Home page and
search javatpoint from there.

We are creating our sample test script step by step to give you a complete
understanding of how we write a Selenium test script in Python programming
language.

For this, follow the below steps:

Step1

In the first step, we will type the following statement to import the web driver:

1. from selenium import webdriver

68
Step2

After that, we will open the Google Chrome browser.

As we can see in the below screenshot, we have multiple types of browsers options
available, and we can select any browser from the list like Chrome, Edge, firefox,
Internet Explorer, opera, safari, etc.

Following are the sample code for opening the Google Chrome browser:

1. driver = webdriver.Chrome()

Step3

In the next step, we will be maximizing our browser window size, and the sample code
is as below:

1. driver.maximize_window()

Step4

Then, we will navigate to the given URL.

The sample code is as below:

1. driver.get("https://www.google.com/")

69
Step5

In this step, we are trying to locate the Google search text box with the help of
its Name attribute value.

o Right-click on the Google search text box, and select the Inspect option in the pop-
up menu as we can see in the below image:

o The developer tool window will be launched with all the specific codes used in the
development of the Google search text box.
o And, copy the value of its Name attribute, that is "q" as we can see in the below image:

Here the sample code:

1. driver.find_element_by_name("q").send_keys("javatpoint")

Step6

Once we identify the Google search text box, and we will identify the Google Search
button.
70
So for this, follow the below process:

o Right-click on the Google searchbutton, and select the Inspect option from the given
pop-up menu as we can see in the below image:

o The developer tool window will be launched with having all the specific codes used in
the development of the Google search button.
o Then, copy the value of its name attribute that is "btnK" as we can see in the below
image:

And, the sample code is as following:

1. driver.find_element_by_name("btnK").send_keys(Keys.ENTER)

Step7
71
In the last step, we are closing the browser.

And, the sample code for closing the browser is as follows:

1. driver.close()

Our final test script will look like this, after completing all the above steps:

1. from Selenium import webdriver


2. import time
3. from Selenium.webdriver.common.keys import Keys
4. print("sample test case started")
5. driver = webdriver.Chrome()
6. #driver=webdriver.firefox()
7. #driver=webdriver.ie()
8. #maximize the window size
9. driver.maximize_window()
10. #navigate to the url
11. driver.get("https://www.google.com/")
12. #identify the Google search text box and enter the value
13. driver.find_element_by_name("q").send_keys("javatpoint")
14. time.sleep(3)
15. #click on the Google search button
16. driver.find_element_by_name("btnK").send_keys(Keys.ENTER)
17. time.sleep(3)
18. #close the browser
19. driver.close()
20. print("sample test case successfully completed")

Note:
Import time: Time is a Python module, which is used to handle the time-related tasks such
as time.sleep().

from Selenium.webdriver.common.keys import Keys:

Here, we are adding Keys libraries from Selenium, like in the above code, we are using
the Enter key instead of click() method to perform a particular scenario.

Run and validate the test scripts

Once we are done with writing the Selenium test script, we will run our test scripts.

72
Here we will run our test scripts in two ways:

o Run in Python IDE


o Run in Command Prompt

Run in Python IDE

So, for this first, we will see how to run the Selenium test script in Python IDE.

o Right-click on the code, and select Run 'Sample1' from the popup menu as we can
see in the below screenshot:

o When we run this script it will give an exception because we don't have the Chrome
driver executable file as we can in the below image:

To overcome this exception, we will download the chrome driver executable from
below
link: https://chromedriver.storage.googleapis.com/index.html?path=79.0.3945.36/

73
o Once we click on the above link, we will click on the zip file based upon our operating
system platform. Like we have Windows platform that's why we clicked on thezip to
download the Executable file as we can see in the below screenshot:

o After downloading the exe file, we can paste this file to the Python folder and unzip it.
o Then, we will create one more folder called libraries as Browsers in the Python IDE.
o Right-click on the Project(SeleniumTest) → New → Directory as we can see in the
below screenshot:

o And, we will add all the driver's executable files in the Browsers folder manually.
o For this, we will copy the chrome driver exe file from the Python folder, and paste in
the Browser folder as we can see in the below image:

o Now go to PyCharm IDE, and copy the Absolute path of chromdriver.exe file as we
can see in the below screenshot:

o Replace the statement "driver = webdriver.Chrome()" with a statement given below:

74
1. driver=webdriver.Chrome(r"C:\Users\JTP\PycharmProjects\SeleniumTest\Brow
sers\chromedriver.exe")
Note: Here, we will use "r" to overcome the Unicode error.

As we can see in the below screenshot, if we do not put r in the code, it will generate
the Syntax Error.

o After that, we will run the sample1 once again, and it will execute the code successfully
as we can see in the below image:

The above test script will launch the Google Chrome browser and automate all the test
scenarios.

75
Run in Command Prompt

To run the above test script in the Command prompt, follow the below process:

o Copy the location of the Sample1.py file as we can see in the below image:

o And paste in the command Prompt, first go to the particular folder then enter the
below command:
Python Sample1.py
76
o Then, press the Enter key as we can see in the below screenshot that the sample test
case stared.
o And after automating all the scenarios, it will show the message as a sample test case
successfully completed.

Conclusion: By the end of this experiment, we got a basic understanding of how to use Selenium with
Python to test a web application. You will be able to set up a Python virtual environment for Selenium
tests, write basic Selenium tests using Python, and integrate Selenium tests with Jenkins. You will also
be able to expand on this by adding more tests, integrating with other tools, and configuring Jenkins to
run tests automatically on a schedule or when code changes are pushed to the repository.

77
Skill Based Lab IV – DevOPs

Experiment No.: 7

To understand Docker Architecture,


install docker desktop and execute
docker commands to manage and
interact with containers.

Experiment No. 7
1. Aim: To understand Docker Architecture, install docker and execute docker commands
78
to manage and interact with containers.

2. Objectives: From this experiment, the student will be able


• To understand Docker architecture and installation of Docker and
execute Docker commands

3. Outcomes: The learner will be able to


• To understand the importance of Docker and use of Docker architecture
in Devops environment.

4. Hardware / Software Required: Linux / Windows Operating System, Docker

5. Theory:

1. Docker &need of Docker– Docker is a containerization platform that packages your


application and all its dependencies together in the form of a docker container to ensure
that your application works seamlessly in any environment.
2. Container? – Docker Container is a standardized unit which can be created on the fly to
deploy a particular application or environment. It could be an Ubuntu container, CentOs
container, etc. to full-fill the requirement from an operating system point of view. Also, it
could be an application-oriented container like CakePHP container or a Tomcat-Ubuntu
container etc.
3. Docker Image
Docker Image can be compared to a template which is used to create Docker Containers.
They are the building blocks of a Docker Container. These Docker Images are created
using the build command.
4. Docker Container

Docker Containers are the ready applications created from Docker Images. Or you can
say they are running instances of the Images and they hold the entire package needed to
run the application. This happens to be the ultimate utility of the technology.
5. Docker Registry

Finally, Docker Registry is where the Docker Images are stored. The Registry can be either
a user’s local repository or a public repository like a Docker Hub allowing multiple users
to collaborate in building an application. Even with multiple teams within the same
organization can exchange or share containers by uploading them to the Docker Hub, which
is a cloud repository similar to GitHub.

6. Docker Architecture?

Docker Architecture includes a Docker client – used to trigger Docker commands, a Docker
Host – running the Docker Daemon and a Docker Registry – storing Docker Images. The
Docker Daemon running within Docker Host is responsible for the images and containers.

79
7. Install Docker Desktop on Windows

1. Double-click Docker Desktop Installer.exe to run the installer.

If you haven’t already downloaded the installer (Docker Desktop Installer.exe), you can
get it from Docker Hub. It typically downloads to your Downloads folder, or you can
run it from the recent downloads bar at the bottom of your web browser.
2. When prompted, ensure the Use WSL 2 instead of Hyper-V option on the
Configuration page is selected or not depending on your choice of backend.

If your system only supports one of the two options, you will not be able to select which
backend to use.

3. Follow the instructions on the installation wizard to authorize the installer and proceed
with the install.

4. When the installation is successful, click Close to complete the installation process.

5. If your admin account is different to your user account, you must add the user to
the docker-users group. Run Computer Management as an administrator and
navigate to Local Users and Groups > Groups > docker-users. Right-click to add the
user to the group. Log out and log back in for the changes to take effect.

8. Docker hub account creation

Your Docker ID becomes your user namespace for hosted Docker services, and becomes your
username on the Docker forums. To create a new Docker ID:

80
1. Go to the Docker Hub signup page.

2. Enter a username that will become your Docker ID.

Your Docker ID must be between 4 and 30 characters long, and can only contain
numbers and lowercase letters. Once you create your Docker ID you can’t reuse it
in the future if you deactivate this account.

3. Enter a unique, valid email address.

4. Enter a password that’s at least 9 characters.

5. Complete the Captcha verification and then select Sign up.

Docker sends a verification email to the address you provided.

6. Verify your email address to complete the registration process.

9. Docker command- following are the Docker commands to be executed

1. docker –version
This command is used to get the currently installed version of docker.
2. docker login
This command is used to login to the docker hub repository
3. docker run
Usage: docker run -it -d <image name>
This command is used to create a container from an image
4. docker build
Usage: docker build <path to docker file>
This command is used to build an image from a specified docker file
5. docker images
This command lists all the locally stored docker images
6. docker push
Usage: docker push <username/image name>
This command is used to push an image to the docker hub repository
7. docker pull
Usage: docker pull <image name>
This command is used to pull images from the docker repository(hub.docker.com)
8. docker ps
81
This command is used to list the running containers
9. docker stop
Usage: docker stop <container id>
This command stops a running container

Note: Students should install docker desktop, download any docker official image and
push updated official docker image on docker hub.

10. Conclusion and Discussion:


Students will be writing their own conclusion based on experiment performed.

11. Viva Questions:


• What is a Container?
• Why Learn Docker?
What are docker images?

12. References:
• Jon Loeliger and Matthew McCullough, Version Control with Git, O’Reilly
Media, Second Edition, 2012.
• Dennis Hutten, Git: Learn Version Control with Git A Step-By-Step Ultimate
Beginners Guide.
• https://docs.docker.com/desktop/install/windows-install/
• Scott Chacon and Ben Straub, Pro Git_ Everything You Need to Know About
Git, apress, Second Edition.

82
Skill Based Lab IV – DevOPs

Experiment No.: 8

To learn Dockerfile instructions, build


an image for sample web application on
Docker Engine.

Experiment No. 8
1. Aim: To learn Dockerfile instructions, build an image for sample web application on
Docker Engine.

83
2. Objectives: From this experiment, the student will be able
• To understand Docker file and build an image for web applications
Docker Engine

3. Outcomes: The learner will be able to


• To understand the importance of Dockerfile building an image.

4. Hardware / Software Required: Linux / Windows Operating System, Docker,


VsCode

5. Theory: Dockerfile

A Dockerfile is a script/text configuration file that contains collections of commands


and instructions that will be automatically executed in sequence in the docker
environment for building a new docker image.This file is written in a popular, human-
readable Markup Language called YAML.A Dockerfile is a text configuration file
written using a special syntaxIt describes step-by-step instructions of all the commands
you need to run to assemble a Docker Image.

• Create a Dockerfile

Creating a Dockerfile is as easy as creating a new file named “Dockerfile” with your
text editor of choice and defining some instructions. The name of the file does not really
matter. Dockerfile is the default name but you can use any filename that you want (and
even have multiple dockerfiles in the same folder)

• docker build

The docker build command processes this file generating a Docker Image in your Local
Image Cache, which you can then start-up using the docker run command, or push to a
permanent Image Repository.The docker build command processes this file generating
a Docker Image in your Local Image Cache, which you can then start-up using the
docker run command, or push to a permanent Image Repository.

❖ Steps for the building an image for sample web application on Docker Engine.
Create a container image in Visual Studio Code

1. First, create a folder named PHP Hello Docker and open it in Visual Studio Code.

84
2. Open this folder in Visual Studio Code and create a file named hello.php or can take any
simple html file with hello.html .

<html>
<?phpecho"Hello world from php container ">
</html>

3. Next, create a file called Dockerfile (without any extension) and write the below code into
the file. Now with Docker file let construct an image.

FROM php

COPY ./ ./

EXPOSE 3000

CMD ["php","-S","0.0.0.0:3000"]

This is a very basic Dockerfile. Dockerfiles describe how to build your Docker image.

4. Use the docker build command on terminal

docker build . -t dockerhubaccountname/foldername //building image

e.g. docker build . -t bharnesmita45/myfirstPHP_image


where myfirstPHP_image is the name of folder created in local machine

5. Now run the container using following command.

docker run --name=php -p=3000:3000 dockerhubaccountname/foldername

e. g. docker run --name=php -p=3000:3000 bharnesmita45/myfirstphp_image

6. After that new container is running on to browser window.


Type localhost:3000 on browser and we will get following output window.

85
Note: Students should build web application, create image through Dockerfile and push
image on Docker hub.

6. Conclusion and Discussion:


Students will be writing their own conclusion based on experiment performed.

7. Viva Questions:
• What is a dockerfile?
• What is Docker hub?
• How do you create a docker container from an image?

8. References:
• Jon Loeliger and Matthew McCullough, Version Control with Git, O’Reilly
Media, Second Edition, 2012.
• Dennis Hutten, Git: Learn Version Control with Git A Step-By-Step Ultimate
Beginners Guide.
• Scott Chacon and Ben Straub, Pro Git_ Everything You Need to Know About
Git, apress, Second Edition.

Skill Based Lab IV – DevOPs


86
Experiment No.: 9

To install and configure software


configuration management and
provisioning tool using ansible.

Experiment No.9
Aim: To install and configure software configuration management and provisioning tool
using ansible.

87
2. Objectives: From this experiment, the student will be able
• To understand DevOps practices for configuration management.
• To understand the working of Ansible configuration management tool.

15. Outcomes: The learner will be able to


• To understand the fundamentalsof DevOps engineering and be fully proficient with DevOps
terminologies, concepts, benefits, and deployment options to meet your business
requirements.
• To understand the fundamentals and importance of configuration management.

16. Hardware / Software Required : Linux / Windows Operating System

17. Theory:

Configuration Management
The process of standardizing and administering resource configurations and entire IT infrastructure
in an automated way is Configuration Management. It is the concept where you put your server
infrastructure as code.It helps to systematically manage, organize, and control the changes in the
documents, codes and other entities during the SDLC.It aims to control costs and work effort
involved in making changes to the software system

To install Ansible on Windows using Cygwin, follow these steps:

1. Download the Cygwin installation file. This file is compatible with both the 32-bit and 64-bit
versions of Windows 10. It automatically installs the right version for your system.

2. Run the Cygwin installation file. On the starting screen of the installation wizard, click Next to
continue.

88
3. Select Install from Internet as the download source and click Next.

4. In the Root Directory field, specify where you want the application installed, then click Next.

5. In the Local Package Directory field, select where you want to install your Cygwin packages, then
click Next.

89
6. Choose the appropriate Internet connection option.

If you aren’t using a proxy, select Direct Connection.

If you are using a proxy, select Use System Proxy Settings or enter the proxy settings manually with
the Use HTTP/FTP Proxy.

90
Click Next to continue.

7. Choose one of the available mirrors to download the installation files, then click Next.

8. On the Select Packages screen, change the View option to Full and type ‘ansible’ in the search bar.

Select both Ansible and Ansible Doc by checking the boxes under Src? and click Next to continue.

91
9. This screen lets you review the installation settings. To confirm and begin the install process, click
on Next.

10. The install wizard will download and install all the selected packages, including Ansible.

11. Once the installation is complete, select whether you want to add a Cygwin desktop and Start
Menu icon, then click on Finish to close the wizard.

92
Ansible Playbook with Jenkins Pipeline

For Jenkins Pipeline we need to install the Ansible plugin.

Go to Manage Jenkins > Manage Plugins >Available > search Ansible.

If you are already installed Ansible Plugin on your Jenkins It will display in the Installed section.

Now we can see the Invoke Ansible Playbook option in the Build Environment section but we need
to configure Ansible path for Jenkins.

Now let’s configure Ansible on our Jenkins.

Go to Manage Jenkins > Global Tool Configuration > It will display Ansible on the list.

93
Now let’s Create New project to execute Ansible playbook.

Step 2) Goto Jenkins Home > New Item > Create New Freestyle Project.

We create a new freestyle project now lets configure our project.

Goto source code management section and add your code repository here you are free to use any of the
source code management platforms like Github, Gitlab and also Bit bucket.

Now let’s configure ansible plugin.

Goto Build section and select Invoke Ansible Playbook. Once you select that option it will display
ansible-playbook configuration option like below.
94
Let see all option provided by Ansible Plugin.

• Ansible Installation: It will display all Ansible installation list that we are configured in Global
Tool Configuration > Ansible.

• Playbook path: We have to provide the Absolute or Relative path of our Ansible-playbook file.

• Inventory: It gives 3 options to configure our host file.

Do not specify Inventory: We have to give our host list in the subdomain option.

File or host list: add a path of our HOST file.

Inline content: It means we are set our host list on the starting of our ansible-playbook file.

• Host subset: If we want to filter a specific set of the host from the provided Host file.

• Credentials: Configure added host’s username and password.

• Vault Credentials: IF you are using ansible vault then configure that credentials.

• become: If you want to set a specific user for ansible-playbook execution select and add the name
of that user.

95
• sudo: If you need to use a sudo user(root) then select this and add the name of that user.

Ansible Ad hoc commands

Ad hoc commands are commands which can be run independently, to perform immediate
functions.
These commands are of one time usage.
Syntax of a typical ad hoc command:
Ansible [-m module_name] [-a args] [options]
Some of the ad hoc commands and their usage is listed below:

Commands Usage

Run reboot for all your company servers in


$ Ansible def -a “/sbin/reboot” -f 10
a group, ‘def’, in 10 parallel forks
To change from the default current user
$ Ansible abc -a “/sbin/reboot” -f 12 -u
account, you will have to pass the
username
username in Ad-hoc commands
Transferring a file to many
$ Ansible def -m copy -a “src =
servers/machines using SCP (Secure Copy
/etc/yum.confdest = /tmp/yum.conf”
Protocol)
$ Ansible def -m file -a “dest =
/path/user1/new mode = 777 owner = user1 Creating new directory
group = user1 state = directory”
$ Ansible def -m file -a “dest =
Deleting whole directory and files
/path/user1/new state = absent”
$ Ansible def -m yum -a “name = demo- Checks if yum package is installed, but
tomcat-1 state = present” does not update it
$ Ansible def -m yum -a “name = demo-
Check the package is not installed
tomcat-1 state = absent”
$ Ansible def -m yum -a “name = demo- Checks the latest version of package is
tomcat-1 state = latest” installed
$ Ansible all -m setup Finds information of all your facts

18. Conclusion and Discussion:


Students are supposed to write your own conclusion

19. Viva Questions:


• What is configuration management?
• Why we need configuration management?
• What are the other tools for configuration management?

20. References:
• “Ansible for DevOps” Server and Configuration Management for Humans by Jeff
Geerling Midwestern Mac publication, LLC, 05-Aug-2020

96
• “Ansible: Up and Running”, 3rd Editionby Bas Meijer, Lorin Hochstein, René Moser.
Released July 2022. Publisher(s): O'Reilly Media, Inc.

97
Skill Based Lab IV – DevOPs

Experiment No.: 10

Case Study: Comparative study of


Software Development Life Cycle –
Waterfall Cycle vs Agile vs DevOps.

98
Experiment No.10
Case Study
Aim: A Comparative study of Software Development Life Cycle – Waterfall Cycle vs Agile
vs DevOps

Objectives: To compares SDLC methodologies used in the industry and provides insights on
which approach to adopt for software development projects.

Outcome: To understand and evaluate strengths and weaknesses of compared methodologies.

Introduction: The software development life cycle (SDLC) is a structured approach to


software development that involves planning, designing, implementing, testing, and deploying
software. Over the years, several SDLC models have been developed to manage the software
development process, and each has its own advantages and disadvantages. This case study
compares three of the most popular SDLC models: Waterfall Cycle, Agile, and DevOps, to
highlight the differences between them and help organizations choose the best one based on
their needs.

Waterfall Cycle: The Waterfall Cycle is a linear, sequential approach to software development
that involves completing each phase of the development process before moving onto the next
one. This model is popular among companies that have a well-defined scope, clear
requirements, and a predictable development environment. The Waterfall Cycle is beneficial
for projects that require a high level of documentation, regulatory compliance, and risk
management. However, it is less suitable for projects that require flexibility, rapid iteration,
and continuous feedback.

Agile: Agile is an iterative, incremental approach to software development that emphasizes


flexibility, collaboration, and continuous improvement. The Agile model is based on the
principles of the Agile Manifesto, which values individuals and interactions, working software,
customer collaboration, and responding to change. Agile is suitable for projects that require
frequent feedback, customer involvement, and changing requirements. The Agile model allows
for faster delivery, more frequent releases, and improved quality through continuous testing
and integration.

DevOps: DevOps is a software development model that emphasizes collaboration between


development and operations teams to streamline the development process and improve
software delivery. DevOps aims to break down the barriers between development and
operations teams, allowing them to work together seamlessly. The DevOps model uses
automated tools to improve the speed, quality, and reliability of software development. DevOps
is suitable for organizations that require fast, reliable, and scalable software development and
deployment.

99
Comparative Study: The table below summarizes the differences between the Waterfall
Cycle, Agile, and DevOps models:

Model Advantages Disadvantages

Waterfall
Cycle Predictable, well-defined process Inflexible, limited customer involvement

Flexible, iterative, customer- Requires more active involvement from


Agile focused the customer

Fast, reliable, scalable, Requires significant investment in


DevOps automation-driven automation

Note: In this case study students will summarize strengths and weaknesses of compared
methodologies in terms introduction, features advantages disadvantages etc. in a table in their
own words.

Additional Learning: The choice of SDLC methodology depends on the specific requirements
of the project. The Waterfall SDLC methodology is suitable for projects with clear and well-
defined requirements, whereas the Agile SDLC methodology is suitable for projects where
changes are expected. The DevOps SDLC methodology is suitable for projects that require
continuous deployment and release of new features. Ultimately, the company should choose
the approach that best fits its specific needs, taking into account factors such as budget, project
scope, and timelines.

Conclusion: Choosing the right SDLC model depends on the specific needs and goals of each
organization. The Waterfall Cycle is suitable for projects with a well-defined scope and clear
requirements, while Agile is ideal for projects that require flexibility, rapid iteration, and
frequent customer involvement. DevOps is a more advanced model that emphasizes
collaboration between development and operations teams and uses automation to streamline
the development process. By understanding the differences between these three models,
organizations can choose the one that best fits their needs and achieve successful software
development.

100

You might also like