diff --git a/bibigrid/core/provider.py b/bibigrid/core/provider.py index 360093ba..759c29f8 100644 --- a/bibigrid/core/provider.py +++ b/bibigrid/core/provider.py @@ -278,14 +278,45 @@ def get_security_group(self, name_or_id): @return: """ + @abstractmethod + def create_volume(self, name, size, volume_type=None, description=None): + """ + Creates a volume + @param name: name of the created volume + @param size: size of the created volume in GB + @param volume_type: depends on the location, but for example NVME or HDD + @param description: a non-functional description to help dashboard users + @return: the created volume + """ + + @abstractmethod def get_server(self, name_or_id): """ Returns server if found else None. @param name_or_id: @return: - """ # TODO Test + """ + + @abstractmethod + def delete_volume(self, name_or_id): + """ + Deletes the volume that has name_or_id. + @param name_or_id: + @return: True if deletion was successful, else False + """ + + @abstractmethod + def list_volumes(self): + """ + Returns a list of all volumes on the provider. + @return: list of volumes + """ def get_mount_info_from_server(self, server): + """ + @param server: server to get the attachment list from + @return: list of dicts containing name and device node of all attached volumes + """ volumes = [] for server_volume in server["volumes"]: volume = self.get_volume_by_id_or_name(server_volume["id"]) diff --git a/bibigrid/openstack/openstack_provider.py b/bibigrid/openstack/openstack_provider.py index db3350da..c50e85ad 100644 --- a/bibigrid/openstack/openstack_provider.py +++ b/bibigrid/openstack/openstack_provider.py @@ -344,10 +344,27 @@ def get_server(self, name_or_id): return self.conn.get_server(name_or_id) def create_volume(self, name, size, volume_type=None, description=None): + """ + Creates a volume + @param name: name of the created volume + @param size: size of the created volume in GB + @param volume_type: depends on the location, but for example NVME or HDD + @param description: a non-functional description to help dashboard users + @return: the created volume + """ return self.conn.create_volume(size=size, name=name, volume_type=volume_type, description=description) def delete_volume(self, name_or_id): + """ + Deletes the volume that has name_or_id. + @param name_or_id: + @return: True if deletion was successful, else False + """ return self.conn.delete_volume(name_or_id=name_or_id) def list_volumes(self): + """ + Returns a list of all volumes on the provider. + @return: list of volumes + """ return self.conn.list_volumes() diff --git a/tests/unit_tests/provider/test_provider.py b/tests/unit_tests/provider/test_provider.py index a3819b30..506d8275 100644 --- a/tests/unit_tests/provider/test_provider.py +++ b/tests/unit_tests/provider/test_provider.py @@ -228,12 +228,16 @@ def test_get_image_mismatch(self): self.assertIsNone(provider.get_image_by_id_or_name("NONE")) def test_create_delete_volume(self): + """ + Checks whether creation and deletion of volumes works + @return: + """ for provider in PROVIDERS: - volume_id = provider.create_volume(name="ProviderTestVolume") + volume_id = provider.create_volume(name="test_create_delete_volume", size=1) self.assertTrue(volume_id) volume = provider.get_volume_by_id_or_name(volume_id) self.assertTrue(volume) - self.assertEqual("ProviderTestVolume", volume["name"]) + self.assertEqual("test_create_delete_volume", volume["name"]) self.assertTrue(provider.delete_volume(volume_id)) diff --git a/tests/unit_tests/startup_tests.py b/tests/unit_tests/startup_tests.py index ddf569b5..a36464a2 100644 --- a/tests/unit_tests/startup_tests.py +++ b/tests/unit_tests/startup_tests.py @@ -37,7 +37,6 @@ def suppress_stdout(): # Configuration at resources/tests/bibigrid_test.yaml # Needs to contain providers and infrastructures for the provider tests # You can use bibigrid_test_exmaple.yaml as the basis - print(os.path.abspath(".")) suite = unittest.TestLoader().discover(start_dir=".", pattern='test_*.py') with suppress_stdout(): unittest.TextTestRunner(verbosity=2).run(suite)