Skip to content

Commit

Permalink
Issue #3465 - MultiNamespace: e2edev tests
Browse files Browse the repository at this point in the history
Signed-off-by: Le Zhang <[email protected]>
  • Loading branch information
LiilyZhang committed Aug 7, 2023
1 parent 3db9813 commit 2555a15
Show file tree
Hide file tree
Showing 17 changed files with 750 additions and 78 deletions.
2 changes: 1 addition & 1 deletion compcheck/comp_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ func ValidatePatternClusterNamespace(isNamespaceScoped bool, nodeNamespace strin
} else {
// is cluster scope
if patternNamespace != "" {
return NewCompCheckError(fmt.Errorf(msgPrinter.Sprintf("The Cluster namespace specified in the pattern '%v' is %v, only pattern with empty clsuter namespace can be registered for cluster scoped agent", patternId, patternNamespace)), COMPCHECK_VALIDATION_ERROR)
return NewCompCheckError(fmt.Errorf(msgPrinter.Sprintf("The Cluster namespace specified in the pattern '%v' is %v, only pattern with empty cluster namespace can be registered for cluster scoped agent", patternId, patternNamespace)), COMPCHECK_VALIDATION_ERROR)
}
}
return nil
Expand Down
32 changes: 24 additions & 8 deletions producer/producer_protocol_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ func (w *BaseProducerProtocolHandler) sendMessage(mt interface{}, pay []byte) er
continue
}
} else {
glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("Sent message for %v to exchange.", messageTarget.ReceiverExchangeId)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("Sent message for %v to exchange.", messageTarget.ReceiverExchangeId)))
}
return nil
}
}
Expand Down Expand Up @@ -469,7 +471,9 @@ func (w *BaseProducerProtocolHandler) MatchNodeType(tcPolicy *policy.Policy, dev
}
}

glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("workload has the correct deployment for the node type '%v'", nodeType)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("workload has the correct deployment for the node type '%v'", nodeType)))
}
return true, nil
}
}
Expand All @@ -487,7 +491,9 @@ func (w *BaseProducerProtocolHandler) MatchClusterNamespace(tcPolicy *policy.Pol
} else {
compResult, _, reason := compcheck.CheckClusterNamespaceCompatibility(nodeType, cutil.GetClusterNamespace(), cutil.IsNamespaceScoped(), tcPolicy.ClusterNamespace, workload.ClusterDeployment, "", true, nil)
if compResult {
glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("cluster namespace matches. %v", reason)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("cluster namespace matches.")))
}
} else {
glog.Errorf(BPPHlogString(w.Name(), fmt.Sprintf("cluster namespace not match. %v", reason)))
}
Expand All @@ -512,7 +518,9 @@ func (w *BaseProducerProtocolHandler) MatchPattern(tcPolicy *policy.Policy, dev
glog.Errorf(BPPHlogString(w.Name(), fmt.Sprintf("pattern from the proposal: '%v' does not match the pattern on the device: '%v'.", tcPolicy.PatternId, device_pattern)))
return false, nil
} else {
glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("pattern from the proposal: '%v' matches the pattern on the device: '%v'.", tcPolicy.PatternId, device_pattern)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("pattern from the proposal: '%v' matches the pattern on the device: '%v'.", tcPolicy.PatternId, device_pattern)))
}
return true, nil
}
}
Expand Down Expand Up @@ -588,20 +596,26 @@ func (w *BaseProducerProtocolHandler) TerminateAgreement(ag *persistence.Establi

func (w *BaseProducerProtocolHandler) GetAgbotMessageEndpoint(agbotId string) (string, []byte, error) {

glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieving agbot %v msg endpoint from exchange", agbotId)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieving agbot %v msg endpoint from exchange", agbotId)))
}

if ag, err := w.getAgbot(agbotId, w.ec.GetExchangeURL(), w.ec.GetExchangeId(), w.ec.GetExchangeToken()); err != nil {
return "", nil, err
} else {
glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieved agbot %v msg endpoint from exchange %v", agbotId, ag.MsgEndPoint)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieved agbot %v msg endpoint from exchange %v", agbotId, ag.MsgEndPoint)))
}
return ag.MsgEndPoint, ag.PublicKey, nil
}

}

func (w *BaseProducerProtocolHandler) getAgbot(agbotId string, url string, deviceId string, token string) (*exchange.Agbot, error) {

glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieving agbot %v from exchange", agbotId)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieving agbot %v from exchange", agbotId)))
}

var resp interface{}
resp = new(exchange.GetAgbotsResponse)
Expand Down Expand Up @@ -632,7 +646,9 @@ func (w *BaseProducerProtocolHandler) getAgbot(agbotId string, url string, devic
if ag, there := ags[agbotId]; !there {
return nil, errors.New(fmt.Sprintf("agbot %v not in GET response %v as expected", agbotId, ags))
} else {
glog.V(5).Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieved agbot %v from exchange %v", agbotId, ag)))
if glog.V(5) {
glog.Infof(BPPHlogString(w.Name(), fmt.Sprintf("retrieved agbot %v from exchange %v", agbotId, ag)))
}
return &ag, nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/docker/fs/etc/agent-in-kube/horizon.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
HZN_EXCHANGE_URL=http://${EX_IP}:8080/v1
HZN_FSS_CSSURL=https://${CSS_IP}:9443
HZN_AGBOT_URL=https://${AGBOT_IP}:3111
HZN_FSS_CSSURL=http://${CSS_IP}:8080
HZN_AGBOT_URL=http://${AGBOT_IP}:8080
HZN_DEVICE_ID=agent-in-kube
HZN_NODE_ID=agent-in-kube
HZN_MGMT_HUB_CERT_PATH=/etc/default/cert/hub.crt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"service": {
"name": "k8s-service-embedded-ns",
"org": "[email protected]",
"arch": "amd64",
"clusterNamespace": "ns-in-policy",
"serviceVersions": [
{
"version": "1.0.0",
"priority":{}
}
]
}
}
14 changes: 14 additions & 0 deletions test/gov/deployment_policies/userdev/bp_k8s_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"service": {
"name": "k8s-service1",
"org": "[email protected]",
"arch": "amd64",
"clusterNamespace": "ns-in-policy",
"serviceVersions": [
{
"version": "1.0.0",
"priority":{}
}
]
}
}
13 changes: 0 additions & 13 deletions test/gov/gov-combined.sh
Original file line number Diff line number Diff line change
Expand Up @@ -508,19 +508,6 @@ if [ "$HA" == "1" ]; then
fi
fi

#Start the edge cluster verification test.
if [ "$NOKUBE" != "1" ] && [ "$TESTFAIL" != "1" ] && [ "${TEST_PATTERNS}" == "" ]
then
echo -e "Verifying edge cluster agreement"
./verify_edge_cluster.sh
if [ $? -ne 0 ]; then
echo "Failed edge cluster verification tests."
exit 1
fi
else
echo -e "Edge cluster agreement verification skipped."
fi

# Clean up remote environment
if [ ${REMOTE_HUB} -eq 1 ]; then
echo "Clean up remote environment"
Expand Down
16 changes: 15 additions & 1 deletion test/gov/hzn_compcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

USERDEV_ADMIN_AUTH="userdev/userdevadmin:userdevadminpw"
export HZN_EXCHANGE_URL="${EXCH_APP_HOST}"
USERDEV_ORG="userdev"

unset HZN_ORG_ID
unset HZN_EXCHANGE_NODE_AUTH
Expand All @@ -23,7 +24,11 @@ else
service_location="/root/input_files/compcheck/service_location.json"
bp_location="/root/input_files/compcheck/business_pol_location.json"
pattern_sloc="/root/input_files/compcheck/pattern_sloc.json"
fi
fi

if [[ "$NOKUBE" != "1" ]]; then
bp_k8s="/root/input_files/compcheck/business_pol_k8s_service1"
fi


# check the the result to see if it matches the expected http code and error
Expand Down Expand Up @@ -212,6 +217,15 @@ if [ $? -eq 0 ]; then
echo "Service bluehorizon.network-services-location_2.0.7_${ARCH} should be compatible but not."
exit 2
fi

if [[ "$NOKUBE" != "1" ]]; then
echo -e "\n${PREFIX} test with conflict namespace"
CMD="hzn deploycheck policy -u $USERDEV_ADMIN_AUTH -B input_files/compcheck/business_pol_k8s_service1.json -n $USERDEV_ORG/agent-in-kube -s agent-namespace"
echo "$CMD"
RES=$($CMD 2>&1)
check_comp_results "$RES" "false" "Node properties do not satisfy constraint requirements."
fi

echo "Compatibility result expected."

PREFIX="HZN userinput compatibility test:"
Expand Down
34 changes: 34 additions & 0 deletions test/gov/input_files/compcheck/business_pol_k8s_service1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"label": "business policy for k8s-service1",
"description": "deploycheck test for k8s-service1",
"service": {
"name": "k8s-service1",
"org": "[email protected]",
"arch": "__ARCH__",
"clusterNamespace": "ns-in-policy",
"serviceVersions": [
{
"version": "1.0.0",
"priority": {},
"upgradePolicy": {}
}
],
"nodeHealth": {
"missing_heartbeat_interval": 1800,
"check_agreement_status": 1800
}
},
"properties": [
{
"name": "iame2edev",
"value": "true"
},
{
"name": "NOK8S",
"value": false
}
],
"constraints": [
"purpose == network-testing && openhorizon.kubernetesNamespace == another-namespace"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"properties":[{"name":"purpose","value":"network-testing"}],"constraints":["service.embedded.ns == operator-embedded-ns"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"serviceOrgid": "[email protected]",
"serviceUrl": "k8s-service-embedded-ns",
"serviceArch": "${ARCH}",
"serviceVersionRange": "[1.0.0,INFINITY)",
"inputs": [
{
"name": "var1",
"value": "k8s String"
},
{
"name": "var2",
"value": 7
},
{
"name": "var3",
"value": 88.8
}
]
}
]

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"properties":[{"name":"purpose","value":"network-testing"}],"constraints":["has.service.embedded.ns == false"]}
23 changes: 23 additions & 0 deletions test/gov/input_files/k8s_deploy/topservice-operator/node_ui.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"serviceOrgid": "[email protected]",
"serviceUrl": "k8s-service1",
"serviceArch": "${ARCH}",
"serviceVersionRange": "[1.0.0,INFINITY)",
"inputs": [
{
"name": "var1",
"value": "k8s String"
},
{
"name": "var2",
"value": 7
},
{
"name": "var3",
"value": 88.8
}
]
}
]

Binary file not shown.
Loading

0 comments on commit 2555a15

Please sign in to comment.