0% found this document useful (0 votes)
17 views6 pages

Test Paper 1

The document discusses various Git, Python and Jenkins concepts and commands. It provides answers to questions related to Git commands like revert, squash, recovering deleted branches. Python concepts covered are functions for formatting numbers, parsing strings. Jenkins topics include continuous integration, Groovy and installing Jenkins.

Uploaded by

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

Test Paper 1

The document discusses various Git, Python and Jenkins concepts and commands. It provides answers to questions related to Git commands like revert, squash, recovering deleted branches. Python concepts covered are functions for formatting numbers, parsing strings. Jenkins topics include continuous integration, Groovy and installing Jenkins.

Uploaded by

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

DevSecOps Test Paper

GIT:
1) Write a command to revert a commit that has already been pushed and made public.
Answer-1 : git revert <commit-id>
We can get commit id from git log.

2) Write a command to squash the last N commits into a single commit.


Answer-2: git rebase -i HEAD~N

3) Suppose one of your teammates accidentally deleted a branch and pushed the changes to the
central git repo. There are no other git repos, and none of your teammates had a local copy. How
would you recover this branch? Write the steps of commands.
Answer-3 git reflog delete-branch-name
Git checkout -b <new-branch> <commit-id-deleted>
Git add .
Git commit -m “”
Git push origin master

4) Write the commands to cherry-pick a merge commit?


Answer-4: git cherry-pick <commit-id>

5) What is a merge conflict in git and how can it be resolved? Write the appropriate commands.
Answer-5 : merge conflict is conflict occur because of changes in a file where one of the branch contents
got modified.
It can be resolved while keeping the desired content and removing the unwanted one.
File get open like >>> and <<<<. Keep the desired changes.
git add <filename>
git commit -m “commit message”
git push origin master
git merge or can share the PR who has merge access.

PYTHON:

6) Write a function named 'format_number' that takes a non-negative number as its only parameter.
Your function should convert the number to a string and add commas as a thousand separators. For
example, calling format_number(1000000) should return "1,000,000".
Answer6-
n=Int(“input number”)
String(n)
If n>0

def format_number(num):
if num<0:
print(“error”)
else:
num1=str(num)
temp_list=[]
temp_list2=[]
for I in range(len(num1)):
temp_list.append(i)
for j in range(0,len(temp_list),-3):
temp_list2.insert(i,”,”)
return temp_list2

7) Write a function in Python to parse a string such that it accepts a parameter- an encoded string. This
encoded string will contain a first name, last name, and an id. You can separate the values in the
string by any number of zeros. The id will not contain any zeros. The function should return a Python
dictionary with the first name, last name, and id values. For example, if the input would be
"John000Doe000123".
Then the function should return: { "first_name": "John", "last_name": "Doe", "id": "123" }

Answer-7 : Input_string="John000Doe000123"

def parse_string(input_string):

print (input_string)

temp_list=[]

list_out=input_string.split(0)  [john,,,]

for i in range(len(list_out)):

if i !=’’:

temp_list.append()
return {“first_name” : temp_list[0], “last_name”: temp_list[1], “id”: temp_list[-1]}

1) What are *args and **kwargs in Python functions?


Answer-8: *arg -> It is the argument variable used in the function to take multiple arguments as tuple.
**kwargs – It is also the argument variable used in the function to take multiple argument
as dictionary.

JENKINS:

2) How is continuous integration achieved using Jenkins?


Answer-9 – continuous integration is achieved using the Jenkins in the way that whenever developer
push the code in the repository then the build gets trigger automatically provided it is enabled in the
Jenkins while creating the pipeline. This process continue as per stages mentioned in the Jenkins file
resulting continuous Deployment or Continuous Delivery.

3) What is Groovy in Jenkins?


Answer-10: groovy is the language used in the Jenkins to achieve the CI/CD.

4) How do you install Jenkins?

Answer-11 : Jenkins can be installed in following way-

a) Check the official website to check the perquisites and follow the instruction.

b) Install the java on the machine you wants to install jenkins

c) Install the Jenkins using yum or apt-get depends on linux flavor or can be install using binary.
Multiple Choice Questions

1. Which command initializes a new Git repository?

a) git new

b) git create

c) git start

d) git init

Answer-1 : git init

2. What does the .git directory store?

a) Configuration files

b) Source code

c) Project documentation

d) Repository metadata and version history

Answer-2 : configuration files

3. What does the HEAD in Git represent?

a) The first commit in the repository

b) The latest commit in the remote repository

c) The currently checked-out commit

d) The base of the current branch


Answer-3: c) -The currently checked-out commit

4. How do you view the differences between the working directory and the last commit?

a) git view

b) git diff

c) git changes

d) git compare
Answer-4: b) git diff

5. Which variable contains the directory which contains logs, jobs, users and other configurations
of jenkins?

a) HOME_JENKINS
b) HOME
c) JENKINS
d) JENKINS_HOME
Answer-5 : d) JENKINS_HOME

6. How to take backup of whole jenkins setup?

a) Copy all data present in JENKINS_HOME directory to backup directory.


b) Create soft link to JENKINS_HOME directory.
c) Copy only jobs and users folder from JENKINS_HOME directory to backup directory.
d) Save the Jenkinsfile in git.
Answer-6: a) Copy all the data present in JENKINS_HOME directory to backup directory

7. Declarative pipeline starts with which tag?

a) stage { }
b) pipeline { }
c) node { }
d) step { }
answer-7 : b-pipeline{}

8. What is the output of the following program :

print "Hello World"[::-1]

a) dlroW olleH
b) Hello Worl
c) d
d) Error
Answer-8: a) dlroW olleH – also depends on python interpretor using print() in python3

9. What is the output of the following code:

L = ['a','b','c','d']

print("".join(L))

a) Error
b) None
c) abcd
d) [‘a’,’b’,’c’,’d’]
Answer-9: c-abcd

10. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?

a) [3, 4, 5, 20, 5, 25, 1, 3]


b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]

Answer10- c) [3, 5, 20, 5, 25, 1, 3]


11. What’s the purpose of the self argument in Python class methods?

a) It’s used to call other methods within the class.


b) It holds a reference to the current object.
c) It’s a placeholder and has no purpose.
d) It refers to the class itself.
Answer-11- b) It holds a reference to the current object.

12. Given the following class

definition: class Circle:

def

init (self, radius):

self._radius = radius

@property

def radius(self):

return self._radius

@radius.setter

def radius(self, value):

if not isinstance(value, (int, float)) or value <= 0:

raise ValueError("positive number expected")

self._radius = value

Which of the following statements about the Circle class are true? (Select all that apply.)

a) The .radius attribute is a class attribute.

b) The .radius attribute is a managed attribute.


c) When creating a Circle, you can initialize .radius only to positive values.
d) After creating a Circle, you can change .radius only to positive values.

Answer-12-: The .radius attribute is a class attribute.

You might also like