<commit_before>package dr

import (
	"bytes"
	"context"
	"fmt"
	"os/exec"
	"strings"
	"text/tabwriter"
	"time"

	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/client-go/dynamic"
	e2e "k8s.io/kubernetes/test/e2e/framework"
	e2elog "k8s.io/kubernetes/test/e2e/framework/log"
	e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"

	"github.com/openshift/origin/test/e2e/upgrade"
	exutil "github.com/openshift/origin/test/extended/util"

	o "github.com/onsi/gomega"
	"github.com/stretchr/objx"
)

const (
	operatorWait = 15 * time.Minute
)

func runCommandAndRetry(command string) string {
	const (
		maxRetries = 10
		pause      = 10
	)
	var (
		retryCount = 0
		out        []byte
		err        error
	)
	e2elog.Logf("command '%s'", command)
	for retryCount = 0; retryCount <= maxRetries; retryCount++ {
		out, err = exec.Command("bash", "-c", command).CombinedOutput()
		e2elog.Logf("output:\n%s", out)
		if err == nil {
			break
		}
		e2elog.Logf("%v", err)
		time.Sleep(time.Second * pause)
	}
	o.Expect(retryCount).NotTo(o.Equal(maxRetries + 1))
	return string(out)
}

func masterNodes(oc *exutil.CLI) []*corev1.Node {
	masterNodes, err := oc.AdminKubeClient().CoreV1().Nodes().List(context.Background(), metav1.ListOptions{
		LabelSelector: "node-role.kubernetes.io/master",
	})
	o.Expect(err).NotTo(o.HaveOccurred())
	var nodes []*corev1.Node
	for i := range masterNodes.Items {
		node := &masterNodes.Items[i]
		nodes = append(nodes, node)
	}
	return nodes
}

func constructEtcdConnectionString(masters []string) string {
	//TODO vrutkovs: replace this nonsense with `etcdctl member list -w json ...`
	etcdConnectionString := ""
	for _, master := range masters {
		result, err := e2essh.SSH("cat /run/etcd/environment", master+":22", e2e.TestContext.Provider)
		o.Expect(err).NotTo(o.HaveOccurred())
		var entry string
		for _, entry = range strings.Split(result.Stdout, "\n") {
			if strings.HasPrefix(entry, "ETCD_DNS_NAME=") {
				break
			}
		}
		etcdDNSName := strings.Split(entry, "=")[1]
		o.Expect(etcdDNSName).NotTo(o.BeEmpty())
		etcdConnectionString = fmt.Sprintf("%setcd-member-%s=https://%s:2380,", etcdConnectionString, master, etcdDNSName)
	}
	return etcdConnectionString[:len(etcdConnectionString)-1]
}

func waitForMastersToUpdate(oc *exutil.CLI, mcps dynamic.NamespaceableResourceInterface) {
	e2elog.Logf("Waiting for MachineConfig master to finish rolling out")
	err := wait.Poll(30*time.Second, 30*time.Minute, func() (done bool, err error) {
		return upgrade.IsPoolUpdated(mcps, "master")
	})
	o.Expect(err).NotTo(o.HaveOccurred())
}<commit_msg>Bug 1835931: Fix panic in test code<commit_after>package dr

import (
	"bytes"
	"context"
	"fmt"
	"os/exec"
	"strings"
	"text/tabwriter"
	"time"

	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/client-go/dynamic"
	e2e "k8s.io/kubernetes/test/e2e/framework"
	e2elog "k8s.io/kubernetes/test/e2e/framework/log"
	e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"

	"github.com/openshift/origin/test/e2e/upgrade"
	exutil "github.com/openshift/origin/test/extended/util"

	o "github.com/onsi/gomega"
	"github.com/stretchr/objx"
)

const (
	operatorWait = 15 * time.Minute
)

func runCommandAndRetry(command string) string {
	const (
		maxRetries = 10
		pause      = 10
	)
	var (
		retryCount = 0
		out        []byte
		err        error
	)
	e2elog.Logf("command '%s'", command)
	for retryCount = 0; retryCount <= maxRetries; retryCount++ {
		out, err = exec.Command("bash", "-c", command).CombinedOutput()
		e2elog.Logf("output:\n%s", out)
		if err == nil {
			break
		}
		e2elog.Logf("%v", err)
		time.Sleep(time.Second * pause)
	}
	o.Expect(retryCount).NotTo(o.Equal(maxRetries + 1))
	return string(out)
}

func masterNodes(oc *exutil.CLI) []*corev1.Node {
	masterNodes, err := oc.AdminKubeClient().CoreV1().Nodes().List(context.Background(), metav1.ListOptions{
		LabelSelector: "node-role.kubernetes.io/master",
	})
	o.Expect(err).NotTo(o.HaveOccurred())
	var nodes []*corev1.Node
	for i := range masterNodes.Items {
		node := &masterNodes.Items[i]
		nodes = append(nodes, node)
	}
	return nodes
}

func constructEtcdConnectionString(masters []string) string {
	//TODO vrutkovs: replace this nonsense with `etcdctl member list -w json ...`
	etcdConnectionString := ""
	for _, master := range masters {
		result, err := e2essh.SSH("cat /run/etcd/environment", master+":22", e2e.TestContext.Provider)
		o.Expect(err).NotTo(o.HaveOccurred())
		var entry string
		for _, entry = range strings.Split(result.Stdout, "\n") {
			if strings.HasPrefix(entry, "ETCD_DNS_NAME=") {
				break
			}
		}
		entries := strings.Split(entry, "=")
		o.Expect(entries).To(o.HaveLen(2))
		etcdDNSName := entries[1]
		o.Expect(etcdDNSName).NotTo(o.BeEmpty())
		etcdConnectionString = fmt.Sprintf("%setcd-member-%s=https://%s:2380,", etcdConnectionString, master, etcdDNSName)
	}
	return etcdConnectionString[:len(etcdConnectionString)-1]
}

func waitForMastersToUpdate(oc *exutil.CLI, mcps dynamic.NamespaceableResourceInterface) {
	e2elog.Logf("Waiting for MachineConfig master to finish rolling out")
	err := wait.Poll(30*time.Second, 30*time.Minute, func() (done bool, err error) {
		return upgrade.IsPoolUpdated(mcps, "master")
	})
	o.Expect(err).NotTo(o.HaveOccurred())
}
{'fraction_non_alphanumeric': 0.1580909768829232, 'fraction_numerical': 0.0197613721103654, 'mean_word_length': 4.386546184738956, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '487754', 'n_tokens_mistral': 2225, 'n_tokens_neox': 2095, 'n_words': 360}