Search

Showing posts with label Devops. Show all posts
Showing posts with label Devops. Show all posts

03 August, 2020

Grafana with Influxdb and python client

Recently I came across this tool called Grafana. Its a tool that you can use to show graphs and statistics of all kinds. The most popular combination for setup , is Grafana with influxdb as a database. 

I am sharing my setup steps, and supporting python scripts that can be used to generate information and write back to the database. And finally we get to see some nice graphs.

Note: I am using a Mac with Catalina OS 10.15. Python 3.6+.

Installation Plan:


1. Influxdb
2. Grafana
3. influxdb client module for Python.

29 July, 2020

Docker : Most useful commands

Docker has a lot to talk about. But I am going to list a few commands here that come handy while working with it on a daily basis. We will list them in a sequence that looks like a tutorial.


1. List all docker containers


docker container ls

2. List all images


docker image ls

docker images

3. Spawn & run from an image, a new container.


docker run image_name COMMAND

29 August, 2018

Setting your first Jenkins project.

Setup Jenkins on your local PC in minutes


Since you are here, I am assuming that you are trying to find out ,  how to start with Jenkins and you have no clue about it . If it's true, then you are in the best place possible .

This is a blog on Jenkins setup for those guys who have absolutely no idea what to do or where to start.

25 June, 2018

How to work on a Python Project when modules versions needed are different? Use virtualenv



Gone are the days when you need to create a VM for working on a different set of tools.  People work on different projects which might need a special version of a module. (Or python itself) . The problem aggravates when  multiple users work on a single shared machine (Test environments or Build machines ) .Virtual Environments help solve problem . And its easy to use and share among fellow teammates.

29 May, 2018

SVN commands you must know as an Test Automation Engineer


In the course of automation and continuous integration , you will someday come across a stage where you have to perform svn operations . And obviously, using command line (forget fancy UIs to do your business) using command line. And then you will have to start digging in,  which will take a substantial amount time ...believe me.

26 February, 2018

GIT Essential Tips


GIT has become one of those tools in e business that you can't ignore anymore. So I suggest you learn to use the basics of the idea called GIT. For my tester friends, as you enter the automation phase, git is going to come around sooner or later. So watch out.



Important everyday command with GIT

1. How to revert to an old commit both on local and remote

git reset --hard HEAD~1

git push -f origin master

2. How to get all branches of a git project

git fetch --all

3. How to delete a branch from local computer

git branch -d name

4. How to delete a remote branch

git push origin --delete branch

5. How to shift changes from one branch to another

git stash
git checkout branch
git stash pop

6. How to create a remote branch from a new local branch

git push -u origin new_branch

Note: -u means, --set-upstream. Refer this.

7. How to see all the existing remote branches

git branch -r

8. How to see all branches (remote & local) 

 git branch -a

9. How to fetch a specific remote branch

This involves multiple steps. Do as follows.

1) First get a list of all remote branches (git fetch -r)
2) Create a branch of that exact remote branch name (git checkout same_branch_name as remote)

10. How to see the diff between two branches

git diff branch_name


11. How to see the diff with names of files only (no details )between two branches

git diff branch_name --name-only


12. How to see last commit details?

git show

13. How to see who changed a file?

git blame filename

14. How to undo a merge?

git merge --abort

15. How to see, what files were changed or created in the last commit ?

git log -p -1 --name-only

16. How to see, what files were changed in a specific commit?

git show --name-only commit_number

(e.g 6021acc151c2b02c364af5fef2bfbbe73c880d38)


17. Remove last commit from branch.

git reset --hard HEAD

18. Remove last to last commit from branch.

git reset --hard HEAD^

19. Make the branch base same as latest master.

git rebase master

20. Retrieve deleted branch from remote

git fetch origin BranchName


21. Force checkout (switch branch ignoring all changes).

git checkout -f other_Branch


22. Solve Merge Conflict (accept your local content or remote)

git checkout --ours filename # For accepting local changes
git checkout --theirs filename # For accepting remote changes

23. Save work without committing and switch to another branch.

In general, if you want to change branch when you have uncommitted changes, git doesn't allow you to do so. For that , you can use something called "stash".

git stash

To recover the stashed files, use :

git stash pop

To drop the stash (you don't want these changes):

git stash drop


24. Merge a specific commit from one branch to another.
 
Sometimes , it might happen that, we only need a SPECIFIC COMMIT from a branch into another branch. Although, this is not a good thing to do, but GIT makes it possible .


Steps:

Find the hash_number for the commit in source branch. (You can use "git log" ) .
Switch to target branch ( Use "git checkout target_branch" ) .
git cherry-pick hash_number .


25. How to create a branch and switch to it in a single step.

git checkout -b your_branch

26. How to see all the git configs set.

git config --list

27. How to see if you need to rebase your branch before pushing changes?

When you created your working local branch from master, you were at the same base commit as master. Now after a few day, probably the master branch has moved ahead of you since others might have pushed new commits into it while you were working .

-----master------------------------my_branch....

After a few day's,


Day 6 --------master--------------------------------------
Day 5 -----commit-new----------------------------------------
Day 4 -----commit-new----------------------------------------
Day 3 -----commit-new----------------------------------------
Day 2 -----commit-new----------------------------------------
Day 1 -----master------------------------my_branch....

A quick way to do it:

$hash1=$(git show-ref --heads -s master)

$hash2=$(git merge-base master add-inventory-arindam)


$ [ "${hash1}" = "${hash2}" ] && echo "OK" || echo "Rebase is required"


28. How to see what changed after you pulled in from remote and saw some files changed?

git diff branch_name@{1} branch_name file_name
Note the {1}

Another way to do it , is use the commits message that looks like :
Updating 647a02393..08c607cff


29. Diff after file has been added to staged area?

If you execute "git diff" after adding your file to the staged area (after git add command), you will not see and results. In order to see the changes made, you need to execute:

git diff --staged filename

30. Move a file from staged area to unstaged area.

If you decided to not commit a file, AFTER you have already moved the file to staged area (by git add filename), you can do so:

git reset HEAD filename

31. Rename a local branch.

If you want to change your local branch name, it is possible.

git branch -m new_name.

32. See what is in the stash.

Sometimes we just want to know, what's in the stash before we pop it out. This can be helpful in many situations.

git stash show
git stash list

To see the diff too,

git show stash


33. Change the commit message for the last (not published) commit in local branch.

git commit --amend -m new_message

#This will change the message of the last commit.

34. Copy a file from one branch to another branch.

While you are in the branch in which you want the file to be.

git checkout source_branch somefile.py

35. Rename a file

git mv file_oldname file_newname


36. Find branch with pattern

git branch --list '*fix_*'      # Search in local branches

                git branch --list -a '*fix_*'  # Search in remote & local


14 January, 2018

How to run a Python program on the internet from anywhere?


I want to run a python program whenever I need and get some information out of it. The problem is, I want to call that through internet. And I want to show the content on a web page or some UI container. That's it. Let put this as a requirement.

Problem: Display some information on my web page calculated by a python program

How do we do it on our local computer? We run our program as : python my_program.py.
So maybe I can do something like: www.mywebsite.com/my_program.py . Can we? No idea.

I expect to collect the response in some variable (no idea how I can create a variable in the first place on html) and then display the contents of this variable. Displaying a simple text on html is known, so that should be easy.