summaryrefslogtreecommitdiff
path: root/ironic/tests/unit
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-05-30 04:47:37 +0000
committerGerrit Code Review <review@openstack.org>2018-05-30 04:47:37 +0000
commit089ea08629f58c550633cd5d1aaac794d58139a8 (patch)
treedc02379c5e8474f09498ec7bb4aad28c5846a51f /ironic/tests/unit
parentb41d62149fe00990ab01a3f58b8e1c731213e663 (diff)
parent254d37033172fb06672fc5743d8b05150208ffb7 (diff)
downloadironic-089ea08629f58c550633cd5d1aaac794d58139a8.tar.gz
Merge "Add Node BIOS support - REST API"
Diffstat (limited to 'ironic/tests/unit')
-rw-r--r--ironic/tests/unit/api/controllers/v1/test_node.py84
-rw-r--r--ironic/tests/unit/objects/utils.py25
2 files changed, 107 insertions, 2 deletions
diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py
index 14c5a9141..228de8c4c 100644
--- a/ironic/tests/unit/api/controllers/v1/test_node.py
+++ b/ironic/tests/unit/api/controllers/v1/test_node.py
@@ -121,6 +121,7 @@ class TestListNodes(test_api_base.BaseApiTest):
self.assertNotIn('traits', data['nodes'][0])
# never expose the chassis_id
self.assertNotIn('chassis_id', data['nodes'][0])
+ self.assertNotIn('bios_interface', data['nodes'][0])
def test_get_one(self):
node = obj_utils.create_test_node(self.context,
@@ -156,6 +157,7 @@ class TestListNodes(test_api_base.BaseApiTest):
self.assertIn('traits', data)
# never expose the chassis_id
self.assertNotIn('chassis_id', data)
+ self.assertIn('bios_interface', data)
def test_get_one_with_json(self):
# Test backward compatibility with guess_content_type_from_ext
@@ -227,6 +229,13 @@ class TestListNodes(test_api_base.BaseApiTest):
headers={api_base.Version.string: '1.36'})
self.assertNotIn('traits', data)
+ def test_node_bios_hidden_in_lower_version(self):
+ node = obj_utils.create_test_node(self.context)
+ data = self.get_json(
+ '/nodes/%s' % node.uuid,
+ headers={api_base.Version.string: '1.39'})
+ self.assertNotIn('bios_interface', data)
+
def test_node_inspect_wait_state_between_api_versions(self):
node = obj_utils.create_test_node(self.context,
provision_state='inspect wait')
@@ -2345,10 +2354,11 @@ class TestPost(test_api_base.BaseApiTest):
self.assertEqual('neutron', result['network_interface'])
def test_create_node_specify_interfaces(self):
- headers = {api_base.Version.string: '1.38'}
+ headers = {api_base.Version.string: '1.40'}
all_interface_fields = api_utils.V31_FIELDS + ['network_interface',
'rescue_interface',
- 'storage_interface']
+ 'storage_interface',
+ 'bios_interface']
for field in all_interface_fields:
if field == 'network_interface':
cfg.CONF.set_override('enabled_%ss' % field, ['flat'])
@@ -2841,6 +2851,14 @@ class TestPost(test_api_base.BaseApiTest):
self.assertEqual('application/json', response.content_type)
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
+ def test_create_node_invalid_bios_interface(self):
+ ndict = test_api_utils.post_get_test_node(bios_interface='foo')
+ response = self.post_json('/nodes', ndict, expect_errors=True,
+ headers={api_base.Version.string:
+ str(api_v1.max_version())})
+ self.assertEqual('application/json', response.content_type)
+ self.assertEqual(http_client.BAD_REQUEST, response.status_int)
+
class TestDelete(test_api_base.BaseApiTest):
@@ -4404,6 +4422,68 @@ class TestAttachDetachVif(test_api_base.BaseApiTest):
self.assertTrue(ret.json['error_message'])
+class TestBIOS(test_api_base.BaseApiTest):
+
+ def setUp(self):
+ super(TestBIOS, self).setUp()
+ self.version = "1.40"
+ self.node = obj_utils.create_test_node(
+ self.context, id=1)
+ self.bios = obj_utils.create_test_bios_setting(self.context,
+ node_id=self.node.id)
+
+ def test_get_all_bios(self):
+ ret = self.get_json('/nodes/%s/bios' % self.node.uuid,
+ headers={api_base.Version.string: self.version})
+
+ expected_json = [
+ {u'created_at': ret['bios'][0]['created_at'],
+ u'updated_at': ret['bios'][0]['updated_at'],
+ u'links': [
+ {u'href': u'http://localhost/v1/nodes/' + self.node.uuid +
+ '/bios/virtualization', u'rel': u'self'},
+ {u'href': u'http://localhost/nodes/' + self.node.uuid +
+ '/bios/virtualization', u'rel': u'bookmark'}], u'name':
+ u'virtualization', u'value': u'on'}]
+ self.assertEqual({u'bios': expected_json}, ret)
+
+ def test_get_all_bios_fails_with_bad_version(self):
+ ret = self.get_json('/nodes/%s/bios' % self.node.uuid,
+ headers={api_base.Version.string: "1.39"},
+ expect_errors=True)
+ self.assertEqual(http_client.NOT_FOUND, ret.status_code)
+
+ def test_get_one_bios(self):
+ ret = self.get_json('/nodes/%s/bios/virtualization' % self.node.uuid,
+ headers={api_base.Version.string: self.version})
+
+ expected_json = {
+ u'virtualization': {
+ u'created_at': ret['virtualization']['created_at'],
+ u'updated_at': ret['virtualization']['updated_at'],
+ u'links': [
+ {u'href': u'http://localhost/v1/nodes/' + self.node.uuid +
+ '/bios/virtualization', u'rel': u'self'},
+ {u'href': u'http://localhost/nodes/' + self.node.uuid +
+ '/bios/virtualization', u'rel': u'bookmark'}],
+ u'name': u'virtualization', u'value': u'on'}}
+ self.assertEqual(expected_json, ret)
+
+ def test_get_one_bios_fails_with_bad_version(self):
+ ret = self.get_json('/nodes/%s/bios/virtualization' % self.node.uuid,
+ headers={api_base.Version.string: "1.39"},
+ expect_errors=True)
+ self.assertEqual(http_client.NOT_FOUND, ret.status_code)
+
+ def test_get_one_bios_fails_if_not_found(self):
+ ret = self.get_json('/nodes/%s/bios/fake_setting' % self.node.uuid,
+ headers={api_base.Version.string: self.version},
+ expect_errors=True)
+ self.assertEqual(http_client.NOT_FOUND, ret.status_code)
+ self.assertIn("fake_setting", ret.json['error_message'])
+ self.assertNotIn(self.node.id, ret.json['error_message'])
+
+
class TestTraits(test_api_base.BaseApiTest):
def setUp(self):
diff --git a/ironic/tests/unit/objects/utils.py b/ironic/tests/unit/objects/utils.py
index 77acd2dd9..99fb6c18d 100644
--- a/ironic/tests/unit/objects/utils.py
+++ b/ironic/tests/unit/objects/utils.py
@@ -230,6 +230,31 @@ def create_test_volume_target(ctxt, **kw):
return volume_target
+def get_test_bios_setting(ctxt, **kw):
+ """Return a BiosSettingList object with appropriate attributes.
+
+ NOTE: The object leaves the attributes marked as changed, such
+ that a create() could be used to commit it to the DB.
+ """
+ kw['object_type'] = 'bios'
+ db_bios_setting = db_utils.get_test_bios_setting(**kw)
+ bios_setting = objects.BIOSSetting(ctxt)
+ for key in db_bios_setting:
+ setattr(bios_setting, key, db_bios_setting[key])
+ return bios_setting
+
+
+def create_test_bios_setting(ctxt, **kw):
+ """Create and return a test bios setting list object.
+
+ Create a BIOS setting list in the DB and return a BIOSSettingList
+ object with appropriate attributes.
+ """
+ bios_setting = get_test_bios_setting(ctxt, **kw)
+ bios_setting.create()
+ return bios_setting
+
+
def get_payloads_with_schemas(from_module):
"""Get the Payload classes with SCHEMAs defined.