public void NodeTypes_Should_Not_Be_Null_Upon_Initialization()
        {
            // Act
            var toscaCloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata());

            // Assert
            toscaCloudServiceArchive.NodeTypes.Should().NotBeNull();
        }
        public void GetArtifactBytes_OnCloudServiceArchive_Without_Artifacts_Should_Throw_ArtifactNotFoundException()
        {
            var toscaCloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata());

            Action action = () => toscaCloudServiceArchive.GetArtifactBytes("not_existing_file.png");

            action.ShouldThrow <ToscaArtifactNotFoundException>()
            .WithMessage("Artifact 'not_existing_file.png' not found in Cloud Service Archive.");
        }
Esempio n. 3
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" });
        }
Esempio n. 4
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 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");
        }
        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. 9
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");
        }
Esempio n. 10
0
        public void Load_Tosca_Cloud_Service_Archive_From_Github()
        {
            using (var tempFile = new TempFile(Path.GetTempPath()))
                using (var client = new WebClient())
                {
                    client.DownloadFile(GithubRepositoryZip, tempFile.FilePath);

                    var toscaCloudServiceArchive = ToscaCloudServiceArchive.Load(tempFile.FilePath);

                    var entryLeafNodeTypes = toscaCloudServiceArchive.GetEntryLeafNodeTypes();
                    entryLeafNodeTypes.Should().HaveCount(1);
                    var nxosNodeType = entryLeafNodeTypes.Single().Value;
                    nxosNodeType.Properties.Should().ContainKey("device_owner");
                }
        }
        public void Node_Type_Without_Derived_From_Should_Have_Root_As_Their_Derived_From()
        {
            // Arrange
            var serviceTemplate = new ToscaServiceTemplate();

            serviceTemplate.NodeTypes.Add("device", new ToscaNodeType());

            // Act
            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata());

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

            // Assert
            cloudServiceArchive.NodeTypes["device"].DerivedFrom.Should().Be("tosca.nodes.Root");
            cloudServiceArchive.NodeTypes["device"].GetDerivedFromEntity().Should().NotBeNull();
        }
        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" });
        }
        public void ToscaMetadata_Should_Not_Be_Null_Upon_Initialization()
        {
            // Act
            var toscaCloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                CreatedBy            = "me",
                CsarVersion          = new Version(1, 12),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(2, 23)
            });

            // Assert
            toscaCloudServiceArchive.CreatedBy.Should().Be("me");
            toscaCloudServiceArchive.CsarVersion.Should().Be(new Version(1, 12));
            toscaCloudServiceArchive.EntryDefinitions.Should().Be("tosca.yaml");
            toscaCloudServiceArchive.ToscaMetaFileVersion.Should().Be(new Version(2, 23));
        }
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 Validation_Should_Not_Pass_When_Archive_With_Cyclic_Reference_Between_Requirements_Is_Loaded()
        {
            // 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, 2, 3),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 1)
            });

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

            byte[] buffer;
            using (var memoryStream = new MemoryStream())
            {
                cloudServiceArchive.Save(memoryStream);
                memoryStream.Flush();
                buffer = memoryStream.GetBuffer();
            }

            // Act
            Action action = () => ToscaCloudServiceArchive.Load(new MemoryStream(buffer));

            // Assert
            action.ShouldThrow <ToscaValidationException>().WithMessage("Circular dependency detected by requirements on node type");
        }
        public void ToscaServiceTemplateAlreadyExistsException_Should_Be_Thrown_When_Same_Service_Template_Added_Twice()
        {
            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("reference1.yml", new ToscaServiceTemplate());
            Action action =
                () => cloudServiceArchive.AddToscaServiceTemplate("reference1.yml", new ToscaServiceTemplate());

            action.ShouldThrow <ToscaServiceTemplateAlreadyExistsException>()
            .WithMessage("Service Template 'reference1.yml' already exists");
        }
Esempio n. 17
0
        public void aaa()
        {
            var mockFileSystem = new MockFileSystem();

            DependencyResolver.Current.Replace <IFileSystem>(mockFileSystem);

            mockFileSystem.AddFile(Path.Combine(Environment.CurrentDirectory, "standard.yaml"),
                                   new MockFileData(@"
tosca_definitions_version: tosca_simple_yaml_1_0"));

            var archiveContent = new[]
            {
                new FileContent("TOSCA.meta",
                                @"
TOSCA-Meta-File-Version: 1.0
CSAR-Version: 1.1
Created-By: OASIS TOSCA TC
Entry-Definitions: definition.yaml
"),

                new FileContent("definition.yaml",
                                @"
tosca_definitions_version: tosca_simple_yaml_1_0
imports:
  - standard: standard.yaml

node_types:
  vendor.switch.NXOS:
    description: Description of NXOS switch
    derived_from: tosca.nodes.Root
    properties:
      device_owner:
        type: string
")
            };

            mockFileSystem.CreateArchive("tosca.zip", archiveContent);

            // Act
            var toscaCloudServiceArchive = ToscaCloudServiceArchive.Load("tosca.zip", Environment.CurrentDirectory);

            // Assert
            toscaCloudServiceArchive.NodeTypes.Should().ContainSingle(a => a.Key == "vendor.switch.NXOS");
        }
        public void GetArtifactBytes_Should_Throw_ArtifactNotFoundException_When_File_Missing_In_Archive()
        {
            // Act
            var toscaServiceTemplate = new ToscaServiceTemplate();
            var toscaNodeType        = new ToscaNodeType();

            toscaServiceTemplate.NodeTypes.Add("device", toscaNodeType);
            var toscaCloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata
            {
                EntryDefinitions = "tosca.yaml"
            });

            // Act
            Action action = () => toscaCloudServiceArchive.GetArtifactBytes("NOT_EXISTING.png");

            // Assert
            action.ShouldThrow <ToscaArtifactNotFoundException>()
            .WithMessage("Artifact 'NOT_EXISTING.png' not found in Cloud Service Archive.");
        }
Esempio n. 19
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 EntryPointServiceTemplate_Returns_EntryDefinitions_Template()
        {
            // Act
            var toscaCloudServiceArchive =
                new ToscaCloudServiceArchive(new ToscaMetadata {
                EntryDefinitions = "tosca1.yaml"
            });

            toscaCloudServiceArchive.AddToscaServiceTemplate("tosca1.yaml",
                                                             new ToscaServiceTemplate {
                Description = "tosca1 description"
            });
            toscaCloudServiceArchive.AddToscaServiceTemplate("base.yaml",
                                                             new ToscaServiceTemplate {
                Description = "base description"
            });

            // Assert
            toscaCloudServiceArchive.GetEntryPointServiceTemplate().Description.Should().Be("tosca1 description");
        }
        public void GetArtifactBytes_Should_Return_Empty_Array_When_File_Is_Empty()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Devil",
                CsarVersion          = new Version(1, 1),
                ToscaMetaFileVersion = new Version(1, 0),
                EntryDefinitions     = "tosca.yaml"
            };

            var toscaCloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            // Act
            toscaCloudServiceArchive.AddArtifact("some_icon.png", "IMAGE".ToByteArray(Encoding.ASCII));

            // Assert
            toscaCloudServiceArchive.GetArtifactBytes("some_icon.png")
            .Should()
            .BeEquivalentTo(new byte[] { 73, 77, 65, 71, 69 });
        }
Esempio n. 24
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"));
        }
        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.");
        }
        public void TraverseNodeTypesByRequirements_Should_Not_Throw_Exception_When_Node_Is_Null()
        {
            // Arrange
            var switchNodeType = new ToscaNodeType();

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

            nxosNodeType.AddRequirement("storage", 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);

            // Act
            Action action = () => cloudServiceArchive.TraverseNodeTypesByRequirements("vendor.switch.NXOS", (a, b) => {});

            // Assert
            action.ShouldNotThrow <Exception>();
        }
Esempio n. 27
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. 28
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 Base_Property_Of_Capability_Type_Is_Capability_Of_Derived_From()
        {
            // Arrange
            var serviceTemplate     = new ToscaServiceTemplate();
            var basicCapabilityType = new ToscaCapabilityType();

            basicCapabilityType.Properties.Add("username", new ToscaProperty {
                Type = "string"
            });
            serviceTemplate.CapabilityTypes.Add("basic", basicCapabilityType);
            serviceTemplate.CapabilityTypes.Add("connectable", new ToscaCapabilityType
            {
                DerivedFrom = "basic"
            });

            // Act
            var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata());

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

            // Assert
            cloudServiceArchive.CapabilityTypes["connectable"].GetDerivedFromEntity().Properties.Should().ContainKey("username");
        }
        public void GetAllProperties_Of_Capability_Type_Deriving_From_A_None_Existing_Capability_Type_Should_Throw_An_Exception()
        {
            // Arrange
            var capabilityType = new ToscaCapabilityType {
                DerivedFrom = "NOT_EXIST"
            };

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

            serviceTemplate.CapabilityTypes.Add("my_cap_type", capabilityType);
            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
            Action action = () => capabilityType.GetAllProperties();

            // Assert
            action.ShouldThrow <ToscaCapabilityTypeNotFoundException>().WithMessage("Capability type 'NOT_EXIST' not found");
        }