migration testing framework

33
1 Developing Platform Independent Migration Testing Framework – Approaches using ANT Vishal Harane SAS R&D, India

Upload: indicthreads

Post on 30-Apr-2015

1.239 views

Category:

Documents


2 download

DESCRIPTION

Session Presented at 2nd IndicThreads.com Conference On Software Quality held on 25-26 March 2011 in Pune, India. WEB: http://Q11.IndicThreads.com

TRANSCRIPT

Page 1: Migration testing framework

1

Developing Platform Independent Migration Testing

Framework – Approaches using ANT

Vishal HaraneSAS R&D, India

Page 2: Migration testing framework

2

Agenda Takeaways

What is Product Migration

Different types of product architecture

Problem area

Automation process flow

Why ANT?

Framework Architecture

Sample scripts with examples

Test execution report

Schedule Automation Script

Page 3: Migration testing framework

3

Takeaways To automate different complex tasks (Non GUI tasks)

To develop platform independent framework

Automate to maximum

(Manual tasks + GUI tasks)

Page 4: Migration testing framework

4

What Is Product Migration?

Migration is the process of moving product from

Smaller machine to bigger

One platform to another

One application to another

One version to another

It is not just a copy, it is more than that

Page 5: Migration testing framework

5

Single Machine Architecture

Grid Architecture

Page 6: Migration testing framework

6

Multi Machine Architecture

Page 7: Migration testing framework

7

Problem Area

Page 8: Migration testing framework

8

Solution?

Develop a framework which automate different tasks

Page 9: Migration testing framework

9

Automation Process Flow

Page 10: Migration testing framework

10

Why ANT?

Ease of use

Platform independent

Is not only a build tool; it can do much more…

Can invoke third party plug-ins tasks

Can handle dependencies between targets

Custom tasks – Java, Groovy, etc.

Page 11: Migration testing framework

11

Framework Architecture

Property Files

ANT Script

Page 12: Migration testing framework

12

ANT Script To Check OS

Run Executable

Check OS

<target name="checkBuild" depends="checkOS"><if><isset property="isWindows"/><then>

<exec executable="${build.location}\setup.exe" ><arg line="-quiet -responsefile ${responsefile}" />

</exec></then><else>

<exec executable="${build.location}/setup.sh" ><arg line="-quiet -responsefile ${responsefile}" />

</exec></else></if>

</target>

<target name="checkOS" ><condition property="isWindows">

<os family="windows"/></condition><condition property="isUnix">

<os family="unix"/></condition>

</target>

Page 13: Migration testing framework

13

ANT Script With Java Integration<project name="testProject" default="checkBuild" >

<target name="checkBuild” ><echo message="Checking availability of build"/><getBuild/><echo message="Build to be tested = ${getBuild.name}"/>

</target>

<!-- Script to generate last weekly build name --> <scriptdef name="getBuild" language="beanshell">

<![CDATA[final String BUILD_INITIALS = “product.";final String DATE_FORMAT = "yyyyMMdd";final long DAY_MILLIS = 86400000;Calendar cal = new GregorianCalendar();int day = cal.getTime().getDay();if(day > 3) {

cal.setTimeInMillis(cal.getTimeInMillis() - ((day - 3) * DAY_MILLIS));} else if (day < 3) {

cal.setTimeInMillis(cal.getTimeInMillis() - ((4 + day) * DAY_MILLIS));}

java.text.DateFormat df = new java.text.SimpleDateFormat(DATE_FORMAT);project.setProperty("getBuild.name", BUILD_INITIALS + df.format(cal.getTime()));

]]></scriptdef>

</project>

Code To Generate product.20110101 Pattern

Page 14: Migration testing framework

14

Configuration Task<target name="checkConfig" >

Windows<property file="${config.dir}\Servers.ini"/><echo message="Stopping the Product Services if they are running."/><!-- Stopping the Product Services --><exec executable="net" ><arg value="stop"/><arg value="${ServiceName}"/><arg value="/y"/></exec>

UNIX<echo message="Stopping the Product Services if they are running."/><!-- Stopping the Product Services --><exec executable="${config.dir}\servers" ><arg value="stop"/></exec>

<echo message="Deleting product configuration directory."/><delete dir="${config.dir}"/>

</target>

Page 15: Migration testing framework

15

Install, Log And Response File Tasks

<target name="checkInstall" ><delete dir="${install.dir}"/>

</target>

<target name="checkLog" ><delete dir="${logdir}"/>

</target>

<target name="checkResponsefile" ><echo message="Editing the response file to use the correct license file from current weekly build."/><replaceregexp file="${responsefile}" match=“product.([0-9]*)" replace="${build.name}" flags="ig"/>

</target>

Page 16: Migration testing framework

16

Main ANT Task<target name="runBuild" depends="checkConfig, checkInstall, checkLogs,

checkResponsefile" ><parallel>

<exec executable="${build.location}/${build.name}/setup.sh" ><arg line="-quiet -responsefile ${responsefile}" />

</exec>

<sequential><waitfor maxwait="120" maxwaitunit="minute" checkevery="1"

checkeveryunit="minute"><available file="${install.dir}\installs.txt" />

</waitfor>

<echo message="Setting up the root permissions...."/><exec executable="/usr/bin/sudo" dir="${install.dir}/utilities/bin">

<arg line="chown root testauth testperm" /></exec>

<exec executable="/usr/bin/sudo" dir="${install.dir}/utilities/bin"><arg line="chmod 4755 testauth testperm" />

</exec></sequential>

</parallel>

Page 17: Migration testing framework

17

Main ANT Task - Continue<waitfor maxwait="120" maxwaitunit="minute" checkevery="1" checkeveryunit="minute">

<not><available file="${logfile}.lck"/></not></waitfor>

<!-- Is Product ran successfully? --><loadfile srcFile="${logfile}" property="product.Error">

<filterchain> <containsregex pattern="Exit Code = -1" flags="gi"/>

</filterchain></loadfile>

<if><isset property="product.Error"/><then>

<!– Code to send mail --></then><else>

<echo message="Product installed successfully"/><antcall target="validateServers" /><antcall target="checkData" />

</else></if>

</target>

Page 18: Migration testing framework

18

Services/Servers Validation Server.xml file contains information related to all services present for a Product

<GetObjects><Servers>

<Server Name="Authentication Service" /> <Server Name="File Service" /> <Server Name="RPC Service" /> <Server Name="WorkAllocation Service" /> <Server Name="Console Service" />

</Servers></GetObjects>

<target name="validateServers" >

<xmlproperty file="${serverxml}" collapseAttributes="true"/><property name="getobjects.servers.name" value="${GetObjects.Servers.Name}"/><echo message="${getobjects.servers.name}" />

<for list="${getobjects.servers.name}" delimiter="," param="currentval"><sequential>

<exec executable="${install.dir}\Utilities\ValidateServer.exe" LogError="true" ><arg value="host=${host} port=${port} username=${username} password=${password}"/><arg value="-servername"/><arg value="@{currentval}"/>

</exec>

Sample XML Containing Server Names

Page 19: Migration testing framework

19

Services/Servers Validation - Cont...

<loadfile srcFile="${validatelog}" property="validate.Success"> <filterchain>

<containsregex pattern="Return code: 0” /></filterchain>

</loadfile>

<if><isset property="validate.Success"/><then>

<echo message="@{currentval} = Successful” /></then><else>

<echo message="@{currentval} = Failed” /></else>

</if>

<unset name="validate.Success"/></sequential></for>

</target>

Page 20: Migration testing framework

20

Web Server Validation Task

<!-- Check whether Tomcat is running -->

<target name="check-port" description="Check whether Tomcat is running"><echo message="Checking whether Tomcat is running"/><condition property="tomcat.running"> <socket server="${tomcat.host}" port="${tomcat.port}"/> </condition>

</target>

<!-- Start Tomcat if it isn't running --><target name="start-tomcat" depends="check-port" description="Start Tomcat if it isn't

running" unless="tomcat.running"><echo message="Starting Tomcat"/><property environment="env"/>

<exec executable="${env.CATALINA_HOME}/bin/${tomcat.executableName}" spawn="true" vmlauncher="false"/>

<sleep seconds="15"/>

</target>

Page 21: Migration testing framework

21

Database Schema Validation Task

Page 22: Migration testing framework

22

Database Schema Validation Task#!/usr/bin/perl (Perl Script)

use DBI;my $temp_table=0;

my $g_dbh = DBI->connect( $test_database, $test_user, $test_password)or die "Can't connect to database $test_database: $DBI::errstr";

my $g_sth = $g_dbh->prepare(q{ select tabname from syscat.tables where tabschema='DB2INST1'})or die "Can't prepare Select statement for getting list of tables: $DBI::errstr";

my $g_rc = $g_sth->executeor die "Can't execute Select statement for getting list of tables: $DBI::errstr";

open(TEMP,">/temp/tables.txt") #get list to tables before migrationor die "Can't open file: $!";

while (($tabname) = $g_sth->fetchrow()) {print TEMP "$tabname\n";$temp_table++;

}close TEMP;

Page 23: Migration testing framework

23

Database Schema Task – Cont…open(PRODUCT,"</temp/tables.txt") or die "$!"; #get list to tables before migrationopen(FILE,">/temp/schema_before_mig.txt") or die "$!"; #get schema details before migration

while ($product_tables = <PRODUCT>) {chomp($product_tables);my $g_sth = $g_dbh->prepare(qq{ select COLNAME, TYPENAME, LENGTH, DEFAULT, NULLS from

syscat.columns where TABNAME=\'$product_tables\' order by COLNAME})or die "Can't prepare Select product describe table statement: $DBI::errstr";

my $g_rc = $g_sth->executeor die "Can't execute Select product describe table statement: $DBI::errstr";

while (($g_Column,$g_Type,$g_Length,$g_default,$g_nulls) = $g_sth->fetchrow()) { print FILE "\n$product_tables:$g_Column:$g_Type:$g_Length:$g_default:$g_nulls"; }

$g_sth->finish;}print FILE "\n";close FILE;close PRODUCT;$g_dbh->disconnect;

Page 24: Migration testing framework

24

Physical Data Files Validation Task

Page 25: Migration testing framework

25

Physical Data Files Task – Cont…<target name="checkData" >

<echo message="Comparing the data files present on source machine with the target machine. “/><resourcecount property="file.lines"><tokens> <concat>

<filterchain> <tokenfilter>

<linetokenizer/> </tokenfilter></filterchain><fileset file="${source.datafile}"/>

</concat></tokens></resourcecount>

<echo message="Total number of Product Data files present on Source machine are :” /><loadfile srcFile="${datacompare.file}" property="file.input"/>

<for list="${file.input}" delimiter="${line.separator}" param="currentval"><sequential>

<echo>@{currentval}</echo><exec executable="C:\Program Files\GnuWin32\bin\find.exe" dir="${config.dir}" output="$

{tmp.target.file}" append="true"><arg line="'@{currentval}' -name '*.sas*' -type f"/>

</exec></sequential>

</for>

Page 26: Migration testing framework

26

Physical Data Files Task – Cont…<exec executable="sort" output="${target.datafile}">

<arg line="${tmp.target.file}"/> </exec>

<!– Code to calculate number of product Data file present on Target machine --> <echo message="Total number of Product Data files present on Target machine are : “/><echo message="Following files are not present in the target environment:”/>

<exec executable="diff" output="${tmp.target.file}" ><arg line="${source.datafile} ${target.datafile}"/>

</exec>

<exec executable="grep" output="${tmp.target.file}"><arg line="&quot;&lt;&quot; ${tmp.target.file}"/>

</exec>

<exec executable="sed" output="${datafile}" append="true"><arg line="-e &quot;s/&lt; //g&quot; ${tmp.target.file}"/>

</exec></target>

Page 27: Migration testing framework

27

Job Submission & Result Validation Software Development Kit (SDK)

Product utilities

Page 28: Migration testing framework

28

Job Submission & Result – Cont…

<exec executable="${install.dir}/Utilities/submitJob" LogError="true" ><arg value="-inputfile ${input_file} -outputfile ${output_file} -comparefile $

{compare_file} -log ${result_log}"/></exec>

<loadfile srcFile="${result_log}" property="result.Success"> <filterchain>

<containsregex pattern="Return code: 0” /></filterchain>

</loadfile>

<if><isset property="result.Success"/><then>

<echo message="Test job result is Successful" /></then><else>

<echo message="Test job failed, please check ${result_log} file for more information" />

</else></if>

Page 29: Migration testing framework

29

Reporting

Page 30: Migration testing framework

30

Schedule Automation Script

Schedule these scripts Daily

Weekly

Utilities Windows scheduler

Unix’s crontab

Page 31: Migration testing framework

31

Questions

Page 32: Migration testing framework

32

References

Explore ANT

http://ant.apache.org/

ANT Manual

http://ant.apache.org/manual/

Page 33: Migration testing framework

33

Thank You !!!

Contact: [email protected]