Create 3 Small Python Scripts from Algorithm

Cancelled Posted Sep 26, 2009 Paid on delivery
Cancelled Paid on delivery

This project is to create three python scripts: WakeUpSlave, GenerateISO and PowerOFF. These scripts will be used to power on a build server, run the build and then turn it off. We will provide the activity diagram and more information to candidates who have experience with python. The algorithm below is a description of the activity diagram.

The script will exchange values between themselves by storing them in files. You should have experience using PING to determine if a remote server is UP or DOWN.

Development and testing will be done on your workstation, where you use local file to exchange variables and ping google to simulate the server.

ALGORITHM

- 1. WakeUpSlave Build is Triggered

-- 1. Increment BuildCount to prevent the server from being powered off. Create this file if it does not exist.

--- 1. x=GetPropertyValue(filename=BUILDCOUNT, initValue=0)

--- 2. SetPropertyValue(filename=BUILDCOUNT, x+1)

-- 2. Get the Server’s PowerDown cycle state. Create this file if it does not exist

--- 1. y=GetPropertyValue(filename=POWERDOWN, FALSE)

-- 3. if y=TRUE: The server has entered the powerdown cycle. Recheck every 5 seconds, up to a maximum of 300 seconds, for the server to come out of the powerdown cycle. If a timeout occurs, fail the build and decrement the buildcounter

--- 1. STARTTIME = now()

--- 2. LOOP:

--- 3. if (now()-STARTTIME) > TIMEOUT_PD, then a timeout has occurred. Reset the build count to the original ‘x’ value and exit with an error message.

---- 1. SetPropertyValue(filename=BUILDCOUNT,x)

---- 2. EXIT (“Timeout: The server has not left the powerdown cycle within the timeout period. Failing.”)

--- 4. wait RECHECK_WAIT seconds

--- 5. y=GetPropertyValue(filename=POWERDOWN, FALSE)

--- 6. If y=TRUE, then go to LOOP

-- 4. Get the UP/DOWN state of the server by using ping. If the server is down, then send the WOL packet and then recheck the server’s state every 5 seconds, up to a maximum of 200 seconds, for the server to come UP. If a timeout occurs, fail the build and decrement the build counter

--- 1. z = GetServerState(url, TIMEOUT_PING)

--- 2. if z=DOWN:

---- 1. send the WOL magic packet.

---- 2. STARTTIME = now()

---- 3. LOOP:

---- 4. if (now()-STARTTIME) > TIMEOUT_PU, then the server did not power up within the timeout period. Reset the build count to the original ‘x’ value and exit with an error message

----- 1. SetPropertyValue(filename=BUILDCOUNT,x)

----- 2. EXIT (“Timeout: The server did not power up within the timeout period. Failing.”)

---- 5. wait RECHECK_WAIT seconds

---- 6. z = GetServerState(url, TIMEOUT_PING)

---- 7. if z=DOWN, then go to LOOP

-- 5. Exit Success

- 2. GenerateISO build project is Triggered (This is a placeholder build. It will be expanded once the powerOn and powerOff is working. This routine will be triggered by Hudson when the previous use case exits successfully.)

-- 1. (Placeholder: the build occurs in this step)

-- 2. Decrement the BuildCounter. The buildcount file must exist and be non-zero; otherwise, there is an error condition.

--- 1. x=GetPropertyValue(filename=BUILDCOUNT, initValue=0)

--- 2. If x=0, then EXIT (“GenerateISO: The ‘buildcount’ file does not exist or its value is invalid”.)

--- 3. SetPropertyValue(filename=BUILDCOUNT, x-1)

-- 3. Set the LastBuild time to now()

--- 1. SetPropertyValue(filename=LASTBUILD, now())

-- 4. Exit Success

- 3. PowerOff Build is Triggered

-- 1. Set the PowerDown state to “True” to prevent a race condition with the WakeUpSlave build.

--- 1. SetPropertyValue(filename=POWERDOWN, TRUE)

-- 2. z = GetServerState(url, TIMEOUT_PING) – Is Pascal UP or DOWN?

--- 1. if z=Down: the server is already off.

---- 1. SetPropertyValue(filename=POWERDOWN, FALSE)

---- 2. Exit Success

-- 3. x=GetPropertyValue(filename=BUILDCOUNT, initValue=0)

--- 1. if x >0, then there are build in progress. Do not powerdown at this time.

---- 1. SetPropertyValue(filename=POWERDOWN, FALSE)

---- 2. Exit Success

-- 4. t = GetPropertyValue(filename=LASTBUILD, now())

--- 1. if (now()-t) < TIME_MAXIDLE: it is too soon to shut down the server

---- 1. SetPropertyValue(filename=POWERDOWN, FALSE)

---- 2. Exit Success

-- 5. Shut Down the Server. This will be a placeholder for the actual shutdown command.

--- 1. Echo to console “Server Shutting Down”

--- 2. (This is where the shutdown command will go)

--- 3. z = GetServerState(url, TIMEOUT_PING)

--- 4. if z=UP:

---- 1. STARTTIME = now()

---- 2. LOOP:

---- 3. if (now()-STARTTIME) > TIMEOUT_PD, then

----- 1. SetPropertyValue(filename=POWERDOWN, FALSE)

----- 2. EXIT (“Timeout: The server did not power Down within the timeout period. Failing.”)

---- 4. wait RECHECK_WAIT seconds

---- 5. z = GetServerState(url, TIMEOUT_PING)

---- 6. if z=UP, then go to LOOP

--- 6. SetPropertyValue(filename=POWERDOWN, FALSE)

--- 7. Exit with Failure (“PowerOff: The server did not poweroff within the time period. Failing.”)

Common Subroutines

- 1. GetPropertyValue(filename, initvalue) (If the ‘filename’ does not exist, then this routine will create it and set it to ‘initvalue’.)

-- 1. Does the file ‘filename’ exist?

--- 1. NO: the file has not been initialized. We need to create this file and store it with ‘initvalue’: SetPropertyValue(filename, initvalue)

-- 2. Get ‘value’ stored in ‘filename’

-- 3. If there is a read or write error, then EXIT (“rw error: Could not get a property value. Fail.”)

-- 4. Return ‘value’

- 2. SetPropertyValue(filename, value)

-- 1. Create a file ‘filename’ and store ‘value’ in it

-- 2. Read ‘filename’ for ‘currentvalue’

-- 3. If ‘currentvalue’ == ‘value’, then RETURN ‘0’

-- 4. Otherwise: there is a read or write error. EXIT (“rw error: Could not set a property value. Fail.”)

- 3. GetServerState(url, timeout)

-- 1. Ping url

-- 2. wait timeout

-- 3. has a response been received?

-- 4. NO: return “DOWN”

-- 5. YES: return “UP”

Python

Project ID: #516127

About the project

2 proposals Remote project Active Sep 27, 2009

2 freelancers are bidding on average $95 for this job

evgendkv

Hello, please check personal message.

$100 USD in 3 days
(2 Reviews)
2.3
bobry

Hello, i use python for system scripts myself :) so i think i'm the guy you need.

$90 USD in 3 days
(1 Review)
0.0