<commit_before>// SPDX-License-Identifier: Apache-2.0
// Copyright 2017-2020 Authors of Cilium

package RuntimeTest

import (
	"context"
	"fmt"
	"os"
	"sync"
	"time"

	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/types"
	"github.com/sirupsen/logrus"

	"github.com/cilium/cilium/api/v1/models"
	"github.com/cilium/cilium/pkg/policy/api"
	. "github.com/cilium/cilium/test/ginkgo-ext"
	"github.com/cilium/cilium/test/helpers"
	"github.com/cilium/cilium/test/helpers/constants"
)

const (
	// Commands
	ping              = "ping"
	ping6             = "ping6"
	http              = "http"
	http6             = "http6"
	httpPrivate       = "http_private"
	http6Private      = "http6_private"
	httpPrivateToken  = "http_private_token"
	http6PrivateToken = "http6_private_token"
	httpPathRewrite   = "http_path_rewrite"
	http6PathRewrite  = "http6_path_rewrite"

	// Policy files
	policyJSON                      = "policy.json"
	invalidJSON                     = "invalid.json"
	multL7PoliciesJSON              = "Policies-l7-multiple.json"
	policiesL7JSON                  = "Policies-l7-simple.json"
	imposePoliciesL7JSON            = "Policies-l7-impose.json"
	policiesL3JSON                  = "Policies-l3-policy.json"
	policiesL4Json                  = "Policies-l4-policy.json"
	policiesL3DependentL7EgressJSON = "Policies-l3-dependent-l7-egress.json"
	policiesReservedInitJSON        = "Policies-reserved-init.json"
)

var _ = Describe("RuntimePolicies", func() {

	var (
		vm            *helpers.SSHMeta
		monitorStop   = func() error { return nil }
		initContainer string
		testStartTime time.Time
	)

	BeforeAll(func() {
		vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)

		// We need to stop and start Cilium separately (vs. doing a restart) to
		// allow us to validate only the logs of the startup. The stop may
		// contain "bad" log messages but they are expected (abrupt stop during
		// endpoint regeneration).
		vm.ExecWithSudo("systemctl stop cilium").ExpectSuccess("Failed trying to stop cilium via systemctl")
		ExpectCiliumNotRunning(vm)
		testStartTime = time.Now()

		// Make sure that Cilium is started with appropriate CLI options
		// (specifically to exclude the local addresses that are populated for
		// CIDR policy tests).
		Expect(vm.SetUpCiliumWithHubble()).To(BeNil())
		ExpectCiliumReady(vm)
		vm.SampleContainersActions(helpers.Create, helpers.CiliumDockerNetwork)
		vm.PolicyDelAll()

		initContainer = "initContainer"

		Expect(vm.WaitEndpointsReady()).Should(BeTrue(), "Endpoints are not ready after timeout")

		vm.ValidateNoErrorsInLogs(time.Since(testStartTime))
	})

	BeforeEach(func() {
		ExpectPolicyEnforcementUpdated(vm, helpers.PolicyEnforcementDefault)
	})

	AfterEach(func() {
		vm.PolicyDelAll().ExpectSuccess("Unable to delete all policies")
	})<commit_msg>test/runtime: define initContainer as const<commit_after>// SPDX-License-Identifier: Apache-2.0
// Copyright 2017-2020 Authors of Cilium

package RuntimeTest

import (
	"context"
	"fmt"
	"os"
	"sync"
	"time"

	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/types"
	"github.com/sirupsen/logrus"

	"github.com/cilium/cilium/api/v1/models"
	"github.com/cilium/cilium/pkg/policy/api"
	. "github.com/cilium/cilium/test/ginkgo-ext"
	"github.com/cilium/cilium/test/helpers"
	"github.com/cilium/cilium/test/helpers/constants"
)

const (
	// Commands
	ping              = "ping"
	ping6             = "ping6"
	http              = "http"
	http6             = "http6"
	httpPrivate       = "http_private"
	http6Private      = "http6_private"
	httpPrivateToken  = "<PASSWORD>"
	http6PrivateToken = "<PASSWORD>"
	httpPathRewrite   = "http_path_rewrite"
	http6PathRewrite  = "http6_path_rewrite"

	// Policy files
	policyJSON                      = "policy.json"
	invalidJSON                     = "invalid.json"
	multL7PoliciesJSON              = "Policies-l7-multiple.json"
	policiesL7JSON                  = "Policies-l7-simple.json"
	imposePoliciesL7JSON            = "Policies-l7-impose.json"
	policiesL3JSON                  = "Policies-l3-policy.json"
	policiesL4Json                  = "Policies-l4-policy.json"
	policiesL3DependentL7EgressJSON = "Policies-l3-dependent-l7-egress.json"
	policiesReservedInitJSON        = "Policies-reserved-init.json"

	initContainer = "initContainer"
)

var _ = Describe("RuntimePolicies", func() {

	var (
		vm            *helpers.SSHMeta
		monitorStop   = func() error { return nil }
		testStartTime time.Time
	)

	BeforeAll(func() {
		vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)

		// We need to stop and start Cilium separately (vs. doing a restart) to
		// allow us to validate only the logs of the startup. The stop may
		// contain "bad" log messages but they are expected (abrupt stop during
		// endpoint regeneration).
		vm.ExecWithSudo("systemctl stop cilium").ExpectSuccess("Failed trying to stop cilium via systemctl")
		ExpectCiliumNotRunning(vm)
		testStartTime = time.Now()

		// Make sure that Cilium is started with appropriate CLI options
		// (specifically to exclude the local addresses that are populated for
		// CIDR policy tests).
		Expect(vm.SetUpCiliumWithHubble()).To(BeNil())
		ExpectCiliumReady(vm)
		vm.SampleContainersActions(helpers.Create, helpers.CiliumDockerNetwork)
		vm.PolicyDelAll()

		Expect(vm.WaitEndpointsReady()).Should(BeTrue(), "Endpoints are not ready after timeout")

		vm.ValidateNoErrorsInLogs(time.Since(testStartTime))
	})

	BeforeEach(func() {
		ExpectPolicyEnforcementUpdated(vm, helpers.PolicyEnforcementDefault)
	})

	AfterEach(func() {
		vm.PolicyDelAll().ExpectSuccess("Unable to delete all policies")
	})
{'fraction_non_alphanumeric': 0.11093333333333333, 'fraction_numerical': 0.012266666666666667, 'mean_word_length': 3.2718299164768414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '7453727', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1902, 'n_words': 368}