Skip to content

Instantly share code, notes, and snippets.

import unittest
from Site import config, Login
from Site.helpers import fetch_excel_values
class Check_Excel_Logins(config.Fixtures_local):
"""
The test reads the excel ,
imports all the data in dictionaries
logs in with every username(email)/password combination
@wehappyfew
wehappyfew / fetch_jenkins_branch_name.py
Last active August 29, 2015 14:21
Get the branch name that is currently in jenkins
__author__ = 'wehappyfew'
# the url of jenkins config.xml
jenkins_url = 'http://11.11.111.11:8686/job/TheJob/config.xml'
j_user = "someone"
j_pass = "somepass"
def get_jenkins_branch_name(jenkins_url, j_user, j_pass):
"""
@wehappyfew
wehappyfew / grid_nodes_num.py
Last active February 9, 2018 14:48
Fetch the number of nodes that are attached to selenium grid
def grid_nodes_num(grid_console_url="http://my_super_company.com:8080/grid/console#"):
import requests
from bs4 import BeautifulSoup
r = requests.get(grid_console_url)
html_doc = r.text
soup = BeautifulSoup(html_doc)
# print soup.prettify() # for debuggimg
grid_nodes = soup.find_all("p", class_="proxyid")
@wehappyfew
wehappyfew / build_jenkins_job.py
Last active August 29, 2015 14:22
Build the current branch of a provided job
def build_jenkins(j_url="http://11.11.11.11:8686/", job_name='SuperJob'):
"""
Build the current branch of a provided job
"""
import time
from jenkins import Jenkins, JenkinsError
# http://jenkins-webapi.readthedocs.org/en/latest/
j = Jenkins(j_url, j_user, j_pass)
j.job_build(job_name) ; print("\nBuild command sent!\n")
@wehappyfew
wehappyfew / fabfile.py
Last active August 29, 2015 14:24
Fabric fabfile to remotely and simultaneously execute commands in multiple linux hosts
__author__ = 'wehappyfew'
# tutorial : http://cewing.github.io/training.codefellows/assignments/day12/fabric.htmlimport boto,boto.ec2
import boto,boto.ec2
from MyProjecte.AWS_credentials import aws_access_key_id,aws_secret_access_key
from fabric.api import env, run, parallel
# Make the connection to AWS account
conn = boto.ec2.connect_to_region(region_name = "us-east-1",
aws_access_key_id = aws_access_key_id,
@wehappyfew
wehappyfew / Jenkins_Multi_Build.py
Last active August 29, 2015 14:24
Do you have an insane number of jenkins and you want to build on all of them? This is for you. The code makes the build one at a time. I shall make it run in parallel.
def build_jenkins(j_user, j_pass, j_url, job_name):
"""
# https://github.com/stackforge/python-jenkins
# http://python-jenkins.readthedocs.org/en/latest/index.html
"""
import time
from jenkins import Jenkins
# set the jenkins object
j = Jenkins(j_url, j_user, j_pass)
@wehappyfew
wehappyfew / update_R53.py
Last active February 22, 2019 04:12
Grab the ips of the newly spawned EC2 instances based on their tag and update their hostnames on Route 53
from my_AWS_credentials import aws_access_key_id,aws_secret_access_key
import boto.route53
from boto.route53.record import ResourceRecordSets
import boto.ec2
import itertools
EC2conn = boto.ec2.connect_to_region(region_name = "us-east-1",
aws_access_key_id = aws_access_key_id,
aws_secret_access_key = aws_secret_access_key)
def fetch_host_ips(EC2conn, tag, state):
def make_POST(live, arg1, arg2, variable_arg):
"""
"""
import requests
payload = {
"arg1_key" : arg1,
"arg2_key" : arg2
}
@wehappyfew
wehappyfew / apend_path_on_runtime.py
Last active September 8, 2015 12:07
The python project is in Jenkin's workspace folder. I want to run a python script on the QA server (Linux).The workspace folder's path must be added (on runtime for now) in the sys.path .That way I can make imports into the script from any module of the project. TODO->For a more permanent solution the path must be hardcoded in a var in the machine.
__author__ = 'wehappyfew'
import sys,os,pprint
# check the sys.path before I add my directory
print("1: -- ",sys.path)
if os.name == "posix": # check if the script runs on Linux
# If I comment it out, it will throw ImportError
# This path should always be appended on runtime,
@wehappyfew
wehappyfew / RDS.py
Last active September 14, 2015 19:21
Connect to RDS and create a read replica of a specific db instance
__author__ = 'wehappyfew'
# http://boto.readthedocs.org/en/latest/ref/rds.html#boto.rds.RDSConnection.create_dbinstance_read_replica
from AWS_project import us_east_1
import boto.rds, os, sys
if os.name == "nt": #if I run it on WIN
from AWS_project import aws_secret_access_key, aws_access_key_id
RDSconn = boto.rds.connect_to_region(us_east_1,