Skip to content

Commit e51af68

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "trivial: Replace references to private _proxy modules"
2 parents 37dc072 + f9d37bf commit e51af68

12 files changed

Lines changed: 85 additions & 63 deletions

File tree

openstackclient/common/clientmanager.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,21 @@
2020
import importlib
2121
import logging
2222
import sys
23-
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, runtime_checkable
23+
from typing import Any, Protocol, TypeVar, runtime_checkable
2424

25+
from keystoneauth1 import access as ksa_access
26+
from openstack.compute import v2 as compute_v2
27+
from openstack.image import v2 as image_v2
28+
from openstack.network import v2 as network_v2
2529
from osc_lib.cli import client_config
2630
from osc_lib import clientmanager
2731
from osc_lib import shell
2832
import stevedore
2933

30-
if TYPE_CHECKING:
31-
from keystoneauth1 import access as ksa_access
32-
from openstack.compute.v2 import _proxy as compute_proxy
33-
from openstack.image.v2 import _proxy as image_proxy
34-
from openstack.network.v2 import _proxy as network_proxy
35-
36-
from openstackclient.api import object_store_v1
34+
from openstackclient.api import object_store_v1
3735

3836
LOG = logging.getLogger(__name__)
39-
4037
PLUGIN_MODULES: list[Any] = []
41-
4238
USER_AGENT = 'python-openstackclient'
4339

4440

@@ -50,23 +46,19 @@ class ClientManager(clientmanager.ClientManager):
5046
in osc-lib so we need to maintain a transition period.
5147
"""
5248

53-
if TYPE_CHECKING:
54-
# we know this will be set by us and will not be nullable
55-
auth_ref: ksa_access.AccessInfo
56-
57-
# this is a hack to keep mypy happy: the actual attributes are set in
58-
# get_plugin_modules below
59-
# TODO(stephenfin): Change the types of identity and volume once we've
60-
# migrated everything to SDK. Hopefully by then we'll have figured out
61-
# how to statically distinguish between the v2 and v3 versions of both
62-
# services...
63-
# TODO(stephenfin): We also need to migrate object storage...
64-
compute: compute_proxy.Proxy
65-
identity: Any
66-
image: image_proxy.Proxy
67-
network: network_proxy.Proxy
68-
object_store: object_store_v1.APIv1
69-
volume: Any
49+
# we know this will be set by us and will not be nullable
50+
auth_ref: ksa_access.AccessInfo
51+
52+
# this is a hack to keep mypy happy: the actual attributes are set in
53+
# get_plugin_modules below
54+
# TODO(stephenfin): Change the types of identity, object store and volume
55+
# once we've migrated everything to SDK
56+
compute: compute_v2.Proxy
57+
identity: Any
58+
image: image_v2.Proxy
59+
network: network_v2.Proxy
60+
object_store: object_store_v1.APIv1
61+
volume: Any
7062

7163
def __init__(
7264
self,

openstackclient/tests/unit/api/test_compute_v2.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from unittest import mock
1818
import uuid
1919

20-
from openstack.compute.v2 import _proxy
20+
from openstack.compute import v2 as compute_v2
2121
from osc_lib import exceptions as osc_lib_exceptions
2222

2323
from openstackclient.api import compute_v2 as compute
@@ -29,7 +29,10 @@ class TestSecurityGroup(utils.TestCase):
2929
def setUp(self):
3030
super().setUp()
3131

32-
self.compute_client = mock.Mock(_proxy.Proxy)
32+
# TODO(stephenfin): Switch to spec_set once keystoneauth exposes
33+
# instance attributes as class attributes
34+
# https://review.opendev.org/c/openstack/keystoneauth/+/994090
35+
self.compute_client = mock.Mock(spec=compute_v2.Proxy)
3336

3437
def test_create_security_group(self):
3538
sg_name = 'name-' + uuid.uuid4().hex
@@ -223,7 +226,7 @@ class TestSecurityGroupRule(utils.TestCase):
223226
def setUp(self):
224227
super().setUp()
225228

226-
self.compute_client = mock.Mock(_proxy.Proxy)
229+
self.compute_client = mock.Mock(spec=compute_v2.Proxy)
227230

228231
def test_create_security_group_rule(self):
229232
sg_id = uuid.uuid4().hex
@@ -281,7 +284,7 @@ class TestNetwork(utils.TestCase):
281284
def setUp(self):
282285
super().setUp()
283286

284-
self.compute_client = mock.Mock(_proxy.Proxy)
287+
self.compute_client = mock.Mock(spec=compute_v2.Proxy)
285288

286289
def test_create_network(self):
287290
net_name = 'name-' + uuid.uuid4().hex
@@ -443,7 +446,7 @@ class TestFloatingIP(utils.TestCase):
443446
def setUp(self):
444447
super().setUp()
445448

446-
self.compute_client = mock.Mock(_proxy.Proxy)
449+
self.compute_client = mock.Mock(spec=compute_v2.Proxy)
447450

448451
def test_create_floating_ip(self):
449452
network = 'network-' + uuid.uuid4().hex
@@ -528,7 +531,7 @@ class TestFloatingIPPool(utils.TestCase):
528531
def setUp(self):
529532
super().setUp()
530533

531-
self.compute_client = mock.Mock(_proxy.Proxy)
534+
self.compute_client = mock.Mock(spec=compute_v2.Proxy)
532535

533536
def test_list_floating_ip_pools(self):
534537
data = {

openstackclient/tests/unit/api/test_volume_v2.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from unittest import mock
1818
import uuid
1919

20-
from openstack.block_storage.v2 import _proxy
20+
from openstack.block_storage import v2 as block_storage_v2
2121
from osc_lib import exceptions as osc_lib_exceptions
2222

2323
from openstackclient.api import volume_v2 as volume
@@ -29,7 +29,10 @@ class TestConsistencyGroup(utils.TestCase):
2929
def setUp(self):
3030
super().setUp()
3131

32-
self.volume_sdk_client = mock.Mock(_proxy.Proxy)
32+
# TODO(stephenfin): Switch to spec_set once keystoneauth exposes
33+
# instance attributes as class attributes
34+
# https://review.opendev.org/c/openstack/keystoneauth/+/994090
35+
self.volume_sdk_client = mock.Mock(spec=block_storage_v2.Proxy)
3336

3437
def test_find_consistency_group_by_id(self):
3538
cg_id = uuid.uuid4().hex

openstackclient/tests/unit/api/test_volume_v3.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from unittest import mock
1818
import uuid
1919

20-
from openstack.block_storage.v3 import _proxy
20+
from openstack.block_storage import v3 as block_storage_v3
2121
from osc_lib import exceptions as osc_lib_exceptions
2222

2323
from openstackclient.api import volume_v3 as volume
@@ -29,7 +29,10 @@ class TestConsistencyGroup(utils.TestCase):
2929
def setUp(self):
3030
super().setUp()
3131

32-
self.volume_sdk_client = mock.Mock(_proxy.Proxy)
32+
# TODO(stephenfin): Switch to spec_set once keystoneauth exposes
33+
# instance attributes as class attributes
34+
# https://review.opendev.org/c/openstack/keystoneauth/+/994090
35+
self.volume_sdk_client = mock.Mock(spec=block_storage_v3.Proxy)
3336

3437
def test_find_consistency_group_by_id(self):
3538
cg_id = uuid.uuid4().hex

openstackclient/tests/unit/compute/v2/fakes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import uuid
2020

2121
from keystoneauth1 import discover
22-
from openstack.compute.v2 import _proxy
22+
from openstack.compute import v2 as compute_v2
2323
from openstack.compute.v2 import availability_zone as _availability_zone
2424
from openstack.compute.v2 import extension as _extension
2525
from openstack.compute.v2 import flavor as _flavor
@@ -44,7 +44,10 @@ class FakeClientMixin:
4444
def setUp(self):
4545
super().setUp()
4646

47-
self.app.client_manager.compute = mock.Mock(_proxy.Proxy)
47+
# TODO(stephenfin): Switch to spec_set once keystoneauth exposes
48+
# instance attributes as class attributes
49+
# https://review.opendev.org/c/openstack/keystoneauth/+/994090
50+
self.app.client_manager.compute = mock.Mock(spec=compute_v2.Proxy)
4851
self.compute_client = self.app.client_manager.compute
4952
self.set_compute_api_version() # default to the lowest
5053

openstackclient/tests/unit/identity/v2_0/fakes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from keystoneauth1 import access
2121
from keystoneauth1 import fixture
22-
from openstack.identity.v2 import _proxy
22+
from openstack.identity import v2 as identity_v2
2323

2424
from openstackclient.tests.unit import fakes
2525
from openstackclient.tests.unit import utils
@@ -193,7 +193,7 @@ def setUp(self):
193193
# TODO(stephenfin): Rename to 'identity_client' once all commands are
194194
# migrated to SDK
195195
self.app.client_manager.sdk_connection.identity = mock.Mock(
196-
_proxy.Proxy
196+
identity_v2.Proxy
197197
)
198198
self.identity_sdk_client = (
199199
self.app.client_manager.sdk_connection.identity

openstackclient/tests/unit/identity/v3/fakes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from keystoneauth1 import access
2222
from keystoneauth1 import fixture
23-
from openstack.identity.v3 import _proxy
23+
from openstack.identity import v3 as identity_v3
2424
from osc_lib.cli import format_columns
2525

2626
from openstackclient.tests.unit import fakes
@@ -647,7 +647,7 @@ def setUp(self):
647647
# TODO(stephenfin): Rename to 'identity_client' once all commands are
648648
# migrated to SDK
649649
self.app.client_manager.sdk_connection.identity = mock.Mock(
650-
_proxy.Proxy
650+
identity_v3.Proxy
651651
)
652652
self.app.client_manager.sdk_connection.identity.api_version = '3'
653653
self.identity_sdk_client = (
@@ -682,7 +682,7 @@ def setUp(self):
682682
# TODO(stephenfin): Rename to 'identity_client' once all commands are
683683
# migrated to SDK
684684
self.app.client_manager.sdk_connection.identity = mock.Mock(
685-
_proxy.Proxy
685+
identity_v3.Proxy
686686
)
687687
self.app.client_manager.sdk_connection.identity.api_version = '3'
688688
self.identity_sdk_client = (
@@ -703,7 +703,7 @@ def setUp(self):
703703
# TODO(stephenfin): Rename to 'identity_client' once all commands are
704704
# migrated to SDK
705705
self.app.client_manager.sdk_connection.identity = mock.Mock(
706-
_proxy.Proxy
706+
identity_v3.Proxy
707707
)
708708
self.app.client_manager.sdk_connection.identity.api_version = '3'
709709
self.identity_sdk_client = (

openstackclient/tests/unit/image/v1/fakes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from unittest import mock
1616
import uuid
1717

18-
from openstack.block_storage.v2 import _proxy as block_storage_v2_proxy
19-
from openstack.image.v1 import _proxy
18+
from openstack.block_storage import v2 as block_storage_v2
19+
from openstack.image import v1 as image_v1
2020
from openstack.image.v1 import image
2121

2222
from openstackclient.tests.unit import fakes
@@ -28,7 +28,10 @@ class FakeClientMixin:
2828
def setUp(self):
2929
super().setUp()
3030

31-
self.app.client_manager.image = mock.Mock(spec=_proxy.Proxy)
31+
# TODO(stephenfin): Switch to spec_set once keystoneauth exposes
32+
# instance attributes as class attributes
33+
# https://review.opendev.org/c/openstack/keystoneauth/+/994090
34+
self.app.client_manager.image = mock.Mock(spec=image_v1.Proxy)
3235
self.image_client = self.app.client_manager.image
3336

3437

@@ -43,7 +46,7 @@ def setUp(self):
4346
self.volume_client = self.app.client_manager.volume
4447

4548
self.app.client_manager.sdk_connection.volume = mock.Mock(
46-
spec=block_storage_v2_proxy.Proxy,
49+
spec=block_storage_v2.Proxy
4750
)
4851
self.app.client_manager.sdk_connection.volume.api_version = '2'
4952
self.volume_sdk_client = self.app.client_manager.sdk_connection.volume

openstackclient/tests/unit/image/v2/fakes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from unittest import mock
1717
import uuid
1818

19-
from openstack.image.v2 import _proxy
19+
from openstack.image import v2 as image_v2
2020
from openstack.image.v2 import cache
2121
from openstack.image.v2 import image
2222
from openstack.image.v2 import member
@@ -35,7 +35,10 @@ class FakeClientMixin:
3535
def setUp(self):
3636
super().setUp()
3737

38-
self.app.client_manager.image = mock.Mock(spec=_proxy.Proxy)
38+
# TODO(stephenfin): Switch to spec_set once keystoneauth exposes
39+
# instance attributes as class attributes
40+
# https://review.opendev.org/c/openstack/keystoneauth/+/994090
41+
self.app.client_manager.image = mock.Mock(spec=image_v2.Proxy)
3942
self.image_client = self.app.client_manager.image
4043

4144

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from unittest import mock
1717
import uuid
1818

19-
from openstack.network.v2 import _proxy
19+
from openstack.network import v2 as network_v2
2020
from openstack.network.v2 import address_group as _address_group
2121
from openstack.network.v2 import address_scope as _address_scope
2222
from openstack.network.v2 import agent as network_agent
@@ -99,7 +99,10 @@ class FakeClientMixin:
9999
def setUp(self):
100100
super().setUp()
101101

102-
self.app.client_manager.network = mock.Mock(spec=_proxy.Proxy)
102+
# TODO(stephenfin): Switch to spec_set once keystoneauth exposes
103+
# instance attributes as class attributes
104+
# https://review.opendev.org/c/openstack/keystoneauth/+/994090
105+
self.app.client_manager.network = mock.Mock(spec=network_v2.Proxy)
103106
self.network_client = self.app.client_manager.network
104107

105108

0 commit comments

Comments
 (0)