From 3681516ab15e9bfce7fd0caeb9cdda3d6aeaab9d Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Sun, 22 Jan 2012 23:10:56 +0100 Subject: [PATCH] Added unit tests for SFA PlanetLab. --- src/nepi/util/sfiapi.py | 35 ++++-- test/testbeds/planetlab/integration.py | 162 ++++++++++++++++--------- 2 files changed, 133 insertions(+), 64 deletions(-) diff --git a/src/nepi/util/sfiapi.py b/src/nepi/util/sfiapi.py index 5b4b3cc1..866792f5 100644 --- a/src/nepi/util/sfiapi.py +++ b/src/nepi/util/sfiapi.py @@ -2,20 +2,26 @@ from nepi.util.parser import sfa +### +# TODO: This API is a mega hack to adapt the sfa interface to the plc interface. +# The right way to implement this would be to make node.py invoke generic +# methods and to adapt the sfa and plc APIs to provide the reuired +# data. + class SFIAPI(object): - def __init__(self): + def __init__(self, slice_id): self._slice_tags = dict() self._slice_nodes = set() self._all_nodes = dict() - self._slice_id = None - - def FetchSliceInfo(self, slice_id): self._slice_id = slice_id + self.FetchSliceInfo() + + def FetchSliceInfo(self): p = sfa.SFAResourcesParser() import commands xml = commands.getoutput("sfi.py resources") self._all_nodes = p.resources_from_xml(xml) - xml = commands.getoutput("sfi.py resources %s" % slice_id) + xml = commands.getoutput("sfi.py resources %s" % self._slice_id) self._slice_tags, self._slice_nodes = p.slice_info_from_xml(xml) def GetSliceNodes(self, slicename): @@ -76,9 +82,19 @@ class SFIAPI(object): def has_all_tags(node_id): data = nodes[node_id] for name, value in filters.iteritems(): - #if (name == '>last_contact' and data['lastcontact'] > value) or \ - if (not name in data or data[name] != value): - return False + if name == 'value' or name == 'tagname': + tagname = filters['tagname'] + tagval = filters['value'] + if data[tagname] != tagval: + return False + elif name == 'node_id': + node_ids = list(value) + if node_id not in node_ids: + return False + else: + #if (name == '>last_contact' and data['lastcontact'] > value) or \ + if (not name in data or data[name] != value): + return False return True return dict((k, value) for k, value in nodes.iteritems() if has_all_tags(k)) @@ -131,7 +147,6 @@ class SFIAPI(object): #print out def sfiapi(slice_id): - api = SFIAPI() - api.FetchSliceInfo(slice_id) + api = SFIAPI(slice_id) return api diff --git a/test/testbeds/planetlab/integration.py b/test/testbeds/planetlab/integration.py index 3c1ef11a..5e5fb412 100755 --- a/test/testbeds/planetlab/integration.py +++ b/test/testbeds/planetlab/integration.py @@ -19,6 +19,7 @@ import unittest class PlanetLabIntegrationTestCase(unittest.TestCase): testbed_id = "planetlab" slicename = "inria_nepi" + slicehrn = "nepi.inria.nepi" plchost = "nepiplc.pl.sophia.inria.fr" host1 = "nepi1.pl.sophia.inria.fr" @@ -40,7 +41,7 @@ class PlanetLabIntegrationTestCase(unittest.TestCase): time.sleep(0.1) shutil.rmtree(self.root_dir) - def make_experiment_desc(self): + def make_experiment_desc(self, use_sfa = False): testbed_id = self.testbed_id slicename = self.slicename plchost = self.plchost @@ -62,11 +63,15 @@ class PlanetLabIntegrationTestCase(unittest.TestCase): pl_desc.set_attribute_value("p2pDeployment", False) # it's interactive, we don't want it in tests pl_desc.set_attribute_value("dedicatedSlice", True) #pl_desc.set_attribute_value("plLogLevel", "DEBUG") + if use_sfa: + pl_desc.set_attribute_value("sfa", True) + pl_desc.set_attribute_value("sliceHrn", self.slicehrn) return pl_desc, exp_desc - def _test_simple(self, daemonize_testbed, controller_access_configuration, environ = None): - pl, exp = self.make_experiment_desc() + def _test_simple(self, daemonize_testbed, controller_access_configuration, + environ = None, use_sfa = False): + pl, exp = self.make_experiment_desc(use_sfa) node1 = pl.create("Node") node2 = pl.create("Node") @@ -90,7 +95,7 @@ class PlanetLabIntegrationTestCase(unittest.TestCase): inst_root_dir = os.path.join(self.root_dir, "instance") os.mkdir(inst_root_dir) pl.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir) - pl.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #pl.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) if environ: pl.set_attribute_value(DC.DEPLOYMENT_ENVIRONMENT_SETUP, environ) @@ -128,11 +133,8 @@ class PlanetLabIntegrationTestCase(unittest.TestCase): import traceback traceback.print_exc() - @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") - @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'), - "Test is interactive, requires NEPI_FULL_TESTS=yes") - def test_spanning_deployment(self): - pl, exp = self.make_experiment_desc() + def _test_spanning_deployment(self, use_sfa = False): + pl, exp = self.make_experiment_desc(use_sfa) pl.set_attribute_value("p2pDeployment", True) # we do want it here - even if interactive @@ -207,49 +209,9 @@ FIONREAD = 0x[0-9a-fA-F]{8}.* import traceback traceback.print_exc() - @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") - def test_simple(self): - self._test_simple( - daemonize_testbed = False, - controller_access_configuration = None) - - @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") - def test_simple_daemonized(self): - access_config = proxy.AccessConfiguration({ - DC.DEPLOYMENT_MODE : DC.MODE_DAEMON, - DC.ROOT_DIRECTORY : self.root_dir, - DC.LOG_LEVEL : DC.DEBUG_LEVEL, - }) - - self._test_simple( - daemonize_testbed = False, - controller_access_configuration = access_config) - - @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") - def test_z_simple_ssh(self): # _z_ cause we want it last - it messes up the process :( - # Recreate environment - environ = ' ; '.join( map("export %s=%r".__mod__, os.environ.iteritems()) ) - - env = test_util.test_environment() - - access_config = proxy.AccessConfiguration({ - DC.DEPLOYMENT_MODE : DC.MODE_DAEMON, - DC.ROOT_DIRECTORY : self.root_dir, - DC.LOG_LEVEL : DC.DEBUG_LEVEL, - DC.DEPLOYMENT_COMMUNICATION : DC.ACCESS_SSH, - DC.DEPLOYMENT_PORT : env.port, - DC.USE_AGENT : True, - DC.DEPLOYMENT_ENVIRONMENT_SETUP : environ, - }) - - self._test_simple( - daemonize_testbed = False, - controller_access_configuration = access_config, - environ = environ) - - - def _test_recover(self, daemonize_testbed, controller_access_configuration, environ = None): - pl, exp = self.make_experiment_desc() + def _test_recover(self, daemonize_testbed, controller_access_configuration, + environ = None, use_sfa = False): + pl, exp = self.make_experiment_desc(use_sfa) pl.set_attribute_value(DC.RECOVERY_POLICY, DC.POLICY_RECOVER) @@ -292,7 +254,7 @@ FIONREAD = 0x[0-9a-fA-F]{8}.* inst_root_dir = os.path.join(self.root_dir, "instance") os.mkdir(inst_root_dir) pl.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir) - pl.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) + #pl.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL) if environ: pl.set_attribute_value(DC.DEPLOYMENT_ENVIRONMENT_SETUP, environ) @@ -345,12 +307,91 @@ FIONREAD = 0x[0-9a-fA-F]{8}.* import traceback traceback.print_exc() + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + def test_simple(self): + self._test_simple( + daemonize_testbed = False, + controller_access_configuration = None) + + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + def test_simple_sfa(self): + self._test_simple( + daemonize_testbed = False, + controller_access_configuration = None, + use_sfa = True) + + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'), + "Test is interactive, requires NEPI_FULL_TESTS=yes") + def test_spanning_deployment(self): + self._test_spanning_deployment() + + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'), + "Test is interactive, requires NEPI_FULL_TESTS=yes") + def test_spanning_deployment_sfa(self): + self._test_spanning_deployment(use_sfa = True) + + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + def test_simple_daemonized(self): + access_config = proxy.AccessConfiguration({ + DC.DEPLOYMENT_MODE : DC.MODE_DAEMON, + DC.ROOT_DIRECTORY : self.root_dir, + DC.LOG_LEVEL : DC.DEBUG_LEVEL, + }) + + self._test_simple( + daemonize_testbed = False, + controller_access_configuration = access_config) + + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + def test_simple_daemonized_sfa(self): + access_config = proxy.AccessConfiguration({ + DC.DEPLOYMENT_MODE : DC.MODE_DAEMON, + DC.ROOT_DIRECTORY : self.root_dir, + DC.LOG_LEVEL : DC.DEBUG_LEVEL, + }) + + self._test_simple( + daemonize_testbed = False, + controller_access_configuration = access_config, + use_sfa = True) + + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + def test_z_simple_ssh(self): # _z_ cause we want it last - it messes up the process :( + # Recreate environment + environ = ' ; '.join( map("export %s=%r".__mod__, os.environ.iteritems()) ) + + env = test_util.test_environment() + + access_config = proxy.AccessConfiguration({ + DC.DEPLOYMENT_MODE : DC.MODE_DAEMON, + DC.ROOT_DIRECTORY : self.root_dir, + DC.LOG_LEVEL : DC.DEBUG_LEVEL, + DC.DEPLOYMENT_COMMUNICATION : DC.ACCESS_SSH, + DC.DEPLOYMENT_PORT : env.port, + DC.USE_AGENT : True, + DC.DEPLOYMENT_ENVIRONMENT_SETUP : environ, + }) + + self._test_simple( + daemonize_testbed = False, + controller_access_configuration = access_config, + environ = environ) + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") def test_recover(self): self._test_recover( daemonize_testbed = False, controller_access_configuration = None) + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + def test_recover_sfa(self): + self._test_recover( + daemonize_testbed = False, + controller_access_configuration = None, + use_sfa = True) + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") def test_recover_daemonized(self): access_config = proxy.AccessConfiguration({ @@ -362,7 +403,20 @@ FIONREAD = 0x[0-9a-fA-F]{8}.* self._test_recover( daemonize_testbed = False, controller_access_configuration = access_config) - + + @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)") + def test_recover_daemonized_sfa(self): + access_config = proxy.AccessConfiguration({ + DC.DEPLOYMENT_MODE : DC.MODE_DAEMON, + DC.ROOT_DIRECTORY : self.root_dir, + DC.LOG_LEVEL : DC.DEBUG_LEVEL, + }) + + self._test_recover( + daemonize_testbed = False, + controller_access_configuration = access_config, + use_sfa = True) + if __name__ == '__main__': unittest.main() -- 2.43.0