DMTF / Redfish-Interface-Emulator

The Redfish Interface Emulator can emulate a Redfish-based interface statically (GET) or dynamically (POST, PATCH, DELETE)
Other
62 stars 25 forks source link

Using for static mockups #55

Closed jomacdon69 closed 5 years ago

jomacdon69 commented 5 years ago

I am really new to this so please be kind... I am seeing the following error when I try to start the Emulator "Traceback (most recent call last): File "emulator.py", line 20, in import g File "/data/Redfish-Interface-Emulator/g.py", line 11, in from flask import Flask ImportError: No module named flask"

Any guidance would be appreciated! Thanks.

billdodd commented 5 years ago

The tool has several third-party python package prerequisites. Installation of python packages is done via pip.

The error you are getting is because one of those prerequisites, Flask, is not installed.

There is a requirements file that comes with this tool specifying all the required packages. The file is packageSets/Env-Local-Python3.5.2_requirements.txt. To install them, go to the directory where you installed the Emulator and run:

pip install -r packageSets/Env-Local-Python3.5.2_requirements.txt 
jomacdon69 commented 5 years ago

Hi Bill, thanks I have it working now... Am I right to think this Emulator can be loaded with static values for me to poll? I have tried a few things but am unable to see the actual data i'm looking for. Finally, my company (and this is why I am looking at this by the way) has recently released a monitoring solution supporting Redfish devices - I would like to poll this emulator with our product and return some data. Thank you!

jcleung5549 commented 5 years ago

The emulator can be used in static mode (just HTTP GETS) by copying in a static mockup into the ./static folder. From the README:

Copying a mockup The location for the static mockup is in the directory ./api_emulator/redfish/static. The emulator comes with a copy of an earlier Redfish mockup. This can be replaced with any new mockup file. If the new mockup has additional resources off the ServiceRoot, then small modifications need to be made in resource_emulator.py to adds these new resources.

Note: the validity of the JSON in the mockup is not tested and will result in error message when you GET the resource. There are plenty of existing tools to check JSON file, beforehand.

jomacdon69 commented 5 years ago

Hi, thanks for your quick reply :) I can see a bunch of directories already in the ./api_emulator/redfish/static location: screenshot from 2019-02-27 15-19-45

jcleung5549 commented 5 years ago

Yes, this is exactly the folders and files you should see. If you traverse the folders, you will see the index.json files which are the mockups for the resources that are returned. The ./static folder holds the entire mockup hierarchy. The Redfish Forum has posted several of their mockups in DSP2043 (https://www.dmtf.org/sites/default/files/DSP2043_1.2.0.zip).

The only index.json file that doesn't exist is the one for ServiceRoot. This because the Emulator generates that GET response on the fly, since Flask intercepts the HTTP requests starting at root. This is programmatic needed when one uses the dynamic resources, that responds to the other HTTP requests (e.g. PATCH, POST, etc.)

jomacdon69 commented 5 years ago

Hi again and thanks for your help! I have removed all the directories from the ./static folder and replaced them with one of the mockups (public-rackmount1), Here is a screen shot of the new directories in the ./static directory: /home/john/Pictures/Screenshot from 2019-02-27 16-27-26.png should I be doing something else to make the new mockup work as I still don't see any values? For example, when I navigate (in the web client) to http://localhost:5000/browse.html and drill into Chassis I cant see the values in the new mockup file. I can see values in the 'Chassis/1U/Power/index'json' file like: Name": "Server Power Control", "PowerConsumedWatts": 344, "PowerRequestedWatts": 800, "PowerAvailableWatts": 0, "PowerCapacityWatts": 800, "PowerAllocatedWatts": 800, "PowerMetrics": { "IntervalInMin": 30, "MinConsumedWatts": 271, "MaxConsumedWatts": 489, "AverageConsumedWatts": 319 Thank you!

jomacdon69 commented 5 years ago
jcleung5549 commented 5 years ago

You should issue an HTTP GET to http://localhost:5000/redfish/v1 (per the Redfish Specification).

ddeel commented 5 years ago

The emulator supports static resources and dynamic resources. Static resources are read-only, meaning you can only use GET operations with them. Dynamic resources respond to POST, PATCH, and DELETE operations, in addition to GET operations.

The only static resources currently being loaded from ./api_emulator/redfish/static are: AccountService, Registries, SessionService, and TaskService.

Chassis and several other resources in the emulator are defined as dynamic resources in ./api_emulator/resource_manager.py. These dynamic resources do not get loaded from ./api_emulator/redfish/static.

resource_manager.py can be edited to turn some (or all) of the dynamic resources into static resources that will be loaded from ./api_emulator/redfish/static. See lines 126-131 in resource_manager.py to see how static resources are loaded.

Note that if you turn some of the dynamic resources into static resources (in your copy of the emulator), then you must also comment out the lines of code that make the corresponding resources dynamic. See lines 137-222 in resource_manager.py to see how dynamic resources are defined by attaching APIs.

It is recommended that you review the emulator README.md file and also the comments within the resource_manager.py file before making any edits to the code.

jomacdon69 commented 5 years ago

Hi, thanks for your help guys... I'm going in circles so I will go back to the start and try again - just one more question while I'm doing that: When I start the emulator, should I expect this comment as it runs "# python emulator.py

jcleung5549 commented 5 years ago

Nope. What are the contents of the emulator-config.json file?

jcleung5549 commented 5 years ago

Specifically, it should include the line - "MODE": "Local"

jomacdon69 commented 5 years ago

Here is the contents of the 'emulator-config.json' file { "MODE": "Local", "HTTPS": "Disable", "SPECS" : "Redfish", "TRAYS": [ "./Resources/Systems/1/index.json" ], "POPULATE": "Emulator" }

ddeel commented 5 years ago

In the emulator-config.json file, "SPECS" should be "SPEC". Other than that, the POPULATE property "Emulator" needs to be a JSON file, and I think the filename needs to include the .json file extension.

I'm assuming you want to use INFRAGEN to populate the emulator, since MOCKUPFOLDERS is not present in the emulator-config.json file.

jomacdon69 commented 5 years ago

Hi again, thank you for the guidance... I have been able to get it running and have been able to Postman - see the results snip-it below: "Name": "Power", "PowerSupplies": [ { "Status": { "State": "Enabled", "Health": "Warning" }, "LastPowerOutputWatts": 192, "Name": "Power Supply Bay 1", "SparePartNumber": "0000001A3a", "SerialNumber": "1z0000001", "MemberId": "0", "@odata.id": "/redfish/v1/Chassis/Chassis-1/Power#/PowerSupplies/0", "LineInputVoltageType": "DCNeg48V", "PowerCapacityWatts": 400, "PowerSupplyType": "DC", "Model": "499253-B21", "RelatedItem": [ { "@odata.id": "/redfish/v1/Chassis/Chassis-1" } ], "LineInputVoltage": -48, "PartNumber": "1z0000001A3a", "FirmwareVersion": "1.00" I am now very happy, I will test this with my monitoring tool tomorrow :)

jcleung5549 commented 5 years ago

Excellent. I commend your diligence.

Did you root cause the original problem? I'd like to add error checking, so your issue could have been debugged more straightforwardly.

jomacdon69 commented 5 years ago

My success came when I replaced the 'emulator-config.json' with the supplied one and didn't modify it - but thank you. I tested the discovery of this Emulator with my monitoring software which I now see needs to authenticate with user/pass combination but te Emulator is running on http not https. I tried to start the Emulator using the command 'python emulator_ssl.py' but it failed :( Here is the error string: "(' * Running in', u'Redfish', 'mode') Traceback (most recent call last): File "emulator_ssl.py", line 386, in main() File "emulator_ssl.py", line 383, in main app.run(kwargs) File "/usr/lib/python2.7/site-packages/flask/app.py", line 841, in run run_simple(host, port, self, options) File "/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 739, in run_simple inner() File "/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 699, in inner fd=fd) File "/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 593, in make_server passthrough_errors, ssl_context, fd=fd) File "/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 528, in init self.socket = ssl_context.wrap_socket(sock, server_side=True) File "/usr/lib/python2.7/site-packages/werkzeug/serving.py", line 450, in wrap_socket ssl_version=self._protocol, **kwargs) File "/usr/lib64/python2.7/ssl.py", line 934, in wrap_socket ciphers=ciphers) File "/usr/lib64/python2.7/ssl.py", line 547, in init self._context.load_cert_chain(certfile, keyfile) IOError: [Errno 2] No such file or directory"

Grrr! Any ideas please?

Thank you!

jcleung5549 commented 5 years ago

A couple of things:

jomacdon69 commented 5 years ago

Hi, THANKS! I have just installed 'yum install httpd' and modified the emulator-config.json. How do I now do the key and cert part please?

jcleung5549 commented 5 years ago

There are sites that will generate self signed key/cert files. You can find them with an internet search. (I prefer not to give a specific URI, less that be view as an endorsement.)

jomacdon69 commented 5 years ago

OK, got the two files :) where do they go specifically and is that all I have to do now? THANKS SO MUCH!

jcleung5549 commented 5 years ago

Place the two files in the same directory as emulator.py.

Thanks for going through this. I wrote the README with full context, so I am sure some details are missing (which I considered intuitively obvious).

jomacdon69 commented 5 years ago

Please don't forget this is my first time on Linux so I am really grateful for all your guidance and maybe now I will be a little better at spotting intuitively obvious stuff - maybe :) I'm going to move the files now and try it!

jomacdon69 commented 5 years ago

OK, I've moved the two files and tried to start the emulator - here is the result:

root@redfish-emulator Redfish-Interface-Emulator]# python emulator.py [u'Redfish']

Any ideas?

jomacdon69 commented 5 years ago

Here is a look in my root folder:

/home/john/Pictures/Screenshot from 2019-03-06 21-53-15.png

jomacdon69 commented 5 years ago

2nd try

screenshot from 2019-03-06 21-53-15

jcleung5549 commented 5 years ago

Rename 81568817_redfish-emulator.cert to server.cert. Rename 81568817_redfish-emulator.key to server.key

billdodd commented 5 years ago

A slight correction: Rename 81568817_redfish-emulator.cert to server.crt. (.crt instead of .cert)

jomacdon69 commented 5 years ago

It failed, then I saw your second post - IT'S NOW WORKING!!!

[root@redfish-emulator Redfish-Interface-Emulator]# ls api_emulator emulator.py packageSets server.crt AUTHORS.md emulator_ssl.py Procfile server.key CHANGELOG.md g.py README.md templates codegen g.pyc requirements.txt test-composed.json doc infragen Resources unittest_data emulator-config.json LICENSE.md runtime.txt unittests.py [root@redfish-emulator Redfish-Interface-Emulator]# python emulator.py [u'Redfish']

jomacdon69 commented 5 years ago

I'm going to test Postman now with authentication... THANK YOU for your perseverance and patience, I am so very HAPPY!

jomacdon69 commented 5 years ago

Working perfectly, thank you just once more!

mraineri commented 5 years ago

Addressed in latest PR