public KubernetesModule( string name, string version, string type, ModuleStatus status, RestartPolicy restartPolicy, ConfigurationInfo configurationInfo, IDictionary <string, EnvVal> env, CombinedDockerConfig settings, ImagePullPolicy imagePullPolicy) { this.Name = name; this.Version = version; this.Type = type; this.DesiredStatus = status; this.RestartPolicy = restartPolicy; this.ConfigurationInfo = configurationInfo; this.Env = env?.ToImmutableDictionary() ?? ImmutableDictionary <string, EnvVal> .Empty; this.Config = settings; this.ImagePullPolicy = imagePullPolicy; }
public TestModuleBase( string name, string version, string type, ModuleStatus desiredStatus, TConfig config, RestartPolicy restartPolicy, ImagePullPolicy imagePullPolicy, ConfigurationInfo configuration, IDictionary <string, EnvVal> env) { this.Name = name; this.Version = Preconditions.CheckNotNull(version, nameof(version)); this.Type = Preconditions.CheckNotNull(type, nameof(type)); this.DesiredStatus = Preconditions.CheckNotNull(desiredStatus, nameof(desiredStatus)); this.Config = Preconditions.CheckNotNull(config, nameof(config)); this.RestartPolicy = Preconditions.CheckIsDefined(restartPolicy); this.ImagePullPolicy = Preconditions.CheckIsDefined(imagePullPolicy); this.ConfigurationInfo = configuration ?? new ConfigurationInfo(); this.Env = env?.ToImmutableDictionary() ?? ImmutableDictionary <string, EnvVal> .Empty; }
public DockerModule( string name, string version, ModuleStatus desiredStatus, RestartPolicy restartPolicy, DockerConfig config, ImagePullPolicy imagePullPolicy, uint priority, ConfigurationInfo configurationInfo, IDictionary <string, EnvVal> env) { this.Name = name; this.Version = version ?? string.Empty; this.DesiredStatus = Preconditions.CheckIsDefined(desiredStatus); this.Config = Preconditions.CheckNotNull(config, nameof(config)); this.RestartPolicy = Preconditions.CheckIsDefined(restartPolicy); this.ImagePullPolicy = Preconditions.CheckIsDefined(imagePullPolicy); this.Priority = priority; this.ConfigurationInfo = configurationInfo ?? new ConfigurationInfo(string.Empty); this.Env = env?.ToImmutableDictionary() ?? ImmutableDictionary <string, EnvVal> .Empty; }
public EdgeAgentDockerRuntimeModule( DockerConfig config, ModuleStatus runtimeStatus, int exitCode, string statusDescription, DateTime lastStartTimeUtc, DateTime lastExitTime, ImagePullPolicy imagePullPolicy, ConfigurationInfo configuration, IDictionary <string, EnvVal> env, string version = "") : base( Core.Constants.EdgeAgentModuleName, version, ModuleStatus.Running, RestartPolicy.Always, config, exitCode, statusDescription, lastStartTimeUtc, lastExitTime, 0, DateTime.MinValue, runtimeStatus, imagePullPolicy, configuration, env) { // You maybe wondering why we are setting this here again even though // the base class does this assignment. This is due to a behavior // in C# where if you have an assignment to a read-only virtual property // from a base constructor when it has been overriden in a sub-class, the // assignment becomes a no-op. In order to fix this we need to assign // this here again so that the correct property assignment happens for real! this.RestartPolicy = RestartPolicy.Always; this.DesiredStatus = ModuleStatus.Running; this.RestartCount = 0; this.LastRestartTimeUtc = DateTime.MinValue; this.Version = version ?? string.Empty; }
DockerRuntimeModule( string name, string version, string type, ModuleStatus status, RestartPolicy restartPolicy, DockerConfig config, int?exitCode, string statusDescription, DateTime lastStartTimeUtc, DateTime lastExitTimeUtc, int restartCount, DateTime lastRestartTimeUtc, ModuleStatus runtimeStatus, ImagePullPolicy imagePullPolicy, uint priority, ConfigurationInfo configurationInfo, IDictionary <string, EnvVal> env, IDictionary <string, string> secrets) : this( name, version, status, restartPolicy, config, exitCode ?? 0, statusDescription, lastStartTimeUtc, lastExitTimeUtc, restartCount, lastRestartTimeUtc, runtimeStatus, imagePullPolicy, priority, configurationInfo, env, secrets) { Preconditions.CheckArgument(type?.Equals("docker") ?? false); }
internal CreateOrUpdateCommandTestData( string moduleName, string moduleType, ImagePullPolicy imagePullPolicy, Dictionary <string, EnvVal> environmentVariables, string deviceId, string moduleId, string edgeletWorkloadUri, string moduleGenerationId, string edgeletAuthScheme, string iotHubHostname, string edgeDeviceHostname, Option <string> parentEdgeHostname, string upstreamProtocol, string edgeletManagementUri, string networkId, string edgeletApiVersion, object settings) { this.ModuleName = Preconditions.CheckNonWhiteSpace(moduleName, nameof(moduleName)); this.ModuleType = Preconditions.CheckNonWhiteSpace(moduleType, nameof(moduleType)); this.ImagePullPolicy = imagePullPolicy; this.EnvironmentVariables = Preconditions.CheckNotNull(environmentVariables, nameof(environmentVariables)); this.DeviceId = Preconditions.CheckNonWhiteSpace(deviceId, nameof(deviceId)); this.ModuleId = Preconditions.CheckNonWhiteSpace(moduleId, nameof(moduleId)); this.EdgeletWorkloadUri = Preconditions.CheckNonWhiteSpace(edgeletWorkloadUri, nameof(edgeletWorkloadUri)); this.ModuleGenerationId = Preconditions.CheckNonWhiteSpace(moduleGenerationId, nameof(moduleGenerationId)); this.EdgeletAuthScheme = Preconditions.CheckNonWhiteSpace(edgeletAuthScheme, nameof(edgeletAuthScheme)); this.IoTHubHostname = Preconditions.CheckNonWhiteSpace(iotHubHostname, nameof(iotHubHostname)); this.EdgeDeviceHostname = Preconditions.CheckNonWhiteSpace(edgeDeviceHostname, nameof(edgeDeviceHostname)); this.ParentEdgeHostname = parentEdgeHostname; this.UpstreamProtocol = Preconditions.CheckNonWhiteSpace(upstreamProtocol, nameof(upstreamProtocol)); this.EdgeletManagementUri = Preconditions.CheckNonWhiteSpace(edgeletManagementUri, nameof(edgeletManagementUri)); this.NetworkId = Preconditions.CheckNonWhiteSpace(networkId, nameof(networkId)); this.EdgeletApiVersion = Preconditions.CheckNonWhiteSpace(edgeletApiVersion, nameof(edgeletApiVersion)); this.Settings = settings; this.ModuleCredentials = new IdentityProviderServiceCredentials(this.EdgeletWorkloadUri, this.ModuleGenerationId, this.EdgeletAuthScheme); }
public KubernetesModule( string name, string version, string type, ModuleStatus status, RestartPolicy restartPolicy, ConfigurationInfo configurationInfo, IDictionary <string, EnvVal> env, KubernetesConfig settings, ImagePullPolicy imagePullPolicy, KubernetesModuleOwner owner) { this.Name = name; this.Version = version; this.Type = type; this.DesiredStatus = status; this.RestartPolicy = restartPolicy; this.ConfigurationInfo = configurationInfo ?? new ConfigurationInfo(string.Empty); this.Env = env?.ToImmutableDictionary() ?? ImmutableDictionary <string, EnvVal> .Empty; this.Config = settings; this.ImagePullPolicy = imagePullPolicy; this.StartupOrder = Core.Constants.DefaultStartupOrder; this.Owner = owner; }
public ModuleSpec(string name, string type, ImagePullPolicy imagePullPolicy, object settings) : this(name, type, imagePullPolicy, settings, new List <EnvVar>()) { }
public NonDockerModule(string name, string version, string type, ModuleStatus desiredStatus, global::Microsoft.Azure.Devices.Edge.Agent.Core.RestartPolicy restartPolicy, ImagePullPolicy imagePullPolicy, ConfigurationInfo configurationInfo, IDictionary <string, EnvVal> env, string config) { this.Name = name; this.Version = version; this.Type = type; this.DesiredStatus = desiredStatus; this.RestartPolicy = restartPolicy; this.ImagePullPolicy = imagePullPolicy; this.ConfigurationInfo = configurationInfo; this.Env = env; this.Config = config; }
public ImagePullPolicyTestConfig(ImagePullPolicy imagePullPolicy, bool pullImage) { this.ImagePullPolicy = imagePullPolicy; this.PullImage = pullImage; }
public async Task AgentStartsUpModules(TestConfig testConfig) { // Build the docker host URL. string dockerHostUrl = ConfigHelper.TestConfig["dockerHostUrl"]; DockerClient client = new DockerClientConfiguration(new Uri(dockerHostUrl)).CreateClient(); try { // Remove any running containers with the same name that may be a left-over // from previous test runs. await RemoveContainer(client, testConfig); // Remove old images and pull a new image if specified in the test config. await PullImage(client, testConfig); // Initialize docker configuration for this module. DockerConfig dockerConfig = testConfig.ImageCreateOptions != null ? new DockerConfig(testConfig.Image, testConfig.ImageCreateOptions) : new DockerConfig(testConfig.Image); ImagePullPolicy imagePullPolicy = ImagePullPolicy.OnCreate; testConfig.ImagePullPolicyTestConfig.ForEach(p => imagePullPolicy = p.ImagePullPolicy); // Initialize an Edge Agent module object. var dockerModule = new DockerModule( testConfig.Name, testConfig.Version, ModuleStatus.Running, global::Microsoft.Azure.Devices.Edge.Agent.Core.RestartPolicy.OnUnhealthy, dockerConfig, imagePullPolicy, null, null); var modules = new Dictionary <string, IModule> { [testConfig.Name] = dockerModule }; var systemModules = new SystemModules(null, null); // Start up the agent and run a "reconcile". var dockerLoggingOptions = new Dictionary <string, string> { { "max-size", "1m" }, { "max-file", "1" } }; var loggingConfig = new DockerLoggingConfig("json-file", dockerLoggingOptions); string sharedAccessKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")); IConfigurationRoot configRoot = new ConfigurationBuilder().AddInMemoryCollection( new Dictionary <string, string> { { "DeviceConnectionString", $"Hostname=fakeiothub;Deviceid=test;SharedAccessKey={sharedAccessKey}" } }).Build(); var runtimeConfig = new DockerRuntimeConfig("1.24.0", "{}"); var runtimeInfo = new DockerRuntimeInfo("docker", runtimeConfig); var deploymentConfigInfo = new DeploymentConfigInfo(1, new DeploymentConfig("1.0", runtimeInfo, systemModules, modules)); var configSource = new Mock <IConfigSource>(); configSource.Setup(cs => cs.Configuration).Returns(configRoot); configSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()).ReturnsAsync(deploymentConfigInfo); // TODO: Fix this up with a real reporter. But before we can do that we need to use // the real configuration source that talks to IoT Hub above. NullReporter reporter = NullReporter.Instance; var restartStateStore = Mock.Of <IEntityStore <string, ModuleState> >(); var configStore = Mock.Of <IEntityStore <string, string> >(); var deploymentConfigInfoSerde = Mock.Of <ISerde <DeploymentConfigInfo> >(); IRestartPolicyManager restartManager = new Mock <IRestartPolicyManager>().Object; var dockerCommandFactory = new DockerCommandFactory(client, loggingConfig, configSource.Object, new CombinedDockerConfigProvider(Enumerable.Empty <AuthConfig>())); IRuntimeInfoProvider runtimeInfoProvider = await RuntimeInfoProvider.CreateAsync(client); IEnvironmentProvider environmentProvider = await DockerEnvironmentProvider.CreateAsync(runtimeInfoProvider, restartStateStore, restartManager); var logFactoryMock = new Mock <ILoggerFactory>(); var logMock = new Mock <ILogger <LoggingCommandFactory> >(); logFactoryMock.Setup(l => l.CreateLogger(It.IsAny <string>())) .Returns(logMock.Object); var commandFactory = new LoggingCommandFactory(dockerCommandFactory, logFactoryMock.Object); var credential = new ConnectionStringCredentials("fake"); var identity = new Mock <IModuleIdentity>(); identity.Setup(id => id.Credentials).Returns(credential); identity.Setup(id => id.ModuleId).Returns(testConfig.Name); IImmutableDictionary <string, IModuleIdentity> identities = new Dictionary <string, IModuleIdentity>() { [testConfig.Name] = identity.Object }.ToImmutableDictionary(); var moduleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>(); moduleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>())).Returns(Task.FromResult(identities)); Agent agent = await Agent.Create( configSource.Object, new RestartPlanner(commandFactory), new OrderedPlanRunner(), reporter, moduleIdentityLifecycleManager.Object, environmentProvider, configStore, deploymentConfigInfoSerde, NullEncryptionProvider.Instance); await agent.ReconcileAsync(CancellationToken.None); // Sometimes the container is still not ready by the time we run the validator. // So we attempt validation multiple times and bail only if all of them fail. bool validated = false; int attempts = 0; const int MaxAttempts = 5; while (!validated && attempts < MaxAttempts) { validated = testConfig.Validator.Validate(); if (!validated) { Thread.Sleep(TimeSpan.FromSeconds(5)); } ++attempts; } Assert.True(validated); } finally { await RemoveContainer(client, testConfig); } }
public TestHubModule(string name, string type, ModuleStatus desiredStatus, TestConfig config, RestartPolicy restartPolicy, ImagePullPolicy imagePullPolicy, uint startupOrder, ConfigurationInfo configuration, IDictionary <string, EnvVal> env) : base(name ?? Constants.EdgeHubModuleName, string.Empty, type, desiredStatus, config, restartPolicy, imagePullPolicy, startupOrder, configuration, env) { this.Version = string.Empty; }
public EdgeAgentDockerModule(string type, DockerConfig settings, ImagePullPolicy imagePullPolicy, ConfigurationInfo configuration, IDictionary <string, EnvVal> env, string version = "") : base(Core.Constants.EdgeAgentModuleName, version, ModuleStatus.Running, RestartPolicy.Always, settings, imagePullPolicy, Core.Constants.HighestPriority, configuration, env) { Preconditions.CheckArgument(type?.Equals("docker") ?? false); }