|
|
|
@ -13,7 +13,12 @@
|
|
|
|
|
# under the License.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
import collections
|
|
|
|
|
import fixtures
|
|
|
|
|
import json
|
|
|
|
|
import mock
|
|
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
from osc_lib.tests import utils as test_utils
|
|
|
|
|
|
|
|
|
@ -22,6 +27,151 @@ from tripleoclient.tests.v2.overcloud_node import fakes
|
|
|
|
|
from tripleoclient.v2 import overcloud_node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestImportNode(fakes.TestOvercloudNode):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super(TestImportNode, self).setUp()
|
|
|
|
|
|
|
|
|
|
self.nodes_list = [{
|
|
|
|
|
"pm_user": "stack",
|
|
|
|
|
"pm_addr": "192.168.122.1",
|
|
|
|
|
"pm_password": "KEY1",
|
|
|
|
|
"pm_type": "pxe_ssh",
|
|
|
|
|
"mac": [
|
|
|
|
|
"00:0b:d0:69:7e:59"
|
|
|
|
|
],
|
|
|
|
|
}, {
|
|
|
|
|
"pm_user": "stack",
|
|
|
|
|
"pm_addr": "192.168.122.2",
|
|
|
|
|
"pm_password": "KEY2",
|
|
|
|
|
"pm_type": "pxe_ssh",
|
|
|
|
|
"mac": [
|
|
|
|
|
"00:0b:d0:69:7e:58"
|
|
|
|
|
]
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
# NOTE(cloudnull): Workflow and client calls are still mocked because
|
|
|
|
|
# mistal is still presnet here.
|
|
|
|
|
self.workflow = self.app.client_manager.workflow_engine
|
|
|
|
|
execution = mock.Mock()
|
|
|
|
|
execution.id = "IDID"
|
|
|
|
|
self.workflow.executions.create.return_value = execution
|
|
|
|
|
client = self.app.client_manager.tripleoclient
|
|
|
|
|
self.websocket = client.messaging_websocket()
|
|
|
|
|
self.websocket.wait_for_messages.return_value = [{
|
|
|
|
|
"status": "SUCCESS",
|
|
|
|
|
"message": "Success",
|
|
|
|
|
"registered_nodes": [{
|
|
|
|
|
"uuid": "MOCK_NODE_UUID"
|
|
|
|
|
}],
|
|
|
|
|
"execution_id": execution.id
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
self.json_file = tempfile.NamedTemporaryFile(
|
|
|
|
|
mode='w', delete=False, suffix='.json')
|
|
|
|
|
json.dump(self.nodes_list, self.json_file)
|
|
|
|
|
self.json_file.close()
|
|
|
|
|
self.addCleanup(os.unlink, self.json_file.name)
|
|
|
|
|
|
|
|
|
|
# Get the command object to test
|
|
|
|
|
self.cmd = overcloud_node.ImportNode(self.app, None)
|
|
|
|
|
|
|
|
|
|
image = collections.namedtuple('image', ['id', 'name'])
|
|
|
|
|
self.app.client_manager.image = mock.Mock()
|
|
|
|
|
self.app.client_manager.image.images.list.return_value = [
|
|
|
|
|
image(id=3, name='overcloud-full'),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.http_boot = '/var/lib/ironic/httpboot'
|
|
|
|
|
|
|
|
|
|
self.useFixture(fixtures.MockPatch(
|
|
|
|
|
'os.path.exists', autospec=True,
|
|
|
|
|
side_effect=lambda path: path in [os.path.join(self.http_boot, i)
|
|
|
|
|
for i in ('agent.kernel',
|
|
|
|
|
'agent.ramdisk')]))
|
|
|
|
|
|
|
|
|
|
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
|
|
|
|
autospec=True)
|
|
|
|
|
def test_import_only(self, mock_playbook):
|
|
|
|
|
parsed_args = self.check_parser(self.cmd,
|
|
|
|
|
[self.json_file.name],
|
|
|
|
|
[('introspect', False),
|
|
|
|
|
('provide', False)])
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
|
|
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
|
|
|
|
autospec=True)
|
|
|
|
|
def test_import_and_introspect(self, mock_playbook):
|
|
|
|
|
parsed_args = self.check_parser(self.cmd,
|
|
|
|
|
[self.json_file.name,
|
|
|
|
|
'--introspect'],
|
|
|
|
|
[('introspect', True),
|
|
|
|
|
('provide', False)])
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
mock_playbook.assert_called_once_with(
|
|
|
|
|
workdir=mock.ANY,
|
|
|
|
|
playbook=mock.ANY,
|
|
|
|
|
inventory=mock.ANY,
|
|
|
|
|
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
|
|
|
|
extra_vars={
|
|
|
|
|
'node_uuids': ['MOCK_NODE_UUID'],
|
|
|
|
|
'run_validations': False,
|
|
|
|
|
'concurrency': 20
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
|
|
|
|
autospec=True)
|
|
|
|
|
def test_import_and_provide(self, mock_playbook):
|
|
|
|
|
parsed_args = self.check_parser(self.cmd,
|
|
|
|
|
[self.json_file.name,
|
|
|
|
|
'--provide'],
|
|
|
|
|
[('introspect', False),
|
|
|
|
|
('provide', True)])
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
|
|
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
|
|
|
|
autospec=True)
|
|
|
|
|
def test_import_and_introspect_and_provide(self, mock_playbook):
|
|
|
|
|
parsed_args = self.check_parser(self.cmd,
|
|
|
|
|
[self.json_file.name,
|
|
|
|
|
'--introspect',
|
|
|
|
|
'--provide'],
|
|
|
|
|
[('introspect', True),
|
|
|
|
|
('provide', True)])
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
mock_playbook.assert_called_once_with(
|
|
|
|
|
workdir=mock.ANY,
|
|
|
|
|
playbook=mock.ANY,
|
|
|
|
|
inventory=mock.ANY,
|
|
|
|
|
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
|
|
|
|
extra_vars={
|
|
|
|
|
'node_uuids': ['MOCK_NODE_UUID'],
|
|
|
|
|
'run_validations': False,
|
|
|
|
|
'concurrency': 20
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
|
|
|
|
autospec=True)
|
|
|
|
|
def test_import_with_netboot(self, mock_playbook):
|
|
|
|
|
parsed_args = self.check_parser(self.cmd,
|
|
|
|
|
[self.json_file.name,
|
|
|
|
|
'--no-deploy-image'],
|
|
|
|
|
[('no_deploy_image', True)])
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
|
|
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
|
|
|
|
autospec=True)
|
|
|
|
|
def test_import_with_no_deployed_image(self, mock_playbook):
|
|
|
|
|
parsed_args = self.check_parser(self.cmd,
|
|
|
|
|
[self.json_file.name,
|
|
|
|
|
'--instance-boot-option',
|
|
|
|
|
'netboot'],
|
|
|
|
|
[('instance_boot_option', 'netboot')])
|
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestIntrospectNode(fakes.TestOvercloudNode):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|