def test_rand_uuid(self): actual = data_utils.rand_uuid() self.assertIsInstance(actual, str) self.assertRegexpMatches(actual, "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]" "{4}-[0-9a-f]{4}-[0-9a-f]{12}$") actual2 = data_utils.rand_uuid() self.assertNotEqual(actual, actual2)
def _associate_node_with_instance(self): self.client.set_node_power_state(self.node["uuid"], "power off") waiters.wait_for_bm_node_status(self.client, self.node["uuid"], "power_state", "power off") instance_uuid = data_utils.rand_uuid() self.client.update_node(self.node["uuid"], instance_uuid=instance_uuid) self.addCleanup(self.client.update_node, uuid=self.node["uuid"], instance_uuid=None) return instance_uuid
def test_create_snapshot_with_nonexistent_volume_id(self): # Create a snapshot with nonexistent volume id s_name = data_utils.rand_name(self.__class__.__name__ + '-snap') self.assertRaises(lib_exc.NotFound, self.snapshots_client.create_snapshot, volume_id=data_utils.rand_uuid(), display_name=s_name)
def test_create_volume_with_nonexistent_volume_type(self): # Should not be able to create volume with non-existent volume type v_name = data_utils.rand_name(self.__class__.__name__ + '-Volume') metadata = {'Type': 'work'} self.assertRaises(lib_exc.NotFound, self.client.create_volume, size='1', volume_type=data_utils.rand_uuid(), display_name=v_name, metadata=metadata)
def test_server_metadata_non_existent_server(self): # GET on a non-existent server should not succeed non_existent_server_id = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.get_server_metadata_item, non_existent_server_id, 'test2')
def test_show_servers_with_nonexistent_hypervisor(self): nonexistent_hypervisor_id = data_utils.rand_uuid() self.assertRaises( lib_exc.NotFound, self.client.list_servers_on_hypervisor, nonexistent_hypervisor_id)
def test_get_nonexistent_hypervisor_uptime(self): nonexistent_hypervisor_id = data_utils.rand_uuid() self.assertRaises( lib_exc.NotFound, self.client.show_hypervisor_uptime, nonexistent_hypervisor_id)
def populate_spam_table(self, table_name, usercount, itemcount): dates = ['2013-12-0%sT16:00:00.000001' % i for i in range(1, 8)] from_headers = ["*****@*****.**" % rand_name() for _ in range(10)] to_headers = ["*****@*****.**" % rand_name() for _ in range(10)] emails = [] new_items = [] for _ in range(usercount): email = "*****@*****.**" % rand_name() emails.append(email) for item in range(itemcount): message_id = rand_uuid() date = random.choice(dates) # put item item = { "user_id": {"S": email}, "date_message_id": {"S": date + "#" + message_id}, "message_id": {"S": message_id}, "from_header": {"S": random.choice(from_headers)}, "to_header": {"S": random.choice(to_headers)}, } new_items.append(item) self.conn.put_item(table_name, item) return new_items
def test_get_nonexistent_volume_type_id(self): # Should not get volume type extra spec for nonexistent type id. extra_specs = {"spec1": "val1"} self.assertRaises( lib_exc.NotFound, self.admin_volume_types_client.show_volume_type_extra_specs, data_utils.rand_uuid(), extra_specs.keys()[0])
def test_get_nonexistent_extra_spec_id(self): # Should not get volume type extra spec for nonexistent extra spec # id. self.assertRaises( lib_exc.NotFound, self.admin_volume_types_client.show_volume_type_extra_specs, self.volume_type['id'], data_utils.rand_uuid())
def test_rebuild_non_existent_server(self): # Rebuild a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(lib_exc.NotFound, self.client.rebuild_server, nonexistent_server, self.image_ref_alt)
def test_delete_nonexistent_volume_type_id(self): # Should not delete volume type extra spec for nonexistent # type id. self.assertRaises( lib_exc.NotFound, self.admin_volume_types_client.delete_volume_type_extra_specs, data_utils.rand_uuid(), "spec1")
def test_delete_metadata_non_existent_server(self): # Should not be able to delete metadata item from a non-existent server non_existent_server_id = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.delete_server_metadata_item, non_existent_server_id, 'd')
def test_update_volume_with_nonexistent_volume_id(self): v_name = data_utils.rand_name(self.__class__.__name__ + '-Volume') metadata = {'Type': 'work'} self.assertRaises(lib_exc.NotFound, self.client.update_volume, volume_id=data_utils.rand_uuid(), display_name=v_name, metadata=metadata)
def test_update_attached_volume_with_nonexistent_volume_in_uri(self): volume = self.create_volume() nonexistent_volume = data_utils.rand_uuid() self.assertRaises(lib_exc.NotFound, self.servers_admin_client.update_attached_volume, self.server['id'], nonexistent_volume, volumeId=volume['id'])
def test_update_metadata_non_existent_server(self): # An update should not happen for a non-existent server non_existent_server_id = data_utils.rand_uuid() meta = {'key1': 'value1', 'key2': 'value2'} self.assertRaises(exceptions.NotFound, self.client.update_server_metadata, non_existent_server_id, meta)
def test_delete_nonexistent_volume_type_id(self): # Should not delete volume type extra spec for nonexistent # type id. extra_specs = {"spec1": "val1"} self.assertRaises( lib_exc.NotFound, self.volume_types_client.delete_volume_type_extra_specs, data_utils.rand_uuid(), extra_specs.keys()[0])
def test_attach_volumes_with_nonexistent_volume_id(self): server = self.create_server(wait_until='ACTIVE') self.assertRaises(lib_exc.NotFound, self.client.attach_volume, data_utils.rand_uuid(), instance_uuid=server['id'], mountpoint=self.mountpoint)
def test_set_nonexistent_image_metadata_item(self): # Negative test: Metadata item should not be set to a # nonexistent image meta = {'key1': 'alt'} self.assertRaises(exceptions.NotFound, self.client.set_image_metadata_item, data_utils.rand_uuid(), 'key1', meta)
def test_create_image_from_nonexistent_server(self): # An image should not be created with invalid server id # Create a new image with invalid server id nonexistent_server_id = data_utils.rand_uuid() name = data_utils.rand_name('image') meta = {'image_type': 'test'} self.assertRaises(exceptions.NotFound, self.__create_image__, nonexistent_server_id, name, meta)
def test_create_port_duplicated_port_uuid(self): node_id = self.node['uuid'] address = data_utils.rand_mac_address() uuid = data_utils.rand_uuid() self.create_port(node_id=node_id, address=address, uuid=uuid) self.assertRaises(exc.Conflict, self.create_port, node_id=node_id, address=address, uuid=uuid)
def test_update_name_of_non_existent_server(self): # Update name of a non-existent server nonexistent_server = data_utils.rand_uuid() new_name = data_utils.rand_name('server') + '_updated' self.assertRaises(lib_exc.NotFound, self.client.update_server, nonexistent_server, name=new_name)
def test_update_nonexistent_extra_spec_id(self): # Should not update volume type extra specs with nonexistent id. extra_spec = {"spec1": "val2"} self.assertRaises( lib_exc.BadRequest, self.admin_volume_types_client.update_volume_type_extra_specs, self.volume_type['id'], data_utils.rand_uuid(), extra_spec)
def test_create_nonexistent_type_id(self): # Should not create volume type extra spec for nonexistent volume # type id. extra_specs = {"spec2": "val1"} self.assertRaises( lib_exc.NotFound, self.admin_volume_types_client.create_volume_type_extra_specs, data_utils.rand_uuid(), extra_specs)
def test_set_metadata_non_existent_server(self): # Set metadata on a non-existent server should not succeed non_existent_server_id = data_utils.rand_uuid() meta = {'meta1': 'data1'} self.assertRaises(exceptions.NotFound, self.client.set_server_metadata, non_existent_server_id, meta)
def test_update_attached_volume_with_nonexistent_volume_in_body(self): volume = self.create_volume() self.attach_volume(self.server, volume) nonexistent_volume = data_utils.rand_uuid() self.assertRaises(lib_exc.BadRequest, self.servers_admin_client.update_attached_volume, self.server['id'], volume['id'], volumeId=nonexistent_volume)
def test_create_port_specifying_uuid(self): node_id = self.node["uuid"] address = data_utils.rand_mac_address() uuid = data_utils.rand_uuid() _, port = self.create_port(node_id=node_id, address=address, uuid=uuid) _, body = self.client.show_port(uuid) self._assertExpected(port, body)
def test_create_region_with_specific_id(self): # Create a region with a specific id r_region_id = data_utils.rand_uuid() r_description = data_utils.rand_name("description") region = self.client.create_region(r_description, unique_region_id=r_region_id)["region"] self.addCleanup(self._delete_region, region["id"]) # Asserting Create Region with specific id response body self.assertEqual(r_region_id, region["id"]) self.assertEqual(r_description, region["description"])
def test_update_volume_with_nonexistent_volume_id(self): v_name = data_utils.rand_name("Volume") metadata = {"Type": "work"} self.assertRaises( lib_exc.NotFound, self.client.update_volume, volume_id=data_utils.rand_uuid(), display_name=v_name, metadata=metadata, )
def test_create_region_with_specific_id(self): # Create a region with a specific id r_region_id = data_utils.rand_uuid() r_description = data_utils.rand_name('description') region = self.client.create_region( region_id=r_region_id, description=r_description)['region'] self.addCleanup(self._delete_region, region['id']) # Asserting Create Region with specific id response body self.assertEqual(r_region_id, region['id']) self.assertEqual(r_description, region['description'])
def test_volume_backup_export_import(self): """Test backup export import functionality. Cinder allows exporting DB backup information through its API so it can be imported back in case of a DB loss. """ volume = self.create_volume() # Create backup backup_name = data_utils.rand_name(self.__class__.__name__ + '-Backup') backup = (self.create_backup(backup_client=self.admin_backups_client, volume_id=volume['id'], name=backup_name)) self.assertEqual(backup_name, backup['name']) # Export Backup export_backup = (self.admin_backups_client.export_backup(backup['id']) ['backup-record']) self.assertIn('backup_service', export_backup) self.assertIn('backup_url', export_backup) self.assertTrue(export_backup['backup_service'].startswith( 'cinder.backup.drivers')) self.assertIsNotNone(export_backup['backup_url']) # NOTE(geguileo): Backups are imported with the same backup id # (important for incremental backups among other things), so we cannot # import the exported backup information as it is, because that Backup # ID already exists. So we'll fake the data by changing the backup id # in the exported backup DB info we have retrieved before importing it # back. new_id = data_utils.rand_uuid() new_url = self._modify_backup_url( export_backup['backup_url'], {'id': new_id}) # Import Backup import_backup = self.admin_backups_client.import_backup( backup_service=export_backup['backup_service'], backup_url=new_url)['backup'] # NOTE(geguileo): We delete both backups, but only one of those # deletions will delete data from the backup back-end because they # were both pointing to the same backend data. self.addCleanup(self._delete_backup, new_id) self.assertIn("id", import_backup) self.assertEqual(new_id, import_backup['id']) waiters.wait_for_volume_resource_status(self.admin_backups_client, import_backup['id'], 'available') # Verify Import Backup backups = self.admin_backups_client.list_backups( detail=True)['backups'] self.assertIn(new_id, [b['id'] for b in backups]) # Restore backup restore = self.admin_backups_client.restore_backup( backup['id'])['restore'] self.addCleanup(self.admin_volume_client.delete_volume, restore['volume_id']) self.assertEqual(backup['id'], restore['backup_id']) waiters.wait_for_volume_resource_status(self.admin_volume_client, restore['volume_id'], 'available') # Verify if restored volume is there in volume list volumes = self.admin_volume_client.list_volumes()['volumes'] self.assertIn(restore['volume_id'], [v['id'] for v in volumes]) waiters.wait_for_volume_resource_status(self.admin_backups_client, import_backup['id'], 'available')
def test_rebuild_non_existent_server(self): # Rebuild a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(lib_exc.NotFound, self.client.rebuild_server, nonexistent_server, self.image_ref)
def test_update_nonexistent_image_metadata(self): # Negative test:An update should not happen for a non-existent image meta = {'os_distro': 'alt1', 'os_version': 'alt2'} self.assertRaises(lib_exc.NotFound, self.client.update_image_metadata, data_utils.rand_uuid(), meta)
def test_get_nonexistent_image_metadata_item(self): # Negative test: Get on non-existent image should not happen self.assertRaises(lib_exc.NotFound, self.client.show_image_metadata_item, data_utils.rand_uuid(), 'os_version')
def test_list_server_actions_invalid_server(self): # List actions of the invalid server id invalid_server_id = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.list_server_actions, invalid_server_id)
def test_suspend_non_existent_server(self): # suspend a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.suspend_server, nonexistent_server)
def test_stop_non_existent_server(self): # Stop a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.servers_client.stop, nonexistent_server)
def test_get_non_existent_server(self): # Get a non existent server details nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.get_server, nonexistent_server)
def test_reboot_non_existent_server(self): # Reboot a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.reboot, nonexistent_server, 'SOFT')
def test_volume_delete_nonexistent_volume_id(self): # Should not be able to delete a non-existent Volume self.assertRaises(lib_exc.NotFound, self.volumes_client.delete_volume, data_utils.rand_uuid())
def test_list_server_metadata_non_existent_server(self): # List metadata on a non-existent server should not succeed non_existent_server_id = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.list_server_metadata, non_existent_server_id)
def test_get_console_output_of_non_existent_server(self): # get the console output for a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.get_console_output, nonexistent_server, 10)
def test_force_delete_nonexistent_server_id(self): # force-delete a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.force_delete_server, nonexistent_server)
def test_delete_nonexistent_image_metadata_item(self): # Negative test: Shouldn't be able to delete metadata # item from non-existent image self.assertRaises(lib_exc.NotFound, self.client.delete_image_metadata_item, data_utils.rand_uuid(), 'os_distro')
def test_restore_nonexistent_server_id(self): # restore-delete a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.restore_soft_deleted_server, nonexistent_server)
def test_volume_delete_nonexistent_volume_id(self): # Negative: Should not be able to delete nonexistent Volume # Creating nonexistent volume id # Trying to DELETE a non existent volume self.assertRaises(lib_exc.NotFound, self.client.delete_volume, data_utils.rand_uuid())
def test_set_nonexistent_image_metadata(self): # Negative test: Metadata should not be set to a non-existent image meta = {'os_distro': 'alt1', 'os_version': 'alt2'} self.assertRaises(lib_exc.NotFound, self.client.set_image_metadata, data_utils.rand_uuid(), meta)
def not_existing_id(): if CONF.service_available.neutron: return data_utils.rand_uuid() else: return data_utils.rand_int_id(start=999)
def test_volume_get_nonexistent_volume_id(self): # Negative: Should not be able to get details of nonexistent volume # Creating a nonexistent volume id # Trying to GET a non existent volume self.assertRaises(lib_exc.NotFound, self.client.show_volume, data_utils.rand_uuid())
def test_volume_get_nonexistent_volume_id(self): # Should not be able to get a non-existent volume self.assertRaises(lib_exc.NotFound, self.volumes_client.show_volume, data_utils.rand_uuid())
def test_shelve_non_existent_server(self): # shelve a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(lib_exc.NotFound, self.client.shelve_server, nonexistent_server)
def test_unreserve_volume_with_nonexistent_volume_id(self): self.assertRaises(lib_exc.NotFound, self.volumes_client.unreserve_volume, data_utils.rand_uuid())
def test_list_nonexistent_image_metadata(self): # Negative test: List on nonexistent image # metadata should not happen self.assertRaises(lib_exc.NotFound, self.client.list_image_metadata, data_utils.rand_uuid())
def test_get_server_action_invalid_request(self): # Get the action details of the provided server with invalid request invalid_request_id = 'req-' + data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.get_server_action, self.server_id, invalid_request_id)
def test_unshelve_non_existent_server(self): # unshelve a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.unshelve_server, nonexistent_server)
def test_resize_nonexistent_server(self): # Resize a non-existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.client.resize, nonexistent_server, self.flavor_ref)
def test_rescue_non_existent_server(self): # Rescue a non-existing server non_existent_server = data_utils.rand_uuid() self.assertRaises(exceptions.NotFound, self.servers_client.rescue_server, non_existent_server)