@@ -18,7 +18,6 @@ import (
18
18
"bytes"
19
19
"fmt"
20
20
"io"
21
- "io/ioutil"
22
21
"math"
23
22
"math/rand"
24
23
"os"
@@ -4135,24 +4134,7 @@ func TestIPv6DisableAllSysctl(t *testing.T) {
4135
4134
for name , conf := range configs (t , true /* noOverlay */ ) {
4136
4135
for _ , test := range tests {
4137
4136
t .Run (test .name + name , func (t * testing.T ) {
4138
- dir , err := os .MkdirTemp (testutil .TmpDir (), "ipv6-test" )
4139
- if err != nil {
4140
- t .Fatalf ("os.MkdirTemp failed: %v" , err )
4141
- }
4142
- defer os .RemoveAll (dir )
4143
- if err := os .Chmod (dir , 0777 ); err != nil {
4144
- t .Fatalf ("error chmoding file: %q, %v" , dir , err )
4145
- }
4146
-
4147
- outputPath := filepath .Join (dir , "output" )
4148
- outputFile , err := createWriteableOutputFile (outputPath )
4149
- if err != nil {
4150
- t .Fatalf ("error creating output file: %v" , err )
4151
- }
4152
- defer outputFile .Close ()
4153
-
4154
- script := fmt .Sprintf ("ip addr >> %q" , outputPath )
4155
- spec := testutil .NewSpecWithArgs ("bash" , "-c" , script )
4137
+ spec := testutil .NewSpecWithArgs ("sleep" , "infinity" )
4156
4138
conf .Network = config .NetworkSandbox
4157
4139
if test .ipv6Disabled {
4158
4140
spec .Linux = & specs.Linux {}
@@ -4175,33 +4157,31 @@ func TestIPv6DisableAllSysctl(t *testing.T) {
4175
4157
if err != nil {
4176
4158
t .Fatalf ("error creating container: %v" , err )
4177
4159
}
4160
+ defer cont .Destroy ()
4178
4161
if err := cont .Start (conf ); err != nil {
4179
4162
t .Fatalf ("error starting container: %v" , err )
4180
4163
}
4181
4164
4182
- // Wait until application has ran.
4183
- if err := waitForFileNotEmpty (outputFile ); err != nil {
4184
- // This can happen when the network does not
4185
- // have any network interfaces configured.
4186
- // We cannot test whether the sysctl works
4187
- // properly in this case. Log a warning and
4188
- // return.
4189
- t .Logf ("No network interfaces are configured: %v" , err )
4190
- return
4165
+ out , err := executeCombinedOutput (conf , cont , nil , "/bin/sh" , "-c" , "ip addr" )
4166
+ if err != nil {
4167
+ t .Fatalf ("error executing 'ip addr' command: %v" , err )
4191
4168
}
4192
4169
4193
- content , err := ioutil .ReadFile (outputPath )
4194
- if err != nil {
4195
- fmt .Println ("Error reading file:" , err )
4170
+ if len (out ) == 0 {
4171
+ // This can happen when the network does not have any network
4172
+ // interfaces configured. We cannot test whether the sysctl works
4173
+ // properly in this case. Log a warning and return.
4174
+ t .Logf ("No output from 'ip addr' command, no network interfaces are configured" )
4196
4175
return
4197
4176
}
4198
- res := strings .Contains (string (content ), "inet6" )
4177
+
4178
+ res := strings .Contains (string (out ), "inet6" )
4199
4179
if test .ipv6Disabled && res {
4200
- t .Fatalf ("IPv6 address present when IPv6 is disabled on all interfaces" )
4180
+ t .Errorf ("IPv6 address present when IPv6 is disabled on all interfaces, output: %v" , string ( out ) )
4201
4181
}
4202
4182
4203
4183
if ! test .ipv6Disabled && ! res {
4204
- t .Fatalf ("IPv6 address not present when IPv6 is enabled on all interfaces" )
4184
+ t .Errorf ("IPv6 address not present when IPv6 is enabled on all interfaces, output: %v" , string ( out ) )
4205
4185
}
4206
4186
})
4207
4187
}
0 commit comments