Skip to content

Commit

Permalink
Merge pull request #166 from ajamias/master
Browse files Browse the repository at this point in the history
Return Node's Future Leases and Future Offers as List
  • Loading branch information
tzumainn authored Jul 19, 2024
2 parents ec8e244 + 32c636f commit 7a33db3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
17 changes: 8 additions & 9 deletions esi_leap/api/controllers/v1/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Node(base.ESILEAPBase):
offer_uuid = wsme.wsattr(wtypes.text)
lease_uuid = wsme.wsattr(wtypes.text)
lessee = wsme.wsattr(wtypes.text)
future_offers = wsme.wsattr(wtypes.text)
future_leases = wsme.wsattr(wtypes.text)
future_offers = wsme.wsattr([wtypes.text])
future_leases = wsme.wsattr([wtypes.text])

def __init__(self, **kwargs):
self.fields = (
Expand Down Expand Up @@ -112,7 +112,7 @@ def get_all(self, resource_class=None, owner=None, lessee=None):
leases = lease_obj.Lease.get_all({"status": [statuses.CREATED]}, context)

for node in nodes:
future_offers = []
f_offer_uuids = []
current_offer = None

node_offers = [
Expand All @@ -121,14 +121,13 @@ def get_all(self, resource_class=None, owner=None, lessee=None):

for offer in node_offers:
if offer.start_time > now:
future_offers.append(offer.uuid)
f_offer_uuids.append(offer.uuid)
elif offer.end_time >= now:
current_offer = offer
future_offers = " ".join(future_offers)

f_lease_uuids = "".join(
[lease.uuid for lease in leases if lease.resource_uuid == node.uuid]
)
f_lease_uuids = [
lease.uuid for lease in leases if lease.resource_uuid == node.uuid
]

n = Node(
name=node.name,
Expand All @@ -142,7 +141,7 @@ def get_all(self, resource_class=None, owner=None, lessee=None):
maintenance=str(node.maintenance),
owner=keystone.get_project_name(node.owner, project_list),
lessee=keystone.get_project_name(node.lessee, project_list),
future_offers=future_offers,
future_offers=f_offer_uuids,
future_leases=f_lease_uuids,
)

Expand Down
31 changes: 29 additions & 2 deletions esi_leap/tests/api/controllers/v1/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.

from datetime import datetime

import mock

from esi_leap.tests.api import base as test_api_base
Expand All @@ -36,6 +38,20 @@ def __init__(self):
self.id = "fake-project-uuid"


class FakeOffer(object):
def __init__(self, uuid, start_time, end_time):
self.uuid = uuid
self.resource_uuid = "fake-uuid"
self.start_time = start_time
self.end_time = end_time


class FakeFutureLease(object):
def __init__(self):
self.uuid = "fake-future-lease-uuid"
self.resource_uuid = "fake-uuid"


class TestNodesController(test_api_base.APITestCase):
def setUp(self):
super(TestNodesController, self).setUp()
Expand All @@ -47,9 +63,16 @@ def setUp(self):
def test_get_all(self, mock_gpl, mock_lga, mock_oga, mock_gnl):
fake_node = FakeIronicNode()
fake_project = FakeProject()
fake_offer = FakeOffer(
"fake-offer-uuid", start_time=datetime.min, end_time=datetime.max
)
fake_future_offer = FakeOffer(
"fake-future-offer-uuid", start_time=datetime.max, end_time=datetime.max
)
fake_future_lease = FakeFutureLease()
mock_gnl.return_value = [fake_node]
mock_oga.return_value = []
mock_lga.return_value = []
mock_oga.return_value = [fake_offer, fake_future_offer]
mock_lga.return_value = [fake_future_lease]
mock_gpl.return_value = [fake_project]

data = self.get_json("/nodes")
Expand All @@ -65,6 +88,10 @@ def test_get_all(self, mock_gpl, mock_lga, mock_oga, mock_gnl):
self.assertEqual(data["nodes"][0]["lease_uuid"], "fake-lease-uuid")
self.assertEqual(data["nodes"][0]["lessee"], "fake-project")
self.assertEqual(data["nodes"][0]["properties"], {"cpu": "40"})
self.assertEqual(data["nodes"][0]["offer_uuid"], "fake-offer-uuid")
self.assertEqual(data["nodes"][0]["lease_uuid"], "fake-lease-uuid")
self.assertEqual(data["nodes"][0]["future_offers"], ["fake-future-offer-uuid"])
self.assertEqual(data["nodes"][0]["future_leases"], ["fake-future-lease-uuid"])

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
Expand Down

0 comments on commit 7a33db3

Please sign in to comment.