Skip to content

Commit

Permalink
JENKINS-18415 Can't run shining panda jobs in 1.519
Browse files Browse the repository at this point in the history
  • Loading branch information
omansion committed Jun 29, 2013
1 parent 8e492a2 commit e77a484
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 98 deletions.
Expand Up @@ -24,6 +24,7 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.TaskListener;
import hudson.util.ArgumentListBuilder;

Expand Down Expand Up @@ -455,7 +456,7 @@ public static String getSignature(Workspace workspace, Python interpreter, boole
// Add the executable MD5
sb.append(executable.digest()).append("\n");
// Get the VIRTUALENV script digest
sb.append(workspace.getMasterVirtualenvPy().digest()).append("\n");
sb.append(Util.getDigestOf(workspace.getVirtualenvPyContent())).append("\n");
// Add the distribute flag
sb.append(useDistribute).append("\n");
// Add the systemSitePackages flag
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/jenkins/plugins/shiningpanda/utils/FilePathUtil.java
Expand Up @@ -23,6 +23,7 @@

import hudson.FilePath;
import hudson.Functions;
import hudson.Util;
import hudson.remoting.Callable;

import java.io.File;
Expand Down Expand Up @@ -211,6 +212,24 @@ public static boolean differ(FilePath filePath1, FilePath filePath2) throws IOEx
return true;
}

/**
* Check if remote file contains the provided content.
*
* @param filePath
* The first file
* @param content
* The content
* @return true if the file contains the provided content, else false
* @throws IOException
* @throws InterruptedException
*/
public static boolean differ(FilePath filePath, String content) throws IOException, InterruptedException
{
if (filePath.exists())
return filePath.digest() != Util.getDigestOf(content);
return true;
}

/**
* Check if the provided path is a file
*
Expand Down Expand Up @@ -239,6 +258,27 @@ public static boolean isDirectory(FilePath filePath) throws IOException, Interru
return filePath != null && filePath.isDirectory();
}

/**
* Synchronize a file or all files in a directory.
*
* @param filePath
* The file to synchronize
* @param content
* The content to synchronize
* @return The synchronized file
* @throws IOException
* @throws InterruptedException
*/
public static FilePath synchronize(FilePath filePath, String content) throws IOException, InterruptedException
{
// Check if differ
if (differ(filePath, content))
// If differ, write
filePath.write(content, "UTF-8");
// Return the file path
return filePath;
}

/**
* Synchronize a file or all files in a directory.
*
Expand Down
Expand Up @@ -39,17 +39,6 @@ public MasterWorkspace(FilePath home)
super(home);
}

/*
* (non-Javadoc)
*
* @see jenkins.plugins.shiningpanda.workspace.Workspace#getVirtualenvPy()
*/
@Override
public FilePath getVirtualenvPy()
{
return getMasterVirtualenvPy();
}

/*
* (non-Javadoc)
*
Expand All @@ -61,15 +50,4 @@ public FilePath getPackagesDir() throws IOException, InterruptedException
return getMasterPackagesDir();
}

/*
* (non-Javadoc)
*
* @see jenkins.plugins.shiningpanda.workspace.Workspace#getBootstrapPy()
*/
@Override
public FilePath getBootstrapPy() throws IOException, InterruptedException
{
return getMasterBootstrapPy();
}

}
Expand Up @@ -42,17 +42,6 @@ public SlaveWorkspace(FilePath home)
super(home);
}

/*
* (non-Javadoc)
*
* @see jenkins.plugins.shiningpanda.workspace.Workspace#getVirtualenvPy()
*/
@Override
public FilePath getVirtualenvPy() throws IOException, InterruptedException
{
return FilePathUtil.synchronize(getMasterVirtualenvPy(), getHome().child(VIRTUALENV));
}

/*
* (non-Javadoc)
*
Expand All @@ -64,14 +53,4 @@ public FilePath getPackagesDir() throws IOException, InterruptedException
return FilePathUtil.isDirectoryOrNull(FilePathUtil.synchronize(getMasterPackagesDir(), getHome().child(PACKAGES)));
}

/*
* (non-Javadoc)
*
* @see jenkins.plugins.shiningpanda.workspace.Workspace#getBootstrapPy()
*/
@Override
public FilePath getBootstrapPy() throws IOException, InterruptedException
{
return FilePathUtil.synchronize(getMasterBootstrapPy(), getHome().child(BOOTSTRAP));
}
}
39 changes: 19 additions & 20 deletions src/main/java/jenkins/plugins/shiningpanda/workspace/Workspace.java
Expand Up @@ -30,6 +30,7 @@
import hudson.model.AbstractProject;
import hudson.model.Node;
import hudson.model.Project;
import hudson.util.IOUtils;

import java.io.IOException;
import java.util.logging.Level;
Expand Down Expand Up @@ -107,23 +108,14 @@ private void setHome(FilePath home)
}

/**
* Folder containing the scripts on master
* Get the VIRTUALENV module content.
*
* @return The folder containing the scripts
*/
private FilePath getScriptsDir()
{
return Jenkins.getInstance().getRootPath().child("plugins").child("shiningpanda").child("scripts");
}

/**
* Get the VIRTUALENV module file on master.
*
* @return The VIRTUALENV module file
* @return The VIRTUALENV module content
* @throws IOException
*/
public FilePath getMasterVirtualenvPy()
public String getVirtualenvPyContent() throws IOException
{
return getScriptsDir().child(VIRTUALENV);
return IOUtils.toString(getClass().getResourceAsStream(VIRTUALENV));
}

/**
Expand All @@ -133,16 +125,20 @@ public FilePath getMasterVirtualenvPy()
* @throws IOException
* @throws InterruptedException
*/
public abstract FilePath getVirtualenvPy() throws IOException, InterruptedException;
public FilePath getVirtualenvPy() throws IOException, InterruptedException
{
return FilePathUtil.synchronize(getHome().child(VIRTUALENV), getVirtualenvPyContent());
}

/**
* Get the BUILDOUT bootstrap file on master.
* Get the BUILDOUT bootstrap module content.
*
* @return The BUILDOUT bootstrap module file
* @return The BUILDOUT bootstrap module content
* @throws IOException
*/
public FilePath getMasterBootstrapPy()
public String getBootstrapPyContent() throws IOException
{
return getScriptsDir().child(BOOTSTRAP);
return IOUtils.toString(getClass().getResourceAsStream(BOOTSTRAP));
}

/**
Expand All @@ -152,7 +148,10 @@ public FilePath getMasterBootstrapPy()
* @throws IOException
* @throws InterruptedException
*/
public abstract FilePath getBootstrapPy() throws IOException, InterruptedException;
public FilePath getBootstrapPy() throws IOException, InterruptedException
{
return FilePathUtil.synchronize(getHome().child(BOOTSTRAP), getBootstrapPyContent());
}

/**
* Get the folder on master where user can put some packages to avoid
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -28,16 +28,6 @@
public class TestMasterWorkspace extends ShiningPandaTestCase
{

public void testGetVirtualenvPy() throws Exception
{
assertEquals(getMasterWorkspace().getMasterVirtualenvPy(), getMasterWorkspace().getVirtualenvPy());
}

public void testGetBootstrapPy() throws Exception
{
assertEquals(getMasterWorkspace().getMasterBootstrapPy(), getMasterWorkspace().getBootstrapPy());
}

public void testGetPackageDirNotExists() throws Exception
{
assertNull("master workspace should not have a package directory", getMasterWorkspace().getPackagesDir());
Expand Down
Expand Up @@ -32,26 +32,6 @@
public class TestSlaveWorkspace extends ShiningPandaTestCase
{

public void testGetVirtualenvPy() throws Exception
{
Workspace workspace = getSlaveWorkspace();
FilePath slavePy = workspace.getVirtualenvPy();
FilePath masterPy = workspace.getMasterVirtualenvPy();
assertFile(slavePy);
assertNotSame("path of virtualenv.py on slave should differ from master one", masterPy.getRemote(), slavePy.getRemote());
assertContentEquals(masterPy, slavePy);
}

public void testGetBootstrapPy() throws Exception
{
Workspace workspace = getSlaveWorkspace();
FilePath slavePy = workspace.getBootstrapPy();
FilePath masterPy = workspace.getMasterBootstrapPy();
assertFile(slavePy);
assertNotSame("path of virtualenv.py on slave should differ from master one", masterPy.getRemote(), slavePy.getRemote());
assertContentEquals(masterPy, slavePy);
}

public void testGetPackageDirNotExists() throws Exception
{
assertNull("slave workspace should not have a package directory", getSlaveWorkspace().getPackagesDir());
Expand Down
Expand Up @@ -21,6 +21,7 @@
*/
package jenkins.plugins.shiningpanda.workspace;

import hudson.FilePath;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixRun;
import hudson.matrix.MatrixBuild;
Expand All @@ -42,14 +43,18 @@
public class TestWorkspace extends ShiningPandaTestCase
{

public void testGetMasterVirtualenvPy() throws Exception
public void testGetVirtualenvPy() throws Exception
{
assertFile(getWorkspace().getMasterVirtualenvPy());
Workspace workspace = getWorkspace();
FilePath slavePy = workspace.getVirtualenvPy();
assertFile(slavePy);
}

public void testGetMasterBootstrapPy() throws Exception
public void testGetBootstrapPy() throws Exception
{
assertFile(getWorkspace().getMasterBootstrapPy());
Workspace workspace = getWorkspace();
FilePath slavePy = workspace.getBootstrapPy();
assertFile(slavePy);
}

public void testGetMasterPackageDirNotExists() throws Exception
Expand Down

0 comments on commit e77a484

Please sign in to comment.