|
22 | 22 | from openstack.network.v2 import address_scope as _address_scope |
23 | 23 | from openstack.network.v2 import auto_allocated_topology as allocated_topology |
24 | 24 | from openstack.network.v2 import availability_zone as _availability_zone |
| 25 | +from openstack.network.v2 import flavor as _flavor |
25 | 26 | from openstack.network.v2 import local_ip as _local_ip |
26 | 27 | from openstack.network.v2 import local_ip_association as _local_ip_association |
27 | 28 | from openstack.network.v2 import network as _network |
28 | 29 | from openstack.network.v2 import network_ip_availability as _ip_availability |
| 30 | +from openstack.network.v2 import network_segment_range as _segment_range |
| 31 | +from openstack.network.v2 import segment as _segment |
29 | 32 |
|
30 | 33 | from openstackclient.tests.unit import fakes |
31 | 34 | from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes_v3 |
@@ -125,186 +128,6 @@ def create_one_extension(attrs=None): |
125 | 128 | return extension |
126 | 129 |
|
127 | 130 |
|
128 | | -class FakeNetworkFlavor(object): |
129 | | - """Fake Network Flavor.""" |
130 | | - |
131 | | - @staticmethod |
132 | | - def create_one_network_flavor(attrs=None): |
133 | | - """Create a fake network flavor. |
134 | | -
|
135 | | - :param Dictionary attrs: |
136 | | - A dictionary with all attributes |
137 | | - :return: |
138 | | - A FakeResource object faking the network flavor |
139 | | - """ |
140 | | - attrs = attrs or {} |
141 | | - |
142 | | - fake_uuid = uuid.uuid4().hex |
143 | | - network_flavor_attrs = { |
144 | | - 'description': 'network-flavor-description-' + fake_uuid, |
145 | | - 'enabled': True, |
146 | | - 'id': 'network-flavor-id-' + fake_uuid, |
147 | | - 'name': 'network-flavor-name-' + fake_uuid, |
148 | | - 'service_type': 'vpn', |
149 | | - 'project_id': 'project-id-' + uuid.uuid4().hex, |
150 | | - 'location': 'MUNCHMUNCHMUNCH', |
151 | | - } |
152 | | - |
153 | | - # Overwrite default attributes. |
154 | | - network_flavor_attrs.update(attrs) |
155 | | - |
156 | | - network_flavor = fakes.FakeResource( |
157 | | - info=copy.deepcopy(network_flavor_attrs), |
158 | | - loaded=True |
159 | | - ) |
160 | | - |
161 | | - network_flavor.is_enabled = network_flavor_attrs['enabled'] |
162 | | - |
163 | | - return network_flavor |
164 | | - |
165 | | - @staticmethod |
166 | | - def create_flavor(attrs=None, count=2): |
167 | | - """Create multiple fake network flavors. |
168 | | -
|
169 | | - :param Dictionary attrs: |
170 | | - A dictionary with all attributes |
171 | | - :param int count: |
172 | | - The number of network flavors to fake |
173 | | - :return: |
174 | | - A list of FakeResource objects faking the network falvors |
175 | | - """ |
176 | | - network_flavors = [] |
177 | | - for i in range(0, count): |
178 | | - network_flavors.append( |
179 | | - FakeNetworkFlavor.create_one_network_flavor(attrs) |
180 | | - ) |
181 | | - return network_flavors |
182 | | - |
183 | | - @staticmethod |
184 | | - def get_flavor(network_flavors=None, count=2): |
185 | | - """Get a list of flavors.""" |
186 | | - if network_flavors is None: |
187 | | - network_flavors = (FakeNetworkFlavor.create_flavor(count)) |
188 | | - return mock.Mock(side_effect=network_flavors) |
189 | | - |
190 | | - |
191 | | -class FakeNetworkSegment(object): |
192 | | - """Fake one or more network segments.""" |
193 | | - |
194 | | - @staticmethod |
195 | | - def create_one_network_segment(attrs=None): |
196 | | - """Create a fake network segment. |
197 | | -
|
198 | | - :param Dictionary attrs: |
199 | | - A dictionary with all attributes |
200 | | - :return: |
201 | | - A FakeResource object faking the network segment |
202 | | - """ |
203 | | - attrs = attrs or {} |
204 | | - |
205 | | - # Set default attributes. |
206 | | - fake_uuid = uuid.uuid4().hex |
207 | | - network_segment_attrs = { |
208 | | - 'description': 'network-segment-description-' + fake_uuid, |
209 | | - 'id': 'network-segment-id-' + fake_uuid, |
210 | | - 'name': 'network-segment-name-' + fake_uuid, |
211 | | - 'network_id': 'network-id-' + fake_uuid, |
212 | | - 'network_type': 'vlan', |
213 | | - 'physical_network': 'physical-network-name-' + fake_uuid, |
214 | | - 'segmentation_id': 1024, |
215 | | - 'location': 'MUNCHMUNCHMUNCH', |
216 | | - } |
217 | | - |
218 | | - # Overwrite default attributes. |
219 | | - network_segment_attrs.update(attrs) |
220 | | - |
221 | | - network_segment = fakes.FakeResource( |
222 | | - info=copy.deepcopy(network_segment_attrs), |
223 | | - loaded=True |
224 | | - ) |
225 | | - |
226 | | - return network_segment |
227 | | - |
228 | | - @staticmethod |
229 | | - def create_network_segments(attrs=None, count=2): |
230 | | - """Create multiple fake network segments. |
231 | | -
|
232 | | - :param Dictionary attrs: |
233 | | - A dictionary with all attributes |
234 | | - :param int count: |
235 | | - The number of network segments to fake |
236 | | - :return: |
237 | | - A list of FakeResource objects faking the network segments |
238 | | - """ |
239 | | - network_segments = [] |
240 | | - for i in range(0, count): |
241 | | - network_segments.append( |
242 | | - FakeNetworkSegment.create_one_network_segment(attrs) |
243 | | - ) |
244 | | - return network_segments |
245 | | - |
246 | | - |
247 | | -class FakeNetworkSegmentRange(object): |
248 | | - """Fake one or more network segment ranges.""" |
249 | | - |
250 | | - @staticmethod |
251 | | - def create_one_network_segment_range(attrs=None): |
252 | | - """Create a fake network segment range. |
253 | | -
|
254 | | - :param Dictionary attrs: |
255 | | - A dictionary with all attributes |
256 | | - :return: |
257 | | - A FakeResource object faking the network segment range |
258 | | - """ |
259 | | - attrs = attrs or {} |
260 | | - |
261 | | - # Set default attributes. |
262 | | - fake_uuid = uuid.uuid4().hex |
263 | | - network_segment_range_attrs = { |
264 | | - 'id': 'network-segment-range-id-' + fake_uuid, |
265 | | - 'name': 'network-segment-name-' + fake_uuid, |
266 | | - 'default': False, |
267 | | - 'shared': False, |
268 | | - 'project_id': 'project-id-' + fake_uuid, |
269 | | - 'network_type': 'vlan', |
270 | | - 'physical_network': 'physical-network-name-' + fake_uuid, |
271 | | - 'minimum': 100, |
272 | | - 'maximum': 106, |
273 | | - 'used': {104: '3312e4ba67864b2eb53f3f41432f8efc', |
274 | | - 106: '3312e4ba67864b2eb53f3f41432f8efc'}, |
275 | | - 'available': [100, 101, 102, 103, 105], |
276 | | - 'location': 'MUNCHMUNCHMUNCH', |
277 | | - } |
278 | | - |
279 | | - # Overwrite default attributes. |
280 | | - network_segment_range_attrs.update(attrs) |
281 | | - |
282 | | - network_segment_range = fakes.FakeResource( |
283 | | - info=copy.deepcopy(network_segment_range_attrs), |
284 | | - loaded=True |
285 | | - ) |
286 | | - |
287 | | - return network_segment_range |
288 | | - |
289 | | - @staticmethod |
290 | | - def create_network_segment_ranges(attrs=None, count=2): |
291 | | - """Create multiple fake network segment ranges. |
292 | | -
|
293 | | - :param Dictionary attrs: |
294 | | - A dictionary with all attributes |
295 | | - :param int count: |
296 | | - The number of network segment ranges to fake |
297 | | - :return: |
298 | | - A list of FakeResource objects faking the network segment ranges |
299 | | - """ |
300 | | - network_segment_ranges = [] |
301 | | - for i in range(0, count): |
302 | | - network_segment_ranges.append( |
303 | | - FakeNetworkSegmentRange.create_one_network_segment_range(attrs) |
304 | | - ) |
305 | | - return network_segment_ranges |
306 | | - |
307 | | - |
308 | 131 | class FakePort(object): |
309 | 132 | """Fake one or more ports.""" |
310 | 133 |
|
@@ -1996,6 +1819,159 @@ def get_networks(networks=None, count=2): |
1996 | 1819 | return mock.Mock(side_effect=networks) |
1997 | 1820 |
|
1998 | 1821 |
|
| 1822 | +def create_one_network_flavor(attrs=None): |
| 1823 | + """Create a fake network flavor. |
| 1824 | +
|
| 1825 | + :param Dictionary attrs: |
| 1826 | + A dictionary with all attributes |
| 1827 | + :return: |
| 1828 | + A Flavor object faking the network flavor |
| 1829 | + """ |
| 1830 | + attrs = attrs or {} |
| 1831 | + |
| 1832 | + fake_uuid = uuid.uuid4().hex |
| 1833 | + network_flavor_attrs = { |
| 1834 | + 'description': 'network-flavor-description-' + fake_uuid, |
| 1835 | + 'is_enabled': True, |
| 1836 | + 'id': 'network-flavor-id-' + fake_uuid, |
| 1837 | + 'name': 'network-flavor-name-' + fake_uuid, |
| 1838 | + 'service_type': 'vpn', |
| 1839 | + 'location': 'MUNCHMUNCHMUNCH', |
| 1840 | + } |
| 1841 | + |
| 1842 | + # Overwrite default attributes. |
| 1843 | + network_flavor_attrs.update(attrs) |
| 1844 | + |
| 1845 | + network_flavor = _flavor.Flavor(**network_flavor_attrs) |
| 1846 | + |
| 1847 | + return network_flavor |
| 1848 | + |
| 1849 | + |
| 1850 | +def create_flavor(attrs=None, count=2): |
| 1851 | + """Create multiple fake network flavors. |
| 1852 | +
|
| 1853 | + :param Dictionary attrs: |
| 1854 | + A dictionary with all attributes |
| 1855 | + :param int count: |
| 1856 | + The number of network flavors to fake |
| 1857 | + :return: |
| 1858 | + A list of Flavor objects faking the network falvors |
| 1859 | + """ |
| 1860 | + network_flavors = [] |
| 1861 | + for i in range(0, count): |
| 1862 | + network_flavors.append(create_one_network_flavor(attrs)) |
| 1863 | + |
| 1864 | + return network_flavors |
| 1865 | + |
| 1866 | + |
| 1867 | +def get_flavor(network_flavors=None, count=2): |
| 1868 | + """Get a list of flavors.""" |
| 1869 | + if network_flavors is None: |
| 1870 | + network_flavors = create_flavor(count) |
| 1871 | + return mock.Mock(side_effect=network_flavors) |
| 1872 | + |
| 1873 | + |
| 1874 | +def create_one_network_segment(attrs=None): |
| 1875 | + """Create a fake network segment. |
| 1876 | +
|
| 1877 | + :param Dictionary attrs: |
| 1878 | + A dictionary with all attributes |
| 1879 | + :return: |
| 1880 | + An Segment object faking the network segment |
| 1881 | + """ |
| 1882 | + attrs = attrs or {} |
| 1883 | + |
| 1884 | + # Set default attributes. |
| 1885 | + fake_uuid = uuid.uuid4().hex |
| 1886 | + network_segment_attrs = { |
| 1887 | + 'description': 'network-segment-description-' + fake_uuid, |
| 1888 | + 'id': 'network-segment-id-' + fake_uuid, |
| 1889 | + 'name': 'network-segment-name-' + fake_uuid, |
| 1890 | + 'network_id': 'network-id-' + fake_uuid, |
| 1891 | + 'network_type': 'vlan', |
| 1892 | + 'physical_network': 'physical-network-name-' + fake_uuid, |
| 1893 | + 'segmentation_id': 1024, |
| 1894 | + 'location': 'MUNCHMUNCHMUNCH', |
| 1895 | + } |
| 1896 | + |
| 1897 | + # Overwrite default attributes. |
| 1898 | + network_segment_attrs.update(attrs) |
| 1899 | + |
| 1900 | + network_segment = _segment.Segment(**network_segment_attrs) |
| 1901 | + |
| 1902 | + return network_segment |
| 1903 | + |
| 1904 | + |
| 1905 | +def create_network_segments(attrs=None, count=2): |
| 1906 | + """Create multiple fake network segments. |
| 1907 | +
|
| 1908 | + :param Dictionary attrs: |
| 1909 | + A dictionary with all attributes |
| 1910 | + :param int count: |
| 1911 | + The number of network segments to fake |
| 1912 | + :return: |
| 1913 | + A list of Segment objects faking the network segments |
| 1914 | + """ |
| 1915 | + network_segments = [] |
| 1916 | + for i in range(0, count): |
| 1917 | + network_segments.append(create_one_network_segment(attrs)) |
| 1918 | + return network_segments |
| 1919 | + |
| 1920 | + |
| 1921 | +def create_one_network_segment_range(attrs=None): |
| 1922 | + """Create a fake network segment range. |
| 1923 | +
|
| 1924 | + :param Dictionary attrs: |
| 1925 | + A dictionary with all attributes |
| 1926 | + :return: |
| 1927 | + A NetworkSegmentRange object faking the network segment range |
| 1928 | + """ |
| 1929 | + attrs = attrs or {} |
| 1930 | + |
| 1931 | + # Set default attributes. |
| 1932 | + fake_uuid = uuid.uuid4().hex |
| 1933 | + network_segment_range_attrs = { |
| 1934 | + 'id': 'network-segment-range-id-' + fake_uuid, |
| 1935 | + 'name': 'network-segment-name-' + fake_uuid, |
| 1936 | + 'default': False, |
| 1937 | + 'shared': False, |
| 1938 | + 'project_id': 'project-id-' + fake_uuid, |
| 1939 | + 'network_type': 'vlan', |
| 1940 | + 'physical_network': 'physical-network-name-' + fake_uuid, |
| 1941 | + 'minimum': 100, |
| 1942 | + 'maximum': 106, |
| 1943 | + 'used': {104: '3312e4ba67864b2eb53f3f41432f8efc', |
| 1944 | + 106: '3312e4ba67864b2eb53f3f41432f8efc'}, |
| 1945 | + 'available': [100, 101, 102, 103, 105], |
| 1946 | + 'location': 'MUNCHMUNCHMUNCH', |
| 1947 | + } |
| 1948 | + |
| 1949 | + # Overwrite default attributes. |
| 1950 | + network_segment_range_attrs.update(attrs) |
| 1951 | + |
| 1952 | + network_segment_range = ( |
| 1953 | + _segment_range.NetworkSegmentRange(**network_segment_range_attrs)) |
| 1954 | + |
| 1955 | + return network_segment_range |
| 1956 | + |
| 1957 | + |
| 1958 | +def create_network_segment_ranges(attrs=None, count=2): |
| 1959 | + """Create multiple fake network segment ranges. |
| 1960 | +
|
| 1961 | + :param Dictionary attrs: |
| 1962 | + A dictionary with all attributes |
| 1963 | + :param int count: |
| 1964 | + The number of network segment ranges to fake |
| 1965 | + :return: |
| 1966 | + A list of NetworkSegmentRange objects faking |
| 1967 | + the network segment ranges |
| 1968 | + """ |
| 1969 | + network_segment_ranges = [] |
| 1970 | + for i in range(0, count): |
| 1971 | + network_segment_ranges.append(create_one_network_segment_range(attrs)) |
| 1972 | + return network_segment_ranges |
| 1973 | + |
| 1974 | + |
1999 | 1975 | def create_one_local_ip(attrs=None): |
2000 | 1976 | """Create a fake local ip. |
2001 | 1977 |
|
|
0 commit comments