def test_it_can_create_and_delete_a_plain_resource_class(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='test_plain_resource_class', service_type='compute')
     #create it in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     self.__check_resource_class(db_rc, 'test_plain_resource_class',
                                 'compute')
     #delete it:
     self.db.delete_resource_class(db_rc.id)
Example #2
0
 def setUp(self):
     super(TestDbRacks, self).setUp()
     #need two resource classes - one for each rack:
     pecan_rc1 = utils.get_test_resource_class(name='rc1', type='compute')
     pecan_rc2 = utils.get_test_resource_class(name='rc2', type='control')
     #create the rc in the db
     self.db_rc1 = self.db.create_resource_class(pecan_rc1)
     self.db_rc2 = self.db.create_resource_class(pecan_rc2)
     #define 2 pecan racks, one without nodes:
     pecan_rack1 = utils.get_test_rack(name='rack_no_nodes',
                                       resource_class=True,
                                       rc_id=self.db_rc1.id)
     pecan_rack2 = utils.get_test_rack(name='rack_has_nodes',
                                       nodes=True,
                                       resource_class=True,
                                       rc_id=self.db_rc2.id)
     #create them in db
     self.rack1 = self.db.create_rack(pecan_rack1)
     self.rack2 = self.db.create_rack(pecan_rack2)
 def test_it_can_retrieve_single_resource_class(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(name='retrieve_rc_test',
                                              service_type='compute')
     #create it:
     created_rc = self.db.create_resource_class(pecan_rc)
     #retrieve and check:
     db_rc = self.db.get_resource_class(created_rc.id)
     self.__check_resource_class(db_rc, 'retrieve_rc_test', 'compute')
     #cleanup
     self.db.delete_resource_class(db_rc.id)
 def test_it_can_retrieve_single_resource_class(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(name='retrieve_rc_test',
                                              service_type='compute')
     #create it:
     created_rc = self.db.create_resource_class(pecan_rc)
     #retrieve and check:
     db_rc = self.db.get_resource_class(created_rc.id)
     self.__check_resource_class(db_rc, 'retrieve_rc_test', 'compute')
     #cleanup
     self.db.delete_resource_class(db_rc.id)
Example #5
0
 def test_it_can_retrieve_all_flavors_for_resource_class(self):
     #create a resource class
     pecan_rc = utils.get_test_resource_class()
     #give it a couple flavors and create it
     pecan_rc.flavors = [utils.get_test_flavor(name='xyz', value='123'),
                         utils.get_test_flavor(name='abc', value='456')]
     db_rc = self.db.create_resource_class(pecan_rc)
     #retrieve the flavors:
     flavs = self.db.get_flavors(db_rc.id)
     self.__check_flavor_capacities(flavs, ['xyz', 'abc'], ['123', '456'])
     #cleanup
     self.db.delete_resource_class(db_rc.id)
 def test_it_can_create_and_delete_a_plain_resource_class(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='test_plain_resource_class',
         service_type='compute')
     #create it in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     self.__check_resource_class(db_rc,
                                 'test_plain_resource_class',
                                 'compute')
     #delete it:
     self.db.delete_resource_class(db_rc.id)
Example #7
0
 def test_it_can_create_a_resource_class_flavor(self):
     #create a resource class:
     pecan_rc = utils.get_test_resource_class()
     db_rc = self.db.create_resource_class(pecan_rc)
     #get a pecan flavor to add:
     pecan_flavor = utils.get_test_flavor(name='bar', value='333')
     db_flavor = self.db.create_resource_class_flavor(db_rc.id,
                                                      pecan_flavor)
     #make test assertions
     self.__check_flavor_capacities([db_flavor], ['bar'], ['333'])
     #cleanup
     self.db.delete_resource_class(db_rc.id)
 def test_it_can_retrieve_all_resource_classes(self):
     created_db_rc_ids = []
     #create a four resource classes
     for i in range(1, 5):
         pecan_rc = utils.get_test_resource_class(name=('rc_' + str(i)),
                                                  service_type='foo')
         db_rc = self.db.create_resource_class(pecan_rc)
         created_db_rc_ids.append(db_rc.id)
     #retrieve the resource classes:
     resource_classes = self.db.get_resource_classes(None)
     self.assertTrue(len(resource_classes) == 4)
     #cleanup
     for rc_id in created_db_rc_ids:
         self.db.delete_resource_class(rc_id)
Example #9
0
 def test_it_can_create_flavors_during_resource_class_create(self):
     #get a pecan resource_class:
     rc = utils.get_test_resource_class()
     #add some flavors:
     rc.flavors = [utils.get_test_flavor(name='a', value='9'),
                   utils.get_test_flavor(name='b', value='8'),
                   utils.get_test_flavor(name='c', value='7')]
     #create rc with flavors in database
     db_rc = self.db.create_resource_class(rc)
     #check the flavors are ok:
     self.__check_flavor_capacities(db_rc.flavors, ['a', 'b', 'c'],
                                                   ['7', '8', '9'])
     #cleanup
     self.db.delete_resource_class(db_rc.id)
 def test_it_can_update_resource_class_name_and_type(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(name='a_plain_resource_class',
                                              service_type='compute')
     #create it:
     db_rc = self.db.create_resource_class(pecan_rc)
     #update:
     pecan_rc.name = 'updated_plain_resource_class'
     pecan_rc.service_type = 'storage'
     updated_db_rc = self.db.update_resource_class(db_rc.id, pecan_rc)
     #check
     self.__check_resource_class(updated_db_rc,
                                 'updated_plain_resource_class', 'storage')
     self.db.delete_resource_class(updated_db_rc.id)
 def test_it_can_retrieve_all_resource_classes(self):
     created_db_rc_ids = []
     #create a four resource classes
     for i in range(1, 5):
         pecan_rc = utils.get_test_resource_class(name=('rc_' + str(i)),
                                                  service_type='foo')
         db_rc = self.db.create_resource_class(pecan_rc)
         created_db_rc_ids.append(db_rc.id)
     #retrieve the resource classes:
     resource_classes = self.db.get_resource_classes(None)
     self.assertTrue(len(resource_classes) == 4)
     #cleanup
     for rc_id in created_db_rc_ids:
         self.db.delete_resource_class(rc_id)
 def test_it_can_update_resource_class_name_and_type(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(name='a_plain_resource_class',
                                              service_type='compute')
     #create it:
     db_rc = self.db.create_resource_class(pecan_rc)
     #update:
     pecan_rc.name = 'updated_plain_resource_class'
     pecan_rc.service_type = 'storage'
     updated_db_rc = self.db.update_resource_class(db_rc.id, pecan_rc)
     #check
     self.__check_resource_class(updated_db_rc,
                                 'updated_plain_resource_class',
                                 'storage')
     self.db.delete_resource_class(updated_db_rc.id)
 def test_it_can_update_resource_class_racks_and_flavors(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='resource_class_update_racks_flavs', service_type='compute')
     #create racks in database:
     db_rack1 = self.db.create_rack(utils.get_test_rack(name='rack1'))
     db_rack2 = self.db.create_rack(utils.get_test_rack(name='rack2'))
     #add racks to resource class:
     pecan_rc.racks = [
         utils.get_test_resource_class_rack(id=db_rack1.id),
         utils.get_test_resource_class_rack(id=db_rack2.id)
     ]
     #give it a couple of flavors too:
     pecan_rc.flavors = [
         utils.get_test_flavor(name='flav1', value='1'),
         utils.get_test_flavor(name='flav2', value='2')
     ]
     #create rc in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     #update racks and flavors:
     pecan_rc.flavors = [
         utils.get_test_flavor(name='flav3', value='3'),
         utils.get_test_flavor(name='flav4', value='4')
     ]
     db_rack3 = self.db.create_rack(utils.get_test_rack(name='rack3'))
     db_rack4 = self.db.create_rack(utils.get_test_rack(name='rack4'))
     pecan_rc.racks = [
         utils.get_test_resource_class_rack(id=db_rack3.id),
         utils.get_test_resource_class_rack(id=db_rack4.id)
     ]
     #update the resource class:
     updated_db_rc = self.db.update_resource_class(db_rc.id, pecan_rc)
     #check:
     #FIXME: THERE IS A BUG IN UPDATE RESOURCECLASS - it doesn't remove
     #the old racks in update operation - adding all ids here so test passes
     self.__check_resource_class(
         updated_db_rc,
         'resource_class_update_racks_flavs',
         'compute',
         flavor_names=['flav3', 'flav4'],
         flavor_values=['3', '4'],
         rack_ids=[db_rack1.id, db_rack2.id, db_rack3.id, db_rack4.id])
     #FIXME: i.e. remove db_rack1.id and db_rack2.id above
     #as they shouldn't be there
     #delete:
     self.db.delete_resource_class(updated_db_rc.id)
     for rack in [db_rack1, db_rack2, db_rack3, db_rack4]:
         self.db.delete_rack(rack.id)
 def test_it_can_create_and_delete_resource_class_with_flavors(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='test_plain_resource_class',
         service_type='compute')
     #give it some flavors:
     pecan_rc.flavors = [utils.get_test_flavor(name='xyz', value='123'),
                         utils.get_test_flavor(name='abc', value='456')]
     #create it in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     self.__check_resource_class(db_rc,
                                 'test_plain_resource_class',
                                 'compute',
                                 flavor_names=['xyz', 'abc'],
                                 flavor_values=['123', '456'])
     #delete it:
     self.db.delete_resource_class(db_rc.id)
Example #15
0
 def test_it_can_retrieve_a_single_flavor(self):
     #create a resource class
     pecan_rc = utils.get_test_resource_class()
     #give it a couple flavors and create it
     pecan_rc.flavors = [utils.get_test_flavor(name='xyz', value='123'),
                         utils.get_test_flavor(name='abc', value='456')]
     db_rc = self.db.create_resource_class(pecan_rc)
     # we cannot rely on the order of the db_rc.flavors items
     if db_rc.flavors[0].name == 'abc':
         abc_flavor = db_rc.flavors[0]
     else:
         abc_flavor = db_rc.flavors[1]
     #retrieve a specific flavor
     flav = self.db.get_flavor(abc_flavor.id)
     self.__check_flavor_capacities([flav], ['abc'], ['456'])
     #cleanup
     self.db.delete_resource_class(db_rc.id)
 def test_it_can_create_and_delete_resource_class_with_flavors(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='test_plain_resource_class', service_type='compute')
     #give it some flavors:
     pecan_rc.flavors = [
         utils.get_test_flavor(name='xyz', value='123'),
         utils.get_test_flavor(name='abc', value='456')
     ]
     #create it in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     self.__check_resource_class(db_rc,
                                 'test_plain_resource_class',
                                 'compute',
                                 flavor_names=['xyz', 'abc'],
                                 flavor_values=['123', '456'])
     #delete it:
     self.db.delete_resource_class(db_rc.id)
Example #17
0
 def test_it_can_update_resource_class_flavors(self):
     #create a resource class
     pecan_rc = utils.get_test_resource_class()
     #give it a flavor:
     pecan_rc.flavors = [utils.get_test_flavor(name='foo', value='99')]
     db_rc = self.db.create_resource_class(pecan_rc)
     #update the resource class with new flavors:
     pecan_rc.flavors = [utils.get_test_flavor(name='one', value='1'),
                         utils.get_test_flavor(name='two', value='2'),
                         utils.get_test_flavor(name='three', value='3')]
     #call the update
     updated_rc = self.db.update_resource_class(db_rc.id, pecan_rc)
     #make test assertions
     self.__check_flavor_capacities(updated_rc.flavors,
                                    ['one', 'two', 'three'],
                                    ['1', '2', '3'])
     #cleanup
     self.db.delete_resource_class(db_rc.id)
 def test_it_can_update_resource_class_racks_and_flavors(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='resource_class_update_racks_flavs',
         service_type='compute')
     #create racks in database:
     db_rack1 = self.db.create_rack(utils.get_test_rack(name='rack1'))
     db_rack2 = self.db.create_rack(utils.get_test_rack(name='rack2'))
     #add racks to resource class:
     pecan_rc.racks = [utils.get_test_resource_class_rack(id=db_rack1.id),
                       utils.get_test_resource_class_rack(id=db_rack2.id)]
     #give it a couple of flavors too:
     pecan_rc.flavors = [utils.get_test_flavor(name='flav1', value='1'),
                         utils.get_test_flavor(name='flav2', value='2')]
     #create rc in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     #update racks and flavors:
     pecan_rc.flavors = [utils.get_test_flavor(name='flav3', value='3'),
                         utils.get_test_flavor(name='flav4', value='4')]
     db_rack3 = self.db.create_rack(utils.get_test_rack(name='rack3'))
     db_rack4 = self.db.create_rack(utils.get_test_rack(name='rack4'))
     pecan_rc.racks = [utils.get_test_resource_class_rack(id=db_rack3.id),
                       utils.get_test_resource_class_rack(id=db_rack4.id)]
     #update the resource class:
     updated_db_rc = self.db.update_resource_class(db_rc.id, pecan_rc)
     #check:
     #FIXME: THERE IS A BUG IN UPDATE RESOURCECLASS - it doesn't remove
     #the old racks in update operation - adding all ids here so test passes
     self.__check_resource_class(updated_db_rc,
                                 'resource_class_update_racks_flavs',
                                 'compute',
                                 flavor_names=['flav3', 'flav4'],
                                 flavor_values=['3', '4'],
                                 rack_ids=[db_rack1.id, db_rack2.id,
                                           db_rack3.id, db_rack4.id])
     #FIXME: i.e. remove db_rack1.id and db_rack2.id above
     #as they shouldn't be there
     #delete:
     self.db.delete_resource_class(updated_db_rc.id)
     for rack in [db_rack1, db_rack2, db_rack3, db_rack4]:
         self.db.delete_rack(rack.id)
 def test_it_can_create_and_delete_resource_class_with_racks(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='resource_class_with_racks',
         service_type='compute')
     #first create racks in database (ids 1 and 2):
     db_rack1 = self.db.create_rack(utils.get_test_rack(name='rack1'))
     db_rack2 = self.db.create_rack(utils.get_test_rack(name='rack2'))
     #add racks to resource class:
     pecan_rc.racks = [utils.get_test_resource_class_rack(id=db_rack1.id),
                       utils.get_test_resource_class_rack(id=db_rack2.id)]
     #create rc with racks in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     #check it:
     self.__check_resource_class(db_rc,
                                 'resource_class_with_racks',
                                 'compute',
                                 rack_ids=[db_rack1.id, db_rack2.id])
     #delete:
     self.db.delete_resource_class(db_rc.id)
     self.db.delete_rack(db_rack1.id)
     self.db.delete_rack(db_rack2.id)
 def test_it_can_create_and_delete_resource_class_with_racks(self):
     #get a pecan resource_class:
     pecan_rc = utils.get_test_resource_class(
         name='resource_class_with_racks', service_type='compute')
     #first create racks in database (ids 1 and 2):
     db_rack1 = self.db.create_rack(utils.get_test_rack(name='rack1'))
     db_rack2 = self.db.create_rack(utils.get_test_rack(name='rack2'))
     #add racks to resource class:
     pecan_rc.racks = [
         utils.get_test_resource_class_rack(id=db_rack1.id),
         utils.get_test_resource_class_rack(id=db_rack2.id)
     ]
     #create rc with racks in db:
     db_rc = self.db.create_resource_class(pecan_rc)
     #check it:
     self.__check_resource_class(db_rc,
                                 'resource_class_with_racks',
                                 'compute',
                                 rack_ids=[db_rack1.id, db_rack2.id])
     #delete:
     self.db.delete_resource_class(db_rc.id)
     self.db.delete_rack(db_rack1.id)
     self.db.delete_rack(db_rack2.id)
Example #21
0
 def test_it_can_update_a_resource_class_flavor(self):
     #create a resource class
     pecan_rc = utils.get_test_resource_class()
     #give it a couple flavors and create it
     pecan_rc.flavors = [utils.get_test_flavor(name='xyz', value='123'),
                         utils.get_test_flavor(name='abc', value='456')]
     db_rc = self.db.create_resource_class(pecan_rc)
     # we cannot rely on the order of the db_rc.flavors items
     if db_rc.flavors[0].name == 'xyz':
         xyz_flavor = db_rc.flavors[0]
     else:
         xyz_flavor = db_rc.flavors[1]
     #now update one of the flavors:
     updated_flav = self.db.update_resource_class_flavor(
         db_rc.id,
         xyz_flavor.id,
         utils.get_test_flavor(name='xyz', value='999'))
     #retrieve updated rc and assert:
     updated_rc = self.db.get_resource_class(db_rc.id)
     self.__check_flavor_capacities(updated_rc.flavors,
                                    ['xyz', 'abc'],
                                    ['999', '456'])
     #cleanup
     self.db.delete_resource_class(db_rc.id)