1+ import json
12import re
23
34import pytest
45
56from tests .integration .helpers import delete_target_id , exec_test_command
6- from tests .integration .linodes .helpers_linodes import create_linode_and_wait
7+ from tests .integration .linodes .helpers_linodes import (
8+ create_linode ,
9+ create_linode_and_wait ,
10+ )
711
812BASE_CMD = ["linode-cli" , "networking" ]
913
@@ -17,6 +21,32 @@ def setup_test_networking():
1721 delete_target_id (target = "linodes" , id = linode_id )
1822
1923
24+ @pytest .fixture (scope = "package" )
25+ def setup_test_networking_shared_ipv4 ():
26+ target_region = "us-southeast"
27+
28+ linode_ids = (
29+ create_linode (test_region = target_region ),
30+ create_linode (test_region = target_region ),
31+ )
32+
33+ yield linode_ids
34+
35+ for id in linode_ids :
36+ delete_target_id (target = "linodes" , id = id )
37+
38+
39+ def has_shared_ip (linode_id : int , ip : str ) -> bool :
40+ shared_ips = json .loads (
41+ exec_test_command (
42+ ["linode-cli" , "linodes" , "ips-list" , "--json" , linode_id ]
43+ ).stdout .decode ()
44+ )[0 ]["ipv4" ]["shared" ]
45+
46+ # Ensure there is a matching shared IP
47+ return len ([v for v in shared_ips if v ["address" ] == ip ]) > 0
48+
49+
2050def test_display_ips_for_available_linodes (setup_test_networking ):
2151 result = exec_test_command (
2252 BASE_CMD + ["ips-list" , "--text" , "--no-headers" , "--delimiter" , "," ]
@@ -89,3 +119,54 @@ def test_allocate_additional_private_ipv4_address(setup_test_networking):
89119 assert re .search (
90120 "ipv4,False,.*,[0-9][0-9][0-9][0-9][0-9][0-9][0-9]*" , result
91121 )
122+
123+
124+ def test_share_ipv4_address (setup_test_networking_shared_ipv4 ):
125+ target_linode , parent_linode = setup_test_networking_shared_ipv4
126+
127+ # Allocate an IPv4 address on the parent Linode
128+ ip_address = json .loads (
129+ exec_test_command (
130+ BASE_CMD
131+ + [
132+ "ip-add" ,
133+ "--type" ,
134+ "ipv4" ,
135+ "--linode_id" ,
136+ parent_linode ,
137+ "--json" ,
138+ "--public" ,
139+ "true" ,
140+ ]
141+ ).stdout .decode ()
142+ )[0 ]["address" ]
143+
144+ # Share the IP address to the target Linode
145+ exec_test_command (
146+ BASE_CMD
147+ + [
148+ "ip-share" ,
149+ "--ips" ,
150+ ip_address ,
151+ "--linode_id" ,
152+ target_linode ,
153+ "--json" ,
154+ ]
155+ )
156+
157+ assert has_shared_ip (target_linode , ip_address )
158+
159+ # Remove the IP shares
160+ exec_test_command (
161+ BASE_CMD
162+ + [
163+ "ip-share" ,
164+ "--ips" ,
165+ "[]" ,
166+ "--linode_id" ,
167+ target_linode ,
168+ "--json" ,
169+ ]
170+ )
171+
172+ assert not has_shared_ip (target_linode , ip_address )
0 commit comments