From: Claudio-Daniel Freire Date: Fri, 22 Apr 2011 15:14:16 +0000 (+0200) Subject: Binary building support - and tests for it X-Git-Tag: nepi_v2~126 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=f63228c680454d41ddfd4fc64b8d60465ad691e8;p=nepi.git Binary building support - and tests for it --- diff --git a/setup.py b/setup.py index 84648593..170568ff 100755 --- 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"] }, ) diff --git a/src/nepi/testbeds/planetlab/application.py b/src/nepi/testbeds/planetlab/application.py index efe2cf8e..c71e852a 100644 --- a/src/nepi/testbeds/planetlab/application.py +++ b/src/nepi/testbeds/planetlab/application.py @@ -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,) + + diff --git a/src/nepi/testbeds/planetlab/metadata_v01.py b/src/nepi/testbeds/planetlab/metadata_v01.py index 5152d48a..8289655e 100644 --- a/src/nepi/testbeds/planetlab/metadata_v01.py +++ b/src/nepi/testbeds/planetlab/metadata_v01.py @@ -33,6 +33,7 @@ def connect_app(testbed_instance, node, app): if app.depends: node.required_packages.update(set( app.depends.split() )) + ### Creation functions ### diff --git a/src/nepi/util/server.py b/src/nepi/util/server.py index 6d37d0dd..68c10fe0 100644 --- a/src/nepi/util/server.py +++ b/src/nepi/util/server.py @@ -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): """ diff --git a/test/testbeds/planetlab/execute.py b/test/testbeds/planetlab/execute.py index b1c4e114..f7da57f1 100755 --- a/test/testbeds/planetlab/execute.py +++ b/test/testbeds/planetlab/execute.py @@ -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()