From 6dbce3791268f1ee4584e6981f5040a1c87a87cf Mon Sep 17 00:00:00 2001 From: Patryk Matuszak <305846+pmtk@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:48:31 +0100 Subject: [PATCH] USHIFT-2228: Test Multus - macvlan CNI --- test/assets/multus/macvlan-nad.yaml | 15 ++++++++++ test/assets/multus/macvlan-pod.yaml | 28 ++++++++++++++++++ test/suites/optional/multus.robot | 44 +++++++++++++++++++++++++---- 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 test/assets/multus/macvlan-nad.yaml create mode 100644 test/assets/multus/macvlan-pod.yaml diff --git a/test/assets/multus/macvlan-nad.yaml b/test/assets/multus/macvlan-nad.yaml new file mode 100644 index 0000000000..52bd6761f1 --- /dev/null +++ b/test/assets/multus/macvlan-nad.yaml @@ -0,0 +1,15 @@ +apiVersion: "k8s.cni.cncf.io/v1" +kind: NetworkAttachmentDefinition +metadata: + name: macvlan-conf +spec: + config: '{ + "cniVersion": "0.4.0", + "name": "test", + "type": "macvlan", + "master": "enp1s0", + "mode": "bridge", + "ipam": { + "type": "dhcp" + } + }' diff --git a/test/assets/multus/macvlan-pod.yaml b/test/assets/multus/macvlan-pod.yaml new file mode 100644 index 0000000000..3c29e519d4 --- /dev/null +++ b/test/assets/multus/macvlan-pod.yaml @@ -0,0 +1,28 @@ +kind: Pod +apiVersion: v1 +metadata: + name: test-macvlan + annotations: + k8s.v1.cni.cncf.io/networks: macvlan-conf + labels: + app: test-macvlan +spec: + terminationGracePeriodSeconds: 0 + containers: + - name: hello-microshift + image: quay.io/microshift/busybox:1.36 + command: ["/bin/sh"] + args: ["-c", "while true; do echo -ne \"HTTP/1.0 200 OK\r\nContent-Length: 16\r\n\r\nHello MicroShift\" | nc -l -p 8080 ; done"] + ports: + - containerPort: 8080 + protocol: TCP + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + runAsNonRoot: true + runAsUser: 1001 + runAsGroup: 1001 + seccompProfile: + type: RuntimeDefault diff --git a/test/suites/optional/multus.robot b/test/suites/optional/multus.robot index 0ba5ecff1d..c4e2cdd4bc 100644 --- a/test/suites/optional/multus.robot +++ b/test/suites/optional/multus.robot @@ -21,6 +21,10 @@ ${PE_BRIDGE_POD_YAML} ./assets/multus/bridge-preexisting-pod.yaml ${PE_BRIDGE_POD_NAME} test-bridge-preexisting ${PE_BRIDGE_IP} 10.10.1.10/24 +${MACVLAN_NAD_YAML} ./assets/multus/macvlan-nad.yaml +${MACVLAN_POD_YAML} ./assets/multus/macvlan-pod.yaml +${MACVLAN_POD_NAME} test-macvlan + *** Test Cases *** Pre-Existing Bridge Interface @@ -67,6 +71,18 @@ No Pre-Existing Bridge Interface ... ${BRIDGE_POD_YAML} ... ${BRIDGE_INTERFACE} +Macvlan + [Documentation] Tests if Pod with macvlan plugin interface is accessible + ... from outside the MicroShift host. + [Setup] Run Keywords + ... Create NAD And Pod ${MACVLAN_NAD_YAML} ${MACVLAN_POD_YAML} + ... AND + ... Named Pod Should Be Ready ${MACVLAN_POD_NAME} ${NAMESPACE} + + Connect To Pod From The Hypervisor ${MACVLAN_POD_NAME} ${NAMESPACE} ${NAMESPACE}/macvlan-conf + + [Teardown] Remove NAD And Pod ${MACVLAN_NAD_YAML} ${MACVLAN_POD_YAML} + *** Keywords *** Create NAD And Pod @@ -75,25 +91,42 @@ Create NAD And Pod Oc Create -n ${NAMESPACE} -f ${nad} Oc Create -n ${NAMESPACE} -f ${pod} -Cleanup Bridge Test - [Documentation] Removes provided NetworkAttachmentDefinition, Pod and network interface to allow for test rerun. - [Arguments] ${nad} ${pod} ${if} +Remove NAD And Pod + [Documentation] Removes provided NetworkAttachmentDefinition and Pod. + [Arguments] ${nad} ${pod} Run Keyword And Continue On Failure ... Oc Delete -n ${NAMESPACE} -f ${pod} Run Keyword And Continue On Failure ... Oc Delete -n ${NAMESPACE} -f ${nad} + +Cleanup Bridge Test + [Documentation] Removes provided NetworkAttachmentDefinition, Pod and network interface to allow for test rerun. + [Arguments] ${nad} ${pod} ${if} + Remove NAD And Pod ${nad} ${pod} Command Should Work ip link delete ${if} Connect To Pod Over Local Interface [Documentation] Makes a HTTP request to 8080 for a given Pod over given interface. [Arguments] ${pod} ${ns} ${if} - ${networks}= Get And Verify Pod Networks ${pod} ${ns} + ${networks}= Get And Verify Pod Networks ${pod} ${ns} ${NAMESPACE}/bridge*-conf ${extra_ip}= Set Variable ${networks}[1][ips][0] ${stdout}= Command Should Work curl -v --interface ${if} ${extra_ip}:8080 Should Contain ${stdout} Hello MicroShift +Connect To Pod From The Hypervisor + [Documentation] Makes a HTTP request to port 8080 of a given Pod from the hypervisor machine. + ... This is a limitation of macvlan devices - virtual devices cannot communicate with the master interface. + [Arguments] ${pod} ${ns} ${extra_cni_name} + + ${networks}= Get And Verify Pod Networks ${pod} ${ns} ${extra_cni_name} + ${extra_ip}= Set Variable ${networks}[1][ips][0] + Should Contain ${extra_ip} 192.168.122 + + ${result}= Process.Run Process curl -v ${extra_ip}:8080 + Should Contain ${result.stdout} Hello MicroShift + Interface Should Not Exist [Documentation] Verifies that network interface does not exist. [Arguments] ${if} @@ -117,7 +150,7 @@ Set IP For Host Interface Get And Verify Pod Networks [Documentation] Obtains interfaces of the Pod from its annotation. ... The annotation is managed by Multus. - [Arguments] ${pod} ${ns} + [Arguments] ${pod} ${ns} ${extra_cni_name} ${networks_str}= Oc Get JsonPath ... pod @@ -131,5 +164,6 @@ Get And Verify Pod Networks Should Be Equal As Integers ${n} 2 Should Be Equal As Strings ${networks}[0][name] ovn-kubernetes Should Match ${networks}[1][name] ${NAMESPACE}/bridge*-conf + Should Match ${networks}[1][name] ${extra_cni_name} RETURN ${networks}