|
| 1 | +(* |
| 2 | + * Copyright (C) 2026 Vates |
| 3 | + * Copyright (C) Citrix Systems Inc. |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as published |
| 7 | + * by the Free Software Foundation; version 2.1 only. with the special |
| 8 | + * exception on linking described in file LICENSE. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + *) |
| 15 | + |
| 16 | +module T = Test_common |
| 17 | + |
| 18 | +let test_trunks_parameter () = |
| 19 | + let __context = T.make_test_database () in |
| 20 | + let vM = T.make_vm ~__context () in |
| 21 | + let network = T.make_network ~__context () in |
| 22 | + let vif = T.make_vif ~__context ~device:"1" ~vM ~network ~trunks:[2201L] () in |
| 23 | + Alcotest.(check (list int64)) |
| 24 | + "test_trunks_parameter testing add_trunks" [3201L; 2201L] |
| 25 | + ( Xapi_vif.add_trunks ~__context ~self:vif ~value:3201L ; |
| 26 | + Db.VIF.get_trunks ~__context ~self:vif |
| 27 | + ) ; |
| 28 | + Alcotest.(check (list int64)) |
| 29 | + "test_trunks_parameter testing remove_trunks" [2201L] |
| 30 | + ( Xapi_vif.remove_trunks ~__context ~self:vif ~value:3201L ; |
| 31 | + Db.VIF.get_trunks ~__context ~self:vif |
| 32 | + ) ; |
| 33 | + Alcotest.(check (list int64)) |
| 34 | + "test_trunks_parameter testing set_trunks" [3201L] |
| 35 | + ( Xapi_vif.set_trunks ~__context ~self:vif ~value:[3201L] ; |
| 36 | + Db.VIF.get_trunks ~__context ~self:vif |
| 37 | + ) ; |
| 38 | + Alcotest.(check (list int64)) |
| 39 | + "test_trunks_parameter testing set_trunks empty" [] |
| 40 | + ( Xapi_vif.set_trunks ~__context ~self:vif ~value:[] ; |
| 41 | + Db.VIF.get_trunks ~__context ~self:vif |
| 42 | + ) ; |
| 43 | + Alcotest.(check_raises) |
| 44 | + "test_trunks_parameter testing invalid VLAN tag" |
| 45 | + Api_errors.(Server_error (Api_errors.vlan_tag_invalid, ["9999"])) |
| 46 | + (fun () -> Xapi_vif.add_trunks ~__context ~self:vif ~value:9999L) |
| 47 | + |
| 48 | +(** try to set trunks on VIF on incompatible network *) |
| 49 | +let test_trunks_coherence_vif_set () = |
| 50 | + let __context = T.make_test_database () in |
| 51 | + (* create a VLAN *) |
| 52 | + let host = T.make_host ~__context () in |
| 53 | + let network = T.make_network ~__context () in |
| 54 | + let tagged_PIF = T.make_pif ~__context ~network ~host () in |
| 55 | + let tag = 3201L in |
| 56 | + let vlan_network = T.make_network ~__context ~bridge:"xapi0" () in |
| 57 | + let untagged_PIF = |
| 58 | + T.make_pif ~__context ~network:vlan_network ~host ~vLAN:tag () |
| 59 | + in |
| 60 | + let _vlan = T.make_vlan ~__context ~tagged_PIF ~untagged_PIF ~tag () in |
| 61 | + (* create VM + VIF using this network *) |
| 62 | + let vM = T.make_vm ~__context () in |
| 63 | + let vif = T.make_vif ~__context ~device:"1" ~vM ~network:vlan_network () in |
| 64 | + Alcotest.(check_raises) |
| 65 | + "test_trunks_coherence_vif_set testing" |
| 66 | + Api_errors.( |
| 67 | + Server_error |
| 68 | + ( Api_errors.network_incompatible_with_trunks |
| 69 | + , [Ref.string_of vlan_network] |
| 70 | + ) |
| 71 | + ) |
| 72 | + (fun () -> Xapi_vif.add_trunks ~__context ~self:vif ~value:2201L) |
| 73 | + |
| 74 | +(** try to add VIF (with trunks) on incompatible network *) |
| 75 | +let test_trunks_coherence_vif_add () = |
| 76 | + let __context = T.make_test_database () in |
| 77 | + (* create a VLAN *) |
| 78 | + let host = T.make_host ~__context () in |
| 79 | + let network = T.make_network ~__context () in |
| 80 | + let tagged_PIF = T.make_pif ~__context ~network ~host () in |
| 81 | + let tag = 3201L in |
| 82 | + let vlan_network = T.make_network ~__context ~bridge:"xapi0" () in |
| 83 | + let untagged_PIF = |
| 84 | + T.make_pif ~__context ~network:vlan_network ~host ~vLAN:tag () |
| 85 | + in |
| 86 | + let _vlan = T.make_vlan ~__context ~tagged_PIF ~untagged_PIF ~tag () in |
| 87 | + (* create VM + VIF using this network *) |
| 88 | + let vM = T.make_vm ~__context () in |
| 89 | + Alcotest.(check_raises) |
| 90 | + "test_trunks_coherence_vif_add testing" |
| 91 | + Api_errors.( |
| 92 | + Server_error |
| 93 | + ( Api_errors.network_incompatible_with_trunks |
| 94 | + , [Ref.string_of vlan_network] |
| 95 | + ) |
| 96 | + ) |
| 97 | + (fun () -> |
| 98 | + let _ : API.ref_VIF = |
| 99 | + Xapi_vif.create ~__context ~device:"1" ~network:vlan_network ~vM |
| 100 | + ~mAC:"00:00:00:00:00:00" ~mTU:1500L ~other_config:[] |
| 101 | + ~currently_attached:true ~qos_algorithm_type:"" |
| 102 | + ~qos_algorithm_params:[] ~locking_mode:`unlocked ~ipv4_allowed:[] |
| 103 | + ~ipv6_allowed:[] ~trunks:[2201L] |
| 104 | + in |
| 105 | + () |
| 106 | + ) |
| 107 | + |
| 108 | +(** try to associate PIF (with VLAN) on Network with trunked-VIF *) |
| 109 | +let test_trunks_coherence_pif_vlan () = |
| 110 | + let __context = T.make_test_database () in |
| 111 | + (* create VM + VIF on plain network *) |
| 112 | + let network = T.make_network ~__context () in |
| 113 | + let vM = T.make_vm ~__context () in |
| 114 | + let _vif = |
| 115 | + T.make_vif ~__context ~device:"1" ~vM ~network ~trunks:[3201L] () |
| 116 | + in |
| 117 | + Alcotest.(check_raises) |
| 118 | + "test_trunks_coherence_pif_vlan testing" |
| 119 | + Api_errors.( |
| 120 | + Server_error |
| 121 | + (Api_errors.network_incompatible_with_trunks, [Ref.string_of network]) |
| 122 | + ) |
| 123 | + (fun () -> |
| 124 | + (* create a VLAN *) |
| 125 | + let host = T.make_host ~__context () in |
| 126 | + let network2 = T.make_network ~__context () in |
| 127 | + let tagged_PIF = T.make_pif ~__context ~network:network2 ~host () in |
| 128 | + let tag = 2201L in |
| 129 | + let untagged_PIF = T.make_pif ~__context ~network ~host ~vLAN:tag () in |
| 130 | + let _vlan = T.make_vlan ~__context ~tagged_PIF ~untagged_PIF ~tag () in |
| 131 | + () |
| 132 | + ) |
| 133 | + |
| 134 | +let test_trunks_move () = |
| 135 | + let __context = T.make_test_database () in |
| 136 | + (* create VM + VIF using this network *) |
| 137 | + let network1 = T.make_network ~__context () in |
| 138 | + let vM = T.make_vm ~__context () in |
| 139 | + let vif = T.make_vif ~__context ~network:network1 ~vM () in |
| 140 | + let network2 = T.make_network ~__context () in |
| 141 | + Alcotest.(check unit) |
| 142 | + "test_trunks_move testing" () |
| 143 | + (Xapi_vif.move ~__context ~self:vif ~network:network2) |
| 144 | + |
| 145 | +let test_trunks_move_to_vlan () = |
| 146 | + let __context = T.make_test_database () in |
| 147 | + (* create VM + VIF (with trunks) *) |
| 148 | + let network1 = T.make_network ~__context () in |
| 149 | + let vM = T.make_vm ~__context () in |
| 150 | + let vif = T.make_vif ~__context ~network:network1 ~vM ~trunks:[3201L] () in |
| 151 | + (* create a VLAN *) |
| 152 | + let host = T.make_host ~__context () in |
| 153 | + let network2 = T.make_network ~__context () in |
| 154 | + let tagged_PIF = T.make_pif ~__context ~network:network2 ~host () in |
| 155 | + let tag = 3201L in |
| 156 | + let vlan_network2 = T.make_network ~__context ~bridge:"xapi0" () in |
| 157 | + let untagged_PIF = |
| 158 | + T.make_pif ~__context ~network:vlan_network2 ~host ~vLAN:tag () |
| 159 | + in |
| 160 | + let _vlan = T.make_vlan ~__context ~tagged_PIF ~untagged_PIF ~tag () in |
| 161 | + (* move the VIF to the vlan_network *) |
| 162 | + Alcotest.(check_raises) |
| 163 | + "test_trunks_move_to_vlan testing" |
| 164 | + Api_errors.( |
| 165 | + Server_error |
| 166 | + ( Api_errors.network_incompatible_with_trunks |
| 167 | + , [Ref.string_of vlan_network2] |
| 168 | + ) |
| 169 | + ) |
| 170 | + (fun () -> Xapi_vif.move ~__context ~self:vif ~network:vlan_network2) |
| 171 | + |
| 172 | +let test = |
| 173 | + [ |
| 174 | + ("test_trunks_parameter", `Quick, test_trunks_parameter) |
| 175 | + ; ("test_trunks_coherence_vif_set", `Quick, test_trunks_coherence_vif_set) |
| 176 | + ; ("test_trunks_coherence_vif_add", `Quick, test_trunks_coherence_vif_add) |
| 177 | + ; ("test_trunks_coherence_pif_vlan", `Quick, test_trunks_coherence_pif_vlan) |
| 178 | + ; ("test_trunks_move", `Quick, test_trunks_move) |
| 179 | + ; ("test_trunks_move_to_vlan", `Quick, test_trunks_move_to_vlan) |
| 180 | + ] |
0 commit comments