public void Validation_Shall_Pass_When_Complex_Data_Type_Consists_Of_Built_In_Type()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var toscaAsString = @"
tosca_definitions_version: tosca_simple_yaml_1_0
data_types:
  tosca.datatypes.Complex:
    properties:
      real:
        type: integer";

            using (var memoryStream = toscaAsString.ToMemoryStream())
            {
                // Act
                var serviceTemplate = ToscaServiceTemplate.Load(memoryStream);
                cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

                // Assert
                List <ValidationResult> results;
                cloudServiceArchive.TryValidate(out results).Should().BeTrue(string.Join(Environment.NewLine, results));
            }
        }
Esempio n. 2
0
        public void When_Derived_From_Node_Type_Not_Found_Proper_Error_Message_Should_Be_In_Place()
        {
            // Arrange
            var nxosNodeType = new ToscaNodeType {
                DerivedFrom = "cloudshell.nodes.Switch"
            };

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType);

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            // Act
            var    validationResults = new List <ValidationResult>();
            Action action            = () => cloudServiceArchive.TryValidate(out validationResults);

            // Assert
            action.ShouldThrow <ToscaNodeTypeNotFoundException>()
            .WithMessage("Node type 'cloudshell.nodes.Switch' not found");
        }
        public void It_Should_Be_Possible_To_Save_And_Load_Cloud_Service_Archive()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml",
                                                        new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            });

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results)
            .Should()
            .BeTrue(string.Join(Environment.NewLine, results.Select(r => r.ErrorMessage)));

            using (var memoryStream = new MemoryStream())
            {
                cloudServiceArchive.Save(memoryStream);

                var serviceArchive = ToscaCloudServiceArchive.Load(memoryStream);

                // Assert
                serviceArchive.CreatedBy.Should().Be("Anonymous");
            }
        }
        public void IsDerivedFrom_Returns_True_When_Derived_From_Another_Capability_Type()
        {
            // Arrange
            var derivedCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };
            var baseCapabilityType = new ToscaCapabilityType();

            var serviceTemplate = new ToscaServiceTemplate()
            {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.CapabilityTypes.Add("base", baseCapabilityType);
            serviceTemplate.CapabilityTypes.Add("derived", derivedCapabilityType);
            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata {
                CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            List <ValidationResult> validationResults;

            cloudServiceArchive.TryValidate(out validationResults)
            .Should().BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            // Assert
            derivedCapabilityType.IsDerivedFrom("base").Should().BeTrue();
        }
Esempio n. 5
0
        public void Exception_Thrown_When_Cyclic_Dependency_Between_Capability_Types_Exists()
        {
            string toscaServiceTemplate = @"
tosca_definitions_version: tosca_simple_yaml_1_0

capability_types:
    tosca.types.SoftwareComponent:
        derived_from: tosca.types.BasicComponent
    tosca.types.BasicComponent:
        derived_from: tosca.types.SoftwareComponent
";

            var serviceTemplate = ToscaServiceTemplate.Load(toscaServiceTemplate.ToMemoryStream());

            var toscaMetadata = new ToscaMetadata
            {
                CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yml", ToscaMetaFileVersion = new Version(1, 1), CreatedBy = "anonymous"
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yml", serviceTemplate);

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results).Should().BeFalse();
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on CapabilityType: 'tosca.types.BasicComponent'"));
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on CapabilityType: 'tosca.types.SoftwareComponent'"));
        }
Esempio n. 6
0
        public void GetAllProperties_Overrides_Properties_Of_Base_Node_Types()
        {
            // Arrange
            var switchNodeType = new ToscaNodeType();

            switchNodeType.Properties.Add("speed", new ToscaProperty
            {
                Type        = "string",
                Default     = "10MBps",
                Required    = true,
                Description = "switch description",
                Tags        = new List <string>(new [] { "read_only" })
            });
            var nxosNodeType = new ToscaNodeType {
                DerivedFrom = "cloudshell.nodes.Switch"
            };

            nxosNodeType.Properties.Add("speed", new ToscaProperty
            {
                Type        = "string",
                Default     = "1GBps",
                Required    = false,
                Description = "nxos description",
                Tags        = new List <string>(new[] { "admin_only" })
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.NodeTypes.Add("cloudshell.nodes.Switch", switchNodeType);
            serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType);

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            var validationResults = new List <ValidationResult>();

            cloudServiceArchive.TryValidate(out validationResults).Should()
            .BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            var allProperties = nxosNodeType.GetAllProperties();

            // Assert
            allProperties["speed"].Default.Should().Be("1GBps");
            allProperties["speed"].Required.Should().BeFalse();
            allProperties["speed"].Description.Should().Be("nxos description");
            allProperties["speed"].Tags.ShouldAllBeEquivalentTo(new [] { "admin_only" });
        }
        public void GetAllProperties_Description_Should_Not_Be_Overriden_When_Another_Capability_Type_Overrides_It()
        {
            // Arrange
            var simpleCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };

            simpleCapabilityType.Properties.Add("list", new ToscaProperty()
            {
                Type = "list", Default = new object[] {}
            });

            var derivedCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };

            derivedCapabilityType.Properties.Add("description", new ToscaProperty
            {
                Type    = "string",
                Default = "derived description"
            });
            var baseCapabilityType = new ToscaCapabilityType();

            baseCapabilityType.Properties.Add("description", new ToscaProperty
            {
                Type    = "string",
                Default = "base description"
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.CapabilityTypes.Add("base", baseCapabilityType);
            serviceTemplate.CapabilityTypes.Add("derived", derivedCapabilityType);
            serviceTemplate.CapabilityTypes.Add("simple", simpleCapabilityType);
            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata {
                CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            List <ValidationResult> validationResults;

            cloudServiceArchive.TryValidate(out validationResults)
            .Should().BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            var descriptionProperty = derivedCapabilityType.GetAllProperties()["description"];

            descriptionProperty = simpleCapabilityType.GetAllProperties()["description"];

            // Assert
            descriptionProperty.Default.Should().Be("base description");
        }
Esempio n. 8
0
        public void GetAllProperties_Constraints_Are_Merged_From_Base_And_Derived_Node_Type()
        {
            // Arrange
            var serviceTemplate = ToscaServiceTemplate.Load(@"
tosca_definitions_version: tosca_simple_yaml_1_0
metadata:
  template_author: Anonymous
  template_name: TOSCA
  template_version: 1.1
node_types:
  cloudshell.nodes.Switch:
    properties:
      speed:
        type: string
        required: true
        default: 10MBps
        constraints: 
          - valid_values: [10MBps, 100MBps, 1GBps]
  vendor.switch.NXOS:
    derived_from: cloudshell.nodes.Switch
    properties:
      speed:
        type: string
        default: 1mps
        constraints: 
          - max_length: 128
".ToMemoryStream());

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            var validationResults = new List <ValidationResult>();

            cloudServiceArchive.TryValidate(out validationResults).Should()
            .BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            var allProperties = serviceTemplate.NodeTypes["vendor.switch.NXOS"].GetAllProperties();

            // Assert
            allProperties["speed"].Default.Should().Be("1mps");
            var validValues = allProperties["speed"].GetConstraintsDictionary()["valid_values"];

            ((List <object>)validValues).ShouldBeEquivalentTo(new[] { "10MBps", "100MBps", "1GBps" });
            var maxLength = allProperties["speed"].GetConstraintsDictionary()["max_length"];

            maxLength.Should().Be("128");
        }
        public void Validation_Valid_Values_Of_Custom_Data_Type_Should_Pass_If_Proper_Parser_Registered()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1, 2),
                EntryDefinitions     = "definitions.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var definitions = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };
            var complexDataType = new ToscaDataType();
            var realProperty    = new ToscaProperty {
                Type = "float"
            };

            complexDataType.Properties.Add("real", realProperty);
            complexDataType.Properties.Add("imaginary", new ToscaProperty {
                Type = "float"
            });
            definitions.DataTypes.Add("tosca.standard.Complex", complexDataType);

            var complexProperty = new ToscaProperty {
                Type = "tosca.standard.Complex"
            };

            complexProperty.Constraints.Add(new Dictionary <string, object> {
                { "valid_values", new List <object> {
                      "1 + 1i"
                  } }
            });

            var basicNodetype = new ToscaNodeType();

            basicNodetype.Properties.Add("complex", complexProperty);

            definitions.NodeTypes.Add("basic", basicNodetype);
            DependencyResolver.Current.RegisterDataTypeConverter(new CustomDataTypeConverter());
            cloudServiceArchive.AddToscaServiceTemplate("definitions.yaml", definitions);

            // Act
            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results);

            // Assert
            results.Should().BeEmpty();
        }
        public void Exception_Should_Be_Thrown_When_Parser_For_Custom_Data_Type_Not_Defined()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1, 2),
                EntryDefinitions     = "definitions.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var definitions = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };
            var complexDataType = new ToscaDataType();
            var realProperty    = new ToscaProperty {
                Type = "float"
            };

            complexDataType.Properties.Add("real", realProperty);
            complexDataType.Properties.Add("imaginary", new ToscaProperty {
                Type = "float"
            });
            definitions.DataTypes.Add("tosca.standard.Complex", complexDataType);

            var complexProperty = new ToscaProperty {
                Type = "tosca.standard.Complex"
            };

            complexProperty.Constraints.Add(new Dictionary <string, object> {
                { "valid_values", new List <object> {
                      "1 + 1i"
                  } }
            });

            var basicNodetype = new ToscaNodeType();

            basicNodetype.Properties.Add("complex", complexProperty);

            definitions.NodeTypes.Add("basic", basicNodetype);
            cloudServiceArchive.AddToscaServiceTemplate("definitions.yaml", definitions);

            // Act
            List <ValidationResult> results;
            Action action = () => cloudServiceArchive.TryValidate(out results);

            // Assert
            action.ShouldThrow <ToscaDataTypeParserNotFoundException>()
            .WithMessage("Parser for data type 'tosca.standard.Complex' nod found.");
        }
        public void GetAllProperties_Override_Base_Properties()
        {
            // Arrange
            var derivedCapabilityType = new ToscaCapabilityType {
                DerivedFrom = "base"
            };

            derivedCapabilityType.Properties.Add("speed", new ToscaProperty
            {
                Type        = "string",
                Required    = false,
                Default     = "10MBps",
                Description = "derived description"
            });
            var baseCapabilityType = new ToscaCapabilityType();

            baseCapabilityType.Properties.Add("speed", new ToscaProperty
            {
                Type        = "string",
                Required    = true,
                Default     = "",
                Description = "base description"
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.CapabilityTypes.Add("base", baseCapabilityType);
            serviceTemplate.CapabilityTypes.Add("derived", derivedCapabilityType);
            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata {
                CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            List <ValidationResult> validationResults;

            cloudServiceArchive.TryValidate(out validationResults)
            .Should().BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            // Assert
            var speedProperty = derivedCapabilityType.GetAllProperties()["speed"];

            speedProperty.Type.Should().Be("string");
            speedProperty.Required.Should().BeFalse();
            speedProperty.Default.Should().Be("10MBps");
            speedProperty.Description.Should().Be("derived description");
        }
Esempio n. 12
0
        public void GetAllCapabilityTypes_Return_Capability_Types_Of_Base_Node_Type()
        {
            // Arrange
            var switchNodeType = new ToscaNodeType();

            switchNodeType.Capabilities.Add("internet", new ToscaCapability {
                Type = "capabilities.internet"
            });
            var nxosNodeType = new ToscaNodeType {
                DerivedFrom = "cloudshell.nodes.Switch"
            };

            nxosNodeType.Capabilities.Add("storage", new ToscaCapability {
                Type = "capability.storage"
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.NodeTypes.Add("cloudshell.nodes.Switch", switchNodeType);
            serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType);
            serviceTemplate.CapabilityTypes.Add("capabilities.internet", new ToscaCapabilityType());
            serviceTemplate.CapabilityTypes.Add("capability.storage", new ToscaCapabilityType());

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            var validationResults = new List <ValidationResult>();

            cloudServiceArchive.TryValidate(out validationResults).Should()
            .BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            var allCapabilityTypes = nxosNodeType.GetAllCapabilityTypes();

            // Assert
            allCapabilityTypes.Should().HaveCount(3);
            allCapabilityTypes.Should().ContainKey("capability.storage");
            allCapabilityTypes.Should().ContainKey("capabilities.internet");
            allCapabilityTypes.Should().ContainKey("tosca.capabilities.Node");
        }
        TraverseNodeTypesByRequirements_Traverses_Nodes_From_Specific_Node_Type_By_Requirements_Of_Its_Base_Node_Type
            ()
        {
            // Arrange
            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            var deviceNodeType = new ToscaNodeType();

            deviceNodeType.AddRequirement("power", new ToscaRequirement {
                Node = "tosca.nodes.port", Capability = "port"
            });

            var switchNodeType = new ToscaNodeType {
                DerivedFrom = "tosca.nodes.device"
            };

            serviceTemplate.NodeTypes.Add("tosca.nodes.port", new ToscaNodeType());
            serviceTemplate.NodeTypes.Add("tosca.nodes.device", deviceNodeType);
            serviceTemplate.NodeTypes.Add("tosca.nodes.switch", switchNodeType);

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "sample.yaml",
                ToscaMetaFileVersion = new Version(1, 1),
                CreatedBy            = "Anonymous"
            });

            cloudServiceArchive.AddToscaServiceTemplate("sample.yaml", serviceTemplate);

            List <ValidationResult> validationResults;

            cloudServiceArchive.TryValidate(out validationResults)
            .Should().BeTrue(string.Join(Environment.NewLine, validationResults.Select(a => a.ErrorMessage)));

            // Act
            var discoveredNodeTypeNames = new List <string>();

            cloudServiceArchive.TraverseNodeTypesByRequirements("tosca.nodes.switch",
                                                                (nodeTypeName, nodeType) => { discoveredNodeTypeNames.Add(nodeTypeName); });

            // Assert
            discoveredNodeTypeNames.ShouldBeEquivalentTo(new[] { "tosca.nodes.port", "tosca.nodes.switch" });
        }
Esempio n. 14
0
        public void GetAllRequirements_Shall_Not_Fail_When_Derived_And_Base_Node_Type_Have_Requirements_With_Same_Key()
        {
            // Arrange
            var switchNodeType = new ToscaNodeType();

            switchNodeType.AddRequirement("internet", new ToscaRequirement {
                Capability = "wi-fi"
            });
            var nxosNodeType = new ToscaNodeType {
                DerivedFrom = "cloudshell.nodes.Switch"
            };

            nxosNodeType.AddRequirement("internet", new ToscaRequirement {
                Capability = "ssd"
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.NodeTypes.Add("cloudshell.nodes.Switch", switchNodeType);
            serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType);

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            var validationResults = new List <ValidationResult>();

            cloudServiceArchive.TryValidate(out validationResults).Should()
            .BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage)));

            // Act
            var allRequirements = nxosNodeType.GetAllRequirements();

            // Assert
            allRequirements.Should().ContainSingle(r => r.Capability == "ssd");
            allRequirements.Should().ContainSingle(r => r.Capability == "wi-fi");
        }
Esempio n. 15
0
        public void Exception_Thrown_When_Type_On_Derived_NodeType_Differs_From_Base_NodeType()
        {
            // Arrange
            var switchNodeType = new ToscaNodeType();

            switchNodeType.Properties.Add("speed", new ToscaProperty
            {
                Type = "string"
            });
            var nxosNodeType = new ToscaNodeType {
                DerivedFrom = "cloudshell.nodes.Switch"
            };

            nxosNodeType.Properties.Add("speed", new ToscaProperty
            {
                Type = "integer"
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.NodeTypes.Add("cloudshell.nodes.Switch", switchNodeType);
            serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType);

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            // Act
            var validationResults = new List <ValidationResult>();

            cloudServiceArchive.TryValidate(out validationResults);

            // Assert
            validationResults.Should().Contain(r => r.ErrorMessage.Equals("Failed to override property: 'speed', changing the data type is not allowed."));
        }
        public void Validation_Shall_Fail_When_Circular_Dependency_Detected_Between_Imports()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1, 2),
                EntryDefinitions     = "definitions.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var definitions = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            definitions.Imports.Add(new Dictionary <string, ToscaImport> {
                { "import", new ToscaImport {
                      File = "import.yaml"
                  } }
            });

            var import = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            import.Imports.Add(new Dictionary <string, ToscaImport> {
                { "import", new ToscaImport {
                      File = "definitions.yaml"
                  } }
            });

            cloudServiceArchive.AddToscaServiceTemplate("import.yaml", import);
            cloudServiceArchive.AddToscaServiceTemplate("definitions.yaml", definitions);

            // Act
            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results);

            // Assert
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on import \'import.yaml\'"));
        }
        public void It_Should_Be_Possible_To_Save_And_Load_Cloud_Service_Archive_With_Artifacts()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddArtifact("readme.txt", "readme content".ToByteArray(Encoding.ASCII));
            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };
            var nodeType = new ToscaNodeType();

            nodeType.Artifacts.Add("readme", new ToscaArtifact {
                Type = "tosca.artifacts.File", File = "readme.txt"
            });
            serviceTemplate.NodeTypes.Add("some_node", nodeType);
            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results)
            .Should()
            .BeTrue(string.Join(Environment.NewLine, results.Select(r => r.ErrorMessage)));

            using (var memoryStream = new MemoryStream())
            {
                cloudServiceArchive.Save(memoryStream);

                var serviceArchive = ToscaCloudServiceArchive.Load(memoryStream);

                // Assert
                serviceArchive.CreatedBy.Should().Be("Anonymous");
                serviceArchive.GetArtifactBytes("readme.txt")
                .Should()
                .BeEquivalentTo("readme content".ToByteArray(Encoding.ASCII));
            }
        }
        public void AddToscaServiceTemplate_Should_Throw_ArtifactNotFoundException_When_File_Missing_In_Archive()
        {
            // Act
            var fileSystem = new MockFileSystem();

            fileSystem.CreateArchive("tosca.zip", new FileContent[0]);

            var toscaNodeType = new ToscaNodeType();

            toscaNodeType.Artifacts.Add("icon", new ToscaArtifact
            {
                File = "device.png",
                Type = "image"
            });
            var toscaServiceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            toscaServiceTemplate.NodeTypes.Add("device", toscaNodeType);
            var toscaCloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                EntryDefinitions     = "tosca.yaml",
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                ToscaMetaFileVersion = new Version(1, 1)
            });

            // Act
            toscaCloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", toscaServiceTemplate);
            List <ValidationResult> validationResults;

            toscaCloudServiceArchive.TryValidate(out validationResults);

            // Assert
            validationResults.Select(a => a.ErrorMessage).ToArray()
            .ShouldAllBeEquivalentTo(new[] { "Artifact 'device.png' not found in Cloud Service Archive." });

            //action.ShouldThrow<ToscaArtifactNotFoundException>()
            //    .WithMessage("Artifact 'device.png' not found in Cloud Service Archive.");
        }
Esempio n. 19
0
        public void GetAllRequirements_Shall_Not_Throw_Validation_Exception_When_Circular_Dependency_Exists()
        {
            // Arrange
            var portNodeType = new ToscaNodeType();

            portNodeType.AddRequirement("internet", new ToscaRequirement {
                Capability = "tosca.capabilities.Attachment", Node = "vendor.devices.Switch"
            });
            var switchNodetype = new ToscaNodeType();

            switchNodetype.AddRequirement("port", new ToscaRequirement {
                Capability = "tosca.capabilities.Attachment", Node = "vendor.parts.Port"
            });

            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            serviceTemplate.NodeTypes.Add("vendor.parts.Port", portNodeType);
            serviceTemplate.NodeTypes.Add("vendor.devices.Switch", switchNodetype);

            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            // Act
            List <ValidationResult> validationResults;

            cloudServiceArchive.TryValidate(out validationResults);

            // Assert
            validationResults.Should().ContainSingle(r =>
                                                     r.ErrorMessage.Equals("Circular dependency detected by requirements on node type"));
        }
Esempio n. 20
0
        public void Exception_Thrown_When_Cyclic_Dependency_Between_Node_Types_Exists()
        {
            string toscaServiceTemplate = @"
tosca_definitions_version: tosca_simple_yaml_1_0

node_types:
    tosca.nodes.SoftwareComponent:
        derived_from: tosca.nodes.BasicComponent
        properties:
            # domain-specific software component version
            component_version:
                type: version
                required: false
            admin_credential:
                type: tosca.datatypes.Credential
                required: false
    tosca.nodes.BasicComponent:
        derived_from: tosca.nodes.SoftwareComponent
";

            var serviceTemplate = ToscaServiceTemplate.Load(toscaServiceTemplate.ToMemoryStream());

            var toscaMetadata = new ToscaMetadata
            {
                CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yml", ToscaMetaFileVersion = new Version(1, 1), CreatedBy = "anonymous"
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yml", serviceTemplate);

            // Act
            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results);

            // Assert
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on NodeType: 'tosca.nodes.BasicComponent'"));
        }
Esempio n. 21
0
        public void Service_Template_With_Complex_Data_Type_Can_Be_Parsed()
        {
            string toscaServiceTemplate = @"
tosca_definitions_version: tosca_simple_yaml_1_0

node_types:
    tosca.nodes.SoftwareComponent:
        derived_from: tosca.nodes.Root
        properties:
            # domain-specific software component version
            component_version:
                type: version
                required: false
            admin_credential:
                type: tosca.datatypes.Credential
                required: false
        requirements:
        - host:
            capability: tosca.capabilities.Container
            node: tosca.nodes.Compute
            relationship: tosca.relationships.HostedOn";

            var serviceTemplate = ToscaServiceTemplate.Load(toscaServiceTemplate.ToMemoryStream());

            var toscaMetadata = new ToscaMetadata
            {
                CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yml", ToscaMetaFileVersion = new Version(1, 1), CreatedBy = "anonymous"
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yml", serviceTemplate);

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results)
            .Should()
            .BeTrue(string.Join(Environment.NewLine, results.Select(r => r.ErrorMessage)));
        }
        public void Exception_Should_Be_Thrown_When_Complex_Data_Type_Consists_Of_Not_Existing_Type()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var toscaAsString = @"
tosca_definitions_version: tosca_simple_yaml_1_0
data_types:
  tosca.datatypes.Complex:
    properties:
      real:
        type: weight";

            using (var memoryStream = toscaAsString.ToMemoryStream())
            {
                // Act
                var serviceTemplate = ToscaServiceTemplate.Load(memoryStream);
                cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

                List <ValidationResult> results;
                cloudServiceArchive.TryValidate(out results);

                results.Should().HaveCount(1);
                results.Should()
                .Contain(
                    a =>
                    a.ErrorMessage.Contains(
                        "Data type 'weight' specified as part of data type 'tosca.datatypes.Complex' not found."));
            }
        }