/usr/lib/python2.7/dist-packages/ironicclient/tests/functional/test_json_response.py is in python-ironicclient 2.2.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | # Copyright (c) 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
import jsonschema
from tempest.lib.common.utils import data_utils
from ironicclient.tests.functional import base
def _validate_json(json_response, schema):
"""Verify JSON is valid.
:param json_response: JSON response from CLI
:type json_response: string
:param schema: expected schema of response
:type json_response: dictionary
"""
json_response = json.loads(json_response)
jsonschema.validate(json_response, schema)
class TestNodeJsonResponse(base.FunctionalTestBase):
"""Test JSON responses for node commands."""
node_schema = {
"type": "object",
"properties": {
"target_power_state": {"type": ["string", "null"]},
"extra": {"type": "object"},
"last_error": {"type": ["string", "null"]},
"updated_at": {"type": ["string", "null"]},
"maintenance_reason": {"type": ["string", "null"]},
"provision_state": {"type": "string"},
"clean_step": {"type": "object"},
"uuid": {"type": "string"},
"console_enabled": {"type": "boolean"},
"target_provision_state": {"type": ["string", "null"]},
"raid_config": {"type": "object"},
"provision_updated_at": {"type": ["string", "null"]},
"maintenance": {"type": "boolean"},
"target_raid_config": {"type": "object"},
"inspection_started_at": {"type": ["string", "null"]},
"inspection_finished_at": {"type": ["string", "null"]},
"power_state": {"type": ["string", "null"]},
"driver": {"type": "string"},
"reservation": {"type": ["string", "null"]},
"properties": {"type": "object"},
"instance_uuid": {"type": ["string", "null"]},
"name": {"type": ["string", "null"]},
"driver_info": {"type": "object"},
"created_at": {"type": "string"},
"driver_internal_info": {"type": "object"},
"chassis_uuid": {"type": ["string", "null"]},
"instance_info": {"type": "object"}
},
"patternProperties": {
".*_interface$": {"type": ["string", "null"]}
},
"additionalProperties": True
}
def setUp(self):
super(TestNodeJsonResponse, self).setUp()
self.node = self.create_node()
def test_node_list_json(self):
"""Test JSON response for nodes list."""
schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"instance_uuid": {"type": ["string", "null"]},
"maintenance": {"type": "boolean"},
"name": {"type": ["string", "null"]},
"power_state": {"type": ["string", "null"]},
"provision_state": {"type": "string"},
"uuid": {"type": "string"}}}
}
response = self.ironic('node-list', flags='--json',
params='', parse=False)
_validate_json(response, schema)
def test_node_show_json(self):
"""Test JSON response for node show."""
response = self.ironic('node-show', flags='--json', params='{0}'
.format(self.node['uuid']), parse=False)
_validate_json(response, self.node_schema)
def test_node_validate_json(self):
"""Test JSON response for node validation."""
schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"interface": {"type": ["string", "null"]},
"result": {"type": ["boolean", "null"]},
"reason": {"type": ["string", "null"]}}}
}
response = self.ironic('node-validate', flags='--json',
params='{0}'.format(self.node['uuid']),
parse=False)
_validate_json(response, schema)
def test_node_show_states_json(self):
"""Test JSON response for node show states."""
schema = {
"type": "object",
"properties": {
"target_power_state": {"type": ["string", "null"]},
"target_provision_state": {"type": ["string", "null"]},
"last_error": {"type": ["string", "null"]},
"console_enabled": {"type": "boolean"},
"provision_updated_at": {"type": ["string", "null"]},
"power_state": {"type": ["string", "null"]},
"provision_state": {"type": "string"}
}
}
response = self.ironic('node-show-states', flags='--json',
params='{0}'.format(self.node['uuid']),
parse=False)
_validate_json(response, schema)
def test_node_create_json(self):
"""Test JSON response for node creation."""
schema = {
"type": "object",
"properties": {
"uuid": {"type": "string"},
"driver_info": {"type": "object"},
"extra": {"type": "object"},
"driver": {"type": "string"},
"chassis_uuid": {"type": ["string", "null"]},
"properties": {"type": "object"},
"name": {"type": ["string", "null"]},
}
}
node_name = 'nodejson'
response = self.ironic('node-create', flags='--json',
params='-d fake -n {0}'.format(node_name),
parse=False)
self.addCleanup(self.delete_node, node_name)
_validate_json(response, schema)
def test_node_update_json(self):
"""Test JSON response for node update."""
node_name = data_utils.rand_name('test')
response = self.ironic('node-update', flags='--json',
params='{0} add name={1}'
.format(self.node['uuid'], node_name),
parse=False)
_validate_json(response, self.node_schema)
class TestDriverJsonResponse(base.FunctionalTestBase):
"""Test JSON responses for driver commands."""
def test_driver_list_json(self):
"""Test JSON response for drivers list."""
schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"hosts": {"type": "string"},
}}
}
response = self.ironic('driver-list', flags='--json', parse=False)
_validate_json(response, schema)
def test_driver_show_json(self):
"""Test JSON response for driver show."""
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"hosts": {
"type": "array",
"items": {"type": "string"}}
}
}
drivers_names = self.get_drivers_names()
for driver in drivers_names:
response = self.ironic('driver-show', flags='--json',
params='{0}'.format(driver), parse=False)
_validate_json(response, schema)
def test_driver_properties_json(self):
"""Test JSON response for driver properties."""
schema = {
"type": "object",
"additionalProperties": {"type": "string"}
}
drivers_names = self.get_drivers_names()
for driver in drivers_names:
response = self.ironic('driver-properties', flags='--json',
params='{0}'.format(driver), parse=False)
_validate_json(response, schema)
class TestChassisJsonResponse(base.FunctionalTestBase):
"""Test JSON responses for chassis commands."""
chassis_schema = {
"type": "object",
"properties": {
"uuid": {"type": "string"},
"updated_at": {"type": ["string", "null"]},
"created_at": {"type": "string"},
"description": {"type": ["string", "null"]},
"extra": {"type": "object"}}
}
def setUp(self):
super(TestChassisJsonResponse, self).setUp()
self.chassis = self.create_chassis()
def test_chassis_list_json(self):
"""Test JSON response for chassis list."""
schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"uuid": {"type": "string"},
"description": {"type": ["string", "null"]}}
}
}
response = self.ironic('chassis-list', flags='--json', parse=False)
_validate_json(response, schema)
def test_chassis_show_json(self):
"""Test JSON response for chassis show."""
response = self.ironic('chassis-show', flags='--json',
params='{0}'.format(self.chassis['uuid']),
parse=False)
_validate_json(response, self.chassis_schema)
def test_chassis_create_json(self):
"""Test JSON response for chassis create."""
response = self.ironic('chassis-create', flags='--json', parse=False)
_validate_json(response, self.chassis_schema)
def test_chassis_update_json(self):
"""Test JSON response for chassis update."""
response = self.ironic(
'chassis-update', flags='--json', params='{0} {1} {2}'.format(
self.chassis['uuid'], 'add', 'description=test-chassis'),
parse=False)
_validate_json(response, self.chassis_schema)
def test_chassis_node_list_json(self):
"""Test JSON response for chassis-node-list command."""
schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"instance_uuid": {"type": ["string", "null"]},
"maintenance": {"type": "boolean"},
"name": {"type": ["string", "null"]},
"power_state": {"type": ["string", "null"]},
"provision_state": {"type": "string"},
"uuid": {"type": "string"}}}
}
self.node = self.create_node()
self.update_node(self.node['uuid'], 'add chassis_uuid={0}'
.format(self.chassis['uuid']))
response = self.ironic('chassis-node-list', flags='--json',
params='{0}'.format(self.chassis['uuid']),
parse=False)
_validate_json(response, schema)
|