Skip to content

Commit

Permalink
fixing some comments about synthesis (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
haim-kermany authored Jan 14, 2025
1 parent 1116174 commit 04af16e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/symbolicexpr/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func (term atomicTerm) labelKey() string {
// todo - make sure that the label is allowed by open shift
switch term.property.(type) {
case *collector.Segment:
return "segment"
Expand Down
4 changes: 2 additions & 2 deletions pkg/synthesis/createK8sResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func newNetworkPolicy(name, description string) *networking.NetworkPolicy {
pol.TypeMeta.Kind = "NetworkPolicy"
pol.TypeMeta.APIVersion = k8sAPIVersion
pol.ObjectMeta.Name = name
pol.ObjectMeta.Labels = map[string]string{"description": description}
pol.ObjectMeta.Annotations = map[string]string{"description": description}
return pol
}

Expand Down Expand Up @@ -175,7 +175,7 @@ func toPods(model *AbstractModelSyn) []*core.Pod {
pod.ObjectMeta.Labels = map[string]string{}
for _, group := range model.epToGroups[vm] {
label, _ := symbolicexpr.NewAtomicTerm(group, group.Name(), false).AsSelector()
pod.ObjectMeta.Labels[label] = label
pod.ObjectMeta.Labels[label] = "true"
}
pods = append(pods, pod)
}
Expand Down
23 changes: 15 additions & 8 deletions pkg/synthesis/synthesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ func (synTest *synthesisTest) runConvertToAbstract(t *testing.T, mode testMode,
suffix = "_ConvertToAbstract.txt"
}
outDir := path.Join("out", synTest.name)
abstractModel, err := NSXToK8sSynthesis(rc, outDir, hintsParm)
require.Nil(t, err)
addDebugFiles(t, rc, abstractModel, outDir)
expectedOutputFileName := filepath.Join(getTestsDirOut(), synTest.name+suffix)
actualOutput := strAllowOnlyPolicy(abstractModel.policy[0])
fmt.Println(actualOutput)
compareOrRegenerateOutputPerTest(t, mode, actualOutput, expectedOutputFileName, synTest.name)
}
func addDebugFiles(t *testing.T, rc *collector.ResourcesContainerModel, abstractModel *AbstractModelSyn, outDir string) {
for _, format := range []string{"txt", "dot"} {
params := common.OutputParameters{
Format: format,
Expand All @@ -121,13 +130,9 @@ func (synTest *synthesisTest) runConvertToAbstract(t *testing.T, mode testMode,
err = common.WriteToFile(path.Join(outDir, "vmware_connectivity."+format), analyzed)
require.Nil(t, err)
}
abstractModel, err := NSXToK8sSynthesis(rc, outDir, hintsParm)
require.Nil(t, err)

actualOutput := strAllowOnlyPolicy(abstractModel.policy[0])
fmt.Println(actualOutput)
expectedOutputFileName := filepath.Join(getTestsDirOut(), synTest.name+suffix)
compareOrRegenerateOutputPerTest(t, mode, actualOutput, expectedOutputFileName, synTest.name)
err := common.WriteToFile(path.Join(outDir, "abstract_model.txt"), actualOutput)
require.Nil(t, err)
}

func TestCollectAndConvertToAbstract(t *testing.T) {
Expand All @@ -146,11 +151,13 @@ func TestCollectAndConvertToAbstract(t *testing.T) {
t.Errorf("didnt got resources")
return
}

abstractModel, err := NSXToK8sSynthesis(rc, path.Join("out", "from_collection"),
outDir := path.Join("out", "from_collection")
abstractModel, err := NSXToK8sSynthesis(rc, outDir,
&symbolicexpr.Hints{GroupsDisjoint: [][]string{}})
require.Nil(t, err)
fmt.Println(strAllowOnlyPolicy(abstractModel.policy[0]))
addDebugFiles(t, rc, abstractModel, outDir)
require.Nil(t, err)
}

func TestConvertToAbsract(t *testing.T) {
Expand Down

0 comments on commit 04af16e

Please sign in to comment.