def test_offer_delete_lessee(self):
        """ Tests that a lessee cannot delete an offer.
            Test steps:
            1) (authorized-owner) Create an offer for an owned node for the
                unauthorized project.
            2) Check that lease details were returned.
            3) (unauthorized-lessee) Attempt to delete the new offer.
            4) Check that the command failed. (returned non-zero exit code)
            5) Check that the proper error message was sent to stderr.
            6) (authorized-owner) (cleanup) Delete the offer from step 1. """
        offer = esi.offer_create(self.clients['authorized-owner'],
                                 self.dummy_node.uuid,
                                 lessee=self.projects['unauthorized']['name'],
                                 resource_type='dummy_node')
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['authorized-owner'],
                        offer['uuid'])

        e = self.assertRaises(CommandFailed,
                              esi.offer_delete,
                              self.clients['unauthorized-lessee'],
                              offer['uuid'])
        self.assertIn('Access was denied to offer %s.' % offer['uuid'],
                      e.stderr.decode())
Beispiel #2
0
    def test_offer_claim_basic(self):
        """ Tests that a lessee can claim an offer made available to them
                and delete the created lease when finished.
            Test steps:
            1) (owner) Create an offer for an owned node.
            2) Check that offer details were returned.
            3) (lessee) Claim the offer created in step 1.
            4) Check that lease details were returned.
            5) (cleanup) (lessee) Delete the lease created in step 3.
            6) (cleanup) (owner) Delete the offer created in step 1. """
        offer = esi.offer_create(self.clients['parent-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node',
                                 lessee=self.projects['child']['name'])
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['parent-owner'],
                        offer['uuid'])

        lease = esi.offer_claim(self.clients['child-lessee'],
                                offer['uuid'])
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['child-lessee'],
                        lease['uuid'])
Beispiel #3
0
    def test_offer_create_sublease(self):
        """ Tests that an owner of a project that has leased a node can
                create offers for said leased node.
            Test steps:
            1) (node-owner) Create a lease on an owned node, specifying
                the sublessee project as the lessee.
            2) Check that offer details were returned.
            3) Wait for the esi-leap manager service to move the lease from
                the created state to the active state.
            4) (sublessee-owner) Create an offer for the node leased to the
                sublessee in step 1.
            5) Check that offer details were returned.
            6) (cleanup) (node-owner) Delete the offer from step 3.
            7) (cleanup) (authorized-owner) Delete the lease from step 1. """
        lease = esi.lease_create(self.clients['node-owner'],
                                 self.dummy_node.uuid,
                                 self.projects['sublessee']['name'],
                                 resource_type='dummy_node')
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete, self.clients['node-owner'],
                        lease['uuid'])

        time.sleep(65)

        offer = esi.offer_create(self.clients['sublessee-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node')
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete, self.clients['sublessee-owner'],
                        offer['uuid'])
Beispiel #4
0
    def test_lease_show_offer_deleted(self):
        """ Tests that leases created thru claiming an offer are deleted after
                the claimed offer has been deleted.
            Test steps:
            1) (owner) Create an offer for an owned node.
            2) Check that offer details were returned.
            3) (lessee) Claim the offer created in step 1.
            4) Check that lease details were returned.
            5) (owner) Delete the offer created in step 1.
            6) View the details of the lease created in step 4 to ensure the
                lease's status is 'deleted'.
            7) (lessee) If not, delete the lease manually. """
        offer = esi.offer_create(self.clients['parent-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node',
                                 lessee=self.projects['child']['name'])
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['parent-owner'],
                        offer['uuid'],
                        fail_ok=True)

        lease = esi.offer_claim(self.clients['child-lessee'],
                                offer['uuid'])
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['child-lessee'],
                        lease['uuid'],
                        fail_ok=True)

        esi.offer_delete(self.clients['parent-owner'], offer['uuid'])
        details = esi.lease_show(self.clients['child-lessee'], lease['uuid'])
        self.assertEqual(details['status'], 'deleted')
Beispiel #5
0
    def test_offer_create_multiple(self):
        """ Tests that more than one offer can be created for the same
                resource provided that the times specified do not conflict.
            Test steps:
            1) Record what the time will be in five minutes.
            2) Create an offer for an owned node, starting at the time
                recorded in step 1 and ending 30 minutes from then.
            3) Check that offer details were returned.
            4) Create an offer for the same node, starting five minutes after
               the end time of the offer created in step 2 and ending 30
               minutes from then.
            5) Check that offer details were returned.
            6) Check that both offers show up when listing offers.
            7) (cleanup) Delete the offer created in step 4.
            8) (cleanup) Delete the offer created in step 2. """
        time_now = datetime.now()
        offer1_start_time = time_now + timedelta(minutes=5)
        offer1_end_time = offer1_start_time + timedelta(minutes=30)
        offer2_start_time = offer1_end_time + timedelta(minutes=5)
        offer2_end_time = offer2_start_time + timedelta(minutes=30)

        offer1 = esi.offer_create(self.clients['main-owner'],
                                  self.dummy_node.uuid,
                                  resource_type='dummy_node',
                                  start_time=str(offer1_start_time),
                                  end_time=str(offer1_end_time))
        self.assertNotEqual(offer1, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['main-owner'],
                        offer1['uuid'])

        offer2 = esi.offer_create(self.clients['main-owner'],
                                  self.dummy_node.uuid,
                                  resource_type='dummy_node',
                                  start_time=str(offer2_start_time),
                                  end_time=str(offer2_end_time))
        self.assertNotEqual(offer2, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['main-owner'],
                        offer2['uuid'])

        listings = esi.offer_list(self.clients['main-owner'])
        uuid_listings = [x['UUID'] for x in listings]
        self.assertNotEqual(listings, [])
        for offer_id in offer1['uuid'], offer2['uuid']:
            self.assertIn(offer_id, uuid_listings)
Beispiel #6
0
    def test_offer_claim_multiple(self):
        """ Tests that more that one lessee can claim the same offer provided
                that the times specified do not conflict.
            Test steps:
            1) (owner) Create an offer for an owned node.
            2) Check that offer details were returned.
            3) Record what the time will be in five minutes.
            4) (subproj1) Claim the offer from step 1, starting at the time
                recorded in step 3 and ending 30 minutes from then.
            5) Check that lease details were returned.
            6) (subproj2) Claim the offer from step 1, starting five minutes
                after the end time of the lease created in step 4 and ending
                30 minutes from then.
            7) Check that lease details were returned.
            8) (owner) Check that both leases show up when listing leases.
            9) (subproj2) (cleanup) Delete the lease created in step 6.
            10) (subproj1) (cleanup) Delete the lease created in step 4.
            11) (owner) (cleanup) Delete the offer created in step 1. """
        offer = esi.offer_create(self.clients['main-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node')
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['main-owner'],
                        offer['uuid'])

        time_now = datetime.now()
        lease1_start_time = time_now + timedelta(minutes=5)
        lease1_end_time = lease1_start_time + timedelta(minutes=30)
        lease2_start_time = lease1_end_time + timedelta(minutes=5)
        lease2_end_time = lease2_start_time + timedelta(minutes=30)

        lease1 = esi.offer_claim(self.clients['subproj1-lessee'],
                                 offer['uuid'],
                                 start_time=str(lease1_start_time),
                                 end_time=str(lease1_end_time))
        self.assertNotEqual(lease1, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['subproj1-lessee'],
                        lease1['uuid'])

        lease2 = esi.offer_claim(self.clients['subproj2-lessee'],
                                 offer['uuid'],
                                 start_time=str(lease2_start_time),
                                 end_time=str(lease2_end_time))
        self.assertNotEqual(lease2, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['subproj2-lessee'],
                        lease2['uuid'])

        listings = esi.lease_list(self.clients['main-owner'])
        uuid_listings = [x['UUID'] for x in listings]
        self.assertNotEqual(listings, [])
        for lease_id in lease1['uuid'], lease2['uuid']:
            self.assertIn(lease_id, uuid_listings)
Beispiel #7
0
 def test_offer_create_basic(self):
     """ Tests that a node owner can create and delete an offer for a node
             that they own.
         Test steps:
         1) Create an offer for an owned node.
         2) Check that offer details were returned.
         3) (cleanup) Delete the offer created in step 1. """
     offer = esi.offer_create(self.clients['parent-owner'],
                              self.dummy_node.uuid,
                              resource_type='dummy_node')
     self.assertNotEqual(offer, {})
     self.addCleanup(esi.offer_delete,
                     self.clients['parent-owner'],
                     offer['uuid'])
Beispiel #8
0
    def test_offer_expire(self):
        """ Tests to ensure expired offers cannot be claimed and that they
                do not show up in the list of offers after expiring.
            Test steps:
            1) Record what the time will be in 30 seconds.
            2) (owner) Create an offer for an owned node that ends at the time
                recorded in step 1.
            3) Check that offer details were returned and that the offer's
                status is 'available'.
            4) Wait 100 seconds to allow the esi-leap manager to move the
                offer from the 'available' state to the 'expired' state.
            5) (owner) Check that state of the offer from step 2 is 'expired'.
            6) (subproj1) Attempt to claim the expired offer.
            7) Check that the command failed. (returned non-zero exit code)
            8) Check that the proper error message was sent to stderr.
            9) (subproj1) Check that the offer does not show up in the list
                of available offers.
            10) (owner) (cleanup) Delete the offer from step 2 if needed. """
        time_now = datetime.now()
        offer_end_time = time_now + timedelta(seconds=30)

        offer = esi.offer_create(self.clients['main-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node',
                                 lessee=self.projects['subproj1']['name'],
                                 end_time=str(offer_end_time))
        self.assertNotEqual(offer, {})
        # NOTE: this ensures the offer is deleted, ignoring failed attempts
        # to delete offers that expired correctly.
        self.addCleanup(esi.offer_delete,
                        self.clients['main-owner'],
                        offer['uuid'],
                        fail_ok=True)
        self.assertEqual(offer['status'], 'available')

        time.sleep(100)

        details = esi.offer_show(self.clients['main-owner'], offer['uuid'])
        self.assertEqual(details['status'], 'expired')

        e = self.assertRaises(CommandFailed,
                              esi.offer_claim,
                              self.clients['subproj1-lessee'],
                              offer['uuid'])
        self.assertIn('Offer with name or uuid %s not found.' % offer['uuid'],
                      e.stderr.decode())

        listings = esi.offer_list(self.clients['subproj1-lessee'])
        self.assertNotIn(offer['uuid'], [x['UUID'] for x in listings])
Beispiel #9
0
    def test_offer_claim_out_of_range(self):
        """ Tests to ensure offers cannot be claimed for a time period that
                is outside of the range of the offer's availability.
            Test steps:
            1) Record the current time.
            2) (owner) Create an offer for an owned node, starting 15 minutes
                after the time recorded in step 1, and ending 30 minutes
                after that.
            3) Check that offer details were returned.
            4) Repeat steps 5 thru 7 with the following ranges (times are
                relative to the time recorded in step 1):
                - 5 minutes after thru 20 minutes after
                - 20 minutes after thru 60 minutes after
                - 5 minutes after thru 60 minutes after
            5) (subproj1) Attempt to claim the offer created in step 2 for a
                time range outside of what was specified during creation.
            6) Check that the command failed. (returned non-zero exit code)
            7) Check that the proper error message was sent to stderr.
            8) (owner) (cleanup) Delete the offer created in step 2. """
        time_now = datetime.now()
        offer_start_time = time_now + timedelta(minutes=15)
        offer_end_time = time_now + timedelta(minutes=30)
        claim_time_early = time_now + timedelta(minutes=5)
        claim_time_valid = offer_start_time + timedelta(minutes=15)
        claim_time_late = offer_end_time + timedelta(minutes=15)

        offer = esi.offer_create(self.clients['main-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node',
                                 start_time=str(offer_start_time),
                                 end_time=str(offer_end_time))
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['main-owner'],
                        offer['uuid'])

        for (start, end) in ((claim_time_early, claim_time_valid),
                             (claim_time_valid, claim_time_late),
                             (claim_time_early, claim_time_late)):
            err = ('Offer %s has no availabilities at given time range %s, %s.'
                   % (offer['uuid'], str(start), str(end)))
            e = self.assertRaises(CommandFailed,
                                  esi.offer_claim,
                                  self.clients['subproj1-lessee'],
                                  offer['uuid'],
                                  start_time=str(start),
                                  end_time=str(end))
            self.assertIn(err, e.stderr.decode())
Beispiel #10
0
    def test_offer_claim_conflict(self):
        """ Tests that two lessees cannot make overlapping claims on the
                same offer.
            Test steps:
            1) (owner) Create an offer for an owned node.
            2) Check that offer details were returned.
            3) Record the current time.
            4) (subproj1) Claim the offer from step 1, ending 30 minutes
                after the time recorded in step 3.
            5) Check that lease details were returned.
            6) (subproj2) Attempt to claim the offer from step 1, starting
                15 minutes after the time recorded in step 3, and ending 30
                minutes after that.
            7) Check that the command failed. (returned non-zero exit code)
            8) Check that the proper error message was sent to stderr.
            9) (subproj1) (cleanup) Delete the lease created in step 4.
            10) (owner) (cleanup) Delete the offer created in step 1. """
        offer = esi.offer_create(self.clients['main-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node')
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['main-owner'],
                        offer['uuid'])

        time_now = datetime.now()
        lease1_end_time = time_now + timedelta(minutes=30)
        lease2_start_time = time_now + timedelta(minutes=15)
        lease2_end_time = lease2_start_time + timedelta(minutes=30)

        lease1 = esi.offer_claim(self.clients['subproj1-lessee'],
                                 offer['uuid'],
                                 end_time=str(lease1_end_time))
        self.assertNotEqual(lease1, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['subproj1-lessee'],
                        lease1['uuid'])

        e = self.assertRaises(CommandFailed,
                              esi.offer_claim,
                              self.clients['subproj2-lessee'],
                              offer['uuid'],
                              start_time=str(lease2_start_time),
                              end_time=str(lease2_end_time))
        err = ('Offer %s has no availabilities at given time range %s, %s' %
               (offer['uuid'], str(lease2_start_time), str(lease2_end_time)))
        self.assertIn(err, e.stderr.decode())
Beispiel #11
0
    def test_offer_show_sublease_parent_deleted(self):
        """ Tests that offers made for a leased node are deleted after the
                node owning project deletes the original lease.
            Test steps:
            1) (node-owner) Create a lease on an owned node, specifying the
                sublessee project as the lessee.
            2) Check that lease details were returned.
            3) Wait for the esi-leap manager service to move the lease from
                the created state to the active state.
            4) (sublessee-owner) Create an offer for the node leased to the
                sublessee in step 1.
            5) Check that offer details were returned.
            6) Delete the offer created in step 1.
            7) View the details of the offer created in step 4 to ensure the
                offer's status is 'deleted'.
            8) (sublessee-owner) If not, delete the offer manually. """
        lease = esi.lease_create(self.clients['node-owner'],
                                 self.dummy_node.uuid,
                                 self.projects['sublessee']['name'],
                                 resource_type='dummy_node')
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['node-owner'],
                        lease['uuid'],
                        fail_ok=True)

        time.sleep(65)
        offer = esi.offer_create(self.clients['sublessee-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node')
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['sublessee-owner'],
                        offer['uuid'],
                        fail_ok=True)

        esi.lease_delete(self.clients['node-owner'], lease['uuid'])
        details = esi.offer_show(self.clients['sublessee-owner'],
                                 offer['uuid'])
        self.assertEqual(details['status'], 'deleted')
Beispiel #12
0
    def test_offer_create_conflict(self):
        """ Tests that two overlapping offers cannot be created for the
                same node.
            Test steps:
            1) Record the current time.
            2) Create an offer for an owned node, ending 30 minutes after the
                time recorded in step 1.
            3) Check that offer details were returned.
            4) Attempt to create another offer for the same node as in step 2,
                starting 15 minutes after the time recorded in step 1, and
                ending 30 minutes after that.
            5) Check that the command failed. (returned non-zero exit code)
            6) Check that the proper error message was sent to stderr.
            7) (cleanup) Delete the offer created in step 2. """
        time_now = datetime.now()
        offer1_end_time = time_now + timedelta(minutes=30)
        offer2_start_time = time_now + timedelta(minutes=15)
        offer2_end_time = offer2_start_time + timedelta(minutes=30)

        offer1 = esi.offer_create(self.clients['main-owner'],
                                  self.dummy_node.uuid,
                                  resource_type='dummy_node',
                                  end_time=str(offer1_end_time))
        self.assertNotEqual(offer1, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['main-owner'],
                        offer1['uuid'])

        e = self.assertRaises(CommandFailed,
                              esi.offer_create,
                              self.clients['main-owner'],
                              self.dummy_node.uuid,
                              resource_type='dummy_node',
                              start_time=str(offer2_start_time),
                              end_time=str(offer2_end_time))
        self.assertIn('Time conflict for dummy_node %s.' %
                      self.dummy_node.uuid,
                      e.stderr.decode())
Beispiel #13
0
    def test_offer_show_basic(self):
        """ Tests basic functionality of "esi offer show" when executed by
                both node owners and lessees with access to offers.
            Test steps:
            1) (owner) Create an offer for an owned node.
            2) Check that offer details were returned.
            3) (owner) Check that the output of 'offer show' contains the
                details of the offer.
            4) (lessee) Check that the output of 'offer show' contains the
                details of the new offer.
            5) (cleanup) (owner) Delete the offer created in step 1. """
        offer = esi.offer_create(self.clients['parent-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node',
                                 lessee=self.projects['child']['name'])
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['parent-owner'],
                        offer['uuid'])

        for client_name in 'parent-owner', 'child-lessee':
            details = esi.offer_show(self.clients[client_name], offer['uuid'])
            for field in offer.keys():
                self.assertEqual(offer[field], details[field])
Beispiel #14
0
    def test_offer_list_basic(self):
        """ Tests basic functionality of "esi offer list" when executed by
                both node owners and lessees with access to offers.
            Test steps:
            1) (owner) Create an offer for an owned node.
            2) Check that offer details were returned.
            3) (owner) Check that the output of 'offer list' contains the new
                offer.
            4) (lessee) Check that the output of 'offer list' contains the
                new offer.
            5) (cleanup) (owner) Delete the offer created in step 1. """
        offer = esi.offer_create(self.clients['parent-owner'],
                                 self.dummy_node.uuid,
                                 resource_type='dummy_node',
                                 lessee=self.projects['child']['name'])
        self.assertNotEqual(offer, {})
        self.addCleanup(esi.offer_delete,
                        self.clients['parent-owner'],
                        offer['uuid'])

        for client_name in 'parent-owner', 'child-lessee':
            listings = esi.offer_list(self.clients[client_name])
            self.assertNotEqual(listings, [])
            self.assertIn(offer['uuid'], [x['UUID'] for x in listings])