Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some extra fields in the OpenStack Network Object: #2015 #2016

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libcloud/compute/drivers/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3160,6 +3160,12 @@ 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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per codecov comment (#2016 (comment)) could you please add additional test cases so all the new code paths are covered?

This includes tests for all those fields being present and not being present (so both the explicit "if" and implicit "else" code branches are covered).

Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

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) is not 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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"updated_at": "2016-03-08T20:19:41",
"vlan_transparent": false,
"description": "",
"is_default": false
"is_default": false,
"tags": ["tag1,tag2"]
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
22 changes: 22 additions & 0 deletions libcloud/test/compute/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,15 @@ 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)
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()
Expand Down Expand Up @@ -3405,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
):
Expand Down