public void TestNoVolMountForNonUds()
        {
            // Arrange
            var runtimeInfo = new Mock <IRuntimeInfo <DockerRuntimeConfig> >();

            runtimeInfo.SetupGet(ri => ri.Config).Returns(new DockerRuntimeConfig("1.24", string.Empty));

            var module = new Mock <IModule <DockerConfig> >();

            module.SetupGet(m => m.Config).Returns(new DockerConfig("nginx:latest"));
            module.SetupGet(m => m.Name).Returns(Constants.EdgeAgentModuleName);

            IConfigurationRoot configRoot = new ConfigurationBuilder().AddInMemoryCollection(
                new Dictionary <string, string>
            {
                { Constants.EdgeletWorkloadUriVariableName, "http://localhost:2375/" },
                { Constants.EdgeletManagementUriVariableName, "http://localhost:2376/" }
            }).Build();
            var configSource = Mock.Of <IConfigSource>(s => s.Configuration == configRoot);
            ICombinedConfigProvider <CombinedDockerConfig> provider = new CombinedEdgeletConfigProvider(new[] { new AuthConfig() }, configSource);

            // Act
            CombinedDockerConfig config = provider.GetCombinedConfig(module.Object, runtimeInfo.Object);

            // Assert
            Assert.NotNull(config.CreateOptions);
            Assert.Null(config.CreateOptions.HostConfig);
        }
        public void InjectNetworkAlias_EdgeHubTest()
        {
            // Arrange
            var runtimeInfo = new Mock <IRuntimeInfo <DockerRuntimeConfig> >();

            runtimeInfo.SetupGet(ri => ri.Config).Returns(new DockerRuntimeConfig("1.24", string.Empty));

            var module = new Mock <IModule <DockerConfig> >();

            module.SetupGet(m => m.Config).Returns(new DockerConfig("nginx:latest"));
            module.SetupGet(m => m.Name).Returns(Constants.EdgeHubModuleName);

            IConfigurationRoot configRoot = new ConfigurationBuilder().AddInMemoryCollection(
                new Dictionary <string, string>
            {
                { Constants.EdgeletWorkloadUriVariableName, "unix:///var/run/iotedgedworkload.sock" },
                { Constants.EdgeletManagementUriVariableName, "unix:///var/run/iotedgedmgmt.sock" },
                { Constants.NetworkIdKey, "testnetwork1" },
                { Constants.EdgeDeviceHostNameKey, "edhk1" }
            }).Build();
            var configSource = Mock.Of <IConfigSource>(s => s.Configuration == configRoot);

            ICombinedConfigProvider <CombinedDockerConfig> provider = new CombinedEdgeletConfigProvider(new[] { new AuthConfig() }, configSource);

            // Act
            CombinedDockerConfig config = provider.GetCombinedConfig(module.Object, runtimeInfo.Object);

            // Assert
            Assert.NotNull(config.CreateOptions);
            Assert.NotNull(config.CreateOptions.NetworkingConfig);
            Assert.NotNull(config.CreateOptions.NetworkingConfig.EndpointsConfig);
            Assert.NotNull(config.CreateOptions.NetworkingConfig.EndpointsConfig["testnetwork1"]);
            Assert.Equal("edhk1", config.CreateOptions.NetworkingConfig.EndpointsConfig["testnetwork1"].Aliases[0]);
        }
        public void ExtensionDataFields_BackwardCompatibility_LowercaseToUppercase()
        {
            // Arrange
            var runtimeInfo = new Mock <IRuntimeInfo <DockerRuntimeConfig> >();

            runtimeInfo.SetupGet(ri => ri.Config).Returns(new DockerRuntimeConfig("1.24", string.Empty));

            // capabilities will remain lowercase because there is no backward compatibility issue for those properties supported after 1.0.9
            string createOptions = "{\"HostConfig\":{\"portBindings\":{\"8883/tcp\":[{\"hostPort\":\"8883\"}]},\"Devices\":[],\"runtime\":\"nvidia\",\"DeviceRequests\":[{\"Driver\":\"\",\"Count\":-1,\"DeviceIDs\":null,\"capabilities\":[[\"gpu\"]],\"Options\":{}}]}}";
            var    module        = new Mock <IModule <DockerConfig> >();

            module.SetupGet(m => m.Config).Returns(new DockerConfig("nginx:latest", createOptions, Option.None <string>()));
            module.SetupGet(m => m.Name).Returns("mod1");

            IConfigurationRoot configRoot = new ConfigurationBuilder().AddInMemoryCollection(
                new Dictionary <string, string>
            {
                { Constants.EdgeletWorkloadUriVariableName, "unix:///var/run/iotedgedworkload.sock" },
                { Constants.EdgeletManagementUriVariableName, "unix:///var/run/iotedgedmgmt.sock" },
                { Constants.NetworkIdKey, "testnetwork1" },
                { Constants.EdgeDeviceHostNameKey, "edhk1" }
            }).Build();
            var configSource = Mock.Of <IConfigSource>(s => s.Configuration == configRoot);

            ICombinedConfigProvider <CombinedDockerConfig> provider = new CombinedEdgeletConfigProvider(new[] { new AuthConfig() }, configSource);

            // Act
            CombinedDockerConfig config = provider.GetCombinedConfig(module.Object, runtimeInfo.Object);

            // Assert
            Assert.NotNull(config.CreateOptions);
            Assert.NotNull(config.CreateOptions.HostConfig);

            var otherProperties = config.CreateOptions.HostConfig.OtherProperties;

            Assert.NotNull(otherProperties);

            var reserializedHostConfig = Newtonsoft.Json.JsonConvert.SerializeObject(config.CreateOptions.HostConfig);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.Equal(
                    "{\"Binds\":[\"\\\\var\\\\run:\\\\var\\\\run\"],\"PortBindings\":{\"8883/tcp\":[{\"HostPort\":\"8883\"}]},\"Devices\":[],\"Runtime\":\"nvidia\",\"DeviceRequests\":[{\"Driver\":\"\",\"Count\":-1,\"DeviceIDs\":null,\"capabilities\":[[\"gpu\"]],\"Options\":{}}]}",
                    reserializedHostConfig);
            }
            else
            {
                Assert.Equal(
                    "{\"Binds\":[\"/var/run/iotedgedworkload.sock:/var/run/iotedgedworkload.sock\"],\"PortBindings\":{\"8883/tcp\":[{\"HostPort\":\"8883\"}]},\"Devices\":[],\"Runtime\":\"nvidia\",\"DeviceRequests\":[{\"Driver\":\"\",\"Count\":-1,\"DeviceIDs\":null,\"capabilities\":[[\"gpu\"]],\"Options\":{}}]}",
                    reserializedHostConfig);
            }
        }
        public void TestVolMount()
        {
            // Arrange
            var runtimeInfo = new Mock <IRuntimeInfo <DockerRuntimeConfig> >();

            runtimeInfo.SetupGet(ri => ri.Config).Returns(new DockerRuntimeConfig("1.24", string.Empty));

            var module = new Mock <IModule <DockerConfig> >();

            module.SetupGet(m => m.Config).Returns(new DockerConfig("nginx:latest"));
            module.SetupGet(m => m.Name).Returns(Constants.EdgeAgentModuleName);

            var unixUris = new Dictionary <string, string>
            {
                { Constants.EdgeletWorkloadUriVariableName, "unix:///path/to/workload.sock" },
                { Constants.EdgeletManagementUriVariableName, "unix:///path/to/mgmt.sock" }
            };

            var windowsUris = new Dictionary <string, string>
            {
                { Constants.EdgeletWorkloadUriVariableName, "unix:///C:/path/to/workload/sock" },
                { Constants.EdgeletManagementUriVariableName, "unix:///C:/path/to/mgmt/sock" }
            };

            IConfigurationRoot configRoot = new ConfigurationBuilder().AddInMemoryCollection(
                RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? windowsUris : unixUris
                ).Build();
            var configSource = Mock.Of <IConfigSource>(s => s.Configuration == configRoot);
            ICombinedConfigProvider <CombinedDockerConfig> provider = new CombinedEdgeletConfigProvider(new[] { new AuthConfig() }, configSource);

            // Act
            CombinedDockerConfig config = provider.GetCombinedConfig(module.Object, runtimeInfo.Object);

            // Assert
            Assert.NotNull(config.CreateOptions);
            Assert.NotNull(config.CreateOptions.HostConfig);
            Assert.NotNull(config.CreateOptions.HostConfig.Binds);
            Assert.Equal(2, config.CreateOptions.HostConfig.Binds.Count);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.Equal("C:\\path\\to\\workload:C:\\path\\to\\workload", config.CreateOptions.HostConfig.Binds[0]);
                Assert.Equal("C:\\path\\to\\mgmt:C:\\path\\to\\mgmt", config.CreateOptions.HostConfig.Binds[1]);
            }
            else
            {
                Assert.Equal("/path/to/workload.sock:/path/to/workload.sock", config.CreateOptions.HostConfig.Binds[0]);
                Assert.Equal("/path/to/mgmt.sock:/path/to/mgmt.sock", config.CreateOptions.HostConfig.Binds[1]);
            }
        }
示例#5
0
        public void TestAddNewRootKeyRegistryCredential()
        {
            var runtimeConfig = new DockerRuntimeConfig(
                "1.0",
                new Dictionary <string, RegistryCredentials>
            {
                ["r1"] = new RegistryCredentials("mcr.microsoft.com", "foo", "foo", "credential")
            });

            var runtimeInfo = new DockerRuntimeInfo("docker", runtimeConfig);

            var module = new Mock <IModule <DockerConfig> >();

            module.SetupGet(m => m.Config).Returns(new DockerConfig("mcr.microsoft.com/windows/nanoserver:1809"));
            module.SetupGet(m => m.Name).Returns(Constants.EdgeAgentModuleName);

            var unixUris = new Dictionary <string, string>
            {
                { Constants.EdgeletWorkloadUriVariableName, "unix:///path/to/workload.sock" },
                { Constants.EdgeletManagementUriVariableName, "unix:///path/to/mgmt.sock" }
            };

            var windowsUris = new Dictionary <string, string>
            {
                { Constants.EdgeletWorkloadUriVariableName, "unix:///C:/path/to/workload/sock" },
                { Constants.EdgeletManagementUriVariableName, "unix:///C:/path/to/mgmt/sock" }
            };

            IConfigurationRoot configRoot = new ConfigurationBuilder().AddInMemoryCollection(
                RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? windowsUris : unixUris).Build();
            var configSource = Mock.Of <IConfigSource>(s => s.Configuration == configRoot);
            var authConfig   = new AuthConfig {
                ServerAddress = "mcr.microsoft.com"
            };
            ICombinedConfigProvider <CombinedDockerConfig> provider = new CombinedEdgeletConfigProvider(new[] { authConfig }, configSource);

            var             systemInfoSample = new SystemInfo("linux", "x86", "1");
            var             moduleManager    = Mock.Of <IModuleManager>(m => m.GetSystemInfoAsync(CancellationToken.None) == Task.FromResult(systemInfoSample));
            ICommandFactory factory          = new EdgeletCommandFactory <CombinedDockerConfig>(moduleManager, configSource, provider);
            // Act
            CombinedDockerConfig config = provider.GetCombinedConfig(module.Object, runtimeInfo);

            // Assert
            Assert.Equal("credential", config.AuthConfig.OrDefault().RegistryToken);
        }