From c3d5c3d83701e8b3d2e2c4e7d91467516a78ad0a Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Thu, 6 Jun 2024 10:37:51 +0200 Subject: [PATCH 1/5] Implements: #2015 --- libcloud/compute/drivers/openstack.py | 4 ++++ libcloud/test/compute/test_openstack.py | 1 + 2 files changed, 5 insertions(+) diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index 360d32ebd0..d6df87bb3b 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -3160,6 +3160,10 @@ def _to_network(self, obj): extra["router:external"] = obj.get("router:external") if obj.get("subnets", None): extra["subnets"] = obj.get("subnets") + if obj.get("tags", None): + extra["tags"] = obj.get("tags") + if obj.get("is_default", None): + extra["is_default"] = obj.get("is_default") return OpenStackNetwork(id=obj["id"], name=obj["name"], cidr=None, driver=self, extra=extra) def ex_list_networks(self): diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py index f81da0cdc7..7820a6657c 100644 --- a/libcloud/test/compute/test_openstack.py +++ b/libcloud/test/compute/test_openstack.py @@ -2121,6 +2121,7 @@ def test_ex_get_network(self): self.assertEqual(network.id, "cc2dad14-827a-feea-416b-f13e50511a0a") self.assertTrue(isinstance(network, OpenStackNetwork)) self.assertEqual(network.name, "net2") + self.assertEqual(network.extra["is_default"], False) def test_ex_list_subnets(self): subnets = self.driver.ex_list_subnets() From 0f8b7c82817dd025036369a715f85d7b0d798789 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Thu, 6 Jun 2024 10:45:33 +0200 Subject: [PATCH 2/5] Fix --- libcloud/compute/drivers/openstack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index d6df87bb3b..d5096b9728 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -3162,7 +3162,7 @@ def _to_network(self, obj): extra["subnets"] = obj.get("subnets") if obj.get("tags", None): extra["tags"] = obj.get("tags") - if obj.get("is_default", None): + if obj.get("is_default", None) is not None: extra["is_default"] = obj.get("is_default") return OpenStackNetwork(id=obj["id"], name=obj["name"], cidr=None, driver=self, extra=extra) From d16c45c2d8ea8d501f938faaa7e1c6162ae767be Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Thu, 6 Jun 2024 11:37:28 +0200 Subject: [PATCH 3/5] Add also description field --- libcloud/compute/drivers/openstack.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index d5096b9728..38b7c64be3 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -3164,6 +3164,8 @@ def _to_network(self, obj): extra["tags"] = obj.get("tags") if obj.get("is_default", None) is not None: extra["is_default"] = obj.get("is_default") + if obj.get("description", None): + extra["description"] = obj.get("description") return OpenStackNetwork(id=obj["id"], name=obj["name"], cidr=None, driver=self, extra=extra) def ex_list_networks(self): From b98e593a3f512c30171ca24988aecc7540732349 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Mon, 17 Jun 2024 08:11:39 +0200 Subject: [PATCH 4/5] Improve coverage --- libcloud/compute/drivers/openstack.py | 2 +- .../test/compute/fixtures/openstack_v1.1/_v2_0__network.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index 38b7c64be3..cea1974567 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -3164,7 +3164,7 @@ def _to_network(self, obj): extra["tags"] = obj.get("tags") if obj.get("is_default", None) is not None: extra["is_default"] = obj.get("is_default") - if obj.get("description", None): + if obj.get("description", None) is not None: extra["description"] = obj.get("description") return OpenStackNetwork(id=obj["id"], name=obj["name"], cidr=None, driver=self, extra=extra) diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network.json index 5686828996..b1b6005700 100644 --- a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network.json +++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network.json @@ -27,6 +27,7 @@ "updated_at": "2016-03-08T20:19:41", "vlan_transparent": false, "description": "", - "is_default": false + "is_default": false, + "tags": ["tag1,tag2"] } } From 00f3a02273443bd92aad1c9ddab260f22a15f076 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Mon, 17 Jun 2024 08:36:41 +0200 Subject: [PATCH 5/5] Improve coverage --- .../_v2_0__network_no_tags.json | 30 +++++++++++++++++++ libcloud/test/compute/test_openstack.py | 21 +++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network_no_tags.json diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network_no_tags.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network_no_tags.json new file mode 100644 index 0000000000..19e54b6a4f --- /dev/null +++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__network_no_tags.json @@ -0,0 +1,30 @@ +{ + "network": { + "admin_state_up": true, + "availability_zone_hints": [], + "availability_zones": [ + "nova" + ], + "created_at": "2016-03-08T20:19:41", + "dns_domain": "my-domain.org.", + "id": "e4e207ac-6707-432b-82b9-244f6859c394", + "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 + } +} diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py index 7820a6657c..51506995bc 100644 --- a/libcloud/test/compute/test_openstack.py +++ b/libcloud/test/compute/test_openstack.py @@ -2122,6 +2122,14 @@ def test_ex_get_network(self): self.assertTrue(isinstance(network, OpenStackNetwork)) self.assertEqual(network.name, "net2") self.assertEqual(network.extra["is_default"], False) + self.assertEqual(network.extra["tags"], ["tag1,tag2"]) + + network = self.driver.ex_get_network("e4e207ac-6707-432b-82b9-244f6859c394") + + self.assertEqual(network.id, "e4e207ac-6707-432b-82b9-244f6859c394") + self.assertTrue(isinstance(network, OpenStackNetwork)) + self.assertEqual(network.name, "net2") + self.assertNotIn("tags", network.extra) def test_ex_list_subnets(self): subnets = self.driver.ex_list_subnets() @@ -3406,6 +3414,19 @@ def _v2_1337_v2_0_networks_cc2dad14_827a_feea_416b_f13e50511a0a( ) raise NotImplementedError() + def _v2_1337_v2_0_networks_e4e207ac_6707_432b_82b9_244f6859c394( + self, method, url, body, headers + ): + if method == "GET": + body = self.fixtures.load("_v2_0__network_no_tags.json") + return ( + httplib.OK, + 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 ):