"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cyborg/tests/unit/api/controllers/v2/test_device_profiles.py" between
openstack-cyborg-6.0.0.tar.gz and openstack-cyborg-7.0.0.tar.gz

About: OpenStack Cyborg provides a general purpose management framework for acceleration resources.
The "Xena" series (latest release).

test_device_profiles.py  (openstack-cyborg-6.0.0):test_device_profiles.py  (openstack-cyborg-7.0.0)
skipping to change at line 48 skipping to change at line 48
has_self_link = True has_self_link = True
url = link['href'] url = link['href']
components = url.split('/') components = url.split('/')
self.assertEqual(components[-1], dp_uuid) self.assertEqual(components[-1], dp_uuid)
self.assertTrue(has_self_link) self.assertTrue(has_self_link)
def _validate_dp(self, in_dp, out_dp): def _validate_dp(self, in_dp, out_dp):
self.assertEqual(in_dp['name'], out_dp['name']) self.assertEqual(in_dp['name'], out_dp['name'])
self.assertEqual(in_dp['uuid'], out_dp['uuid']) self.assertEqual(in_dp['uuid'], out_dp['uuid'])
self.assertEqual(in_dp['groups'], out_dp['groups']) self.assertEqual(in_dp['groups'], out_dp['groups'])
self.assertEqual(in_dp['description'], out_dp['description'])
# Check that the link is properly set up # Check that the link is properly set up
self._validate_links(out_dp['links'], in_dp['uuid']) self._validate_links(out_dp['links'], in_dp['uuid'])
@mock.patch('cyborg.objects.DeviceProfile.list') @mock.patch('cyborg.objects.DeviceProfile.list')
def test_get_one_by_uuid(self, mock_dp): def test_get_one_by_uuid(self, mock_dp):
dp = self.fake_dp_objs[0] dp = self.fake_dp_objs[0]
mock_dp.return_value = [dp] mock_dp.return_value = [dp]
url = self.DP_URL + '/%s' url = self.DP_URL + '/%s'
data = self.get_json(url % dp['uuid'], headers=self.headers) data = self.get_json(url % dp['uuid'], headers=self.headers)
skipping to change at line 85 skipping to change at line 86
def test_create(self, mock_cond_dp): def test_create(self, mock_cond_dp):
dp = [self.fake_dps[0]] dp = [self.fake_dps[0]]
mock_cond_dp.return_value = self.fake_dp_objs[0] mock_cond_dp.return_value = self.fake_dp_objs[0]
dp[0]['created_at'] = str(dp[0]['created_at']) dp[0]['created_at'] = str(dp[0]['created_at'])
response = self.post_json(self.DP_URL, dp, headers=self.headers) response = self.post_json(self.DP_URL, dp, headers=self.headers)
out_dp = jsonutils.loads(response.controller_output) out_dp = jsonutils.loads(response.controller_output)
self.assertEqual(HTTPStatus.CREATED, response.status_int) self.assertEqual(HTTPStatus.CREATED, response.status_int)
self._validate_dp(dp[0], out_dp) self._validate_dp(dp[0], out_dp)
def test_create_with_unsupported_trait(self): def test_create_with_no_name(self):
test_unsupport_dp = self.fake_dps[0] test_unsupported_dp = self.fake_dps[0]
# delete dp name for test
del test_unsupported_dp['name']
test_unsupported_dp['created_at'] = str(
test_unsupported_dp['created_at'])
self.assertRaisesRegex(
webtest.app.AppError,
"DeviceProfile name needed.",
self.post_json,
self.DP_URL,
[test_unsupported_dp],
headers=self.headers)
def test_create_with_unsupported_name(self):
test_unsupported_dp = self.fake_dps[0]
# generate special dp name for test
test_unsupported_dp['name'] = '!'
test_unsupported_dp['created_at'] = str(
test_unsupported_dp['created_at'])
self.assertRaisesRegex(
webtest.app.AppError,
".*Device profile name must be of the form *",
self.post_json,
self.DP_URL,
[test_unsupported_dp],
headers=self.headers)
def test_create_with_no_groups(self):
test_unsupported_dp = self.fake_dps[0]
# delete dp groups for test
del test_unsupported_dp['groups']
test_unsupported_dp['created_at'] = str(
test_unsupported_dp['created_at'])
self.assertRaisesRegex(
webtest.app.AppError,
"DeviceProfile needs groups field.",
self.post_json,
self.DP_URL,
[test_unsupported_dp],
headers=self.headers)
def test_create_with_unsupported_group_key(self):
test_unsupported_dp = self.fake_dps[0]
# generate special dp group key for test
del test_unsupported_dp['groups'][0]['resources:FPGA']
test_unsupported_dp['groups'][0]['fake:FPGA'] = 'required'
test_unsupported_dp['created_at'] = str(
test_unsupported_dp['created_at'])
self.assertRaisesRegex(
webtest.app.AppError,
".*Device profile group keys must be of the form *",
self.post_json,
self.DP_URL,
[test_unsupported_dp],
headers=self.headers)
def test_create_with_unsupported_trait_value(self):
test_unsupported_dp = self.fake_dps[0]
# generate special dp trait value for test
test_unsupported_dp['groups'][0][
'trait:CUSTOM_FPGA_INTEL_PAC_ARRIA10'] = 'fake'
test_unsupported_dp['created_at'] = str(
test_unsupported_dp['created_at'])
self.assertRaisesRegex(
webtest.app.AppError,
".*Unsupported trait value fake *",
self.post_json,
self.DP_URL,
[test_unsupported_dp],
headers=self.headers)
def test_create_with_unsupported_trait_name(self):
test_unsupported_dp = self.fake_dps[0]
# generate special trait for test # generate special trait for test
del test_unsupport_dp['groups'][0][ del test_unsupported_dp['groups'][0][
'trait:CUSTOM_FPGA_INTEL_PAC_ARRIA10'] 'trait:CUSTOM_FPGA_INTEL_PAC_ARRIA10']
test_unsupport_dp['groups'][0]['trait:FAKE_TRAIT'] = 'required' test_unsupported_dp['groups'][0]['trait:FAKE_TRAIT'] = 'required'
dp = [test_unsupport_dp] test_unsupported_dp['created_at'] = str(
dp[0]['created_at'] = str(dp[0]['created_at']) test_unsupported_dp['created_at'])
self.assertRaisesRegex( self.assertRaisesRegex(
webtest.app.AppError, webtest.app.AppError,
".*Unsupported trait name format FAKE_TRAIT.*", ".*Unsupported trait name format FAKE_TRAIT.*",
self.post_json, self.post_json,
self.DP_URL, self.DP_URL,
dp, [test_unsupported_dp],
headers=self.headers) headers=self.headers)
@mock.patch('cyborg.conductor.rpcapi.ConductorAPI.device_profile_create') @mock.patch('cyborg.conductor.rpcapi.ConductorAPI.device_profile_create')
def test_create_with_extra_space_in_trait(self, mock_cond_dp): def test_create_with_extra_space_in_trait(self, mock_cond_dp):
test_unsupport_dp = self.fake_dps[0] test_unsupported_dp = self.fake_dps[0]
# generate a requested dp which has extra space in trait # generate a requested dp which has extra space in trait
del test_unsupport_dp['groups'][0][ del test_unsupported_dp['groups'][0][
'trait:CUSTOM_FPGA_INTEL_PAC_ARRIA10'] 'trait:CUSTOM_FPGA_INTEL_PAC_ARRIA10']
test_unsupport_dp['groups'][0][ test_unsupported_dp['groups'][0][
'trait: CUSTOM_FPGA_INTEL_PAC_ARRIA10'] = 'required' 'trait: CUSTOM_FPGA_INTEL_PAC_ARRIA10'] = 'required'
dp = [test_unsupport_dp]
mock_cond_dp.return_value = self.fake_dp_objs[0] mock_cond_dp.return_value = self.fake_dp_objs[0]
dp[0]['created_at'] = str(dp[0]['created_at']) test_unsupported_dp['created_at'] = str(
test_unsupported_dp['created_at'])
response = self.post_json(self.DP_URL, dp, headers=self.headers) response = self.post_json(
self.DP_URL, [test_unsupported_dp], headers=self.headers)
out_dp = jsonutils.loads(response.controller_output) out_dp = jsonutils.loads(response.controller_output)
# check that the extra space in trait: # check that the extra space in trait:
# {'trait: CUSTOM_FPGA_INTEL_PAC_ARRIA10': 'required'} is # {'trait: CUSTOM_FPGA_INTEL_PAC_ARRIA10': 'required'} is
# successful stripped by the _validate_post_request function, and # successful stripped by the _validate_post_request function, and
# the created device_profile has no extra space in trait # the created device_profile has no extra space in trait
# {'trait:CUSTOM_FPGA_INTEL_PAC_ARRIA10': 'required} # {'trait:CUSTOM_FPGA_INTEL_PAC_ARRIA10': 'required}
self.assertTrue(out_dp['groups'] == self.fake_dp_objs[0]['groups']) self.assertTrue(out_dp['groups'] == self.fake_dp_objs[0]['groups'])
@mock.patch('cyborg.conductor.rpcapi.ConductorAPI.device_profile_create') @mock.patch('cyborg.conductor.rpcapi.ConductorAPI.device_profile_create')
def test_create_with_extra_space_in_rc(self, mock_cond_dp): def test_create_with_extra_space_in_rc(self, mock_cond_dp):
test_unsupport_dp = self.fake_dps[0] test_unsupported_dp = self.fake_dps[0]
# generate a requested dp which has extra space in rc # generate a requested dp which has extra space in rc
del test_unsupport_dp['groups'][0]['resources:FPGA'] del test_unsupported_dp['groups'][0]['resources:FPGA']
test_unsupport_dp['groups'][0]['resources: FPGA '] = '1' test_unsupported_dp['groups'][0]['resources: FPGA '] = '1'
dp = [test_unsupport_dp]
mock_cond_dp.return_value = self.fake_dp_objs[0] mock_cond_dp.return_value = self.fake_dp_objs[0]
dp[0]['created_at'] = str(dp[0]['created_at']) test_unsupported_dp['created_at'] = str(
test_unsupported_dp['created_at'])
response = self.post_json(self.DP_URL, dp, headers=self.headers) response = self.post_json(
self.DP_URL, [test_unsupported_dp], headers=self.headers)
out_dp = jsonutils.loads(response.controller_output) out_dp = jsonutils.loads(response.controller_output)
# check that the extra space in rc:{'resources: FPGA ': '1'} is # check that the extra space in rc:{'resources: FPGA ': '1'} is
# successful stripped by the _validate_post_request function, and # successful stripped by the _validate_post_request function, and
# the created device_profile has no extra space in # the created device_profile has no extra space in
# rc:{'resources:FPGA': '1'} # rc:{'resources:FPGA': '1'}
self.assertTrue(out_dp['groups'] == self.fake_dp_objs[0]['groups']) self.assertTrue(out_dp['groups'] == self.fake_dp_objs[0]['groups'])
def test_create_with_unsupported_rc(self): def test_create_with_unsupported_rc(self):
test_unsupport_dp = self.fake_dps[0] test_unsupported_dp = self.fake_dps[0]
# generate a special rc for test # generate a special rc for test
del test_unsupport_dp['groups'][0]['resources:FPGA'] del test_unsupported_dp['groups'][0]['resources:FPGA']
test_unsupport_dp['groups'][0]["resources:FAKE_RC"] = '1' test_unsupported_dp['groups'][0]["resources:FAKE_RC"] = '1'
dp = [test_unsupport_dp] test_unsupported_dp['created_at'] = str(
dp[0]['created_at'] = str(dp[0]['created_at']) test_unsupported_dp['created_at'])
self.assertRaisesRegex( self.assertRaisesRegex(
webtest.app.AppError, webtest.app.AppError,
".*Unsupported resource class FAKE_RC.*", ".*Unsupported resource class FAKE_RC.*",
self.post_json, self.post_json,
self.DP_URL, self.DP_URL,
dp, [test_unsupported_dp],
headers=self.headers) headers=self.headers)
def test_create_with_invalid_resource_value(self): def test_create_with_invalid_resource_value(self):
test_unsupport_dp = self.fake_dps[0] test_unsupported_dp = self.fake_dps[0]
del test_unsupport_dp['groups'][0]['resources:FPGA'] del test_unsupported_dp['groups'][0]['resources:FPGA']
test_unsupport_dp['groups'][0]["resources:CUSTOM_FAKE_RC"] = 'fake' test_unsupported_dp['groups'][0]["resources:CUSTOM_FAKE_RC"] = 'fake'
dp = [test_unsupport_dp] test_unsupported_dp['created_at'] = str(
dp[0]['created_at'] = str(dp[0]['created_at']) test_unsupported_dp['created_at'])
self.assertRaisesRegex( self.assertRaisesRegex(
webtest.app.AppError, webtest.app.AppError,
".*Resources nummber fake is invalid.*", ".*Resources number fake is invalid.*",
self.post_json, self.post_json,
self.DP_URL, self.DP_URL,
dp, [test_unsupported_dp],
headers=self.headers) headers=self.headers)
@mock.patch('cyborg.conductor.rpcapi.ConductorAPI.device_profile_delete') @mock.patch('cyborg.conductor.rpcapi.ConductorAPI.device_profile_delete')
@mock.patch('cyborg.objects.DeviceProfile.get_by_name') @mock.patch('cyborg.objects.DeviceProfile.get_by_name')
@mock.patch('cyborg.objects.DeviceProfile.get_by_uuid') @mock.patch('cyborg.objects.DeviceProfile.get_by_uuid')
def test_delete(self, mock_dp_uuid, mock_dp_name, mock_cond_del): def test_delete(self, mock_dp_uuid, mock_dp_name, mock_cond_del):
# Delete by UUID # Delete by UUID
url = self.DP_URL + "/5d2c0797-c3cd-4f4b-b0d0-2cc5e99ef66e" url = self.DP_URL + "/5d2c0797-c3cd-4f4b-b0d0-2cc5e99ef66e"
response = self.delete(url, headers=self.headers) response = self.delete(url, headers=self.headers)
self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int) self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int)
 End of changes. 22 change blocks. 
32 lines changed or deleted 112 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)