mirror of https://github.com/k3s-io/k3s
modifying readFileContentInLoop to display iteratively file content and eventually check initial content
parent
961a02a602
commit
e2c315ee99
|
@ -24,3 +24,4 @@ up_to
|
||||||
valid_flag
|
valid_flag
|
||||||
retry_time
|
retry_time
|
||||||
file_content_in_loop
|
file_content_in_loop
|
||||||
|
break_on_expected_content
|
||||||
|
|
|
@ -12,5 +12,5 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
FROM gcr.io/google_containers/mounttest:0.5
|
FROM gcr.io/google_containers/mounttest:0.6
|
||||||
USER 1001
|
USER 1001
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
TAG = 0.3
|
TAG = 0.4
|
||||||
PREFIX = gcr.io/google_containers
|
PREFIX = gcr.io/google_containers
|
||||||
|
|
||||||
all: push
|
all: push
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
TAG = 0.5
|
TAG = 0.6
|
||||||
PREFIX = gcr.io/google_containers
|
PREFIX = gcr.io/google_containers
|
||||||
|
|
||||||
all: push
|
all: push
|
||||||
|
|
|
@ -37,6 +37,7 @@ var (
|
||||||
readFileContentPath = ""
|
readFileContentPath = ""
|
||||||
readFileContentInLoopPath = ""
|
readFileContentInLoopPath = ""
|
||||||
retryDuration = 180
|
retryDuration = 180
|
||||||
|
breakOnExpectedContent = true
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -51,6 +52,7 @@ func init() {
|
||||||
flag.StringVar(&readFileContentPath, "file_content", "", "Path to read the file content from")
|
flag.StringVar(&readFileContentPath, "file_content", "", "Path to read the file content from")
|
||||||
flag.StringVar(&readFileContentInLoopPath, "file_content_in_loop", "", "Path to read the file content in loop from")
|
flag.StringVar(&readFileContentInLoopPath, "file_content_in_loop", "", "Path to read the file content in loop from")
|
||||||
flag.IntVar(&retryDuration, "retry_time", 180, "Retry time during the loop")
|
flag.IntVar(&retryDuration, "retry_time", 180, "Retry time during the loop")
|
||||||
|
flag.BoolVar(&breakOnExpectedContent, "break_on_expected_content", true, "Break out of loop on expected content, (use with --file_content_in_loop flag only)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// This program performs some tests on the filesystem as dictated by the
|
// This program performs some tests on the filesystem as dictated by the
|
||||||
|
@ -120,7 +122,7 @@ func main() {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = readFileContentInLoop(readFileContentInLoopPath, retryDuration)
|
err = readFileContentInLoop(readFileContentInLoopPath, retryDuration, breakOnExpectedContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
@ -217,13 +219,14 @@ func readFileContent(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initialContent string = "mount-tester new file\n"
|
||||||
|
|
||||||
func readWriteNewFile(path string, perm os.FileMode) error {
|
func readWriteNewFile(path string, perm os.FileMode) error {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
content := "mount-tester new file\n"
|
err := ioutil.WriteFile(path, []byte(initialContent), perm)
|
||||||
err := ioutil.WriteFile(path, []byte(content), perm)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error writing new file %q: %v\n", path, err)
|
fmt.Printf("error writing new file %q: %v\n", path, err)
|
||||||
return err
|
return err
|
||||||
|
@ -232,19 +235,14 @@ func readWriteNewFile(path string, perm os.FileMode) error {
|
||||||
return readFileContent(path)
|
return readFileContent(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFileContentInLoop(path string, retryDuration int) error {
|
func readFileContentInLoop(path string, retryDuration int, breakOnExpectedContent bool) error {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var content []byte
|
return testFileContent(path, retryDuration, breakOnExpectedContent)
|
||||||
content = testFileContent(path, retryDuration)
|
|
||||||
|
|
||||||
fmt.Printf("content of file %q: %v\n", path, string(content))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFileContent(filePath string, retryDuration int) []byte {
|
func testFileContent(filePath string, retryDuration int, breakOnExpectedContent bool) error {
|
||||||
var (
|
var (
|
||||||
contentBytes []byte
|
contentBytes []byte
|
||||||
err error
|
err error
|
||||||
|
@ -253,18 +251,18 @@ func testFileContent(filePath string, retryDuration int) []byte {
|
||||||
retryTime := time.Second * time.Duration(retryDuration)
|
retryTime := time.Second * time.Duration(retryDuration)
|
||||||
for start := time.Now(); time.Since(start) < retryTime; time.Sleep(2 * time.Second) {
|
for start := time.Now(); time.Since(start) < retryTime; time.Sleep(2 * time.Second) {
|
||||||
contentBytes, err = ioutil.ReadFile(filePath)
|
contentBytes, err = ioutil.ReadFile(filePath)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
//Expected content "mount-tester new file\n", length 22
|
fmt.Printf("Error reading file %s: %v, retrying\n", filePath, err)
|
||||||
if len(contentBytes) == 22 {
|
continue
|
||||||
|
}
|
||||||
|
fmt.Printf("content of file %q: %v\n", filePath, string(contentBytes))
|
||||||
|
if breakOnExpectedContent {
|
||||||
|
if string(contentBytes) != initialContent {
|
||||||
|
fmt.Printf("Unexpected content. Expected: %s. Retrying", initialContent)
|
||||||
|
continue
|
||||||
|
}
|
||||||
break
|
break
|
||||||
} else {
|
|
||||||
fmt.Printf("Unexpected length of file: found %d, expected %d.Retry", len(contentBytes), 22)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fmt.Printf("Error read file %s: %v, retry", filePath, err)
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return contentBytes
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue