def test_create_delete_volume(self): """ Tests the creation then deletion of an OpenStack volume to ensure clean() does not raise an Exception. """ # Create Volume self.volume_creator = OpenStackVolume(self.os_creds, self.volume_settings) created_volume = self.volume_creator.create(block=True) self.assertIsNotNone(created_volume) retrieved_volume = cinder_utils.get_volume( self.cinder, self.keystone, volume_settings=self.volume_settings, project_name=self.os_creds.project_name) self.assertIsNotNone(retrieved_volume) self.assertEqual(created_volume, retrieved_volume) # Delete Volume manually self.volume_creator.clean() self.assertIsNone( cinder_utils.get_volume(self.cinder, self.keystone, volume_settings=self.volume_settings, project_name=self.os_creds.project_name)) # Must not throw an exception when attempting to cleanup non-existent # volume self.volume_creator.clean() self.assertIsNone(self.volume_creator.get_volume())
def test_create_two_vol_same_name_diff_proj(self): """ Creates a volume as admin to the project of os_creds then instantiates a creator object with the os_creds project to ensure it initializes without creation """ vol_name = self.guid + '-vol' self.volume_creators.append( OpenStackVolume(self.admin_os_creds, VolumeConfig(name=vol_name))) admin_vol = self.volume_creators[0].create(block=True) self.assertIsNotNone(admin_vol) admin_key = keystone_utils.keystone_client(self.admin_os_creds, self.admin_os_session) admin_proj = keystone_utils.get_project( admin_key, project_name=self.admin_os_creds.project_name) self.assertEqual(admin_vol.project_id, admin_proj.id) admin_cinder = cinder_utils.cinder_client(self.admin_os_creds, self.admin_os_session) admin_vol_get = cinder_utils.get_volume( admin_cinder, admin_key, volume_name=vol_name, project_name=self.admin_os_creds.project_name) self.assertIsNotNone(admin_vol_get) self.assertEqual(admin_vol, admin_vol_get) self.volume_creators.append( OpenStackVolume(self.os_creds, VolumeConfig(name=vol_name))) proj_vol = self.volume_creators[1].create(block=True) self.assertIsNotNone(proj_vol) self.assertNotEqual(admin_vol, proj_vol) proj_key = keystone_utils.keystone_client(self.os_creds, self.os_session) proj_cinder = cinder_utils.cinder_client(self.os_creds, self.os_session) proj_vol_get = cinder_utils.get_volume( proj_cinder, proj_key, volume_name=vol_name, project_name=self.os_creds.project_name) self.assertIsNotNone(proj_vol_get) self.assertEqual(proj_vol, proj_vol_get)
def __create_vm(self, block=False): """ Responsible for creating the VM instance :param block: Thread will block until instance has either become active, error, or timeout waiting. Floating IPs will be assigned after active when block=True """ self.__vm = nova_utils.create_server(self._nova, self.__keystone, self.__neutron, self.__glance, self.instance_settings, self.image_settings, self._os_creds.project_name, self.keypair_settings) logger.info('Created instance with name - %s', self.instance_settings.name) if block: if not self.vm_active(block=True): raise VmInstanceCreationError( 'Fatal error, VM did not become ACTIVE within the alloted ' 'time') # Create server should do this but found it needed to occur here for sec_grp_name in self.instance_settings.security_group_names: if self.vm_active(block=True): nova_utils.add_security_group(self._nova, self.__vm, sec_grp_name) else: raise VmInstanceCreationError( 'Cannot applying security group with name ' + sec_grp_name + ' to VM that did not activate with name - ' + self.instance_settings.name) if self.instance_settings.volume_names: for volume_name in self.instance_settings.volume_names: volume = cinder_utils.get_volume( self.__cinder, self.__keystone, volume_name=volume_name, project_name=self._os_creds.project_name) if volume and self.vm_active(block=True): vm = nova_utils.attach_volume(self._nova, self.__neutron, self.__keystone, self.__vm, volume, self._os_creds.project_name) if vm: self.__vm = vm else: logger.warn('Volume [%s] attachment timeout ', volume.name) else: logger.warn('Unable to attach volume named [%s]', volume_name) self.__apply_floating_ips()
def initialize(self): """ Loads the existing Volume :return: The Volume domain object or None """ super(self.__class__, self).initialize() self.__volume = cinder_utils.get_volume( self._cinder, self._keystone, volume_settings=self.volume_settings, project_name=self._os_creds.project_name) return self.__volume
def test_create_delete_volume(self): """ Tests the cinder_utils.create_volume() """ volume_settings = VolumeConfig(name=self.volume_name) self.volume = cinder_utils.create_volume( self.cinder, self.keystone, volume_settings) self.assertIsNotNone(self.volume) self.assertEqual(self.volume_name, self.volume.name) self.assertTrue(volume_active(self.cinder, self.volume)) volume = cinder_utils.get_volume( self.cinder, self.keystone, volume_settings=volume_settings, project_name=self.os_creds.project_name) self.assertIsNotNone(volume) validation_utils.objects_equivalent(self.volume, volume) cinder_utils.delete_volume(self.cinder, self.volume) self.assertTrue(volume_deleted(self.cinder, self.volume)) self.assertIsNone( cinder_utils.get_volume( self.cinder, self.keystone, volume_settings, project_name=self.os_creds.project_name))
def test_create_volume_simple(self): """ Tests the creation of a simple OpenStack volume. """ # Create Volume self.volume_creator = OpenStackVolume(self.os_creds, self.volume_settings) created_volume = self.volume_creator.create(block=True) self.assertIsNotNone(created_volume) retrieved_volume = cinder_utils.get_volume( self.cinder, self.keystone, volume_settings=self.volume_settings, project_name=self.os_creds.project_name) self.assertIsNotNone(retrieved_volume) self.assertEqual(created_volume.id, retrieved_volume.id) self.assertTrue(created_volume == retrieved_volume)
def test_create_same_volume(self): """ Tests the creation of an OpenStack volume when one already exists. """ # Create Volume self.volume_creator = OpenStackVolume(self.os_creds, self.volume_settings) volume1 = self.volume_creator.create(block=True) retrieved_volume = cinder_utils.get_volume( self.cinder, self.keystone, volume_settings=self.volume_settings, project_name=self.os_creds.project_name) self.assertEqual(volume1, retrieved_volume) # Should be retrieving the instance data os_volume_2 = OpenStackVolume(self.os_creds, self.volume_settings) volume2 = os_volume_2.create(block=True) self.assertEqual(volume1, volume2)