ironic-python-agent/ironic_python_agent/tests/unit/extensions/test_poll.py
Kaifeng Wang 61c95554ff Adds poll mode deployment support
Adds a new poll extension to provide get_hardware_info and get_node_info
interfaces.

get_hardware_info will be used for node validation by ironic deploy
drivers.

get_node_info will be used for sending lookup data to IPA.

standalone mode is assumed as debug only, but it's not the case
considering the poll mode will be introduced, slightly updates the
description, also prevents the mdns lookup when standalone is true.

Story: 1526486
Task: 28724

Change-Id: I5ad772a18cc4584585c5a7b6fb127547cece1998
2020-06-21 16:44:00 +08:00

60 lines
2.7 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import mock
from ironic_python_agent import agent
from ironic_python_agent import errors
from ironic_python_agent.extensions import poll
from ironic_python_agent import hardware
from ironic_python_agent.tests.unit import base
class TestPollExtension(base.IronicAgentTest):
def setUp(self):
super(TestPollExtension, self).setUp()
self.mock_agent = mock.Mock(spec=agent.IronicPythonAgent)
self.agent_extension = poll.PollExtension(agent=self.mock_agent)
self.fake_cpu = hardware.CPU(model_name='fuzzypickles',
frequency=1024,
count=1,
architecture='generic',
flags='')
@mock.patch.object(hardware, 'dispatch_to_managers',
autospec=True)
def test_get_hardware_info_success(self, mock_dispatch):
mock_dispatch.return_value = {'foo': 'bar'}
result = self.agent_extension.get_hardware_info()
mock_dispatch.assert_called_once_with('list_hardware_info')
self.assertEqual({'foo': 'bar'}, result.command_result)
self.assertEqual('SUCCEEDED', result.command_status)
def test_set_node_info_success(self):
self.mock_agent.standalone = True
node_info = {'node': {'uuid': 'fake-node', 'properties': {}},
'config': {'agent_token_required': True,
'agent_token': 'blah' * 8}}
result = self.agent_extension.set_node_info(node_info=node_info)
self.mock_agent.process_lookup_data.assert_called_once_with(node_info)
self.assertEqual('SUCCEEDED', result.command_status)
def test_set_node_info_not_standalone(self):
self.mock_agent.standalone = False
node_info = {'node': {'uuid': 'fake-node', 'properties': {}},
'config': {'agent_token_required': True,
'agent_token': 'blah' * 8}}
self.assertRaises(errors.InvalidCommandError,
self.agent_extension.set_node_info,
node_info=node_info)
self.assertFalse(self.mock_agent.process_lookup_data.called)