Skip to content

Commit

Permalink
updated tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverStiensmeier committed Nov 28, 2024
1 parent 93d2844 commit a21d127
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
33 changes: 32 additions & 1 deletion bibigrid/core/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
17 changes: 17 additions & 0 deletions bibigrid/openstack/openstack_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 6 additions & 2 deletions tests/unit_tests/provider/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/startup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a21d127

Please sign in to comment.