Ejemplo n.º 1
0
    def test_lease_create_sublease(self):
        """ Tests that an owner of a project that has leased a node can
                create a lease on 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 a lease on the node leased to the
                sublessee in step 1.
            5) Check that lease details were returned.
            6) (cleanup) (sublessee-owner) Delete the lease from step 3.
            7) (cleanup) (node-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)

        sublease = esi.lease_create(self.clients['sublessee-owner'],
                                    self.dummy_node.uuid,
                                    self.projects['project']['name'],
                                    resource_type='dummy_node')
        self.assertNotEqual(sublease, {})
        self.addCleanup(esi.lease_delete, self.clients['sublessee-owner'],
                        sublease['uuid'])
Ejemplo n.º 2
0
    def test_lease_create_multiple(self):
        """ Tests that more than one lease 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 a lease on an owned node, starting at the time recorded
                in step 1 and ending 30 minutes from then.
            3) Check that lease details were returned.
            4) Create a lease on the same node, starting five minutes after
               the end time of the lease created in step 2 and ending 30
               minutes from then.
            5) Check that lease details were returned.
            6) Check that both lease show up when listing leases.
            7) (cleanup) Delete the lease created in step 4.
            8) (cleanup) Delete the lease created in step 2. """
        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.lease_create(self.clients['main-owner'],
                                  self.dummy_node.uuid,
                                  self.projects['main']['name'],
                                  resource_type='dummy_node',
                                  start_time=str(lease1_start_time),
                                  end_time=str(lease1_end_time))
        self.assertNotEqual(lease1, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['main-owner'],
                        lease1['uuid'])

        lease2 = esi.lease_create(self.clients['main-owner'],
                                  self.dummy_node.uuid,
                                  self.projects['main']['name'],
                                  resource_type='dummy_node',
                                  start_time=str(lease2_start_time),
                                  end_time=str(lease2_end_time))
        self.assertNotEqual(lease2, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['main-owner'],
                        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)
Ejemplo n.º 3
0
    def test_lease_delete_unauthorized(self):
        """ Tests that an owner can't delete a lease that they do not have
                access to.
            Test steps:
            1) (authorized-owner) Create a lease on an owned node.
            2) Check that lease details were returned.
            3) (unauthorized-owner) Attempt to delete the lease from step 1.
            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 lease from step 1. """
        lease = esi.lease_create(self.clients['authorized-owner'],
                                 self.dummy_node.uuid,
                                 self.projects['authorized']['name'],
                                 resource_type='dummy_node')
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['authorized-owner'],
                        lease['uuid'])

        e = self.assertRaises(CommandFailed,
                              esi.lease_delete,
                              self.clients['unauthorized-owner'],
                              lease['uuid'])
        self.assertIn('Access was denied to lease %s.' % lease['uuid'],
                      e.stderr.decode())
Ejemplo n.º 4
0
    def test_lease_show_basic(self):
        """ Tests basic functionality of "esi lease show" when executed by
                both node owners and the lessee of the lease.
            Test steps:
            1) (owner) Create a lease on 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. """
        lease = esi.lease_create(self.clients['parent-owner'],
                                 self.dummy_node.uuid,
                                 self.projects['child']['name'],
                                 resource_type='dummy_node',
                                 start_time='9999-01-01')
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['parent-owner'],
                        lease['uuid'])

        for client_name in 'parent-owner', 'child-lessee':
            details = esi.lease_show(self.clients[client_name], lease['uuid'])
            for field in lease.keys():
                self.assertEqual(lease[field], details[field])
Ejemplo n.º 5
0
    def test_lease_show_sublease_parent_deleted(self):
        """ Tests that leases made on 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 a lease on the node leased to the
                sublessee in step 1.
            5) Check that lease details were returned.
            6) Delete the original lease created in step 1.
            7) View the details of the lease created in step 4 to ensure the
                lease's status is 'deleted'.
            8) (sublessee-owner) If not, delete the lease 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)
        sublease = esi.lease_create(self.clients['sublessee-owner'],
                                    self.dummy_node.uuid,
                                    self.projects['project']['name'],
                                    resource_type='dummy_node')
        self.assertNotEqual(sublease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['sublessee-owner'],
                        sublease['uuid'],
                        fail_ok=True)

        esi.lease_delete(self.clients['node-owner'], lease['uuid'])
        details = esi.lease_show(self.clients['sublessee-owner'],
                                 sublease['uuid'])
        self.assertEqual(details['status'], 'deleted')
Ejemplo n.º 6
0
 def test_lease_create_basic(self):
     """ Tests that a node owner can create and delete a lease on a node
             that they own.
         Test steps:
         1) Create a lease on an owned node.
         2) Check that lease details were returned.
         3) (cleanup) Delete the lease created in step 1. """
     lease = esi.lease_create(self.clients['parent-owner'],
                              self.dummy_node.uuid,
                              self.projects['child']['name'],
                              resource_type='dummy_node',
                              start_time='9999-01-01')
     self.assertNotEqual(lease, {})
     self.addCleanup(esi.lease_delete,
                     self.clients['parent-owner'],
                     lease['uuid'])
Ejemplo n.º 7
0
    def test_offer_create_sublease_out_of_range(self):
        """ Tests to ensure an offer for a leased node cannot be created for
                a time period outside of the original lease's availability.
            Test steps:
            1) Record the current time.
            2) (main-owner) Create a lease for an owned node, ending 30
                minutes after the time recorded in step 1.
            3) Check that lease details were returned.
            4) Wait for the esi-leap manager service to move the lease from
                the created state to the active state.
            5) (subproj1-owner) Attempt to create an offer on the node leased
                in step 2, starting 15 minutes after the time recorded in
                step 1, and ending 45 minutes after.
            6) Check that the command failed. (returned non-zero exit code)
            7) Check that the proper error message was sent to stderr.
            8) (main-owner) (cleanup) Delete the offer created in step 2. """
        time_now = datetime.now()
        lease_end_time = time_now + timedelta(minutes=30)
        offer_start_time = time_now + timedelta(minutes=15)
        offer_end_time = time_now + timedelta(minutes=45)

        lease = esi.lease_create(self.clients['main-owner'],
                                 self.dummy_node.uuid,
                                 self.projects['subproj1']['name'],
                                 resource_type='dummy_node',
                                 end_time=str(lease_end_time))
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['main-owner'],
                        lease['uuid'])

        time.sleep(65)

        err = ('You do not have permissions on dummy_node %s for the time '
               'range %s - %s.') % (self.dummy_node.uuid,
                                    str(offer_start_time), str(offer_end_time))
        e = self.assertRaises(CommandFailed,
                              esi.offer_create,
                              self.clients['subproj1-owner'],
                              self.dummy_node.uuid,
                              resource_type='dummy_node',
                              start_time=str(offer_start_time),
                              end_time=str(offer_end_time))
        self.assertIn(err, e.stderr.decode())
Ejemplo n.º 8
0
    def test_lease_list_basic(self):
        """ Tests basic functionality of "esi lease list" when executed by
                a node owner.
            Test steps:
            1) Create a lease on an owned node.
            2) Check that lease details were returned.
            3) Check that the output of 'lease list' contains the new lease.
            4) (cleanup) Delete the lease created in step 1. """
        lease = esi.lease_create(self.clients['parent-owner'],
                                 self.dummy_node.uuid,
                                 self.projects['child']['name'],
                                 resource_type='dummy_node',
                                 start_time='9999-01-01')
        self.assertNotEqual(lease, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['parent-owner'],
                        lease['uuid'])

        listings = esi.lease_list(self.clients['parent-owner'])
        self.assertNotEqual(listings, [])
        self.assertIn(lease['uuid'], [x['UUID'] for x in listings])
Ejemplo n.º 9
0
    def test_lease_create_conflict(self):
        """ Tests that two overlapping leases cannot be created on the
                same node.
            Test steps:
            1) Record the current time.
            2) Create a lease on an owned node, ending 30 minutes after the
                time recorded in step 1.
            3) Check that lease details were returned.
            4) Attempt to create another lease on 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 lease created in step 2. """
        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.lease_create(self.clients['main-owner'],
                                  self.dummy_node.uuid,
                                  self.projects['main']['name'],
                                  resource_type='dummy_node',
                                  end_time=str(lease1_end_time))
        self.assertNotEqual(lease1, {})
        self.addCleanup(esi.lease_delete,
                        self.clients['main-owner'],
                        lease1['uuid'])

        e = self.assertRaises(CommandFailed,
                              esi.lease_create,
                              self.clients['main-owner'],
                              self.dummy_node.uuid,
                              self.projects['main']['name'],
                              resource_type='dummy_node',
                              start_time=str(lease2_start_time),
                              end_time=str(lease2_end_time))
        self.assertIn('Time conflict for dummy_node %s.' %
                      self.dummy_node.uuid,
                      e.stderr.decode())
Ejemplo n.º 10
0
    def test_lease_expire(self):
        """ Tests to ensure expired leases do not show up in the list of
                leases after expiring.
            Test steps:
            1) Record what the time will be in 30 seconds.
            2) Create an lease on an owned node that ends at the time recorded
                in step 1.
            3) Check that lease details were returned and that the lease's
                status is either 'created' or 'active'.
            4) Wait 100 seconds to allow the esi-leap manager to move the
                lease into the 'expired' state.
            5) Check that state of the lease from step 2 is 'expired'.
            6) Check that the lease does not show up in the list
                of leases.
            7) (cleanup) Delete the lease from step 2 if needed. """
        time_now = datetime.now()
        lease_end_time = time_now + timedelta(seconds=30)

        lease = esi.lease_create(self.clients['main-owner'],
                                 self.dummy_node.uuid,
                                 self.projects['main']['name'],
                                 resource_type='dummy_node',
                                 end_time=str(lease_end_time))
        self.assertNotEqual(lease, {})
        # NOTE: this ensures the lease is deleted, ignoring failed attempts
        # to delete leases that expired correctly.
        self.addCleanup(esi.lease_delete,
                        self.clients['main-owner'],
                        lease['uuid'],
                        fail_ok=True)
        self.assertIn(lease['status'], ('created', 'active'))

        time.sleep(100)

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

        listings = esi.lease_list(self.clients['main-owner'])
        self.assertNotIn(lease['uuid'], [x['UUID'] for x in listings])
Ejemplo n.º 11
0
    def test_offer_claim_sublease(self):
        """ Tests that an offer for a subleased node can be claimed.
            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) (project-lessee) Claim the offer created in step 3.
            7( Check that lease details were returned.
            8) (cleanup) (project-lessee) Delete the lease from step 5.
            9) (cleanup) (sublessee-owner) Delete the offer from step 3.
            10) (cleanup) (node-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'])

        sublease = esi.offer_claim(self.clients['project-lessee'],
                                   offer['uuid'])
        self.assertNotEqual(sublease, {})
        self.addCleanup(esi.lease_delete, self.clients['project-lessee'],
                        sublease['uuid'])