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");
            }
        }
Esempio n. 2
0
 protected override void ProcessRecord()
 {
     foreach (var path in Path)
     {
         WriteObject(ToscaCloudServiceArchive.Load(path, ImportPath));
     }
 }
Esempio n. 3
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");
                }
        }
Esempio n. 4
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");
        }
Esempio n. 5
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 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));
            }
        }