Binary building support - and tests for it
authorClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Fri, 22 Apr 2011 15:14:16 +0000 (17:14 +0200)
committerClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Fri, 22 Apr 2011 15:14:16 +0000 (17:14 +0200)
setup.py
src/nepi/testbeds/planetlab/application.py
src/nepi/testbeds/planetlab/metadata_v01.py
src/nepi/util/server.py
test/testbeds/planetlab/execute.py

index 8464859..170568f 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -20,5 +20,5 @@ setup(
             "nepi.util.parser",
             "nepi.util" ],
         package_dir = {"": "src"},
-        package_data = {"nepi.testbeds.planetlab" : ["scripts/*.py"] },
+        package_data = {"nepi.testbeds.planetlab" : ["scripts/*.py", "scripts/consts.c"] },
     )
index efe2cf8..c71e852 100644 (file)
@@ -189,6 +189,10 @@ class Application(object):
     
 
     def setup(self):
+        self._make_home()
+        self._build()
+        
+    def _make_home(self):
         # Make sure all the paths are created where 
         # they have to be created for deployment
         (out,err),proc = server.popen_ssh_command(
@@ -218,4 +222,54 @@ class Application(object):
             if proc.wait():
                 raise RuntimeError, "Failed to set up application: %s %s" % (out,err,)
 
+    def _build(self):
+        if self.sources:
+            sources = self.sources.split(' ')
+            
+            # Copy all sources
+            for source in sources:
+                (out,err),proc = server.popen_scp(
+                    source,
+                    "%s@%s:%s" % (self.slicename, self.node.hostname, 
+                        os.path.join(self.home_path,'.'),),
+                    ident_key = self.ident_path
+                    )
+            
+                if proc.wait():
+                    raise RuntimeError, "Failed upload source file %r: %s %s" % (source, out,err,)
+            
+        if self.buildDepends:
+            # Install build dependencies
+            (out,err),proc = server.popen_ssh_command(
+                "sudo -S yum -y install %(packages)s" % {
+                    'packages' : self.buildDepends
+                },
+                host = self.node.hostname,
+                port = None,
+                user = self.slicename,
+                agent = None,
+                ident_key = self.ident_path
+                )
+        
+            if proc.wait():
+                raise RuntimeError, "Failed instal build dependencies: %s %s" % (out,err,)
         
+            
+        if self.build:
+            # Install build dependencies
+            (out,err),proc = server.popen_ssh_command(
+                "cd %(home)s ; %(command)s" % {
+                    'command' : self.build,
+                    'home' : server.shell_escape(self.home_path),
+                },
+                host = self.node.hostname,
+                port = None,
+                user = self.slicename,
+                agent = None,
+                ident_key = self.ident_path
+                )
+        
+            if proc.wait():
+                raise RuntimeError, "Failed instal build sources: %s %s" % (out,err,)
+
+
index 5152d48..8289655 100644 (file)
@@ -33,6 +33,7 @@ def connect_app(testbed_instance, node, app):
     if app.depends:
         node.required_packages.update(set(
             app.depends.split() ))
+    
 
 ### Creation functions ###
 
index 6d37d0d..68c10fe 100644 (file)
@@ -368,7 +368,9 @@ def popen_ssh_command(command, host, port, user, agent,
                 stderr = subprocess.PIPE)
         return (proc.communicate(stdin), proc)
  
-def popen_scp(source, dest, port, agent, 
+def popen_scp(source, dest, 
+            port = None, 
+            agent = None, 
             recursive = False,
             ident_key = None):
         """
index b1c4e11..f7da57f 100755 (executable)
@@ -113,6 +113,53 @@ class PlanetLabExecuteTestCase(unittest.TestCase):
         instance.stop()
         instance.shutdown()
         
+    @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
+    def test_build(self):
+        instance = self.make_instance()
+        
+        instance.defer_create(2, "Node")
+        instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
+        instance.defer_create(3, "NodeInterface")
+        instance.defer_connect(2, "devs", 3, "node")
+        instance.defer_create(4, "Internet")
+        instance.defer_connect(3, "inet", 4, "devs")
+        instance.defer_create(10, "Application")
+        instance.defer_create_set(10, "command", "./consts")
+        instance.defer_create_set(10, "buildDepends", "gcc")
+        instance.defer_create_set(10, "build", "gcc consts.c -o consts")
+        instance.defer_create_set(10, "sources", os.path.join(os.path.dirname(planetlab.__file__),'scripts','consts.c'))
+        instance.defer_add_trace(10, "stdout")
+        instance.defer_connect(10, "node", 2, "apps")
+
+        instance.do_setup()
+        instance.do_create()
+        instance.do_connect()
+        instance.do_preconfigure()
+        instance.do_configure()
+        
+        instance.start()
+        while instance.status(10) != STATUS_FINISHED:
+            time.sleep(0.5)
+        ping_result = instance.trace(10, "stdout") or ""
+        comp_result = \
+r""".*ETH_P_ALL = 0x[0-9a-fA-F]{8}
+ETH_P_IP = 0x[0-9a-fA-F]{8}
+TUNSETIFF = 0x[0-9a-fA-F]{8}
+IFF_NO_PI = 0x[0-9a-fA-F]{8}
+IFF_TAP = 0x[0-9a-fA-F]{8}
+IFF_TUN = 0x[0-9a-fA-F]{8}
+IFF_VNET_HDR = 0x[0-9a-fA-F]{8}
+TUN_PKT_STRIP = 0x[0-9a-fA-F]{8}
+IFHWADDRLEN = 0x[0-9a-fA-F]{8}
+IFNAMSIZ = 0x[0-9a-fA-F]{8}
+IFREQ_SZ = 0x[0-9a-fA-F]{8}
+FIONREAD = 0x[0-9a-fA-F]{8}.*
+"""
+        self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
+            "Unexpected trace:\n" + ping_result)
+        instance.stop()
+        instance.shutdown()
+        
 
 if __name__ == '__main__':
     unittest.main()