Added testcase to verify error exceeding max telemetry reports

Changes:
        - Added testcase 'Verify Error After Exceeding Maximum Report Creation'

Tested:
        - Ran the testcase from sandbox successfully.

Change-Id: I8584a1537b29b70e73ddae6b69f3226915342936

Change-Id: I8268c43025e4f9829ac2b9bb56d43bcb43f7b5f2
Signed-off-by: manashsarma <manashsarma@in.ibm.com>
diff --git a/redfish/telemetry_service/test_telemetry_report.robot b/redfish/telemetry_service/test_telemetry_report.robot
index e34887b..8f58443 100644
--- a/redfish/telemetry_service/test_telemetry_report.robot
+++ b/redfish/telemetry_service/test_telemetry_report.robot
@@ -66,6 +66,28 @@
     ${resp}=  Redfish.Get  ${metric_definition_base_uri}/${report_name}
     Should Be True  '${resp.dict["MetricReportDefinitionType"]}' == 'Periodic'
 
+
+Verify Error After Exceeding Maximum Report Creation
+    [Documentation]  Verify error while creating telemetry report more than max report limit.
+    [Tags]  Verify_Error_After_Exceeding_Maximum_Report_Creation
+
+    ${report_name}=  Set Variable  Testreport
+
+    # Delete any existing reports.
+    Delete All Telemetry Reports
+
+    # Create maximum number of reports.
+    ${resp}=  Redfish.Get Properties  /redfish/v1/TelemetryService
+    FOR  ${i}  IN RANGE  ${resp["MaxReports"]}
+        Create Basic Telemetry Report   Ambient_0_Temp   ${report_name}${i}  success
+    END
+
+    # Attempt another report creation and it should fail.
+    Create Basic Telemetry Report   Ambient_0_Temp   ${report_name}${resp["MaxReports"]}  fail
+
+    # Now delete the reports created.
+    Delete All Telemetry Reports
+
 *** Keywords ***
 
 Suite Setup Execution
@@ -78,3 +100,53 @@
     [Documentation]  Do test teardown operation.
 
     FFDC On Test Case Fail
+
+
+Create Basic Telemetry Report
+    [Documentation]  Create a basic telemetry report with single metric.
+    [Arguments]  ${metric_definition_name}   ${report_name}  ${expected_result}=success
+
+    # Description of argument(s):
+    # metric_definition_name    Name of metric definition like Ambient_0_Temp.
+    # report_name               Name of telemetry report which needs to be created.
+    # expected_result           Expected result of report creation - success or fail.
+
+    ${resp}=  Redfish.Get Properties
+    ...  /redfish/v1/TelemetryService/MetricDefinitions/${metric_definition_name}
+    # Example of response from above Redfish GET request.
+    # "@odata.id": "/redfish/v1/TelemetryService/MetricDefinitions/Ambient_0_Temp",
+    # "@odata.type": "#MetricDefinition.v1_0_3.MetricDefinition",
+    # "Id": "Ambient_0_Temp",
+    # "IsLinear": true,
+    # "MaxReadingRange": 127.0,
+    # "MetricDataType": "Decimal",
+    # "MetricProperties": [
+    #     "/redfish/v1/Chassis/chassis/Sensors/temperature_Ambient_0_Temp"
+    # ],
+    # "MetricType": "Gauge",
+    # "MinReadingRange": -128.0,
+    # "Name": "Ambient_0_Temp",
+    # "Units": "Cel"
+
+    ${body}=  Catenate  {"Id": "${report_name}",
+    ...  "MetricReportDefinitionType": "OnRequest",
+    ...  "ReportActions":["LogToMetricReportsCollection"],
+    ...  "Metrics":[{"MetricProperties":${resp["MetricProperties"]}}]}
+    ${body}=  Replace String  ${body}  '  "
+    ${dict}  Evaluate  json.loads('''${body}''')  json
+
+    ${status_code_expected}=  Set Variable If
+    ...  '${expected_result}' == 'success'  [${HTTP_CREATED}]
+    ...  '${expected_result}' == 'fail'  [${HTTP_BAD_REQUEST}]
+
+    Redfish.Post  ${metric_definition_base_uri}  body=&{dict}
+     ...  valid_status_codes=${status_code_expected}
+
+
+Delete All Telemetry Reports
+    [Documentation]  Delete all existing telemetry reports.
+
+    ${report_list}=  Redfish_Utils.Get Member List  /redfish/v1/TelemetryService/MetricReportDefinitions
+    FOR  ${report}  IN  @{report_list}
+      Redfish.Delete  ${report}  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
+    END