libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vd...@apache.org
Subject [13/18] libcloud git commit: Fix tests
Date Wed, 19 Sep 2018 08:09:49 GMT
Fix tests


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/b4e957f4
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/b4e957f4
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/b4e957f4

Branch: refs/heads/trunk
Commit: b4e957f43ab01c2d85571d8d91badf622a91bdea
Parents: 9980d03
Author: micafer <micafer1@upv.es>
Authored: Fri May 25 12:30:09 2018 +0200
Committer: micafer <micafer1@upv.es>
Committed: Fri May 25 12:30:09 2018 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 36 +++++-----
 libcloud/test/common/test_openstack_identity.py |  7 +-
 .../compute/fixtures/openstack/_v2_0__auth.json | 22 ++++++
 .../fixtures/openstack/_v2_0__networks.json     | 33 ---------
 .../fixtures/openstack/_v2_0__subnets.json      | 62 ----------------
 .../openstack_v1.1/_v2_0__networks.json         | 64 +++++++++++++++++
 .../openstack_v1.1/_v2_0__networks_POST.json    | 33 +++++++++
 .../fixtures/openstack_v1.1/_v2_0__subnets.json | 62 ++++++++++++++++
 libcloud/test/compute/test_openstack.py         | 75 ++++++++++++--------
 9 files changed, 246 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index a4300ae..44342d5 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -80,6 +80,12 @@ class OpenStackImageConnection(OpenStackBaseConnection):
     service_region = 'RegionOne'
 
 
+class OpenStackNetworkConnection(OpenStackBaseConnection):
+    service_type = 'network'
+    service_name = 'neutron'
+    service_region = 'RegionOne'
+
+
 class OpenStackNodeDriver(NodeDriver, OpenStackDriverMixin):
     """
     Base OpenStack node driver. Should not be used directly.
@@ -2479,13 +2485,6 @@ class OpenStack_2_Connection(OpenStackComputeConnection):
     accept_format = 'application/json'
     default_content_type = 'application/json; charset=UTF-8'
 
-    def __init__(self, *args, **kwargs):
-        if 'ex_force_image_url' in kwargs:
-            del kwargs['ex_force_image_url']
-        if 'ex_force_network_url' in kwargs:
-            del kwargs['ex_force_network_url']
-        super(OpenStack_2_Connection, self).__init__(*args, **kwargs)
-
     def encode_data(self, data):
         return json.dumps(data)
 
@@ -2499,10 +2498,7 @@ class OpenStack_2_ImageConnection(OpenStackImageConnection):
         return json.dumps(data)
 
 
-class OpenStack_2_NetworkConnection(OpenStackBaseConnection):
-    service_type = 'network'
-    service_name = 'neutron'
-    service_region = 'RegionOne'
+class OpenStack_2_NetworkConnection(OpenStackNetworkConnection):
     responseCls = OpenStack_1_1_Response
     accept_format = 'application/json'
     default_content_type = 'application/json; charset=UTF-8'
@@ -2549,22 +2545,24 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         if 'ex_force_auth_version' not in kwargs:
             kwargs['ex_force_auth_version'] = '3.x_password'
 
-        original_ex_force_base_url = kwargs.get('ex_force_base_url', None)
+        original_ex_force_base_url = kwargs.get('ex_force_base_url')
 
         # We run the init once to get the Glance V2 API connection
         # and put that on the object under self.image_connection.
-        self._ex_force_base_url = str(kwargs.pop('ex_force_image_url',
-                                                 None))
-        kwargs['ex_force_base_url'] = self._ex_force_base_url
+        if original_ex_force_base_url or kwargs.get('ex_force_image_url'):
+            kwargs['ex_force_base_url'] = \
+                str(kwargs.pop('ex_force_image_url',
+                               original_ex_force_base_url))
         self.connectionCls = self.image_connectionCls
         super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
         self.image_connection = self.connection
 
         # We run the init once to get the Neutron V2 API connection
         # and put that on the object under self.image_connection.
-        self._ex_force_base_url = str(kwargs.pop('ex_force_network_url',
-                                                 None))
-        kwargs['ex_force_base_url'] = self._ex_force_base_url
+        if original_ex_force_base_url or kwargs.get('ex_force_network_url'):
+            kwargs['ex_force_base_url'] = \
+                str(kwargs.pop('ex_force_network_url',
+                               original_ex_force_base_url))
         self.connectionCls = self.network_connectionCls
         super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
         self.network_connection = self.connection
@@ -2774,7 +2772,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
             extra['subnets'] = obj.get('subnets')
         return OpenStack_2_SubNet(id=obj['id'],
                                   name=obj['name'],
-                                  cidr=None,
+                                  cidr=obj['cidr'],
                                   driver=self,
                                   extra=extra)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py
index 9ac042c..1b6e144 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -525,7 +525,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
         catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                           auth_version='2.0')
         entries = catalog.get_entries()
-        self.assertEqual(len(entries), 7)
+        self.assertEqual(len(entries), 8)
 
         entry = [e for e in entries if e.service_name == 'cloudServers'][0]
         self.assertEqual(entry.service_type, 'compute')
@@ -591,8 +591,8 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
         catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                           auth_version='2.0')
         service_types = catalog.get_service_types()
-        self.assertEqual(service_types, ['compute', 'image', 'object-store',
-                                         'rax:object-cdn'])
+        self.assertEqual(service_types, ['compute', 'image', 'network', 
+                                         'object-store', 'rax:object-cdn'])
 
         service_types = catalog.get_service_types(region='ORD')
         self.assertEqual(service_types, ['rax:object-cdn'])
@@ -611,6 +611,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
                                          'cloudServersOpenStack',
                                          'cloudServersPreprod',
                                          'glance',
+                                         'neutron',
                                          'nova'])
 
         service_names = catalog.get_service_names(service_type='compute')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
index 91fe35b..79c6776 100644
--- a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
+++ b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
@@ -101,6 +101,28 @@
             {
                 "endpoints": [
                     {
+                        "region": "RegionOne",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    },
+                    {
+                        "region": "fr1",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "neutron",
+                "type": "network"
+            },
+            {
+                "endpoints": [
+                    {
                         "region": "DFW",
                         "tenantId": "613469",
                         "publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/1337",

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/compute/fixtures/openstack/_v2_0__networks.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack/_v2_0__networks.json b/libcloud/test/compute/fixtures/openstack/_v2_0__networks.json
deleted file mode 100644
index 7c54850..0000000
--- a/libcloud/test/compute/fixtures/openstack/_v2_0__networks.json
+++ /dev/null
@@ -1,33 +0,0 @@
-{
-    "network": {
-        "admin_state_up": true,
-        "availability_zone_hints": [],
-        "availability_zones": [
-            "nova"
-        ],
-        "created_at": "2016-03-08T20:19:41",
-        "dns_domain": "my-domain.org.",
-        "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
-        "ipv4_address_scope": null,
-        "ipv6_address_scope": null,
-        "l2_adjacency": false,
-        "mtu": 1500,
-        "name": "private-network",
-        "port_security_enabled": true,
-        "project_id": "4fd44f30292945e481c7b8a0c8908869",
-        "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e",
-        "revision_number": 1,
-        "router:external": false,
-        "shared": true,
-        "status": "ACTIVE",
-        "subnets": [
-            "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
-        ],
-        "tags": ["tag1,tag2"],
-        "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
-        "updated_at": "2016-03-08T20:19:41",
-        "vlan_transparent": false,
-        "description": "",
-        "is_default": true
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/compute/fixtures/openstack/_v2_0__subnets.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack/_v2_0__subnets.json b/libcloud/test/compute/fixtures/openstack/_v2_0__subnets.json
deleted file mode 100644
index d3f2763..0000000
--- a/libcloud/test/compute/fixtures/openstack/_v2_0__subnets.json
+++ /dev/null
@@ -1,62 +0,0 @@
-{
-    "subnets": [
-        {
-            "name": "private-subnet",
-            "enable_dhcp": true,
-            "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
-            "segment_id": null,
-            "project_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
-            "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
-            "dns_nameservers": [],
-            "allocation_pools": [
-                {
-                    "start": "10.0.0.2",
-                    "end": "10.0.0.254"
-                }
-            ],
-            "host_routes": [],
-            "ip_version": 4,
-            "gateway_ip": "10.0.0.1",
-            "cidr": "10.0.0.0/24",
-            "id": "08eae331-0402-425a-923c-34f7cfe39c1b",
-            "created_at": "2016-10-10T14:35:34Z",
-            "description": "",
-            "ipv6_address_mode": null,
-            "ipv6_ra_mode": null,
-            "revision_number": 2,
-            "service_types": [],
-            "subnetpool_id": null,
-            "tags": ["tag1,tag2"],
-            "updated_at": "2016-10-10T14:35:34Z"
-        },
-        {
-            "name": "my_subnet",
-            "enable_dhcp": true,
-            "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
-            "segment_id": null,
-            "project_id": "4fd44f30292945e481c7b8a0c8908869",
-            "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
-            "dns_nameservers": [],
-            "allocation_pools": [
-                {
-                    "start": "192.0.0.2",
-                    "end": "192.255.255.254"
-                }
-            ],
-            "host_routes": [],
-            "ip_version": 4,
-            "gateway_ip": "192.0.0.1",
-            "cidr": "192.0.0.0/8",
-            "id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0b",
-            "created_at": "2016-10-10T14:35:47Z",
-            "description": "",
-            "ipv6_address_mode": null,
-            "ipv6_ra_mode": null,
-            "revision_number": 2,
-            "service_types": [],
-            "subnetpool_id": null,
-            "tags": ["tag1,tag2"],
-            "updated_at": "2016-10-10T14:35:47Z"
-        }
-    ]
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks.json
new file mode 100644
index 0000000..fac0dcf
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks.json
@@ -0,0 +1,64 @@
+{
+    "networks": [
+        {
+            "admin_state_up": true,
+            "availability_zone_hints": [],
+            "availability_zones": [
+                "nova"
+            ],
+            "created_at": "2016-03-08T20:19:41",
+            "dns_domain": "my-domain.org.",
+            "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+            "ipv4_address_scope": null,
+            "ipv6_address_scope": null,
+            "l2_adjacency": false,
+            "mtu": 1500,
+            "name": "net1",
+            "port_security_enabled": true,
+            "project_id": "4fd44f30292945e481c7b8a0c8908869",
+            "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e",
+            "revision_number": 1,
+            "router:external": false,
+            "shared": false,
+            "status": "ACTIVE",
+            "subnets": [
+                "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
+            ],
+            "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
+            "updated_at": "2016-03-08T20:19:41",
+            "vlan_transparent": true,
+            "description": "",
+            "is_default": false
+        },
+        {
+            "admin_state_up": true,
+            "availability_zone_hints": [],
+            "availability_zones": [
+                "nova"
+            ],
+            "created_at": "2016-03-08T20:19:41",
+            "dns_domain": "my-domain.org.",
+            "id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
+            "ipv4_address_scope": null,
+            "ipv6_address_scope": null,
+            "l2_adjacency": false,
+            "mtu": 1500,
+            "name": "net2",
+            "port_security_enabled": true,
+            "project_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
+            "qos_policy_id": "bfdb6c39f71e4d44b1dfbda245c50819",
+            "revision_number": 3,
+            "router:external": false,
+            "shared": false,
+            "status": "ACTIVE",
+            "subnets": [
+                "08eae331-0402-425a-923c-34f7cfe39c1b"
+            ],
+            "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
+            "updated_at": "2016-03-08T20:19:41",
+            "vlan_transparent": false,
+            "description": "",
+            "is_default": false
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_POST.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_POST.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_POST.json
new file mode 100644
index 0000000..bf5b748
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_POST.json
@@ -0,0 +1,33 @@
+{
+    "network":
+        {
+            "admin_state_up": true,
+            "availability_zone_hints": [],
+            "availability_zones": [
+                "nova"
+            ],
+            "created_at": "2016-03-08T20:19:41",
+            "dns_domain": "my-domain.org.",
+            "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+            "ipv4_address_scope": null,
+            "ipv6_address_scope": null,
+            "l2_adjacency": false,
+            "mtu": 1500,
+            "name": "net1",
+            "port_security_enabled": true,
+            "project_id": "4fd44f30292945e481c7b8a0c8908869",
+            "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e",
+            "revision_number": 1,
+            "router:external": false,
+            "shared": false,
+            "status": "ACTIVE",
+            "subnets": [
+                "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
+            ],
+            "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
+            "updated_at": "2016-03-08T20:19:41",
+            "vlan_transparent": true,
+            "description": "",
+            "is_default": false
+        }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnets.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnets.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnets.json
new file mode 100644
index 0000000..d3f2763
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnets.json
@@ -0,0 +1,62 @@
+{
+    "subnets": [
+        {
+            "name": "private-subnet",
+            "enable_dhcp": true,
+            "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
+            "segment_id": null,
+            "project_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
+            "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
+            "dns_nameservers": [],
+            "allocation_pools": [
+                {
+                    "start": "10.0.0.2",
+                    "end": "10.0.0.254"
+                }
+            ],
+            "host_routes": [],
+            "ip_version": 4,
+            "gateway_ip": "10.0.0.1",
+            "cidr": "10.0.0.0/24",
+            "id": "08eae331-0402-425a-923c-34f7cfe39c1b",
+            "created_at": "2016-10-10T14:35:34Z",
+            "description": "",
+            "ipv6_address_mode": null,
+            "ipv6_ra_mode": null,
+            "revision_number": 2,
+            "service_types": [],
+            "subnetpool_id": null,
+            "tags": ["tag1,tag2"],
+            "updated_at": "2016-10-10T14:35:34Z"
+        },
+        {
+            "name": "my_subnet",
+            "enable_dhcp": true,
+            "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+            "segment_id": null,
+            "project_id": "4fd44f30292945e481c7b8a0c8908869",
+            "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
+            "dns_nameservers": [],
+            "allocation_pools": [
+                {
+                    "start": "192.0.0.2",
+                    "end": "192.255.255.254"
+                }
+            ],
+            "host_routes": [],
+            "ip_version": 4,
+            "gateway_ip": "192.0.0.1",
+            "cidr": "192.0.0.0/8",
+            "id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0b",
+            "created_at": "2016-10-10T14:35:47Z",
+            "description": "",
+            "ipv6_address_mode": null,
+            "ipv6_ra_mode": null,
+            "revision_number": 2,
+            "service_types": [],
+            "subnetpool_id": null,
+            "tags": ["tag1,tag2"],
+            "updated_at": "2016-10-10T14:35:47Z"
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b4e957f4/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index e1dd271..0a44460 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1399,24 +1399,6 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
 
         self.assertEqual(pool.delete_floating_ip.call_count, 1)
 
-    def test_ex_list_network(self):
-        networks = self.driver.ex_list_networks()
-        network = networks[0]
-
-        self.assertEqual(len(networks), 3)
-        self.assertEqual(network.name, 'test1')
-        self.assertEqual(network.cidr, '127.0.0.0/24')
-
-    def test_ex_create_network(self):
-        network = self.driver.ex_create_network(name='test1',
-                                                cidr='127.0.0.0/24')
-        self.assertEqual(network.name, 'test1')
-        self.assertEqual(network.cidr, '127.0.0.0/24')
-
-    def test_ex_delete_network(self):
-        network = self.driver.ex_list_networks()[0]
-        self.assertTrue(self.driver.ex_delete_network(network=network))
-
     def test_ex_get_metadata_for_node(self):
         image = NodeImage(id=11, name='Ubuntu 8.10 (intrepid)', driver=self.driver)
         size = NodeSize(1, '256 slice', None, None, None, None, driver=self.driver)
@@ -1568,9 +1550,7 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
     driver_type = OpenStack_2_NodeDriver
     driver_kwargs = {
         'ex_force_auth_version': '2.0',
-        'ex_force_auth_url': 'https://auth.api.example.com:8774',
-        'ex_force_image_url': 'https://auth.api.example.com:9292',
-        'ex_force_network_url': 'https://auth.api.example.com:9696'
+        'ex_force_auth_url': 'https://auth.api.example.com'
     }
 
     def setUp(self):
@@ -1580,6 +1560,11 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         # normally authentication happens lazily, but we force it here
         self.driver.image_connection._populate_hosts_and_request_paths()
 
+        self.driver_klass.network_connectionCls.conn_class = OpenStack_2_0_MockHttp
+        self.driver_klass.network_connectionCls.auth_url = "https://auth.api.example.com"
+        # normally authentication happens lazily, but we force it here
+        self.driver.network_connection._populate_hosts_and_request_paths()
+
     def test_ex_force_auth_token_passed_to_connection(self):
         base_url = 'https://servers.api.rackspacecloud.com/v1.1/slug'
         kwargs = {
@@ -1698,8 +1683,8 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         networks = self.driver.ex_list_networks()
         network = networks[0]
 
-        self.assertEqual(len(networks), 1)
-        self.assertEqual(network.name, 'private-network')
+        self.assertEqual(len(networks), 2)
+        self.assertEqual(network.name, 'net1')
         self.assertEqual(network.extra['subnets'], ['54d6f61d-db07-451c-9ab3-b9609b6b6f0b'])
 
     def test_ex_list_subnets(self):
@@ -1710,6 +1695,22 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         self.assertEqual(subnet.name, 'private-subnet')
         self.assertEqual(subnet.cidr, '10.0.0.0/24')
 
+    def test_ex_list_network(self):
+        networks = self.driver.ex_list_networks()
+        network = networks[0]
+
+        self.assertEqual(len(networks), 2)
+        self.assertEqual(network.name, 'net1')
+
+    def test_ex_create_network(self):
+        network = self.driver.ex_create_network(name='net1',
+                                                cidr='127.0.0.0/24')
+        self.assertEqual(network.name, 'net1')
+
+    def test_ex_delete_network(self):
+        network = self.driver.ex_list_networks()[0]
+        self.assertTrue(self.driver.ex_delete_network(network=network))
+
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False
     should_list_volumes = True
@@ -2141,6 +2142,26 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
 
         return (status_code, body, self.json_content_headers, httplib.responses[httplib.OK])
 
+    def _v2_1337_v2_0_networks(self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__networks.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        elif method == 'POST':
+            body = self.fixtures.load('_v2_0__networks_POST.json')
+            return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
+        raise NotImplementedError()
+
+    def _v2_1337_v2_0_networks_d32019d3_bc6e_4319_9c1d_6722fc136a22(self, method, url, body,
headers):
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__networks_POST.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'DELETE':
+            body = ''
+            return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_v2_0_subnets(self, method, url, body, headers):
+        body = self.fixtures.load('_v2_0__subnets.json')
+        return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
 # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures
 # work fine.
@@ -2161,14 +2182,6 @@ class OpenStack_2_0_MockHttp(OpenStack_1_1_MockHttp):
             setattr(self, new_name, method_type(method, self,
                                                 OpenStack_2_0_MockHttp))
 
-    def _v2_0_networks(self, method, url, body, headers):
-        body = self.auth_fixtures.load('_v2_0__networks.json')
-        return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
-
-    def _v2_0_subnets(self, method, url, body, headers):
-        body = self.auth_fixtures.load('_v2_0__subnets.json')
-        return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
-
 class OpenStack_1_1_Auth_2_0_Tests(OpenStack_1_1_Tests):
     driver_args = OPENSTACK_PARAMS + ('1.1',)
     driver_kwargs = {'ex_force_auth_version': '2.0'}


Mime
View raw message