Add API test for network segment range extension

Co-authored-by: Allain Legacy <Allain.legacy@windriver.com>

Partially-implements: blueprint network-segment-range-management
Change-Id: I4758fcdd45ac1f84d872ff1f6e1da8a8d4671a80
diff --git a/neutron_tempest_plugin/api/base.py b/neutron_tempest_plugin/api/base.py
index 2943198..7b91d94 100644
--- a/neutron_tempest_plugin/api/base.py
+++ b/neutron_tempest_plugin/api/base.py
@@ -135,6 +135,7 @@
         cls.reserved_subnet_cidrs = set()
         cls.keypairs = []
         cls.trunks = []
+        cls.network_segment_ranges = []
 
     @classmethod
     def resource_cleanup(cls):
@@ -244,6 +245,12 @@
             for keypair in cls.keypairs:
                 cls._try_delete_resource(cls.delete_keypair, keypair)
 
+            # Clean up network_segment_ranges
+            for network_segment_range in cls.network_segment_ranges:
+                cls._try_delete_resource(
+                    cls.admin_client.delete_network_segment_range,
+                    network_segment_range['id'])
+
         super(BaseNetworkTest, cls).resource_cleanup()
 
     @classmethod
@@ -913,6 +920,25 @@
         return metering_label_rule
 
     @classmethod
+    def create_network_segment_range(cls, name, shared,
+                                     project_id, network_type,
+                                     physical_network, minimum,
+                                     maximum):
+        """Wrapper utility that returns a test network segment range."""
+        network_segment_range_args = {'name': name,
+                                      'shared': shared,
+                                      'project_id': project_id,
+                                      'network_type': network_type,
+                                      'physical_network': physical_network,
+                                      'minimum': minimum,
+                                      'maximum': maximum}
+        body = cls.admin_client.create_network_segment_range(
+            **network_segment_range_args)
+        network_segment_range = body['network_segment_range']
+        cls.network_segment_ranges.append(network_segment_range)
+        return network_segment_range
+
+    @classmethod
     def create_flavor(cls, name, description, service_type):
         """Wrapper utility that returns a test flavor."""
         body = cls.admin_client.create_flavor(