Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Remove tripleoclient.baremetal wrapper
Browse files Browse the repository at this point in the history
The Ironic client now supports the OSC plugin interface directly, so
this wrapper is no longer needed. Removing it will allow us to specify
which Ironic API version to use via the standard mechanisms.

Change-Id: If92855c307ecd389fbe6050e426d0ced959a9665
Depends-On: Icdbd28c487351af6d67205837aa536aedb31b41a
  • Loading branch information
Miles Gould committed Feb 9, 2016
1 parent cff4ff4 commit 000f67a
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 100 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ passlib>=1.6
python-ironic-inspector-client>=1.3.0
# os-cloud-config>=0.3.1
python-heatclient>=0.6.0
python-ironicclient>=0.8.0
python-ironicclient>=1.1.0 # Apache-2.0
python-openstackclient>=2.0.0
six>=1.9.0

Expand Down
26 changes: 0 additions & 26 deletions tripleoclient/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import logging

from ironicclient import client as ironic_client
from openstackclient.common import utils


Expand Down Expand Up @@ -64,33 +63,8 @@ class ClientWrapper(object):

def __init__(self, instance):
self._instance = instance
self._baremetal = None
self._orchestration = None

@property
def baremetal(self):
"""Returns an baremetal service client"""

# TODO(d0ugal): When the ironicclient has it's own OSC plugin, the
# following client handling code should be removed in favor of the
# upstream version.

if self._baremetal is not None:
return self._baremetal

endpoint = self._instance.get_endpoint_for_service_type(
"baremetal",
region_name=self._instance._region_name,
)

token = self._instance.auth.get_token(self._instance.session)

self._baremetal = ironic_client.get_client(
1, os_auth_token=token, ironic_url=endpoint,
ca_file=self._instance._cli_options.os_cacert)

return self._baremetal

@property
def orchestration(self):
"""Returns an orchestration service client"""
Expand Down
15 changes: 6 additions & 9 deletions tripleoclient/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@

class TestPlugin(base.TestCase):

@mock.patch('ironicclient.client.get_client')
def test_make_client(self, ironic_get_client):
def test_make_client(self):
clientmgr = mock.MagicMock()
clientmgr._api_version.__getitem__.return_value = '1'
clientmgr.get_endpoint_for_service_type.return_value = fakes.AUTH_URL

client = plugin.make_client(clientmgr)

# The client should have a baremetal property. Accessing it should
# The client should have an orchestration property. Accessing it should
# fetch it from the clientmanager:
baremetal = client.baremetal
orchestration = client.orchestration
# The second access should return the same clients:
self.assertIs(client.baremetal, baremetal)
# The second access should return the same client:
self.assertIs(client.orchestration, orchestration)

# And the functions should only be called per property:
self.assertEqual(clientmgr.get_endpoint_for_service_type.call_count, 2)
self.assertEqual(clientmgr.auth.get_token.call_count, 2)
# And the functions should only be called when the client is created:
self.assertEqual(clientmgr.get_endpoint_for_service_type.call_count, 1)
self.assertEqual(clientmgr.auth.get_token.call_count, 1)
13 changes: 1 addition & 12 deletions tripleoclient/tests/v1/baremetal/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,11 @@ def list(self, *args, **kwargs):
for uuid in (sorted(self.states.keys()))]


class FakeClientWrapper(object):

def __init__(self):
self._instance = mock.Mock()
self._baremetal = mock.Mock()

@property
def baremetal(self):
return self._baremetal


class TestBaremetal(utils.TestCommand):

def setUp(self):
super(TestBaremetal, self).setUp()

self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
self.app.client_manager.tripleoclient = FakeClientWrapper()
self.app.client_manager.baremetal = mock.Mock()
self.app.client_manager.image = mock.Mock()
54 changes: 27 additions & 27 deletions tripleoclient/tests/v1/baremetal/test_baremetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_json_import(self, mock_register_nodes):
'mac': ['00:0b:d0:69:7e:58']
}
],
client=self.app.client_manager.tripleoclient.baremetal,
client=self.app.client_manager.baremetal,
keystone_client=None)

@mock.patch('os_cloud_config.nodes.register_all_nodes', autospec=True)
Expand Down Expand Up @@ -405,7 +405,7 @@ def test_instack_json_import(self, mock_register_nodes):
'mac': ['00:0b:d0:69:7e:58']
}
],
client=self.app.client_manager.tripleoclient.baremetal,
client=self.app.client_manager.baremetal,
keystone_client=None)

@mock.patch('os_cloud_config.nodes.register_all_nodes', autospec=True)
Expand Down Expand Up @@ -439,7 +439,7 @@ def test_csv_import(self, mock_register_nodes):
'mac': ['00:7c:ef:3d:eb:60']
}
],
client=self.app.client_manager.tripleoclient.baremetal,
client=self.app.client_manager.baremetal,
keystone_client=None)


Expand All @@ -455,7 +455,7 @@ def setUp(self):
@mock.patch.object(baremetal.inspector_client, 'get_status', autospec=True)
@mock.patch.object(baremetal.inspector_client, 'introspect', autospec=True)
def test_introspect_bulk_one(self, inspection_mock, get_status_mock):
client = self.app.client_manager.tripleoclient.baremetal
client = self.app.client_manager.baremetal
client.node = fakes.FakeBaremetalNodeClient(
states={"ABCDEFGH": "available"},
transitions={
Expand All @@ -479,7 +479,7 @@ def test_introspect_bulk_one(self, inspection_mock, get_status_mock):
@mock.patch.object(baremetal.inspector_client, 'introspect', autospec=True)
def test_introspect_bulk_failed(self, introspect_mock, get_status_mock):

client = self.app.client_manager.tripleoclient.baremetal
client = self.app.client_manager.baremetal
client.node = fakes.FakeBaremetalNodeClient(
states={"ABCDEFGH": "available", "IJKLMNOP": "available"},
transitions={
Expand Down Expand Up @@ -510,7 +510,7 @@ def test_introspect_bulk_failed(self, introspect_mock, get_status_mock):
@mock.patch.object(baremetal.inspector_client, 'get_status', autospec=True)
@mock.patch.object(baremetal.inspector_client, 'introspect', autospec=True)
def test_introspect_bulk(self, introspect_mock, get_status_mock):
client = self.app.client_manager.tripleoclient.baremetal
client = self.app.client_manager.baremetal
client.node = fakes.FakeBaremetalNodeClient(
states={
"ABC": "available",
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_introspect_bulk(self, introspect_mock, get_status_mock):
@mock.patch.object(baremetal.inspector_client, 'get_status', autospec=True)
@mock.patch.object(baremetal.inspector_client, 'introspect', autospec=True)
def test_introspect_bulk_timeout(self, introspect_mock, get_status_mock):
client = self.app.client_manager.tripleoclient.baremetal
client = self.app.client_manager.baremetal
client.node = fakes.FakeBaremetalNodeClient(
states={
"ABC": "available",
Expand Down Expand Up @@ -591,7 +591,7 @@ def test_introspect_bulk_timeout(self, introspect_mock, get_status_mock):
@mock.patch.object(baremetal.inspector_client, 'introspect', autospec=True)
def test_introspect_bulk_transition_fails(self, introspect_mock,
get_status_mock):
client = self.app.client_manager.tripleoclient.baremetal
client = self.app.client_manager.baremetal
client.node = fakes.FakeBaremetalNodeClient(
states={
"ABC": "available",
Expand Down Expand Up @@ -636,7 +636,7 @@ def setUp(self):
@mock.patch.object(baremetal.inspector_client, 'get_status', autospec=True)
def test_status_bulk_one(self, get_status_mock):

client = self.app.client_manager.tripleoclient.baremetal
client = self.app.client_manager.baremetal
client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH")
]
Expand All @@ -658,7 +658,7 @@ def test_status_bulk_one(self, get_status_mock):
@mock.patch.object(baremetal.inspector_client, 'get_status', autospec=True)
def test_status_bulk(self, get_status_mock):

client = self.app.client_manager.tripleoclient.baremetal
client = self.app.client_manager.baremetal
client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH"),
mock.Mock(uuid="IJKLMNOP"),
Expand Down Expand Up @@ -719,7 +719,7 @@ def test_configure_ready_state(self, mock_run_introspection,
nodes = [mock.Mock(uuid='foo', driver='drac'),
mock.Mock(uuid='bar', driver='ilo'),
mock.Mock(uuid='baz', driver='drac')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = nodes

argslist = ['--delete-existing-raid-volumes']
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_configure_ready_state_with_delete_existing_raid_volumes(
nodes = [mock.Mock(uuid='foo', driver='drac'),
mock.Mock(uuid='bar', driver='ilo'),
mock.Mock(uuid='baz', driver='drac')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = nodes

parsed_args = self.check_parser(self.cmd, [], [])
Expand All @@ -784,7 +784,7 @@ def test_configure_ready_state_with_delete_existing_raid_volumes(
return_value=0)
def test__configure_bios(self, mock_sleep_time):
nodes = [mock.Mock(uuid='foo')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
self.cmd.bm_client = bm_client

self.cmd._configure_bios(nodes)
Expand All @@ -797,7 +797,7 @@ def test__configure_bios(self, mock_sleep_time):
return_value=0)
def test__configure_root_raid_volumes(self, mock_sleep_time):
nodes = [mock.Mock(uuid='foo')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
self.cmd.bm_client = bm_client

self.cmd._configure_root_raid_volumes(nodes)
Expand All @@ -813,7 +813,7 @@ def test__configure_root_raid_volumes(self, mock_sleep_time):
return_value=0)
def test__configure_nonroot_raid_volumes(self, mock_sleep_time):
nodes = [mock.Mock(uuid='foo')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
self.cmd.bm_client = bm_client

self.cmd._configure_nonroot_raid_volumes(nodes)
Expand All @@ -829,7 +829,7 @@ def test__configure_nonroot_raid_volumes(self, mock_sleep_time):
return_value=0)
def test__wait_for_drac_config_jobs(self, mock_sleep_time):
nodes = [mock.Mock(uuid='foo')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.vendor_passthru.side_effect = [
mock.Mock(unfinished_jobs={'percent_complete': '34',
'id': 'JID_343938731947',
Expand All @@ -850,7 +850,7 @@ def test__wait_for_drac_config_jobs(self, mock_sleep_time):
return_value=0)
def test__wait_for_drac_config_jobs_times_out(self, mock_sleep_time):
nodes = [mock.Mock(uuid='foo')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.vendor_passthru.return_value = mock.Mock(
unfinished_jobs={'percent_complete': '34',
'id': 'JID_343938731947',
Expand All @@ -867,7 +867,7 @@ def test__wait_for_drac_config_jobs_times_out(self, mock_sleep_time):
def test__delete_raid_volumes(self, mock_sleep_time):
node_with_raid_volume = mock.Mock(uuid='foo')
nodes = [node_with_raid_volume, mock.Mock(uuid='bar')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.vendor_passthru.side_effect = [
mock.Mock(virtual_disks=[
{'controller': 'RAID.Integrated.1-1',
Expand Down Expand Up @@ -896,7 +896,7 @@ def test__delete_raid_volumes(self, mock_sleep_time):

def test__change_power_state(self):
nodes = [mock.Mock(uuid='foo')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
self.cmd.bm_client = bm_client

self.cmd._change_power_state(nodes, 'reboot')
Expand All @@ -909,7 +909,7 @@ def test__change_power_state(self):
def test__run_introspection(self, mock_wait_for_node_introspection,
mock_introspect):
nodes = [mock.Mock(uuid='foo')]
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
self.cmd.bm_client = bm_client
self.cmd.inspector_url = None

Expand All @@ -933,7 +933,7 @@ def setUp(self):
def test_configure_boot(self, find_resource_mock):

find_resource_mock.return_value = mock.Mock(id="IDIDID")
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH"),
mock.Mock(uuid="IJKLMNOP"),
Expand Down Expand Up @@ -981,7 +981,7 @@ def test_configure_boot(self, find_resource_mock):
def test_configure_boot_with_suffix(self, find_resource_mock):

find_resource_mock.return_value = mock.Mock(id="IDIDID")
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH"),
mock.Mock(uuid="IJKLMNOP"),
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def test_configure_boot_with_suffix(self, find_resource_mock):
def test_configure_boot_in_transition(self, _, find_resource_mock):
find_resource_mock.return_value = mock.Mock(id="IDIDID")

bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = [mock.Mock(uuid="ABCDEFGH",
power_state=None),
]
Expand Down Expand Up @@ -1065,7 +1065,7 @@ def test_configure_boot_in_transition(self, _, find_resource_mock):
def test_configure_boot_timeout(self, _, find_resource_mock):
find_resource_mock.return_value = mock.Mock(id="IDIDID")

bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = [mock.Mock(uuid="ABCDEFGH",
power_state=None),
]
Expand All @@ -1080,7 +1080,7 @@ def test_configure_boot_timeout(self, _, find_resource_mock):
def test_configure_boot_skip_maintenance(self, find_resource_mock):

find_resource_mock.return_value = mock.Mock(id="IDIDID")
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH", maintenance=False),
]
Expand All @@ -1099,7 +1099,7 @@ def test_configure_boot_skip_maintenance(self, find_resource_mock):
def test_configure_boot_existing_properties(self, find_resource_mock):

find_resource_mock.return_value = mock.Mock(id="IDIDID")
bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal
bm_client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH"),
mock.Mock(uuid="IJKLMNOP"),
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def setUp(self):

def test_success(self):

bm_client = self.app.client_manager.tripleoclient.baremetal
bm_client = self.app.client_manager.baremetal

bm_client.node.list.return_value = [
mock.Mock(uuid='UUID1'),
Expand Down
6 changes: 1 addition & 5 deletions tripleoclient/tests/v1/overcloud_deploy/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ class FakeClientWrapper(object):
def __init__(self):
self._instance = mock.Mock()
self._orchestration = mock.Mock()
self._baremetal = mock.Mock()

@property
def orchestration(self):
return self._orchestration

@property
def baremetal(self):
return self._baremetal


class TestDeployOvercloud(utils.TestCommand):

Expand All @@ -66,6 +61,7 @@ def setUp(self):

self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
self.app.client_manager.tripleoclient = FakeClientWrapper()
self.app.client_manager.baremetal = mock.Mock()
self.app.client_manager.network = mock.Mock()
self.app.client_manager.compute = mock.Mock()
self.app.client_manager.identity = mock.Mock()
Expand Down
Loading

0 comments on commit 000f67a

Please sign in to comment.