-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CheckOptionsAttribute for Param/SNMP/OID@options (#67)
- Loading branch information
1 parent
a2459af
commit f3af4ca
Showing
11 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
Protocol/Error Messages/Protocol/Params/Param/SNMP/OID/CheckOptionsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// <auto-generated>This is auto-generated code by Validator Management Tool. Do not modify.</auto-generated> | ||
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.SNMP.OID.CheckOptionsAttribute | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Skyline.DataMiner.CICD.Models.Protocol.Read; | ||
using Skyline.DataMiner.CICD.Validators.Common.Interfaces; | ||
using Skyline.DataMiner.CICD.Validators.Common.Model; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces; | ||
|
||
internal static class Error | ||
{ | ||
public static IValidationResult EmptyAttribute(IValidate test, IReadable referenceNode, IReadable positionNode, string paramId) | ||
{ | ||
return new ValidationResult | ||
{ | ||
Test = test, | ||
CheckId = CheckId.CheckOptionsAttribute, | ||
ErrorId = ErrorIds.EmptyAttribute, | ||
FullId = "2.76.1", | ||
Category = Category.Param, | ||
Severity = Severity.Warning, | ||
Certainty = Certainty.Certain, | ||
Source = Source.Validator, | ||
FixImpact = FixImpact.NonBreaking, | ||
GroupDescription = "", | ||
Description = String.Format("Empty attribute '{0}' in {1} '{2}'.", "SNMP/OID@options", "Param", paramId), | ||
HowToFix = "", | ||
ExampleCode = "", | ||
Details = "", | ||
HasCodeFix = true, | ||
|
||
PositionNode = positionNode, | ||
ReferenceNode = referenceNode, | ||
}; | ||
} | ||
|
||
public static IValidationResult UntrimmedAttribute(IValidate test, IReadable referenceNode, IReadable positionNode, string paramId, string untrimmedValue) | ||
{ | ||
return new ValidationResult | ||
{ | ||
Test = test, | ||
CheckId = CheckId.CheckOptionsAttribute, | ||
ErrorId = ErrorIds.UntrimmedAttribute, | ||
FullId = "2.76.2", | ||
Category = Category.Param, | ||
Severity = Severity.Warning, | ||
Certainty = Certainty.Certain, | ||
Source = Source.Validator, | ||
FixImpact = FixImpact.NonBreaking, | ||
GroupDescription = "", | ||
Description = String.Format("Untrimmed attribute '{0}' in {1} '{2}'. Current value '{3}'.", "SNMP/OID@options", "Param", paramId, untrimmedValue), | ||
HowToFix = "", | ||
ExampleCode = "", | ||
Details = "", | ||
HasCodeFix = true, | ||
|
||
PositionNode = positionNode, | ||
ReferenceNode = referenceNode, | ||
}; | ||
} | ||
|
||
public static IValidationResult MissingInstanceOption(IValidate test, IReadable referenceNode, IReadable positionNode, string paramId) | ||
{ | ||
return new ValidationResult | ||
{ | ||
Test = test, | ||
CheckId = CheckId.CheckOptionsAttribute, | ||
ErrorId = ErrorIds.MissingInstanceOption, | ||
FullId = "2.76.3", | ||
Category = Category.Param, | ||
Severity = Severity.Major, | ||
Certainty = Certainty.Certain, | ||
Source = Source.Validator, | ||
FixImpact = FixImpact.NonBreaking, | ||
GroupDescription = "", | ||
Description = String.Format("Missing value '{0}' in attribute '{1}'. {2} {3} '{4}'.", "instance", "SNMP/OID@options", "Table", "PID", paramId), | ||
HowToFix = "", | ||
ExampleCode = "", | ||
Details = "The instance option is always required when using the partialSNMP option. If not present, the data in the table can be incomplete or shifted.", | ||
HasCodeFix = true, | ||
|
||
PositionNode = positionNode, | ||
ReferenceNode = referenceNode, | ||
}; | ||
} | ||
} | ||
|
||
internal static class ErrorIds | ||
{ | ||
public const uint EmptyAttribute = 1; | ||
public const uint UntrimmedAttribute = 2; | ||
public const uint MissingInstanceOption = 3; | ||
} | ||
|
||
/// <summary> | ||
/// Contains the identifiers of the checks. | ||
/// </summary> | ||
public static class CheckId | ||
{ | ||
/// <summary> | ||
/// The check identifier. | ||
/// </summary> | ||
public const uint CheckOptionsAttribute = 76; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
Protocol/Tests/Protocol/Params/Param/SNMP/OID/CheckOptionsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.SNMP.OID.CheckOptionsAttribute | ||
{ | ||
using System.Collections.Generic; | ||
|
||
using Skyline.DataMiner.CICD.Models.Protocol.Read; | ||
using Skyline.DataMiner.CICD.Validators.Common.Interfaces; | ||
using Skyline.DataMiner.CICD.Validators.Common.Model; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common.Attributes; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common.Extensions; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Generic; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Helpers; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces; | ||
|
||
[Test(CheckId.CheckOptionsAttribute, Category.Param)] | ||
internal class CheckOptionsAttribute : IValidate, ICodeFix/*, ICompare*/ | ||
{ | ||
public List<IValidationResult> Validate(ValidatorContext context) | ||
{ | ||
List<IValidationResult> results = new List<IValidationResult>(); | ||
|
||
foreach (IParamsParam param in context.EachParamWithValidId()) | ||
{ | ||
if (param.SNMP?.OID == null) | ||
{ | ||
continue; | ||
} | ||
|
||
ValidateHelper helper = new ValidateHelper(this, context, results, param); | ||
|
||
if (helper.ValidateBasics()) | ||
{ | ||
continue; | ||
} | ||
|
||
helper.ValidateInstanceOption(); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
public ICodeFixResult Fix(CodeFixContext context) | ||
{ | ||
CodeFixResult result = new CodeFixResult(); | ||
|
||
if (context.Protocol?.Params == null) | ||
{ | ||
result.Message = "No Params found!"; | ||
return result; | ||
} | ||
|
||
var paramReadNode = (IParamsParam)context.Result.ReferenceNode; | ||
var paramEditNode = context.Protocol.Params.Get(paramReadNode); | ||
if (paramEditNode == null) | ||
{ | ||
result.Message = "No Param Edit Node found!"; | ||
return result; | ||
} | ||
|
||
if (paramEditNode.SNMP == null) | ||
{ | ||
result.Message = "No SNMP tag found."; | ||
return result; | ||
} | ||
|
||
if (paramEditNode.SNMP.OID == null) | ||
{ | ||
result.Message = "No OID tag found."; | ||
return result; | ||
} | ||
|
||
switch (context.Result.ErrorId) | ||
{ | ||
case ErrorIds.EmptyAttribute: | ||
paramEditNode.SNMP.OID.Options = null; | ||
result.Success = true; | ||
break; | ||
|
||
case ErrorIds.UntrimmedAttribute: | ||
// Value is already trimmed | ||
paramEditNode.SNMP.OID.Options = paramReadNode.SNMP.OID.Options.Value; | ||
result.Success = true; | ||
break; | ||
|
||
case ErrorIds.MissingInstanceOption: | ||
if (paramEditNode.SNMP.OID.Options == null) | ||
{ | ||
result.Message = "No options attribute found."; | ||
break; | ||
} | ||
|
||
paramEditNode.SNMP.OID.Options.Value = paramEditNode.SNMP.OID.Options.Value.Insert(0, "instance;"); | ||
result.Success = true; | ||
break; | ||
|
||
default: | ||
result.Message = $"This error ({context.Result.ErrorId}) isn't implemented."; | ||
break; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
////public List<IValidationResult> Compare(MajorChangeCheckContext context) | ||
////{ | ||
//// List<IValidationResult> results = new List<IValidationResult>(); | ||
|
||
//// return results; | ||
////} | ||
} | ||
|
||
internal class ValidateHelper : ValidateHelperBase | ||
{ | ||
private readonly IParamsParam param; | ||
private readonly SnmpOidOptions options; | ||
private readonly IValueTag<string> optionsAttribute; | ||
|
||
public ValidateHelper(IValidate test, ValidatorContext context, List<IValidationResult> results, IParamsParam param) : base(test, context, results) | ||
{ | ||
this.param = param; | ||
optionsAttribute = param.SNMP?.OID?.Options; | ||
options = param.SNMP?.OID?.GetOptions(); | ||
} | ||
|
||
/// <summary> | ||
/// Validates the basics. | ||
/// </summary> | ||
/// <returns>True when nothing further needs to be validated (e.g.: missing attribute).</returns> | ||
public bool ValidateBasics() | ||
{ | ||
(GenericStatus status, string _, string _) = GenericTests.CheckBasics(optionsAttribute, isRequired: true); | ||
|
||
// Missing | ||
if (status.HasFlag(GenericStatus.Missing)) | ||
{ | ||
// No error, but no point in checking further. | ||
return true; | ||
} | ||
|
||
// Empty | ||
if (status.HasFlag(GenericStatus.Empty)) | ||
{ | ||
results.Add(Error.EmptyAttribute(test, param, optionsAttribute, param.Id.RawValue)); | ||
return true; | ||
} | ||
|
||
// Untrimmed | ||
if (status.HasFlag(GenericStatus.Untrimmed)) | ||
{ | ||
results.Add(Error.UntrimmedAttribute(test, param, optionsAttribute, param.Id.RawValue, optionsAttribute.RawValue)); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public void ValidateInstanceOption() | ||
{ | ||
if (options.HasInstance) | ||
{ | ||
// Has instance already. | ||
return; | ||
} | ||
|
||
if (options.PartialSnmp != null) | ||
{ | ||
// Has partialSnmp options specified | ||
results.Add(Error.MissingInstanceOption(test, param, optionsAttribute, param.Id.RawValue)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.