def test_delete_flavor(self, mock_db_delete_flavor): expected = exception.confirmation( confirm_code="DELETED", confirm_detail="This flavor {0} has been deleted successfully". format("00000000-0000-0000-0000-000000000000")) result = flavors.delete_flavor("00000000-0000-0000-0000-000000000000") self.assertEqual(expected, result)
def set_boot_source(nodeid, request): nodes_url = get_base_resource_url("Nodes") node_url = os.path.normpath("/".join([nodes_url, nodeid])) resp = send_request(node_url) if resp.status_code != http_client.OK: # Raise exception if don't find node raise exception.RedfishException(resp.json(), status_code=resp.status_code) node = resp.json() boot_enabled = request.get("Boot", {}).get("Enabled") boot_target = request.get("Boot", {}).get("Target") allowable_boot_target = \ node["Boot"]["*****@*****.**"] if not boot_enabled or not boot_target: raise exception.BadRequest( detail="The content of set boot source request is malformed. " "Please refer to Valence api specification to correct it.") if boot_enabled not in ["Disabled", "Once", "Continuous"]: raise exception.BadRequest( detail="The parameter Enabled '{0}' is not in allowable list " "['Disabled', 'Once', 'Continuous'].".format(boot_enabled)) if allowable_boot_target and \ boot_target not in allowable_boot_target: raise exception.BadRequest( detail="The parameter Target '{0}' is not in allowable list " "{1}.".format(boot_target, allowable_boot_target)) action_resp = send_request(node_url, 'PATCH', headers={'Content-type': 'application/json'}, json={ "Boot": { "BootSourceOverrideEnabled": boot_enabled, "BootSourceOverrideTarget": boot_target } }) if action_resp.status_code != http_client.NO_CONTENT: raise exception.RedfishException(action_resp.json(), status_code=action_resp.status_code) else: # Set boot source successfully LOG.debug("Set boot source of composed node {0} to '{1}' with enabled " "state '{2}' successfully.".format(nodes_url, boot_target, boot_enabled)) return exception.confirmation( confirm_code="Set Boot Source of Composed Node", confirm_detail="The boot source of composed node has been set to " "'{0}' with enabled state '{1}' successfully.".format( boot_target, boot_enabled))
def delete_composed_node(nodeid): nodes_url = get_base_resource_url("Nodes") delete_url = nodes_url + '/' + str(nodeid) resp = send_request(delete_url, "DELETE") if resp.status_code == http_client.NO_CONTENT: # we should return 200 status code instead of 204, because 204 means # 'No Content', the message in resp_dict will be ignored in that way return exception.confirmation( confirm_code="DELETED", confirm_detail="This composed node has been deleted successfully.") else: raise exception.RedfishException(resp.json(), status_code=resp.status_code)
def test_reset_node_success(self, mock_get_url, mock_request): """Test successfully reset node status""" mock_get_url.return_value = '/redfish/v1/Nodes' fake_node_detail = fakes.mock_request_get(fakes.fake_node_detail(), http_client.OK) fake_node_action_resp = fakes.mock_request_get({}, http_client.NO_CONTENT) mock_request.side_effect = [fake_node_detail, fake_node_action_resp] result = redfish.reset_node("1", {"Reset": {"Type": "On"}}) expected = exception.confirmation( confirm_code="Reset Composed Node", confirm_detail="This composed node has been set to 'On' " "successfully.") self.assertEqual(expected, result)
def reset_node(nodeid, request): nodes_url = get_base_resource_url("Nodes") node_url = os.path.normpath("/".join([nodes_url, nodeid])) resp = send_request(node_url) if resp.status_code != http_client.OK: # Raise exception if don't find node raise exception.RedfishException(resp.json(), status_code=resp.status_code) node = resp.json() action_type = request.get("Reset", {}).get("Type") allowable_actions = node["Actions"]["#ComposedNode.Reset"][ "*****@*****.**"] if not action_type: raise exception.BadRequest( detail="The content of node action request is malformed. Please " "refer to Valence api specification to correct it.") if allowable_actions and action_type not in allowable_actions: raise exception.BadRequest( detail="Action type '{0}' is not in allowable action list " "{1}.".format(action_type, allowable_actions)) target_url = node["Actions"]["#ComposedNode.Reset"]["target"] action_resp = send_request(target_url, 'POST', headers={'Content-type': 'application/json'}, json={"ResetType": action_type}) if action_resp.status_code != http_client.NO_CONTENT: raise exception.RedfishException(action_resp.json(), status_code=action_resp.status_code) else: # Reset node successfully LOG.debug("Post action '{0}' to node {1} successfully.".format( action_type, target_url)) return exception.confirmation( confirm_code="Reset Composed Node", confirm_detail="This composed node has been set to '{0}' " "successfully.".format(action_type))
def test_set_boot_source_success(self, mock_get_url, mock_request): """Test successfully reset node status""" mock_get_url.return_value = '/redfish/v1/Nodes' fake_node_detail = fakes.mock_request_get(fakes.fake_node_detail(), http_client.OK) fake_node_action_resp = fakes.mock_request_get({}, http_client.NO_CONTENT) mock_request.side_effect = [fake_node_detail, fake_node_action_resp] result = redfish.set_boot_source( "1", {"Boot": { "Enabled": "Once", "Target": "Hdd" }}) expected = exception.confirmation( confirm_code="Set Boot Source of Composed Node", confirm_detail="The boot source of composed node has been set to " "'{0}' with enabled state '{1}' successfully.".format( "Hdd", "Once")) self.assertEqual(expected, result)
def delete(self, podm_uuid): podmanagers.delete_podmanager(podm_uuid) resp_dict = exception.confirmation(confirm_detail="DELETED") return utils.make_response(http_client.OK, resp_dict)
def delete_flavor(flavorid): db_api.Connection.delete_flavor(flavorid) return exception.confirmation( confirm_code="DELETED", confirm_detail="This flavor {0} has been deleted successfully".format( flavorid))