diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py new file mode 100644 index 00000000..67b44ef4 --- /dev/null +++ b/tests/integration/conftest.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# MIT License +# +# Copyright (c) 2023 FABRIC Testbed +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import socket +import time +import pytest + +from fabrictestbed_extensions.fablib.fablib import FablibManager + + +@pytest.fixture(scope="session") +def fablib(): + return FablibManager() + + +@pytest.fixture(scope="session") +def fabric_slice(fablib): + # Give the slice a unique name so that slice creation will not + # fail (because there is an existing slice with the same name) and + # we will have some hints about the test that created the slice. + time_stamp = time.strftime("%Y-%m-%d %H:%M:%S") + host = socket.gethostname() + slice_name = f"integration test @ {time_stamp} on {host}" + + print(f"Creating slice '{slice_name}'..") + slice = fablib.new_slice(name=slice_name) + + yield slice + + slice.delete() diff --git a/tests/integration/test_hello_fabric.py b/tests/integration/test_hello_fabric.py index 80b10a8a..92ea2071 100644 --- a/tests/integration/test_hello_fabric.py +++ b/tests/integration/test_hello_fabric.py @@ -1,70 +1,60 @@ -import socket -import time -import unittest +#!/usr/bin/env python3 +# MIT License +# +# Copyright (c) 2023 FABRIC Testbed +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. from fabrictestbed_extensions.fablib.fablib import FablibManager from fabrictestbed_extensions.fablib.node import Node from fabrictestbed_extensions.fablib.slice import Slice -class HelloFabricTests(unittest.TestCase): +def test_fablib_hello(fablib, fabric_slice): """ - Run some basic tests against the testbed. + Create a slice with a single node, and echo a message from the node. """ - def test_fablib_hello(self): - """ - Create a slice with a single node, and echo a message from the node. - """ - fablib = FablibManager() + assert isinstance(fablib, FablibManager) + assert isinstance(fabric_slice, Slice) - fablib.show_config() + # Add a node. + node_name = "node-1" + site_name = fablib.get_random_site() + slice_name = fabric_slice.get_name() - # fablib.list_sites() + print(f"Adding node '{node_name}' at site '{site_name}' to slice '{slice_name}'..") - # Give the slice a unique name so that slice creation will not - # fail (because there is an existing slice with the same name) and - # we will have some hints about the test that created the slice. - time_stamp = time.strftime("%Y-%m-%d %H:%M:%S") - host = socket.gethostname() - slice_name = f"integration test @ {time_stamp} on {host}" + node = fabric_slice.add_node(name=node_name, site=site_name) + assert isinstance(node, Node) - print(f"Creating slice '{slice_name}'..") - slice = fablib.new_slice(name=slice_name) + # Submit the slice. + print(f"Submitting slice '{slice_name}'..") + fabric_slice.submit() - self.assertIsInstance(slice, Slice) + print(f"Slice '{slice_name}' status:") + fabric_slice.show() - try: - # Add a node. - node_name = "node-1" - site_name = fablib.get_random_site() + print(f"Testing node '{node_name}' on slice '{slice_name}'...") - print( - f"Adding node '{node_name}' at site '{site_name}' to slice '{slice_name}'.." - ) - node = slice.add_node(name=node_name, site=site_name) + for node in fabric_slice.get_nodes(): + stdout, stderr = node.execute("echo Hello, FABRIC from node `hostname -s`") - self.assertIsInstance(node, Node) - - # Submit the slice. - print(f"Submitting slice '{slice_name}'..") - slice.submit() - - print(f"Slice '{slice_name}' status:") - slice.show() - - print(f"Testing node '{node_name}' on slice '{slice_name}'...") - for node in slice.get_nodes(): - stdout, stderr = node.execute( - "echo Hello, FABRIC from node `hostname -s`" - ) - - self.assertEqual(stdout, f"Hello, FABRIC from node {node_name}\n") - self.assertEqual(stderr, "") - - finally: - slice.delete() - - -if __name__ == "__main__": - unittest.main() + assert stdout == f"Hello, FABRIC from node {node_name}\n" + assert stderr == ""