Example #1
0
        public async Task ReturnsModuleRuntimeInfoWhenPodsAreUpdated()
        {
            V1Pod edgeagent1 = BuildPodList()["edgeagent"];

            edgeagent1.Metadata.Name = "edgeagent_123";
            edgeagent1.Status.ContainerStatuses
            .First(c => c.Name == "edgeagent").State.Running.StartedAt = new DateTime(2019, 10, 28);
            V1Pod edgeagent2 = BuildPodList()["edgeagent"];

            edgeagent2.Metadata.Name = "edgeAgent_456";
            edgeagent2.Status.ContainerStatuses
            .First(c => c.Name == "edgeagent").State.Running.StartedAt = new DateTime(2019, 10, 29);
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            runtimeInfo.CreateOrUpdateAddPodInfo(edgeagent1);
            runtimeInfo.CreateOrUpdateAddPodInfo(edgeagent2);
            runtimeInfo.RemovePodInfo(edgeagent1);

            var modules = await runtimeInfo.GetModules(CancellationToken.None);

            var info = modules.Single();

            Assert.NotNull(info);
            Assert.Equal(info.StartTime, Option.Some(new DateTime(2019, 10, 29)));
        }
        public async Task ReturnsLastKnowModuleState()
        {
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            foreach ((string podName, var pod) in BuildPodList())
            {
                runtimeInfo.CreateOrUpdateAddPodInfo(podName, pod);
            }

            Dictionary <string, V1Pod> modified = BuildPodList();

            modified["edgeagent"].Status.ContainerStatuses[0].State.Running    = null;
            modified["edgeagent"].Status.ContainerStatuses[0].State.Terminated = new V1ContainerStateTerminated(139, finishedAt: DateTime.Parse("2019-06-12T16:13:07Z"), startedAt: DateTime.Parse("2019-06-12T16:11:22Z"));
            modified["edgehub"].Status.ContainerStatuses[0].State.Running      = null;
            modified["edgehub"].Status.ContainerStatuses[1].State.Waiting      = new V1ContainerStateWaiting("waiting", "reason");
            modified["simulatedtemperaturesensor"].Status.ContainerStatuses[1].State.Running = null;
            foreach ((string podName, var pod) in modified)
            {
                runtimeInfo.CreateOrUpdateAddPodInfo(podName, pod);
            }

            var modules = (await runtimeInfo.GetModules(CancellationToken.None)).ToList();

            Assert.Equal(3, modules.Count);
            foreach (var i in modules)
            {
                if (!string.Equals("edgeAgent", i.Name))
                {
                    Assert.Equal(ModuleStatus.Unknown, i.ModuleStatus);
                }
                else
                {
                    Assert.Equal(ModuleStatus.Failed, i.ModuleStatus);
                }

                if (string.Equals("edgeHub", i.Name))
                {
                    Assert.Equal(Option.None <DateTime>(), i.ExitTime);
                    Assert.Equal(Option.None <DateTime>(), i.StartTime);
                }
                else
                {
                    Assert.Equal(new DateTime(2019, 6, 12), i.StartTime.OrDefault().Date);
                    Assert.Equal(new DateTime(2019, 6, 12), i.ExitTime.OrDefault().Date);
                }

                if (i is ModuleRuntimeInfo <DockerReportedConfig> d)
                {
                    Assert.NotEqual("unknown:unknown", d.Config.Image);
                }
            }
        }
Example #3
0
        public async Task ConvertsPodsToModules()
        {
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            foreach (V1Pod pod in BuildPodList().Values)
            {
                runtimeInfo.CreateOrUpdateAddPodInfo(pod);
            }

            var modules = (await runtimeInfo.GetModules(CancellationToken.None)).ToList();

            Assert.Equal(3, modules.Count);
            foreach (var module in modules)
            {
                Assert.Contains("Started", module.Description);
                Assert.Equal(ModuleStatus.Running, module.ModuleStatus);
                Assert.Equal(new DateTime(2019, 6, 12), module.StartTime.GetOrElse(DateTime.MinValue).Date);
                Assert.Equal("docker", module.Type);
                if (module is ModuleRuntimeInfo <DockerReportedConfig> config)
                {
                    Assert.NotEqual("unknown:unknown", config.Config.Image);
                }
            }
        }
        public async Task ReturnModuleStatusWithPodConditionsWhenThereAreNoContainers()
        {
            var   client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var   moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var   runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);
            V1Pod pod           = CreatePodWithPodParametersOnly("Pending", string.Empty, string.Empty);

            pod.Status.Conditions = new List <V1PodCondition>()
            {
                new V1PodCondition
                {
                    LastTransitionTime = new DateTime(2020, 02, 05, 10, 10, 10),
                    Message            = "Ready",
                    Reason             = "Scheduling",
                },
                new V1PodCondition
                {
                    LastTransitionTime = new DateTime(2020, 02, 05, 10, 10, 15),
                    Message            = "persistentvolumeclaim module-a-pvc not found",
                    Reason             = "Unschedulable",
                }
            };
            runtimeInfo.CreateOrUpdateAddPodInfo(pod);
            string expectedDescription = "Module Failed with container status Unknown More Info: persistentvolumeclaim module-a-pvc not found K8s reason: Unschedulable";

            ModuleRuntimeInfo info = (await runtimeInfo.GetModules(CancellationToken.None)).Single();

            Assert.Equal(ModuleStatus.Failed, info.ModuleStatus);
            Assert.Equal(expectedDescription, info.Description);
        }
        public async Task ReturnsRestModulesWhenSomeModulesInfoRemoved()
        {
            Dictionary <string, V1Pod> pods = BuildPodList();
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            runtimeInfo.CreateOrUpdateAddPodInfo("edgeagent", pods["edgeagent"]);
            runtimeInfo.CreateOrUpdateAddPodInfo("edgehub", pods["edgehub"]);
            runtimeInfo.RemovePodInfo("edgeagent");

            var modules = await runtimeInfo.GetModules(CancellationToken.None);

            var info = modules.Single();

            Assert.NotNull(info);
            Assert.Equal("edgeHub", info.Name);
        }
Example #6
0
        public async Task ReturnModuleStatusWhenPodIsAbnormal(V1Pod pod, string description, ModuleStatus status)
        {
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            runtimeInfo.CreateOrUpdateAddPodInfo(pod);

            ModuleRuntimeInfo info = (await runtimeInfo.GetModules(CancellationToken.None)).Single();

            Assert.Equal(status, info.ModuleStatus);
            Assert.Equal(description, info.Description);
        }
Example #7
0
        public async Task ReturnsModulesWhenModuleInfoAdded()
        {
            V1Pod edgeagent     = BuildPodList()["edgeagent"];
            var   client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var   moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var   runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            runtimeInfo.CreateOrUpdateAddPodInfo(edgeagent);

            var modules = await runtimeInfo.GetModules(CancellationToken.None);

            var info = modules.Single();

            Assert.NotNull(info);
            Assert.Equal("edgeAgent", info.Name);
        }
        public async Task ReturnModuleStatusWithPodConditionsIsEmpty()
        {
            var   client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var   moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var   runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);
            V1Pod pod           = CreatePodWithPodParametersOnly("Pending", string.Empty, string.Empty);

            pod.Status.Conditions = null;
            runtimeInfo.CreateOrUpdateAddPodInfo(pod);
            string expectedDescription = "Module Failed with Unknown pod status";

            ModuleRuntimeInfo info = (await runtimeInfo.GetModules(CancellationToken.None)).Single();

            Assert.Equal(ModuleStatus.Failed, info.ModuleStatus);
            Assert.Equal(expectedDescription, info.Description);
        }
Example #9
0
        public async Task ReturnsLastKnowModuleState()
        {
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            foreach (V1Pod pod in BuildPodList().Values)
            {
                runtimeInfo.CreateOrUpdateAddPodInfo(pod);
            }

            Dictionary <string, V1Pod> modified = BuildPodList();

            DateTime agentStartTime = new DateTime(2019, 6, 11);

            modified["edgeagent"].Status.Phase     = "Running";
            modified["edgeagent"].Status.StartTime = agentStartTime;

            string pendingDescription = "0/1 node available";

            modified["edgehub"].Status.Phase  = "Pending";
            modified["edgehub"].Status.Reason = pendingDescription;

            string finishedDescription = "Pod finished";

            modified["simulatedtemperaturesensor"].Status.Phase  = "Succeeded";
            modified["simulatedtemperaturesensor"].Status.Reason = finishedDescription;
            modified["simulatedtemperaturesensor"].Status.ContainerStatuses[1].State.Running    = null;
            modified["simulatedtemperaturesensor"].Status.ContainerStatuses[1].State.Terminated = new V1ContainerStateTerminated(139, finishedAt: DateTime.Parse("2019-06-12T16:13:07Z"), startedAt: DateTime.Parse("2019-06-12T16:11:22Z"));

            foreach (V1Pod pod in modified.Values)
            {
                runtimeInfo.CreateOrUpdateAddPodInfo(pod);
            }

            var modules = (await runtimeInfo.GetModules(CancellationToken.None)).ToList();

            Assert.Equal(3, modules.Count);

            // Normal operation statuses
            foreach (var i in modules)
            {
                if (string.Equals("edgeAgent", i.Name))
                {
                    Assert.Equal(ModuleStatus.Running, i.ModuleStatus);
                    Assert.Equal($"Started at {agentStartTime.ToString()}", i.Description);
                }
                else if (string.Equals("edgeHub", i.Name))
                {
                    Assert.Equal(ModuleStatus.Failed, i.ModuleStatus);
                    Assert.Equal(pendingDescription, i.Description);
                    Assert.Equal(Option.None <DateTime>(), i.ExitTime);
                }
                else if (string.Equals("SimulatedTemperatureSensor", i.Name))
                {
                    Assert.Equal(ModuleStatus.Stopped, i.ModuleStatus);
                    Assert.Equal(finishedDescription, i.Description);
                    Assert.Equal(new DateTime(2019, 6, 12), i.StartTime.OrDefault().Date);
                    Assert.Equal(new DateTime(2019, 6, 12), i.ExitTime.OrDefault().Date);
                }
                else
                {
                    Assert.True(false, $"Missing module {i.Name} in validation");
                }

                if (i is ModuleRuntimeInfo <DockerReportedConfig> d)
                {
                    Assert.NotEqual("unknown:unknown", d.Config.Image);
                }
            }

            string unknownDescription = "Could not reach pod";

            modified["edgeagent"].Status.Phase  = "Unknown";
            modified["edgeagent"].Status.Reason = unknownDescription;

            modified["edgehub"].Status = null;

            foreach (V1Pod pod in modified.Values)
            {
                runtimeInfo.CreateOrUpdateAddPodInfo(pod);
            }

            var abnormalModules = (await runtimeInfo.GetModules(CancellationToken.None)).ToList();

            Assert.Equal(3, modules.Count);

            // Abnormal operation statuses
            foreach (var i in abnormalModules)
            {
                if (string.Equals("edgeAgent", i.Name))
                {
                    Assert.Equal(ModuleStatus.Failed, i.ModuleStatus);
                    Assert.Equal(unknownDescription, i.Description);
                }
                else if (string.Equals("edgeHub", i.Name))
                {
                    Assert.Equal(ModuleStatus.Failed, i.ModuleStatus);
                    Assert.Equal("Unable to get pod status", i.Description);
                }
                else if (string.Equals("SimulatedTemperatureSensor", i.Name))
                {
                }
                else
                {
                    Assert.True(false, $"Missing module {i.Name} in validation");
                }
            }
        }