1# Licensed under the Apache License, Version 2.0 (the "License"); you may 2# not use this file except in compliance with the License. You may obtain 3# a copy of the License at 4# 5# http://www.apache.org/licenses/LICENSE-2.0 6# 7# Unless required by applicable law or agreed to in writing, software 8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10# License for the specific language governing permissions and limitations 11# under the License. 12 13from openstack.accelerator.v2 import accelerator_request as arq 14from openstack.tests.unit import base 15 16 17FAKE_ID = '0725b527-e51a-41df-ad22-adad5f4546ad' 18FAKE_RP_UUID = 'f4b7fe6c-8ab4-4914-a113-547af022935b' 19FAKE_INSTANCE_UUID = '1ce4a597-9836-4e02-bea1-a3a6cbe7b9f9' 20FAKE_ATTACH_INFO_STR = '{"bus": "5e", '\ 21 '"device": "00", '\ 22 '"domain": "0000", '\ 23 '"function": "1"}' 24 25FAKE = { 26 'uuid': FAKE_ID, 27 'device_profile_name': 'fake-devprof', 28 'device_profile_group_id': 0, 29 'device_rp_uuid': FAKE_RP_UUID, 30 'instance_uuid': FAKE_INSTANCE_UUID, 31 'attach_handle_type': 'PCI', 32 'attach_handle_info': FAKE_ATTACH_INFO_STR, 33} 34 35 36class TestAcceleratorRequest(base.TestCase): 37 38 def test_basic(self): 39 sot = arq.AcceleratorRequest() 40 self.assertEqual('arq', sot.resource_key) 41 self.assertEqual('arqs', sot.resources_key) 42 self.assertEqual('/accelerator_requests', sot.base_path) 43 self.assertTrue(sot.allow_create) 44 self.assertTrue(sot.allow_fetch) 45 self.assertFalse(sot.allow_commit) 46 self.assertTrue(sot.allow_delete) 47 self.assertTrue(sot.allow_list) 48 self.assertTrue(sot.allow_patch) 49 50 def test_make_it(self): 51 sot = arq.AcceleratorRequest(**FAKE) 52 self.assertEqual(FAKE_ID, sot.uuid) 53 self.assertEqual(FAKE['device_profile_name'], sot.device_profile_name) 54 self.assertEqual(FAKE['device_profile_group_id'], 55 sot.device_profile_group_id) 56 self.assertEqual(FAKE_RP_UUID, sot.device_rp_uuid) 57 self.assertEqual(FAKE_INSTANCE_UUID, sot.instance_uuid) 58 self.assertEqual(FAKE['attach_handle_type'], sot.attach_handle_type) 59 self.assertEqual(FAKE_ATTACH_INFO_STR, sot.attach_handle_info) 60