|
24 | 24 | from openstack.network.v2 import availability_zone as _availability_zone |
25 | 25 | from openstack.network.v2 import local_ip as _local_ip |
26 | 26 | from openstack.network.v2 import local_ip_association as _local_ip_association |
| 27 | +from openstack.network.v2 import network as _network |
| 28 | +from openstack.network.v2 import network_ip_availability as _ip_availability |
27 | 29 |
|
28 | 30 | from openstackclient.tests.unit import fakes |
29 | 31 | from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes_v3 |
@@ -90,56 +92,6 @@ def setUp(self): |
90 | 92 | ) |
91 | 93 |
|
92 | 94 |
|
93 | | -class FakeIPAvailability(object): |
94 | | - """Fake one or more network ip availabilities.""" |
95 | | - |
96 | | - @staticmethod |
97 | | - def create_one_ip_availability(attrs=None): |
98 | | - """Create a fake list with ip availability stats of a network. |
99 | | -
|
100 | | - :param Dictionary attrs: |
101 | | - A dictionary with all attributes |
102 | | - :return: |
103 | | - A FakeResource object with network_name, network_id, etc. |
104 | | - """ |
105 | | - attrs = attrs or {} |
106 | | - |
107 | | - # Set default attributes. |
108 | | - network_ip_attrs = { |
109 | | - 'network_id': 'network-id-' + uuid.uuid4().hex, |
110 | | - 'network_name': 'network-name-' + uuid.uuid4().hex, |
111 | | - 'project_id': '', |
112 | | - 'subnet_ip_availability': [], |
113 | | - 'total_ips': 254, |
114 | | - 'used_ips': 6, |
115 | | - 'location': 'MUNCHMUNCHMUNCH', |
116 | | - } |
117 | | - network_ip_attrs.update(attrs) |
118 | | - |
119 | | - network_ip_availability = fakes.FakeResource( |
120 | | - info=copy.deepcopy(network_ip_attrs), |
121 | | - loaded=True) |
122 | | - |
123 | | - return network_ip_availability |
124 | | - |
125 | | - @staticmethod |
126 | | - def create_ip_availability(count=2): |
127 | | - """Create fake list of ip availability stats of multiple networks. |
128 | | -
|
129 | | - :param int count: |
130 | | - The number of networks to fake |
131 | | - :return: |
132 | | - A list of FakeResource objects faking network ip availability stats |
133 | | - """ |
134 | | - network_ip_availabilities = [] |
135 | | - for i in range(0, count): |
136 | | - network_ip_availability = \ |
137 | | - FakeIPAvailability.create_one_ip_availability() |
138 | | - network_ip_availabilities.append(network_ip_availability) |
139 | | - |
140 | | - return network_ip_availabilities |
141 | | - |
142 | | - |
143 | 95 | class FakeExtension(object): |
144 | 96 | """Fake one or more extension.""" |
145 | 97 |
|
@@ -173,111 +125,6 @@ def create_one_extension(attrs=None): |
173 | 125 | return extension |
174 | 126 |
|
175 | 127 |
|
176 | | -class FakeNetwork(object): |
177 | | - """Fake one or more networks.""" |
178 | | - |
179 | | - @staticmethod |
180 | | - def create_one_network(attrs=None): |
181 | | - """Create a fake network. |
182 | | -
|
183 | | - :param Dictionary attrs: |
184 | | - A dictionary with all attributes |
185 | | - :return: |
186 | | - A FakeResource object, with id, name, etc. |
187 | | - """ |
188 | | - attrs = attrs or {} |
189 | | - |
190 | | - # Set default attributes. |
191 | | - network_attrs = { |
192 | | - 'id': 'network-id-' + uuid.uuid4().hex, |
193 | | - 'name': 'network-name-' + uuid.uuid4().hex, |
194 | | - 'status': 'ACTIVE', |
195 | | - 'description': 'network-description-' + uuid.uuid4().hex, |
196 | | - 'dns_domain': 'example.org.', |
197 | | - 'mtu': '1350', |
198 | | - 'project_id': 'project-id-' + uuid.uuid4().hex, |
199 | | - 'admin_state_up': True, |
200 | | - 'shared': False, |
201 | | - 'subnets': ['a', 'b'], |
202 | | - 'provider:network_type': 'vlan', |
203 | | - 'provider:physical_network': 'physnet1', |
204 | | - 'provider:segmentation_id': "400", |
205 | | - 'router:external': True, |
206 | | - 'availability_zones': [], |
207 | | - 'availability_zone_hints': [], |
208 | | - 'is_default': False, |
209 | | - 'port_security_enabled': True, |
210 | | - 'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex, |
211 | | - 'ipv4_address_scope': 'ipv4' + uuid.uuid4().hex, |
212 | | - 'ipv6_address_scope': 'ipv6' + uuid.uuid4().hex, |
213 | | - 'tags': [], |
214 | | - 'location': 'MUNCHMUNCHMUNCH', |
215 | | - } |
216 | | - |
217 | | - # Overwrite default attributes. |
218 | | - network_attrs.update(attrs) |
219 | | - |
220 | | - network = fakes.FakeResource(info=copy.deepcopy(network_attrs), |
221 | | - loaded=True) |
222 | | - |
223 | | - # Set attributes with special mapping in OpenStack SDK. |
224 | | - network.is_router_external = network_attrs['router:external'] |
225 | | - network.is_admin_state_up = network_attrs['admin_state_up'] |
226 | | - network.is_port_security_enabled = \ |
227 | | - network_attrs['port_security_enabled'] |
228 | | - network.subnet_ids = network_attrs['subnets'] |
229 | | - network.is_shared = network_attrs['shared'] |
230 | | - network.is_tags = network_attrs['tags'] |
231 | | - network.provider_network_type = \ |
232 | | - network_attrs['provider:network_type'] |
233 | | - network.provider_physical_network = \ |
234 | | - network_attrs['provider:physical_network'] |
235 | | - network.provider_segmentation_id = \ |
236 | | - network_attrs['provider:segmentation_id'] |
237 | | - network.ipv4_address_scope_id = \ |
238 | | - network_attrs['ipv4_address_scope'] |
239 | | - network.ipv6_address_scope_id = \ |
240 | | - network_attrs['ipv6_address_scope'] |
241 | | - |
242 | | - return network |
243 | | - |
244 | | - @staticmethod |
245 | | - def create_networks(attrs=None, count=2): |
246 | | - """Create multiple fake networks. |
247 | | -
|
248 | | - :param Dictionary attrs: |
249 | | - A dictionary with all attributes |
250 | | - :param int count: |
251 | | - The number of networks to fake |
252 | | - :return: |
253 | | - A list of FakeResource objects faking the networks |
254 | | - """ |
255 | | - networks = [] |
256 | | - for i in range(0, count): |
257 | | - networks.append(FakeNetwork.create_one_network(attrs)) |
258 | | - |
259 | | - return networks |
260 | | - |
261 | | - @staticmethod |
262 | | - def get_networks(networks=None, count=2): |
263 | | - """Get an iterable Mock object with a list of faked networks. |
264 | | -
|
265 | | - If networks list is provided, then initialize the Mock object with the |
266 | | - list. Otherwise create one. |
267 | | -
|
268 | | - :param List networks: |
269 | | - A list of FakeResource objects faking networks |
270 | | - :param int count: |
271 | | - The number of networks to fake |
272 | | - :return: |
273 | | - An iterable Mock object with side_effect set to a list of faked |
274 | | - networks |
275 | | - """ |
276 | | - if networks is None: |
277 | | - networks = FakeNetwork.create_networks(count) |
278 | | - return mock.Mock(side_effect=networks) |
279 | | - |
280 | | - |
281 | 128 | class FakeNetworkFlavor(object): |
282 | 129 | """Fake Network Flavor.""" |
283 | 130 |
|
@@ -2019,6 +1866,136 @@ def create_availability_zones(attrs=None, count=2): |
2019 | 1866 | return availability_zones |
2020 | 1867 |
|
2021 | 1868 |
|
| 1869 | +def create_one_ip_availability(attrs=None): |
| 1870 | + """Create a fake list with ip availability stats of a network. |
| 1871 | +
|
| 1872 | + :param Dictionary attrs: |
| 1873 | + A dictionary with all attributes |
| 1874 | + :return: |
| 1875 | + A NetworkIPAvailability object with network_name, network_id, etc. |
| 1876 | + """ |
| 1877 | + attrs = attrs or {} |
| 1878 | + |
| 1879 | + # Set default attributes. |
| 1880 | + network_ip_attrs = { |
| 1881 | + 'network_id': 'network-id-' + uuid.uuid4().hex, |
| 1882 | + 'network_name': 'network-name-' + uuid.uuid4().hex, |
| 1883 | + 'project_id': '', |
| 1884 | + 'subnet_ip_availability': [], |
| 1885 | + 'total_ips': 254, |
| 1886 | + 'used_ips': 6, |
| 1887 | + 'location': 'MUNCHMUNCHMUNCH', |
| 1888 | + } |
| 1889 | + network_ip_attrs.update(attrs) |
| 1890 | + |
| 1891 | + network_ip_availability = _ip_availability.NetworkIPAvailability( |
| 1892 | + **network_ip_attrs) |
| 1893 | + |
| 1894 | + return network_ip_availability |
| 1895 | + |
| 1896 | + |
| 1897 | +def create_ip_availability(count=2): |
| 1898 | + """Create fake list of ip availability stats of multiple networks. |
| 1899 | +
|
| 1900 | + :param int count: |
| 1901 | + The number of networks to fake |
| 1902 | + :return: |
| 1903 | + A list of NetworkIPAvailability objects faking |
| 1904 | + network ip availability stats |
| 1905 | + """ |
| 1906 | + network_ip_availabilities = [] |
| 1907 | + for i in range(0, count): |
| 1908 | + network_ip_availability = create_one_ip_availability() |
| 1909 | + network_ip_availabilities.append(network_ip_availability) |
| 1910 | + |
| 1911 | + return network_ip_availabilities |
| 1912 | + |
| 1913 | + |
| 1914 | +def create_one_network(attrs=None): |
| 1915 | + """Create a fake network. |
| 1916 | +
|
| 1917 | + :param Dictionary attrs: |
| 1918 | + A dictionary with all attributes |
| 1919 | + :return: |
| 1920 | + An Network object, with id, name, etc. |
| 1921 | + """ |
| 1922 | + attrs = attrs or {} |
| 1923 | + |
| 1924 | + # Set default attributes. |
| 1925 | + network_attrs = { |
| 1926 | + 'created_at': '2021-11-29T10:10:23.000000', |
| 1927 | + 'id': 'network-id-' + uuid.uuid4().hex, |
| 1928 | + 'name': 'network-name-' + uuid.uuid4().hex, |
| 1929 | + 'status': 'ACTIVE', |
| 1930 | + 'description': 'network-description-' + uuid.uuid4().hex, |
| 1931 | + 'dns_domain': 'example.org.', |
| 1932 | + 'mtu': '1350', |
| 1933 | + 'project_id': 'project-id-' + uuid.uuid4().hex, |
| 1934 | + 'admin_state_up': True, |
| 1935 | + 'shared': False, |
| 1936 | + 'subnets': ['a', 'b'], |
| 1937 | + 'segments': 'network-segment-' + uuid.uuid4().hex, |
| 1938 | + 'provider:network_type': 'vlan', |
| 1939 | + 'provider:physical_network': 'physnet1', |
| 1940 | + 'provider:segmentation_id': "400", |
| 1941 | + 'router:external': True, |
| 1942 | + 'availability_zones': [], |
| 1943 | + 'availability_zone_hints': [], |
| 1944 | + 'is_default': False, |
| 1945 | + 'is_vlan_transparent': True, |
| 1946 | + 'port_security_enabled': True, |
| 1947 | + 'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex, |
| 1948 | + 'ipv4_address_scope': 'ipv4' + uuid.uuid4().hex, |
| 1949 | + 'ipv6_address_scope': 'ipv6' + uuid.uuid4().hex, |
| 1950 | + 'tags': [], |
| 1951 | + 'location': 'MUNCHMUNCHMUNCH', |
| 1952 | + 'updated_at': '2021-11-29T10:10:25.000000', |
| 1953 | + } |
| 1954 | + |
| 1955 | + # Overwrite default attributes. |
| 1956 | + network_attrs.update(attrs) |
| 1957 | + |
| 1958 | + network = _network.Network(**network_attrs) |
| 1959 | + |
| 1960 | + return network |
| 1961 | + |
| 1962 | + |
| 1963 | +def create_networks(attrs=None, count=2): |
| 1964 | + """Create multiple fake networks. |
| 1965 | +
|
| 1966 | + :param Dictionary attrs: |
| 1967 | + A dictionary with all attributes |
| 1968 | + :param int count: |
| 1969 | + The number of networks to fake |
| 1970 | + :return: |
| 1971 | + A list of Network objects faking the networks |
| 1972 | + """ |
| 1973 | + networks = [] |
| 1974 | + for i in range(0, count): |
| 1975 | + networks.append(create_one_network(attrs)) |
| 1976 | + |
| 1977 | + return networks |
| 1978 | + |
| 1979 | + |
| 1980 | +def get_networks(networks=None, count=2): |
| 1981 | + """Get an iterable Mock object with a list of faked networks. |
| 1982 | +
|
| 1983 | + If networks list is provided, then initialize the Mock object with the |
| 1984 | + list. Otherwise create one. |
| 1985 | +
|
| 1986 | + :param List networks: |
| 1987 | + A list of Network objects faking networks |
| 1988 | + :param int count: |
| 1989 | + The number of networks to fake |
| 1990 | + :return: |
| 1991 | + An iterable Mock object with side_effect set to a list of faked |
| 1992 | + networks |
| 1993 | + """ |
| 1994 | + if networks is None: |
| 1995 | + networks = create_networks(count) |
| 1996 | + return mock.Mock(side_effect=networks) |
| 1997 | + |
| 1998 | + |
2022 | 1999 | def create_one_local_ip(attrs=None): |
2023 | 2000 | """Create a fake local ip. |
2024 | 2001 |
|
|
0 commit comments