MCPcopy Index your code
hub / github.com/containerd/containerd / TestNriPluginNetworkingLifecycle

Function TestNriPluginNetworkingLifecycle

integration/nri_linux_test.go:109–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107}
108
109func TestNriPluginNetworkingLifecycle(t *testing.T) {
110 skipNriTestIfNecessary(t)
111
112 t.Log("Test that NRI plugins get pod networking attributes during the pod lifecycle.")
113
114 var (
115 tc = &nriTest{
116 t: t,
117 }
118 podName = "pod-net-lifecycle"
119 )
120
121 tc.setup()
122
123 hookExecs := 0
124 // override hooks are executed after the sync events, use channels to synchronize the test
125 runPodSandboxCh := make(chan struct{})
126 stopPodSandboxCh := make(chan struct{})
127 removePodSandboxCh := make(chan struct{})
128
129 plugin := &mockPlugin{
130 runPodSandbox: func(mp *mockPlugin, pod *api.PodSandbox) error {
131 t.Logf("runPodSandbox pod %s/%s: namespace=%s ips=%v", pod.GetNamespace(), pod.GetName(), getNetworkNamespace(pod), pod.GetIps())
132 if pod.Name != podName {
133 return nil
134 }
135 defer close(runPodSandboxCh)
136 // get the pod network namespace
137 ns := getNetworkNamespace(pod)
138 // test only creates pods with network
139 require.NotEmpty(t, ns)
140 require.ElementsMatch(t, pod.GetIps(), getNetworkNamespaceIPs(ns))
141 hookExecs++
142 return nil
143 },
144 stopPodSandbox: func(mp *mockPlugin, pod *api.PodSandbox) error {
145 t.Logf("stopPodSandbox pod %s/%s: namespace=%s ips=%v", pod.GetNamespace(), pod.GetName(), getNetworkNamespace(pod), pod.GetIps())
146 if pod.Name != podName {
147 return nil
148 }
149 defer close(stopPodSandboxCh)
150 // get the pod network namespace
151 ns := getNetworkNamespace(pod)
152 // test only creates pods with network
153 require.NotEmpty(t, ns)
154 require.ElementsMatch(t, pod.GetIps(), getNetworkNamespaceIPs(ns))
155 hookExecs++
156 return nil
157 },
158 removePodSandbox: func(mp *mockPlugin, pod *api.PodSandbox) error {
159 t.Logf("removePodSandbox pod %s/%s: namespace=%s ips=%v", pod.GetNamespace(), pod.GetName(), getNetworkNamespace(pod), pod.GetIps())
160 if pod.Name != podName {
161 return nil
162 }
163 defer close(removePodSandboxCh)
164 // get the pod network namespace
165 ns := getNetworkNamespace(pod)
166 // test only creates pods with network but at this point networking namespace is not present

Callers

nothing calls this directly

Calls 14

WaitMethod · 0.95
skipNriTestIfNecessaryFunction · 0.85
getNetworkNamespaceFunction · 0.85
getNetworkNamespaceIPsFunction · 0.85
PodSandboxConfigFunction · 0.85
EventTypeTypeAlias · 0.85
LogMethod · 0.80
setupMethod · 0.80
connectNewPluginMethod · 0.80
GetNamespaceMethod · 0.65
GetNameMethod · 0.65
RunPodSandboxMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…